diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 4f49eda50795..adcd9902ec69 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -995,40 +995,41 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, gLastFocusedPresContextWeak, &blurevent, nsnull, &blurstatus); + nsCOMPtr esm; if (!mCurrentFocus && gLastFocusedContent) { // We also need to blur the previously focused content node here, // if we don't have a focused content node in this document. // (SendFocusBlur isn't called in this case). - + if (gLastFocusedContent) { + nsCOMPtr doc = gLastFocusedContent->GetCurrentDoc(); + if (doc) { + nsIPresShell *shell = doc->GetPrimaryShell(); + if (shell) { + nsCOMPtr oldPresContext = shell->GetPresContext(); + esm = oldPresContext->EventStateManager(); + if (esm) { + esm->SetFocusedContent(gLastFocusedContent); + } + } + } + } nsCOMPtr blurContent = gLastFocusedContent; blurevent.target = nsnull; nsEventDispatcher::Dispatch(gLastFocusedContent, gLastFocusedPresContextWeak, &blurevent, nsnull, &blurstatus); - - // XXX bryner this isn't quite right -- it can result in - // firing two blur events on the content. - - nsCOMPtr doc; - if (gLastFocusedContent) // could have changed in Dispatch - doc = gLastFocusedContent->GetDocument(); - if (doc) { - nsIPresShell *shell = doc->GetPrimaryShell(); - if (shell) { - nsCOMPtr oldPresContext = - shell->GetPresContext(); - - nsCOMPtr esm; - esm = oldPresContext->EventStateManager(); - esm->SetFocusedContent(gLastFocusedContent); - nsEventDispatcher::Dispatch(gLastFocusedContent, - oldPresContext, - &blurevent, nsnull, &blurstatus); - esm->SetFocusedContent(nsnull); - NS_IF_RELEASE(gLastFocusedContent); - } - } } + if (ourWindow) { + // Clear the target so that Dispatch can set it back correctly. + blurevent.target = nsnull; + nsEventDispatcher::Dispatch(ourWindow, gLastFocusedPresContextWeak, + &blurevent, nsnull, &blurstatus); + } + + if (esm) { + esm->SetFocusedContent(nsnull); + } + NS_IF_RELEASE(gLastFocusedContent); } if (focusController) diff --git a/content/events/test/Makefile.in b/content/events/test/Makefile.in index c159ab6d6e73..d9b8928ffcdf 100644 --- a/content/events/test/Makefile.in +++ b/content/events/test/Makefile.in @@ -63,6 +63,8 @@ _TEST_FILES = \ test_bug443985.html \ test_bug447736.html \ test_bug456273.html \ + test_bug457672.html \ + bug457672.html \ test_draggableprop.html \ test_dragstart.html \ $(NULL) diff --git a/content/events/test/bug457672.html b/content/events/test/bug457672.html new file mode 100644 index 000000000000..9d290c3f65b7 --- /dev/null +++ b/content/events/test/bug457672.html @@ -0,0 +1,12 @@ + + + + + + + diff --git a/content/events/test/test_bug457672.html b/content/events/test/test_bug457672.html new file mode 100644 index 000000000000..cf31cb3f8a5b --- /dev/null +++ b/content/events/test/test_bug457672.html @@ -0,0 +1,52 @@ + + + + + Test for Bug 457672 + + + + + +Mozilla Bug 457672 +

+ +
+
+
+
+
+ +