diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 184fbd1c82b..e96db063b08 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -847,6 +847,14 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, if (focusController) { + // Make sure the focus controller is up-to-date, since restoring + // focus memory may have caused focus to go elsewhere. + + if (gLastFocusedDocument && gLastFocusedDocument == mDocument) { + nsCOMPtr focusElement = do_QueryInterface(mCurrentFocus); + focusController->SetFocusedElement(focusElement); + } + PRBool isSuppressed; focusController->GetSuppressFocus(&isSuppressed); while (isSuppressed) { @@ -857,14 +865,6 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, focusController->GetSuppressFocus(&isSuppressed); } focusController->SetSuppressFocusScroll(PR_FALSE); - - // Make sure the focus controller is up-to-date, since restoring - // focus memory may have caused focus to go elsewhere. - - if (gLastFocusedDocument && gLastFocusedDocument == mDocument) { - nsCOMPtr focusElement = do_QueryInterface(mCurrentFocus); - focusController->SetFocusedElement(focusElement); - } } } break; @@ -3892,20 +3892,6 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) // only raise window if the the focus controller is active SendFocusBlur(mPresContext, aContent, fcActive); -#ifdef DEBUG_aleventhal - nsCOMPtr currentWindow = - do_QueryInterface(GetDocumentOuterWindow(mDocument)); - if (currentWindow) { - nsIFocusController *fc = currentWindow->GetRootFocusController(); - if (fc) { - nsCOMPtr focusedElement; - fc->GetFocusedElement(getter_AddRefs(focusedElement)); - if (!SameCOMIdentity(mCurrentFocus, focusedElement)) { - printf("\n\nFocus out of whack!!!\n\n"); - } - } - } -#endif // If we now have focused content, ensure that the canvas focus ring // is removed. if (mDocument) { @@ -4113,6 +4099,23 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, EnsureDocument(presShell); + // Make sure we're not switching command dispatchers, if so, + // surpress the blurred one + if(gLastFocusedDocument && mDocument) { + nsIFocusController *newFocusController = nsnull; + nsIFocusController *oldFocusController = nsnull; + nsCOMPtr newWindow = + do_QueryInterface(GetDocumentOuterWindow(mDocument)); + nsCOMPtr oldWindow = + do_QueryInterface(GetDocumentOuterWindow(gLastFocusedDocument)); + if(newWindow) + newFocusController = newWindow->GetRootFocusController(); + if(oldWindow) + oldFocusController = oldWindow->GetRootFocusController(); + if(oldFocusController && oldFocusController != newFocusController) + oldFocusController->SetSuppressFocus(PR_TRUE, "SendFocusBlur Window Switch"); + } + nsCOMPtr esm; esm = oldPresContext->EventStateManager(); esm->SetFocusedContent(gLastFocusedContent); @@ -4136,7 +4139,6 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, if (previousFocus && previousFocus != focusAfterBlur) { // The content node's blur handler focused something else. // In this case, abort firing any more blur or focus events. - EnsureFocusSynchronization(); return NS_OK; } } @@ -4153,6 +4155,23 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, nsEventStatus status = nsEventStatus_eIgnore; nsEvent event(PR_TRUE, NS_BLUR_CONTENT); + // Make sure we're not switching command dispatchers, if so, + // surpress the blurred one + if (mDocument) { + nsIFocusController *newFocusController = nsnull; + nsIFocusController *oldFocusController = nsnull; + nsCOMPtr newWindow = + do_QueryInterface(GetDocumentOuterWindow(mDocument)); + nsCOMPtr oldWindow = + do_QueryInterface(GetDocumentOuterWindow(gLastFocusedDocument)); + + if (newWindow) + newFocusController = newWindow->GetRootFocusController(); + oldFocusController = oldWindow->GetRootFocusController(); + if (oldFocusController && oldFocusController != newFocusController) + oldFocusController->SetSuppressFocus(PR_TRUE, "SendFocusBlur Window Switch #2"); + } + gLastFocusedPresContext->EventStateManager()->SetFocusedContent(nsnull); nsCOMPtr temp = gLastFocusedDocument; NS_RELEASE(gLastFocusedDocument); @@ -4164,10 +4183,7 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, if (previousFocus && mCurrentFocus != previousFocus) { // The document's blur handler focused something else. - // Abort firing any additional blur or focus events, and make sure - // nsFocusController:mFocusedElement is not nulled out, but agrees - // with our current concept of focus. - EnsureFocusSynchronization(); + // Abort firing any additional blur or focus events. return NS_OK; } @@ -4177,7 +4193,6 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, if (previousFocus && mCurrentFocus != previousFocus) { // The window's blur handler focused something else. // Abort firing any additional blur or focus events. - EnsureFocusSynchronization(); return NS_OK; } } @@ -4268,27 +4283,6 @@ nsEventStateManager::GetFocusedContent(nsIContent** aContent) return NS_OK; } -void nsEventStateManager::EnsureFocusSynchronization() -{ - // Sometimes the focus can get out of whack due to a blur handler - // resetting focus. In addition, we fire onchange from the blur handler - // for some controls, which is another place where focus can be changed. - // XXX Ideally we will eventually store focus in one place instead of - // the focus controller, esm, tabbrowser and some frames, so that it - // cannot get out of sync. - // See Bug 304751, calling FireOnChange() inside - // nsComboboxControlFrame::SetFocus() is bad - nsCOMPtr currentWindow = - do_QueryInterface(GetDocumentOuterWindow(mDocument)); - if (currentWindow) { - nsIFocusController *fc = currentWindow->GetRootFocusController(); - if (fc) { - nsCOMPtr focusedElement = do_QueryInterface(mCurrentFocus); - fc->SetFocusedElement(focusedElement); - } - } -} - NS_IMETHODIMP nsEventStateManager::SetFocusedContent(nsIContent* aContent) { diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 800d91bd379..6b96022242a 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -162,14 +162,6 @@ public: } protected: - /** - * In certain situations the focus controller's concept of focus gets out of - * whack with mCurrentFocus. This is used in known cases to reset the focus - * controller's focus. At some point we should probably move to a single - * focus storage mechanism because tracking it in several places is error-prone. - */ - void EnsureFocusSynchronization(); - void UpdateCursor(nsPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus); /** * Turn a GUI mouse event into a mouse event targeted at the specified diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index b1c3fcec308..175b85b2f37 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -483,15 +483,11 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) // on eventWindow. -bryner nsCOMPtr kungFuDeathGrip(eventWindow); + focusController->SetSuppressFocus(PR_TRUE, "Activation Suppression"); + nsCOMPtr domWindow = do_QueryInterface(piWin); - if (domWindow == focusedWindow) { - break; // Already focused - } - - focusController->SetSuppressFocus(PR_TRUE, "Activation Suppression"); - NS_ASSERTION(domWindow, "windows must support nsIDOMWindowInternal");