Bug 593372 - Part 3: Always process mouse and keyboard events in the right order. r=jmathies a=blocking-betaN

This commit is contained in:
Cameron McCormack 2011-02-11 20:56:12 -05:00
Родитель c64d86a8b5
Коммит 3b1306e5aa
1 изменённых файлов: 28 добавлений и 24 удалений

Просмотреть файл

@ -89,29 +89,35 @@ using mozilla::crashreporter::LSPAnnotate;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
static BOOL PeekKeyAndIMEMessage(LPMSG msg, HWND hwnd) static PRBool PeekUIMessage(MSG* aMsg)
{ {
MSG msg1, msg2, *lpMsg; MSG keyMsg, imeMsg, mouseMsg, *pMsg = 0;
BOOL b1, b2; PRBool haveKeyMsg, haveIMEMsg, haveMouseMsg;
b1 = ::PeekMessageW(&msg1, NULL, WM_KEYFIRST, WM_IME_KEYLAST, PM_NOREMOVE);
b2 = ::PeekMessageW(&msg2, NULL, NS_WM_IMEFIRST, NS_WM_IMELAST, PM_NOREMOVE); haveKeyMsg = ::PeekMessageW(&keyMsg, NULL, WM_KEYFIRST, WM_IME_KEYLAST, PM_NOREMOVE);
if (b1 || b2) { haveIMEMsg = ::PeekMessageW(&imeMsg, NULL, NS_WM_IMEFIRST, NS_WM_IMELAST, PM_NOREMOVE);
if (b1 && b2) { haveMouseMsg = ::PeekMessageW(&mouseMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE);
if (msg1.time < msg2.time)
lpMsg = &msg1; if (haveKeyMsg) {
else pMsg = &keyMsg;
lpMsg = &msg2; }
} else if (b1) if (haveIMEMsg && (!pMsg || imeMsg.time < pMsg->time)) {
lpMsg = &msg1; pMsg = &imeMsg;
else
lpMsg = &msg2;
if (!nsIMM32Handler::CanOptimizeKeyAndIMEMessages(lpMsg)) {
return false;
}
return ::PeekMessageW(msg, hwnd, lpMsg->message, lpMsg->message, PM_REMOVE);
} }
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 /*static*/ LRESULT CALLBACK
@ -321,10 +327,8 @@ nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
do { do {
MSG msg; MSG msg;
// Give priority to system messages (in particular keyboard, mouse, timer, // Give priority to keyboard and mouse messages.
// and paint messages). if (PeekUIMessage(&msg) ||
if (PeekKeyAndIMEMessage(&msg, NULL) ||
::PeekMessageW(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) ||
::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { ::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
gotMessage = PR_TRUE; gotMessage = PR_TRUE;
if (msg.message == WM_QUIT) { if (msg.message == WM_QUIT) {