Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / nsAppShell.h
blob921a166436139a3f741f59692e15c9de498e92ca
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 /*
7 * Runs the main native Cocoa run loop, interrupting it as needed to process
8 * Gecko events.
9 */
11 #ifndef nsAppShell_h_
12 #define nsAppShell_h_
14 #import <AppKit/NSApplication.h>
16 #include "nsBaseAppShell.h"
17 #include "nsTArray.h"
19 class ProfilingStack;
21 namespace mozilla {
22 class nsAvailableMemoryWatcherBase;
25 // GeckoNSApplication
27 // Subclass of NSApplication for filtering out certain events.
28 @interface GeckoNSApplication : NSApplication {
30 @property(readonly) BOOL didLaunch;
31 @end
33 @class AppShellDelegate;
35 class nsAppShell : public nsBaseAppShell {
36 public:
37 NS_IMETHOD ResumeNative(void) override;
39 nsAppShell();
41 nsresult Init();
43 NS_IMETHOD Run(void) override;
44 NS_IMETHOD Exit(void) override;
45 NS_IMETHOD OnProcessNextEvent(nsIThreadInternal* aThread,
46 bool aMayWait) override;
47 NS_IMETHOD AfterProcessNextEvent(nsIThreadInternal* aThread,
48 bool aEventWasProcessed) override;
50 void OnRunLoopActivityChanged(CFRunLoopActivity aActivity);
52 // public only to be visible to Objective-C code that must call it
53 void WillTerminate();
55 static void OnMemoryPressureChanged(
56 dispatch_source_memorypressure_flags_t aPressureLevel);
58 protected:
59 virtual ~nsAppShell();
61 virtual void ScheduleNativeEventCallback() override;
62 virtual bool ProcessNextNativeEvent(bool aMayWait) override;
64 void InitMemoryPressureObserver();
66 static void ProcessGeckoEvents(void* aInfo);
68 protected:
69 CFMutableArrayRef mAutoreleasePools;
71 AppShellDelegate* mDelegate;
72 CFRunLoopRef mCFRunLoop;
73 CFRunLoopSourceRef mCFRunLoopSource;
75 // An observer for the profiler that is notified when the event loop enters
76 // and exits the waiting state.
77 CFRunLoopObserverRef mCFRunLoopObserver;
79 // Non-null while the native event loop is in the waiting state.
80 ProfilingStack* mProfilingStackWhileWaiting = nullptr;
82 // For getting notifications from the OS about memory pressure state changes.
83 dispatch_source_t mMemoryPressureSource = nullptr;
85 bool mRunningEventLoop;
86 bool mStarted;
87 bool mTerminated;
88 bool mSkippedNativeCallback;
89 bool mRunningCocoaEmbedded;
91 int32_t mNativeEventCallbackDepth;
92 // Can be set from different threads, so must be modified atomically
93 int32_t mNativeEventScheduledDepth;
96 #endif // nsAppShell_h_