Bug 957019 Don't check mouse cursor position at handling non-mouse message in nsWindow::DealWithPopups() r=jimm+enndeakin
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 14 Jan 2014 09:13:25 +0900
changeset 163231 79595e16949f7a7e3d6aeb1e2ac409f0be4fee5b
parent 163230 10d56cf4ca6d590dc43e1b9d0c323805ae7c78d8
child 163232 5475b2719136aa2d4d319a20d63fcd03983b19bf
push id25986
push userkwierso@gmail.com
push dateTue, 14 Jan 2014 04:44:33 +0000
treeherdermozilla-central@b114534a9386 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs957019
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 957019 Don't check mouse cursor position at handling non-mouse message in nsWindow::DealWithPopups() r=jimm+enndeakin
widget/windows/nsWindow.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -7385,35 +7385,49 @@ nsWindow::DealWithPopups(HWND aWnd, UINT
         if (window && window->IsPopup()) {
           // Cancel notifying widget listeners of deactivating the previous
           // active window (see WM_KILLFOCUS case in ProcessMessage()).
           sJustGotDeactivate = false;
           // Reactivate the window later.
           ::PostMessageW(aWnd, MOZ_WM_REACTIVATE, aWParam, aLParam);
           return true;
         }
-      } else if (sPendingNCACTIVATE && LOWORD(aWParam) == WA_INACTIVE &&
-                 NeedsToHandleNCActivateDelayed(aWnd)) {
-        // If focus moves to non-popup widget or focusable popup, the window
-        // needs to update its nonclient area.
+        // Don't rollup the popup when focus moves back to the parent window
+        // from a popup because such case is caused by strange mouse drivers.
+        nsWindow* prevWindow =
+          WinUtils::GetNSWindowPtr(reinterpret_cast<HWND>(aLParam));
+        if (prevWindow && prevWindow->IsPopup()) {
+          return false;
+        }
+      } else if (LOWORD(aWParam) == WA_INACTIVE) {
         nsWindow* activeWindow =
           WinUtils::GetNSWindowPtr(reinterpret_cast<HWND>(aLParam));
-        if (!activeWindow || !activeWindow->IsPopup()) {
-          sSendingNCACTIVATE = true;
-          ::SendMessageW(aWnd, WM_NCACTIVATE, false, 0);
-          sSendingNCACTIVATE = false;
+        if (sPendingNCACTIVATE && NeedsToHandleNCActivateDelayed(aWnd)) {
+          // If focus moves to non-popup widget or focusable popup, the window
+          // needs to update its nonclient area.
+          if (!activeWindow || !activeWindow->IsPopup()) {
+            sSendingNCACTIVATE = true;
+            ::SendMessageW(aWnd, WM_NCACTIVATE, false, 0);
+            sSendingNCACTIVATE = false;
+          }
+          sPendingNCACTIVATE = false;
         }
-        sPendingNCACTIVATE = false;
+        // If focus moves from/to popup, we don't need to rollup the popup
+        // because such case is caused by strange mouse drivers.
+        if (activeWindow) {
+          if (activeWindow->IsPopup()) {
+            return false;
+          }
+          nsWindow* deactiveWindow = WinUtils::GetNSWindowPtr(aWnd);
+          if (deactiveWindow && deactiveWindow->IsPopup()) {
+            return false;
+          }
+        }
       }
-      // XXX Why do we need to check the message pos?
-      if (!EventIsInsideWindow(popupWindow) &&
-          GetPopupsToRollup(rollupListener, &popupsToRollup)) {
-        break;
-      }
-      return false;
+      break;
 
     case MOZ_WM_REACTIVATE:
       // The previous active window should take back focus.
       if (::IsWindow(reinterpret_cast<HWND>(aLParam))) {
         ::SetForegroundWindow(reinterpret_cast<HWND>(aLParam));
       }
       return true;
 
@@ -7427,17 +7441,16 @@ nsWindow::DealWithPopups(HWND aWnd, UINT
         // WM_ACTIVATE.
         *aResult = TRUE;
         sPendingNCACTIVATE = true;
         return true;
       }
       return false;
 
     case WM_MOUSEACTIVATE:
-      // XXX Why do we need to check the message pos?
       if (!EventIsInsideWindow(popupWindow) &&
           GetPopupsToRollup(rollupListener, &popupsToRollup)) {
         // WM_MOUSEACTIVATE may be caused by moving the mouse (e.g., X-mouse
         // of TweakUI is enabled. Then, check if the popup should be rolled up
         // with rollup listener. If not, just consume the message.
         if (HIWORD(aLParam) == WM_MOUSEMOVE &&
             !rollupListener->ShouldRollupOnMouseActivate()) {
           return true;
@@ -7451,33 +7464,24 @@ nsWindow::DealWithPopups(HWND aWnd, UINT
       // requests to activate the window while it is displayed. Windows will
       // automatically activate the popup on the mousedown otherwise.
       return true;
 
     case WM_KILLFOCUS:
       // If focus moves to other window created in different process/thread,
       // e.g., a plugin window, popups should be rolled up.
       if (IsDifferentThreadWindow(reinterpret_cast<HWND>(aWParam))) {
-        // XXX Why do we need to check the message pos?
-        if (!EventIsInsideWindow(popupWindow) &&
-            GetPopupsToRollup(rollupListener, &popupsToRollup)) {
-          break;
-        }
+        break;
       }
       return false;
 
     case WM_MOVING:
     case WM_SIZING:
     case WM_MENUSELECT:
-      // XXX Why do we need to check the message pos?
-      if (!EventIsInsideWindow(popupWindow) &&
-          GetPopupsToRollup(rollupListener, &popupsToRollup)) {
-        break;
-      }
-      return false;
+      break;
 
     default:
       return false;
   }
 
   // Only need to deal with the last rollup for left mouse down events.
   NS_ASSERTION(!mLastRollup, "mLastRollup is null");