merge to backout bug 112294
authorTed Mielczarek <ted.mielczarek@gmail.com>
Wed, 23 Jul 2008 08:51:30 -0400
changeset 16135 2d5f6f032ae1e839f67a583879736208e7cbe828
parent 16133 e59d2885390684076df9c26d786a7de0cb15ea5e (current diff)
parent 16134 ed6642a02b2d4cdb2a8bd6a5f081c60d85c198ee (diff)
child 16137 c550da35f987212031e114247df3bf1742407791
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs112294
milestone1.9.1a1pre
merge to backout bug 112294
content/events/test/test_bug112294.html
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -688,17 +688,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mActiveContent);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHoverContent);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDragOverContent);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mURLTargetContent);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentFocus);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastFocus);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastContentFocus);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstBlurEvent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstDocumentBlurEvent);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstFocusEvent);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOverEventElement);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOutEventElement);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mAccessKeys);
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEventStateManager)
@@ -712,17 +711,16 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mActiveContent);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHoverContent);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDragOverContent);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mURLTargetContent);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentFocus);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastFocus);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastContentFocus);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstBlurEvent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstDocumentBlurEvent);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstFocusEvent);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOverEventElement);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOutEventElement);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument);
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mAccessKeys);
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 
@@ -1087,42 +1085,39 @@ nsEventStateManager::PreHandleEvent(nsPr
                 nsEventDispatcher::Dispatch(gLastFocusedContent, oldPresContext,
                                             &event, nsnull, &status);
                 esm->SetFocusedContent(nsnull);
                 NS_IF_RELEASE(gLastFocusedContent);
               }
             }
           }
 
-          // Clear our global variables before firing the event to prevent
-          // duplicate blur events (bug 112294).
-          nsCOMPtr<nsIDocument> lastFocusedDocument;
-          lastFocusedDocument.swap(gLastFocusedDocument);
-          nsCOMPtr<nsPresContext> lastFocusedPresContext;
-          lastFocusedPresContext.swap(gLastFocusedPresContext);
-          mCurrentTarget = nsnull;
-
           // fire blur on document and window
