From 8fa769bf013bdd9185aa46aab37f8afcd59aafbb Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Sun, 14 Apr 2002 03:37:42 +0000 Subject: [PATCH] Relanding pavlov's changes for bug 129953, in pieces. git-svn-id: svn://10.0.0.236/trunk@118949 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/windows/nsAppShell.cpp | 53 ++++++++++++++++++----- mozilla/xpcom/build/nsXPComInit.cpp | 2 + 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/mozilla/widget/src/windows/nsAppShell.cpp b/mozilla/widget/src/windows/nsAppShell.cpp index c585ee8ef0e..9c39929c09d 100644 --- a/mozilla/widget/src/windows/nsAppShell.cpp +++ b/mozilla/widget/src/windows/nsAppShell.cpp @@ -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 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 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); diff --git a/mozilla/xpcom/build/nsXPComInit.cpp b/mozilla/xpcom/build/nsXPComInit.cpp index f8a14143e80..c7cfc9c6f6b 100644 --- a/mozilla/xpcom/build/nsXPComInit.cpp +++ b/mozilla/xpcom/build/nsXPComInit.cpp @@ -131,6 +131,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsConsoleService); NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService); NS_GENERIC_FACTORY_CONSTRUCTOR(nsExceptionService); NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl); +NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerManager); NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariant); @@ -248,6 +249,7 @@ static const nsModuleComponentInfo components[] = { COMPONENT(XPCOMPROXY, nsProxyObjectManager::Create), COMPONENT(TIMER, nsTimerImplConstructor), + COMPONENT(TIMERMANAGER, nsTimerManagerConstructor), #define COMPONENT_SUPPORTS(TYPE, Type) \ COMPONENT(SUPPORTS_##TYPE, nsSupports##Type##ImplConstructor)