Bug 593372 - Part 3: Always process mouse and keyboard events in the right order. r=:jimm
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 08 Feb 2011 18:06:49 -0500
changeset 62185 0da0c99b690d1f222e5676d04706f8eeab93a332
parent 62184 c0ee311faca1713c4e30d1dd1bb9916210e6c41e
child 62186 d2db6c6be747f9228e66b8d2b66d23c88dff2732
push id18633
push usereakhgari@mozilla.com
push dateTue, 08 Feb 2011 23:07:49 +0000
treeherdermozilla-central@d2db6c6be747 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs593372
milestone2.0b12pre
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 593372 - Part 3: Always process mouse and keyboard events in the right order. r=:jimm
widget/src/windows/nsAppShell.cpp
--- a/widget/src/windows/nsAppShell.cpp
+++ b/widget/src/windows/nsAppShell.cpp
@@ -84,39 +84,45 @@ namespace crashreporter {
 void LSPAnnotate();
 } // namespace crashreporter
 } // namespace mozilla
 
 using mozilla::crashreporter::LSPAnnotate;
 
 //-------------------------------------------------------------------------
 
-static BOOL PeekKeyAndIMEMessage(LPMSG msg, HWND hwnd)
+static PRBool PeekUIMessage(MSG* aMsg)
 {
-  MSG msg1, msg2, *lpMsg;
-  BOOL b1, b2;
-  b1 = ::PeekMessageW(&msg1, NULL, WM_KEYFIRST, WM_IME_KEYLAST, PM_NOREMOVE);
-  b2 = ::PeekMessageW(&msg2, NULL, NS_WM_IMEFIRST, NS_WM_IMELAST, PM_NOREMOVE);
-  if (b1 || b2) {
-    if (b1 && b2) {
-      if (msg1.time < msg2.time)
-        lpMsg = &msg1;
-      else
-        lpMsg = &msg2;
-    } else if (b1)
-      lpMsg = &msg1;
-    else
-      lpMsg = &msg2;
-    if (!nsIMM32Handler::CanOptimizeKeyAndIMEMessages(lpMsg)) {
-      return false;
-    }
-    return ::PeekMessageW(msg, hwnd, lpMsg->message, lpMsg->message, PM_REMOVE);
+  MSG keyMsg, imeMsg, mouseMsg, *pMsg = 0;
+  PRBool haveKeyMsg, haveIMEMsg, haveMouseMsg;
+
+  haveKeyMsg = ::PeekMessageW(&keyMsg, NULL, WM_KEYFIRST, WM_IME_KEYLAST, PM_NOREMOVE);
+  haveIMEMsg = ::PeekMessageW(&imeMsg, NULL, NS_WM_IMEFIRST, NS_WM_IMELAST, PM_NOREMOVE);
+  haveMouseMsg = ::PeekMessageW(&mouseMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE);
+
+  if (haveKeyMsg) {
+    pMsg = &keyMsg;
+  }
+  if (haveIMEMsg && (!pMsg || imeMsg.time < pMsg->time)) {
+    pMsg = &imeMsg;
   }
 
-  return false;
+  if (pMsg && !nsIMM32Handler::CanOptimizeKeyAndIMEMessages(pMsg)) {
+    return PR_FALSE;
+  }
+
+  if (haveMouseMsg && (!pMsg || mouseMsg.time < pMsg->time)) {
+    pMsg = &mouseMsg;
+  }
+
+  if (!pMsg) {
+    return PR_FALSE;
+  }
+
+  return ::PeekMessageW(aMsg, NULL, pMsg->message, pMsg->message, PM_REMOVE);
 }
 
 /*static*/ LRESULT CALLBACK
 nsAppShell::EventWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
   if (uMsg == sMsgId) {
     nsAppShell *as = reinterpret_cast<nsAppShell *>(lParam);
     as->NativeEventCallback();
@@ -316,20 +322,18 @@ nsAppShell::ProcessNextNativeEvent(PRBoo
     CollectNewLoadedModules();
   }
 #endif
 
   PRBool gotMessage = PR_FALSE;
 
   do {
     MSG msg;
-    // Give priority to system messages (in particular keyboard, mouse, timer,
-    // and paint messages).
-    if (PeekKeyAndIMEMessage(&msg, NULL) ||
-        ::PeekMessageW(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) || 
+    // Give priority to keyboard and mouse messages.
+    if (PeekUIMessage(&msg) ||
         ::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
       gotMessage = PR_TRUE;
       if (msg.message == WM_QUIT) {
         ::PostQuitMessage(msg.wParam);
         Exit();
       } else {
         ::TranslateMessage(&msg);
         ::DispatchMessageW(&msg);