Relanding pavlov's changes for bug 129953, in pieces.

git-svn-id: svn://10.0.0.236/trunk@118949 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbaron%fas.harvard.edu
2002-04-14 03:37:42 +00:00
parent 0c211fb13a
commit 8fa769bf01
2 changed files with 45 additions and 10 deletions

View File

@@ -89,12 +89,21 @@ NS_METHOD nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)
//
//-------------------------------------------------------------------------
#include "nsITimerManager.h"
NS_METHOD nsAppShell::Run(void)
{
NS_ADDREF_THIS();
MSG msg;
int keepGoing = 1;
nsresult rv;
nsCOMPtr<nsITimerManager> timerManager(do_GetService("@mozilla.org/timer/manager;1", &rv));
if (NS_FAILED(rv)) return rv;
timerManager->SetUseIdleTimers(PR_TRUE);
gKeepGoing = 1;
// Process messages
do {
@@ -116,15 +125,26 @@ NS_METHOD nsAppShell::Run(void)
mDispatchListener->AfterDispatch();
}
} else {
if (!gKeepGoing) {
// In this situation, PostQuitMessage() was called, but the WM_QUIT
// message was removed from the event queue by someone else -
// (see bug #54725). So, just exit the loop as if WM_QUIT had been
// reeceived...
keepGoing = 0;
PRBool hasTimers;
timerManager->HasIdleTimers(&hasTimers);
if (hasTimers) {
do {
timerManager->FireNextIdleTimer();
timerManager->HasIdleTimers(&hasTimers);
} while (hasTimers && !::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE));
} else {
// Block and wait for any posted application message
::WaitMessage();
if (!gKeepGoing) {
// In this situation, PostQuitMessage() was called, but the WM_QUIT
// message was removed from the event queue by someone else -
// (see bug #54725). So, just exit the loop as if WM_QUIT had been
// reeceived...
keepGoing = 0;
} else {
// Block and wait for any posted application message
::WaitMessage();
}
}
}
@@ -149,6 +169,10 @@ nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent)
BOOL gotMessage = false;
nsresult rv;
nsCOMPtr<nsITimerManager> timerManager(do_GetService("@mozilla.org/timer/manager;1", &rv));
if (NS_FAILED(rv)) return rv;
do {
// Give priority to system messages (in particular keyboard, mouse,
// timer, and paint messages).
@@ -158,8 +182,17 @@ nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent)
gotMessage = true;
} else {
// Block and wait for any posted application message
::WaitMessage();
PRBool hasTimers;
timerManager->HasIdleTimers(&hasTimers);
if (hasTimers) {
do {
timerManager->FireNextIdleTimer();
timerManager->HasIdleTimers(&hasTimers);
} while (hasTimers && !::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE));
} else {
// Block and wait for any posted application message
::WaitMessage();
}
}
} while (!gotMessage);