widget/cocoa/nsAppShell.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:5339ee452001
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/. */
5
6 /*
7 * Runs the main native Cocoa run loop, interrupting it as needed to process
8 * Gecko events.
9 */
10
11 #ifndef nsAppShell_h_
12 #define nsAppShell_h_
13
14 class nsCocoaWindow;
15
16 #include "nsBaseAppShell.h"
17 #include "nsTArray.h"
18
19 typedef struct _nsCocoaAppModalWindowListItem {
20 _nsCocoaAppModalWindowListItem(NSWindow *aWindow, NSModalSession aSession) :
21 mWindow(aWindow), mSession(aSession), mWidget(nullptr) {}
22 _nsCocoaAppModalWindowListItem(NSWindow *aWindow, nsCocoaWindow *aWidget) :
23 mWindow(aWindow), mSession(nil), mWidget(aWidget) {}
24 NSWindow *mWindow; // Weak
25 NSModalSession mSession; // Weak (not retainable)
26 nsCocoaWindow *mWidget; // Weak
27 } nsCocoaAppModalWindowListItem;
28
29 class nsCocoaAppModalWindowList {
30 public:
31 nsCocoaAppModalWindowList() {}
32 ~nsCocoaAppModalWindowList() {}
33 // Push a Cocoa app-modal window onto the top of our list.
34 nsresult PushCocoa(NSWindow *aWindow, NSModalSession aSession);
35 // Pop the topmost Cocoa app-modal window off our list.
36 nsresult PopCocoa(NSWindow *aWindow, NSModalSession aSession);
37 // Push a Gecko-modal window onto the top of our list.
38 nsresult PushGecko(NSWindow *aWindow, nsCocoaWindow *aWidget);
39 // Pop the topmost Gecko-modal window off our list.
40 nsresult PopGecko(NSWindow *aWindow, nsCocoaWindow *aWidget);
41 // Return the "session" of the top-most visible Cocoa app-modal window.
42 NSModalSession CurrentSession();
43 // Has a Gecko modal dialog popped up over a Cocoa app-modal dialog?
44 bool GeckoModalAboveCocoaModal();
45 private:
46 nsTArray<nsCocoaAppModalWindowListItem> mList;
47 };
48
49 // GeckoNSApplication
50 //
51 // Subclass of NSApplication for filtering out certain events.
52 @interface GeckoNSApplication : NSApplication
53 {
54 }
55 @end
56
57 @class AppShellDelegate;
58
59 class nsAppShell : public nsBaseAppShell
60 {
61 public:
62 NS_IMETHOD ResumeNative(void);
63
64 nsAppShell();
65
66 nsresult Init();
67
68 NS_IMETHOD Run(void);
69 NS_IMETHOD Exit(void);
70 NS_IMETHOD OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait,
71 uint32_t aRecursionDepth);
72 NS_IMETHOD AfterProcessNextEvent(nsIThreadInternal *aThread,
73 uint32_t aRecursionDepth,
74 bool aEventWasProcessed);
75
76 // public only to be visible to Objective-C code that must call it
77 void WillTerminate();
78
79 protected:
80 virtual ~nsAppShell();
81
82 virtual void ScheduleNativeEventCallback();
83 virtual bool ProcessNextNativeEvent(bool aMayWait);
84
85 bool InGeckoMainEventLoop();
86
87 static void ProcessGeckoEvents(void* aInfo);
88
89 protected:
90 CFMutableArrayRef mAutoreleasePools;
91
92 AppShellDelegate* mDelegate;
93 CFRunLoopRef mCFRunLoop;
94 CFRunLoopSourceRef mCFRunLoopSource;
95
96 bool mRunningEventLoop;
97 bool mStarted;
98 bool mTerminated;
99 bool mSkippedNativeCallback;
100 bool mRunningCocoaEmbedded;
101
102 // mHadMoreEventsCount and kHadMoreEventsCountMax are used in
103 // ProcessNextNativeEvent().
104 uint32_t mHadMoreEventsCount;
105 // Setting kHadMoreEventsCountMax to '10' contributed to a fairly large
106 // (about 10%) increase in the number of calls to malloc (though without
107 // effecting the total amount of memory used). Cutting it to '3'
108 // reduced the number of calls by 6%-7% (reducing the original regression
109 // to 3%-4%). See bmo bug 395397.
110 static const uint32_t kHadMoreEventsCountMax = 3;
111
112 int32_t mRecursionDepth;
113 int32_t mNativeEventCallbackDepth;
114 // Can be set from different threads, so must be modified atomically
115 int32_t mNativeEventScheduledDepth;
116 };
117
118 #endif // nsAppShell_h_

mercurial