Bug 456439 - add about:rights and a "Know Your Rights" infobar to Firefox. r=gavin...
[wine-gecko.git] / widget / src / xpwidgets / nsBaseAppShell.h
blobb6d76b6fee97821c5503381abbade75ffe9b3b61
1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Widget code.
17 * The Initial Developer of the Original Code is Google Inc.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Darin Fisher <darin@meer.net> (original author)
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsBaseAppShell_h__
39 #define nsBaseAppShell_h__
41 #include "nsIAppShell.h"
42 #include "nsIThreadInternal.h"
43 #include "nsIObserver.h"
44 #include "nsIRunnable.h"
45 #include "nsCOMPtr.h"
46 #include "prinrval.h"
48 /**
49 * A singleton that manages the UI thread's event queue. Subclass this class
50 * to enable platform-specific event queue support.
52 class nsBaseAppShell : public nsIAppShell, public nsIThreadObserver,
53 public nsIObserver
55 public:
56 NS_DECL_ISUPPORTS
57 NS_DECL_NSIAPPSHELL
58 NS_DECL_NSITHREADOBSERVER
59 NS_DECL_NSIOBSERVER
61 nsBaseAppShell();
63 protected:
64 virtual ~nsBaseAppShell() {}
66 /**
67 * This method is called by subclasses when the app shell singleton is
68 * instantiated.
70 nsresult Init();
72 /**
73 * Called by subclasses from a native event. See ScheduleNativeEventCallback.
75 void NativeEventCallback();
77 /**
78 * Implemented by subclasses. Invoke NativeEventCallback from a native
79 * event. This method may be called on any thread.
81 virtual void ScheduleNativeEventCallback() = 0;
83 /**
84 * Implemented by subclasses. Process the next native event. Only wait for
85 * the next native event if mayWait is true. This method is only called on
86 * the main application thread.
88 * @param mayWait
89 * If "true", then this method may wait if necessary for the next available
90 * native event. DispatchNativeEvent may be called to unblock a call to
91 * ProcessNextNativeEvent that is waiting.
92 * @return
93 * This method returns "true" if a native event was processed.
95 virtual PRBool ProcessNextNativeEvent(PRBool mayWait) = 0;
97 PRInt32 mSuspendNativeCount;
99 private:
100 PRBool DoProcessNextNativeEvent(PRBool mayWait);
102 nsCOMPtr<nsIRunnable> mDummyEvent;
104 * mBlockedWait points back to a slot that controls the wait loop in
105 * an outer OnProcessNextEvent invocation. Nested calls always set
106 * it to PR_FALSE to unblock an outer loop, since all events may
107 * have been consumed by the inner event loop(s).
109 PRBool *mBlockedWait;
110 PRInt32 mFavorPerf;
111 PRInt32 mNativeEventPending;
112 PRUint32 mEventloopNestingLevel;
113 PRIntervalTime mStarvationDelay;
114 PRIntervalTime mSwitchTime;
115 PRIntervalTime mLastNativeEventTime;
116 enum EventloopNestingState {
117 eEventloopNone, // top level thread execution
118 eEventloopXPCOM, // innermost native event loop is ProcessNextNativeEvent
119 eEventloopOther // innermost native event loop is a native library/plugin etc
121 EventloopNestingState mEventloopNestingState;
122 PRPackedBool mRunWasCalled;
123 PRPackedBool mExiting;
125 * mBlockNativeEvent blocks the appshell from processing native events.
126 * It is set to PR_TRUE while a nested native event loop (eEventloopOther)
127 * is processing gecko events in NativeEventCallback(), thus queuing up
128 * native events until we return to that loop (bug 420148).
129 * We force mBlockNativeEvent to PR_FALSE in case handling one of the gecko
130 * events spins up a nested XPCOM event loop (eg. modal window) which would
131 * otherwise lead to a "deadlock" where native events aren't processed at all.
133 PRPackedBool mBlockNativeEvent;
136 #endif // nsBaseAppShell_h__