diff --git a/widget/src/windows/nsAppShell.cpp b/widget/src/windows/nsAppShell.cpp index ba6b7d479a81..a5e874111b2e 100644 --- a/widget/src/windows/nsAppShell.cpp +++ b/widget/src/windows/nsAppShell.cpp @@ -54,6 +54,9 @@ const PRUnichar* kAppShellEventId = L"nsAppShell:EventID"; const PRUnichar* kTaskbarButtonEventId = L"TaskbarButtonCreated"; +// The maximum time we allow before forcing a native event callback +#define NATIVE_EVENT_STARVATION_LIMIT mozilla::TimeDuration::FromSeconds(1) + static UINT sMsgId; #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7 @@ -135,6 +138,8 @@ nsAppShell::Init() LSPAnnotate(); #endif + mLastNativeEventScheduled = TimeStamp::Now(); + if (!sMsgId) sMsgId = RegisterWindowMessageW(kAppShellEventId); @@ -306,6 +311,9 @@ nsAppShell::ScheduleNativeEventCallback() { // Post a message to the hidden message window NS_ADDREF_THIS(); // will be released when the event is processed + // Time stamp this event so we can detect cases where the event gets + // dropping in sub classes / modal loops we do not control. + mLastNativeEventScheduled = TimeStamp::Now(); ::PostMessage(mEventWnd, sMsgId, 0, reinterpret_cast(this)); } @@ -348,5 +356,12 @@ nsAppShell::ProcessNextNativeEvent(PRBool mayWait) if (mNativeCallbackPending && mEventloopNestingLevel == 1) DoProcessMoreGeckoEvents(); + // Check for starved native callbacks. If we haven't processed one + // of these events in NATIVE_EVENT_STARVATION_LIMIT, fire one off. + if ((TimeStamp::Now() - mLastNativeEventScheduled) > + NATIVE_EVENT_STARVATION_LIMIT) { + ScheduleNativeEventCallback(); + } + return gotMessage; } diff --git a/widget/src/windows/nsAppShell.h b/widget/src/windows/nsAppShell.h index 0352495d4bb9..fc43018eaee3 100644 --- a/widget/src/windows/nsAppShell.h +++ b/widget/src/windows/nsAppShell.h @@ -40,6 +40,7 @@ #include "nsBaseAppShell.h" #include +#include "mozilla/TimeStamp.h" /** * Native Win32 Application shell wrapper @@ -51,6 +52,7 @@ public: mEventWnd(NULL), mNativeCallbackPending(PR_FALSE) {} + typedef mozilla::TimeStamp TimeStamp; nsresult Init(); void DoProcessMoreGeckoEvents(); @@ -72,6 +74,7 @@ protected: protected: HWND mEventWnd; PRBool mNativeCallbackPending; + TimeStamp mLastNativeEventScheduled; }; #endif // nsAppShell_h__