1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/cocoa/nsAppShell.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * Runs the main native Cocoa run loop, interrupting it as needed to process 1.11 + * Gecko events. 1.12 + */ 1.13 + 1.14 +#ifndef nsAppShell_h_ 1.15 +#define nsAppShell_h_ 1.16 + 1.17 +class nsCocoaWindow; 1.18 + 1.19 +#include "nsBaseAppShell.h" 1.20 +#include "nsTArray.h" 1.21 + 1.22 +typedef struct _nsCocoaAppModalWindowListItem { 1.23 + _nsCocoaAppModalWindowListItem(NSWindow *aWindow, NSModalSession aSession) : 1.24 + mWindow(aWindow), mSession(aSession), mWidget(nullptr) {} 1.25 + _nsCocoaAppModalWindowListItem(NSWindow *aWindow, nsCocoaWindow *aWidget) : 1.26 + mWindow(aWindow), mSession(nil), mWidget(aWidget) {} 1.27 + NSWindow *mWindow; // Weak 1.28 + NSModalSession mSession; // Weak (not retainable) 1.29 + nsCocoaWindow *mWidget; // Weak 1.30 +} nsCocoaAppModalWindowListItem; 1.31 + 1.32 +class nsCocoaAppModalWindowList { 1.33 +public: 1.34 + nsCocoaAppModalWindowList() {} 1.35 + ~nsCocoaAppModalWindowList() {} 1.36 + // Push a Cocoa app-modal window onto the top of our list. 1.37 + nsresult PushCocoa(NSWindow *aWindow, NSModalSession aSession); 1.38 + // Pop the topmost Cocoa app-modal window off our list. 1.39 + nsresult PopCocoa(NSWindow *aWindow, NSModalSession aSession); 1.40 + // Push a Gecko-modal window onto the top of our list. 1.41 + nsresult PushGecko(NSWindow *aWindow, nsCocoaWindow *aWidget); 1.42 + // Pop the topmost Gecko-modal window off our list. 1.43 + nsresult PopGecko(NSWindow *aWindow, nsCocoaWindow *aWidget); 1.44 + // Return the "session" of the top-most visible Cocoa app-modal window. 1.45 + NSModalSession CurrentSession(); 1.46 + // Has a Gecko modal dialog popped up over a Cocoa app-modal dialog? 1.47 + bool GeckoModalAboveCocoaModal(); 1.48 +private: 1.49 + nsTArray<nsCocoaAppModalWindowListItem> mList; 1.50 +}; 1.51 + 1.52 +// GeckoNSApplication 1.53 +// 1.54 +// Subclass of NSApplication for filtering out certain events. 1.55 +@interface GeckoNSApplication : NSApplication 1.56 +{ 1.57 +} 1.58 +@end 1.59 + 1.60 +@class AppShellDelegate; 1.61 + 1.62 +class nsAppShell : public nsBaseAppShell 1.63 +{ 1.64 +public: 1.65 + NS_IMETHOD ResumeNative(void); 1.66 + 1.67 + nsAppShell(); 1.68 + 1.69 + nsresult Init(); 1.70 + 1.71 + NS_IMETHOD Run(void); 1.72 + NS_IMETHOD Exit(void); 1.73 + NS_IMETHOD OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait, 1.74 + uint32_t aRecursionDepth); 1.75 + NS_IMETHOD AfterProcessNextEvent(nsIThreadInternal *aThread, 1.76 + uint32_t aRecursionDepth, 1.77 + bool aEventWasProcessed); 1.78 + 1.79 + // public only to be visible to Objective-C code that must call it 1.80 + void WillTerminate(); 1.81 + 1.82 +protected: 1.83 + virtual ~nsAppShell(); 1.84 + 1.85 + virtual void ScheduleNativeEventCallback(); 1.86 + virtual bool ProcessNextNativeEvent(bool aMayWait); 1.87 + 1.88 + bool InGeckoMainEventLoop(); 1.89 + 1.90 + static void ProcessGeckoEvents(void* aInfo); 1.91 + 1.92 +protected: 1.93 + CFMutableArrayRef mAutoreleasePools; 1.94 + 1.95 + AppShellDelegate* mDelegate; 1.96 + CFRunLoopRef mCFRunLoop; 1.97 + CFRunLoopSourceRef mCFRunLoopSource; 1.98 + 1.99 + bool mRunningEventLoop; 1.100 + bool mStarted; 1.101 + bool mTerminated; 1.102 + bool mSkippedNativeCallback; 1.103 + bool mRunningCocoaEmbedded; 1.104 + 1.105 + // mHadMoreEventsCount and kHadMoreEventsCountMax are used in 1.106 + // ProcessNextNativeEvent(). 1.107 + uint32_t mHadMoreEventsCount; 1.108 + // Setting kHadMoreEventsCountMax to '10' contributed to a fairly large 1.109 + // (about 10%) increase in the number of calls to malloc (though without 1.110 + // effecting the total amount of memory used). Cutting it to '3' 1.111 + // reduced the number of calls by 6%-7% (reducing the original regression 1.112 + // to 3%-4%). See bmo bug 395397. 1.113 + static const uint32_t kHadMoreEventsCountMax = 3; 1.114 + 1.115 + int32_t mRecursionDepth; 1.116 + int32_t mNativeEventCallbackDepth; 1.117 + // Can be set from different threads, so must be modified atomically 1.118 + int32_t mNativeEventScheduledDepth; 1.119 +}; 1.120 + 1.121 +#endif // nsAppShell_h_