2006-05-10 17:30:15 +00:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-06-02 01:14:02 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
/*
|
|
|
|
* Runs the main native Cocoa run loop, interrupting it as needed to process
|
|
|
|
* Gecko events.
|
|
|
|
*/
|
2005-06-02 01:14:02 +00:00
|
|
|
|
2007-01-18 06:34:07 +00:00
|
|
|
#ifndef nsAppShell_h_
|
|
|
|
#define nsAppShell_h_
|
2005-06-02 01:14:02 +00:00
|
|
|
|
2009-03-18 22:51:40 +00:00
|
|
|
class nsCocoaWindow;
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsBaseAppShell.h"
|
2009-03-18 22:51:40 +00:00
|
|
|
#include "nsTArray.h"
|
2005-06-02 01:14:02 +00:00
|
|
|
|
2008-10-17 21:58:47 +00:00
|
|
|
typedef struct _nsCocoaAppModalWindowListItem {
|
2009-03-18 22:51:40 +00:00
|
|
|
_nsCocoaAppModalWindowListItem(NSWindow *aWindow, NSModalSession aSession) :
|
2012-07-30 14:20:58 +00:00
|
|
|
mWindow(aWindow), mSession(aSession), mWidget(nullptr) {}
|
2009-03-18 22:51:40 +00:00
|
|
|
_nsCocoaAppModalWindowListItem(NSWindow *aWindow, nsCocoaWindow *aWidget) :
|
|
|
|
mWindow(aWindow), mSession(nil), mWidget(aWidget) {}
|
2008-10-17 21:58:47 +00:00
|
|
|
NSWindow *mWindow; // Weak
|
|
|
|
NSModalSession mSession; // Weak (not retainable)
|
2009-03-18 22:51:40 +00:00
|
|
|
nsCocoaWindow *mWidget; // Weak
|
2008-10-17 21:58:47 +00:00
|
|
|
} nsCocoaAppModalWindowListItem;
|
|
|
|
|
|
|
|
class nsCocoaAppModalWindowList {
|
|
|
|
public:
|
2009-03-18 22:51:40 +00:00
|
|
|
nsCocoaAppModalWindowList() {}
|
|
|
|
~nsCocoaAppModalWindowList() {}
|
|
|
|
// Push a Cocoa app-modal window onto the top of our list.
|
|
|
|
nsresult PushCocoa(NSWindow *aWindow, NSModalSession aSession);
|
|
|
|
// Pop the topmost Cocoa app-modal window off our list.
|
|
|
|
nsresult PopCocoa(NSWindow *aWindow, NSModalSession aSession);
|
|
|
|
// Push a Gecko-modal window onto the top of our list.
|
|
|
|
nsresult PushGecko(NSWindow *aWindow, nsCocoaWindow *aWidget);
|
|
|
|
// Pop the topmost Gecko-modal window off our list.
|
|
|
|
nsresult PopGecko(NSWindow *aWindow, nsCocoaWindow *aWidget);
|
|
|
|
// Return the "session" of the top-most visible Cocoa app-modal window.
|
2008-10-17 21:58:47 +00:00
|
|
|
NSModalSession CurrentSession();
|
2009-03-18 22:51:40 +00:00
|
|
|
// Has a Gecko modal dialog popped up over a Cocoa app-modal dialog?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GeckoModalAboveCocoaModal();
|
2008-10-17 21:58:47 +00:00
|
|
|
private:
|
2009-03-18 22:51:40 +00:00
|
|
|
nsTArray<nsCocoaAppModalWindowListItem> mList;
|
2008-10-17 21:58:47 +00:00
|
|
|
};
|
|
|
|
|
2012-06-07 00:26:45 +00:00
|
|
|
// GeckoNSApplication
|
|
|
|
//
|
|
|
|
// Subclass of NSApplication for filtering out certain events.
|
|
|
|
@interface GeckoNSApplication : NSApplication
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
@class AppShellDelegate;
|
2005-06-02 01:14:02 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
class nsAppShell : public nsBaseAppShell
|
|
|
|
{
|
|
|
|
public:
|
2007-09-19 19:17:06 +00:00
|
|
|
NS_IMETHOD ResumeNative(void);
|
2007-03-22 23:04:51 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsAppShell();
|
2005-06-02 01:14:02 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsresult Init();
|
2005-06-02 01:14:02 +00:00
|
|
|
|
2006-06-01 18:35:47 +00:00
|
|
|
NS_IMETHOD Run(void);
|
2007-09-19 19:17:06 +00:00
|
|
|
NS_IMETHOD Exit(void);
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aRecursionDepth);
|
2006-06-07 00:06:11 +00:00
|
|
|
NS_IMETHOD AfterProcessNextEvent(nsIThreadInternal *aThread,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aRecursionDepth);
|
2006-06-01 18:35:47 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// public only to be visible to Objective-C code that must call it
|
2006-06-15 17:24:25 +00:00
|
|
|
void WillTerminate();
|
2006-05-10 17:30:15 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsAppShell();
|
|
|
|
|
|
|
|
virtual void ScheduleNativeEventCallback();
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool ProcessNextNativeEvent(bool aMayWait);
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool InGeckoMainEventLoop();
|
2007-09-27 16:23:31 +00:00
|
|
|
|
2007-09-19 19:17:06 +00:00
|
|
|
static void ProcessGeckoEvents(void* aInfo);
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
protected:
|
2006-06-07 00:06:11 +00:00
|
|
|
CFMutableArrayRef mAutoreleasePools;
|
2006-05-10 17:30:15 +00:00
|
|
|
|
|
|
|
AppShellDelegate* mDelegate;
|
2007-09-19 19:17:06 +00:00
|
|
|
CFRunLoopRef mCFRunLoop;
|
|
|
|
CFRunLoopSourceRef mCFRunLoopSource;
|
2006-05-17 00:25:35 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mRunningEventLoop;
|
|
|
|
bool mStarted;
|
|
|
|
bool mTerminated;
|
|
|
|
bool mSkippedNativeCallback;
|
|
|
|
bool mRunningCocoaEmbedded;
|
2007-09-19 19:17:06 +00:00
|
|
|
|
|
|
|
// mHadMoreEventsCount and kHadMoreEventsCountMax are used in
|
|
|
|
// ProcessNextNativeEvent().
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mHadMoreEventsCount;
|
2007-09-26 23:05:34 +00:00
|
|
|
// Setting kHadMoreEventsCountMax to '10' contributed to a fairly large
|
|
|
|
// (about 10%) increase in the number of calls to malloc (though without
|
|
|
|
// effecting the total amount of memory used). Cutting it to '3'
|
|
|
|
// reduced the number of calls by 6%-7% (reducing the original regression
|
|
|
|
// to 3%-4%). See bmo bug 395397.
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint32_t kHadMoreEventsCountMax = 3;
|
2007-09-27 16:23:31 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRecursionDepth;
|
|
|
|
int32_t mNativeEventCallbackDepth;
|
2009-06-17 15:30:46 +00:00
|
|
|
// Can be set from different threads, so must be modified atomically
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mNativeEventScheduledDepth;
|
2006-05-10 17:30:15 +00:00
|
|
|
};
|
|
|
|
|
2007-01-18 06:34:07 +00:00
|
|
|
#endif // nsAppShell_h_
|