Bug 1793629 - Implement attention indicator for the unified extensions button, r...
[gecko.git] / widget / nsBaseAppShell.h
blob6f7bd1893ac5c8524cbd237e244708aa955987df
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 int32_t mFavorPerf;
101 mozilla::Atomic<bool> mNativeEventPending;
102 PRIntervalTime mStarvationDelay;
103 PRIntervalTime mSwitchTime;
104 PRIntervalTime mLastNativeEventTime;
105 enum EventloopNestingState {
106 eEventloopNone, // top level thread execution
107 eEventloopXPCOM, // innermost native event loop is ProcessNextNativeEvent
108 eEventloopOther // innermost native event loop is a native library/plugin
109 // etc
111 EventloopNestingState mEventloopNestingState;
112 bool mRunning;
113 bool mExiting;
115 * mBlockNativeEvent blocks the appshell from processing native events.
116 * It is set to true while a nested native event loop (eEventloopOther)
117 * is processing gecko events in NativeEventCallback(), thus queuing up
118 * native events until we return to that loop (bug 420148).
119 * We force mBlockNativeEvent to false in case handling one of the gecko
120 * events spins up a nested XPCOM event loop (eg. modal window) which would
121 * otherwise lead to a "deadlock" where native events aren't processed at all.
123 bool mBlockNativeEvent;
125 * Tracks whether we have processed any gecko events in NativeEventCallback so
126 * that we can avoid erroneously entering a blocking loop waiting for gecko
127 * events to show up during OnProcessNextEvent. This is required because on
128 * OS X ProcessGeckoEvents may be invoked inside the context of
129 * ProcessNextNativeEvent and may result in NativeEventCallback being invoked
130 * and in turn invoking NS_ProcessPendingEvents. Because
131 * ProcessNextNativeEvent may be invoked prior to the NS_HasPendingEvents
132 * waiting loop, this is the only way to make the loop aware that events may
133 * have been processed.
135 * This variable is set to false in OnProcessNextEvent prior to the first
136 * call to DoProcessNextNativeEvent. It is set to true by
137 * NativeEventCallback after calling NS_ProcessPendingEvents.
139 bool mProcessedGeckoEvents;
142 #endif // nsBaseAppShell_h__