-          if (lastFocusedDocument) {
+          if (gLastFocusedDocument) {
             // get the window here, in case the event causes
             // gLastFocusedDocument to change.
 
-            nsCOMPtr<nsPIDOMWindow> window(lastFocusedDocument->GetWindow());
+            nsCOMPtr<nsPIDOMWindow> window(gLastFocusedDocument->GetWindow());
 
             event.target = nsnull;
-            nsEventDispatcher::Dispatch(lastFocusedDocument,
-                                        lastFocusedPresContext,
+            nsEventDispatcher::Dispatch(gLastFocusedDocument,
+                                        gLastFocusedPresContext,
                                         &event, nsnull, &status);
 
             if (window) {
               event.target = nsnull;
-              nsEventDispatcher::Dispatch(window, lastFocusedPresContext,
+              nsEventDispatcher::Dispatch(window, gLastFocusedPresContext,
                                           &event, nsnull, &status);
             }
           }
+
+          // Now clear our our global variables
+          mCurrentTarget = nsnull;
+          NS_IF_RELEASE(gLastFocusedDocument);
+          gLastFocusedPresContext = nsnull;
         }
       }
 #endif
     }
     break;
 
  case NS_ACTIVATE:
     {
@@ -1233,25 +1228,18 @@ nsEventStateManager::PreHandleEvent(nsPr
       nsCOMPtr<nsIFocusController> focusController =
         GetFocusControllerForDocument(mDocument);
 
       if (focusController)
         focusController->SetSuppressFocus(PR_TRUE, "Deactivate Suppression");
 
       // Now fire blurs.  Blur the content, then the document, then the window.
 
-      if (gLastFocusedDocument && gLastFocusedDocument == mDocument &&
-          gLastFocusedDocument != mFirstDocumentBlurEvent) {
-
-        PRBool clearFirstDocumentBlurEvent = PR_FALSE;
-        if (!mFirstDocumentBlurEvent) {
-          mFirstDocumentBlurEvent = gLastFocusedDocument;
-          clearFirstDocumentBlurEvent = PR_TRUE;
-        }
-          
+      if (gLastFocusedDocument && gLastFocusedDocument == mDocument) {
+
         nsEventStatus status = nsEventStatus_eIgnore;
         nsEvent event(PR_TRUE, NS_BLUR_CONTENT);
         event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
 
         if (gLastFocusedContent) {
           nsIPresShell *shell = gLastFocusedDocument->GetPrimaryShell();
           if (shell) {
             nsCOMPtr<nsPresContext> oldPresContext = shell->GetPresContext();
@@ -1271,35 +1259,31 @@ nsEventStateManager::PreHandleEvent(nsPr
                                           &event, nsnull, &status);
             }
 
             esm->SetFocusedContent(nsnull);
             NS_IF_RELEASE(gLastFocusedContent);
           }
         }
 
-        // Clear our global variables before firing the event to prevent
-        // duplicate blur events (bug 112294).
-        mCurrentTarget = nsnull;
-        NS_IF_RELEASE(gLastFocusedDocument);
-        gLastFocusedPresContext = nsnull;
-
         // fire blur on document and window
         event.target = nsnull;
         nsEventDispatcher::Dispatch(mDocument, aPresContext, &event, nsnull,
                                     &status);
 
         if (ourWindow) {
           event.target = nsnull;
           nsEventDispatcher::Dispatch(ourWindow, aPresContext, &event, nsnull,
                                       &status);
         }
-        if (clearFirstDocumentBlurEvent) {
-          mFirstDocumentBlurEvent = nsnull;
-        }
+
+        // Now clear our our global variables
+        mCurrentTarget = nsnull;
+        NS_IF_RELEASE(gLastFocusedDocument);
+        gLastFocusedPresContext = nsnull;
       }
 
       if (focusController) {
         focusController->SetActive(PR_FALSE);
         focusController->SetSuppressFocus(PR_FALSE, "Deactivate Suppression");
       }
     }
 
--- a/content/events/src/nsEventStateManager.h
+++ b/content/events/src/nsEventStateManager.h
@@ -374,17 +374,16 @@ protected:
   EFocusedWithType mLastFocusedWith;
 
   // DocShell Traversal Data Memebers
   nsCOMPtr<nsIContent> mLastContentFocus;
 
   //Anti-recursive stack controls
 
   nsCOMPtr<nsIContent> mFirstBlurEvent;
-  nsCOMPtr<nsIDocument> mFirstDocumentBlurEvent;
   nsCOMPtr<nsIContent> mFirstFocusEvent;
 
   // The last element on which we fired a mouseover event, or null if
   // the last mouseover event we fired has finished processing.
   nsCOMPtr<nsIContent> mFirstMouseOverEventElement;
 
   // The last element on which we fired a mouseout event, or null if
   // the last mouseout event we fired has finished processing.
--- a/content/events/test/Makefile.in
+++ b/content/events/test/Makefile.in
@@ -40,17 +40,16 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = content/events/test
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
-		test_bug112294.html \
 		test_bug238987.html \
 		test_bug288392.html \
 		test_bug328885.html \
 		test_bug336682_1.html \
 		test_bug336682_2.xul \
 		test_bug336682.js \
 		test_bug367781.html \
 		test_bug368835.html \
deleted file mode 100644
--- a/content/events/test/test_bug112294.html
+++ /dev/null
@@ -1,68 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=112294
--->
-<head>
-  <title>Test for Bug 112294</title>
-  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=112294">Mozilla Bug 112294</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-  
-</div>
-<pre id="test">
-<script class="testbody" type="text/javascript">
-
-/** Test for Bug 112294 **/
-
-var countFocus = 0;
-var countBlur = 0;
-
-function handleBlur()
-{
-  ++countBlur;
-  if (countBlur < 5)
-  {
-    // Try to simulate an alert
-	alert = window.open("about:blank", "Alert", "width=200,height=200");
-	alert.focus();
-	alert.close();
-  }    
-}
-
-function handleFocus()
-{
-  ++countFocus;
-}
-
-function doTest()
-{
-  window.focus();
-  window.onblur = handleBlur;
-  window.onfocus = handleFocus;
-  
-  var popup = window.open("about:blank", "Bug 112294", "width=10,height=10");
-  popup.focus();
-  popup.close();
-  setTimeout(finishTest, 0);
-}
-
-function finishTest()
-{
-  is(countFocus, 1, "onfocus count");
-  is(countBlur, 1, "onblur count");
-  SimpleTest.finish();
-}
-
-SimpleTest.waitForExplicitFinish();
-setTimeout(doTest, 0);
-
-</script>
-</pre>
-</body>
-</html>
--- a/dom/src/base/nsFocusController.cpp
+++ b/dom/src/base/nsFocusController.cpp
@@ -517,18 +517,17 @@ nsFocusController::SetSuppressFocus(PRBo
   }
   else if(mSuppressFocus > 0) {
     --mSuppressFocus;
     //#ifdef DEBUG_hyatt
     //printf("[%p] SuppressFocus decremented to %d. The reason is %s.\n", this, mSuppressFocus, aReason);
     //#endif
   }
   else 
-    // It's ok to unsuppress even if no suppression is active (bug 112294)
-    return NS_OK;
+    NS_ASSERTION(PR_FALSE, "Attempt to decrement focus controller's suppression when no suppression active!\n");
 
   // we are unsuppressing after activating, so update focus-related commands
   // we need this to update command, including the case where there is no element
   // because nsPresShell::UnsuppressPainting may have just now unsuppressed
   // focus on the currently focused window
   if (!mSuppressFocus) {
     // Always update commands if we have a current element
     // and mNeedUpdateCommands is true (checked in nsFC::UpdateCommands)
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -670,28 +670,18 @@ nsWindowWatcher::OpenWindowJSInternal(ns
         // chrome is always allowed, so clear the flag if the opener is chrome
         if (popupConditions) {
           popupConditions = !isCallerChrome;
         }
 
         if (popupConditions)
           contextFlags |= nsIWindowCreator2::PARENT_IS_LOADING_OR_RUNNING_TIMEOUT;
 
-        PRBool parentVisible = PR_TRUE;
-        if (parentChrome)
-        {
-          nsCOMPtr<nsIBaseWindow> parentWindow(do_GetInterface(parentTreeOwner));
-          nsCOMPtr<nsIWidget> parentWidget;
-          if (parentWindow)
-            parentWindow->GetMainWidget(getter_AddRefs(parentWidget));
-          if (parentWidget)
-            parentWidget->IsVisible(parentVisible);            
-        }
         PRBool cancel = PR_FALSE;
-        rv = windowCreator2->CreateChromeWindow2(parentVisible ? parentChrome : nsnull, chromeFlags,
+        rv = windowCreator2->CreateChromeWindow2(parentChrome, chromeFlags,
                                                  contextFlags, uriToLoad,
                                                  &cancel,
                                                  getter_AddRefs(newChrome));
         if (NS_SUCCEEDED(rv) && cancel) {
           newChrome = 0; // just in case
           rv = NS_ERROR_ABORT;
         }
       }
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -1603,18 +1603,16 @@ PRBool nsWindow::CanTakeFocus()
   return PR_FALSE;
 #else
   return PR_TRUE;
 #endif
 }
 
 NS_METHOD nsWindow::Show(PRBool bState)
 {
-  mIsVisible = bState;
-
   if (mWnd) {
     if (bState) {
       if (!mIsVisible && mWindowType == eWindowType_toplevel) {
         switch (mSizeMode) {
           case nsSizeMode_Maximized :
             ::ShowWindow(mWnd, SW_SHOWMAXIMIZED);
             break;
           case nsSizeMode_Minimized :
@@ -1669,16 +1667,18 @@ NS_METHOD nsWindow::Show(PRBool bState)
     }
   }
   
 #ifdef MOZ_XUL
   if (!mIsVisible && bState)
     Invalidate(PR_FALSE);
 #endif
 
+  mIsVisible = bState;
+
   return NS_OK;
 }
 
 //-------------------------------------------------------------------------
 //
 // Return PR_TRUE if the whether the component is visible, PR_FALSE otherwise
 //
 //-------------------------------------------------------------------------
--- a/xpfe/appshell/src/nsXULWindow.cpp
+++ b/xpfe/appshell/src/nsXULWindow.cpp
@@ -473,41 +473,33 @@ NS_IMETHODIMP nsXULWindow::Destroy()
   // a convenience, the hide prevents user interaction with the partially
   // destroyed window. This is especially necessary when the eldest window
   // in a stack of modal windows is destroyed first. It happens.
   ExitModalLoop(NS_OK);
   if (mWindow)
     mWindow->Show(PR_FALSE);
 
 #if defined(XP_WIN) || defined(XP_OS2)
-  // We need to explicitly set the focus on Windows, but 
-  // only if the parent is visible.
+  // We need to explicitly set the focus on Windows
   nsCOMPtr<nsIBaseWindow> parent(do_QueryReferent(mParentWindow));
   if (parent) {
-    PRBool parentVisible = PR_TRUE;
-    nsCOMPtr<nsIWidget> parentWidget;
-    parent->GetMainWidget(getter_AddRefs(parentWidget));
-    if (parentWidget)
-      parentWidget->IsVisible(parentVisible);
-    if (parentVisible) {
-      nsCOMPtr<nsIBaseWindow> baseHiddenWindow;
-      if (appShell) {
-        nsCOMPtr<nsIXULWindow> hiddenWindow;
-        appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
-        if (hiddenWindow)
-          baseHiddenWindow = do_GetInterface(hiddenWindow);
-      }
-      // somebody screwed up somewhere. hiddenwindow shouldn't be anybody's
-      // parent. still, when it happens, skip activating it.
-      if (baseHiddenWindow != parent) {
-        nsCOMPtr<nsIWidget> parentWidget;
-        parent->GetMainWidget(getter_AddRefs(parentWidget));
-        if (parentWidget)
-          parentWidget->PlaceBehind(eZPlacementTop, 0, PR_TRUE);
-      }
+    nsCOMPtr<nsIBaseWindow> baseHiddenWindow;
+    if (appShell) {
+      nsCOMPtr<nsIXULWindow> hiddenWindow;
+      appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
+      if (hiddenWindow)
+        baseHiddenWindow = do_GetInterface(hiddenWindow);
+    }
+    // somebody screwed up somewhere. hiddenwindow shouldn't be anybody's
+    // parent. still, when it happens, skip activating it.
+    if (baseHiddenWindow != parent) {
+      nsCOMPtr<nsIWidget> parentWidget;
+      parent->GetMainWidget(getter_AddRefs(parentWidget));
+      if (parentWidget)
+        parentWidget->PlaceBehind(eZPlacementTop, 0, PR_TRUE);
     }
   }
 #endif
    
   mDOMWindow = nsnull;
   if (mDocShell) {
     nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
     shellAsWin->Destroy();