Bug 1889091 - Part 4: Remove extra stack pointer move. r=jandem
[gecko.git] / widget / nsBaseAppShell.h
blobfabc0e188afe43e99e1020e037468616ff29a0b7
1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsBaseAppShell_h__
7 #define nsBaseAppShell_h__
9 #include "mozilla/Atomics.h"
10 #include "nsIAppShell.h"
11 #include "nsIThreadInternal.h"
12 #include "nsIObserver.h"
13 #include "nsIRunnable.h"
14 #include "nsCOMPtr.h"
15 #include "nsTArray.h"
16 #include "prinrval.h"
18 /**
19 * A singleton that manages the UI thread's event queue. Subclass this class
20 * to enable platform-specific event queue support.
22 class nsBaseAppShell : public nsIAppShell,
23 public nsIThreadObserver,
24 public nsIObserver {
25 public:
26 NS_DECL_THREADSAFE_ISUPPORTS
27 NS_DECL_NSIAPPSHELL
29 NS_DECL_NSITHREADOBSERVER
30 NS_DECL_NSIOBSERVER
32 nsBaseAppShell();
34 /**
35 * Called by subclasses. Reset the internal timezone when the user's system
36 * timezone changes.
38 static void OnSystemTimezoneChange();
40 protected:
41 virtual ~nsBaseAppShell();
43 /**
44 * This method is called by subclasses when the app shell singleton is
45 * instantiated.
47 nsresult Init();
49 /**
50 * Called by subclasses from a native event. See ScheduleNativeEventCallback.
52 void NativeEventCallback();
54 /**
55 * Make a decision as to whether or not NativeEventCallback will
56 * trigger gecko event processing when there are pending gecko
57 * events.
59 virtual void DoProcessMoreGeckoEvents();
61 /**
62 * Implemented by subclasses. Invoke NativeEventCallback from a native
63 * event. This method may be called on any thread.
65 virtual void ScheduleNativeEventCallback() = 0;
67 /**
68 * Implemented by subclasses. Process the next native event. Only wait for
69 * the next native event if mayWait is true. This method is only called on
70 * the main application thread.
72 * @param mayWait
73 * If "true", then this method may wait if necessary for the next available
74 * native event. DispatchNativeEvent may be called to unblock a call to
75 * ProcessNextNativeEvent that is waiting.
76 * @return
77 * This method returns "true" if a native event was processed.
79 virtual bool ProcessNextNativeEvent(bool mayWait) = 0;
81 int32_t mSuspendNativeCount;
82 uint32_t mEventloopNestingLevel;
84 private:
85 bool DoProcessNextNativeEvent(bool mayWait);
87 bool DispatchDummyEvent(nsIThread* target);
89 void IncrementEventloopNestingLevel();
90 void DecrementEventloopNestingLevel();
92 nsCOMPtr<nsIRunnable> mDummyEvent;
93 /**
94 * mBlockedWait points back to a slot that controls the wait loop in
95 * an outer OnProcessNextEvent invocation. Nested calls always set
96 * it to false to unblock an outer loop, since all events may
97 * have been consumed by the inner event loop(s).
99 bool* mBlockedWait;
100 mozilla::Atomic<bool> mNativeEventPending;
101 PRIntervalTime mGeckoTaskBurstStartTime;
102 PRIntervalTime mLastNativeEventTime;
103 enum EventloopNestingState {
104 eEventloopNone, // top level thread execution
105 eEventloopXPCOM, // innermost native event loop is ProcessNextNativeEvent
106 eEventloopOther // innermost native event loop is a native library/plugin
107 // etc
109 EventloopNestingState mEventloopNestingState;
110 bool mRunning;
111 bool mExiting;
113 * mBlockNativeEvent blocks the appshell from processing native events.
114 * It is set to true while a nested native event loop (eEventloopOther)
115 * is processing gecko events in NativeEventCallback(), thus queuing up
116 * native events until we return to that loop (bug 420148).
117 * We force mBlockNativeEvent to false in case handling one of the gecko
118 * events spins up a nested XPCOM event loop (eg. modal window) which would
119 * otherwise lead to a "deadlock" where native events aren't processed at all.
121 bool mBlockNativeEvent;
123 * Tracks whether we have processed any gecko events in NativeEventCallback so
124 * that we can avoid erroneously entering a blocking loop waiting for gecko
125 * events to show up during OnProcessNextEvent. This is required because on
126 * OS X ProcessGeckoEvents may be invoked inside the context of
127 * ProcessNextNativeEvent and may result in NativeEventCallback being invoked
128 * and in turn invoking NS_ProcessPendingEvents. Because
129 * ProcessNextNativeEvent may be invoked prior to the NS_HasPendingEvents
130 * waiting loop, this is the only way to make the loop aware that events may
131 * have been processed.
133 * This variable is set to false in OnProcessNextEvent prior to the first
134 * call to DoProcessNextNativeEvent. It is set to true by
135 * NativeEventCallback after calling NS_ProcessPendingEvents.
137 bool mProcessedGeckoEvents;
140 #endif // nsBaseAppShell_h__