2006-05-10 21:30:15 +04:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
2012-05-21 15:12:37 +04: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 05:14:02 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
/*
|
|
|
|
* Runs the main native Cocoa run loop, interrupting it as needed to process
|
|
|
|
* Gecko events.
|
|
|
|
*/
|
2005-06-02 05:14:02 +04:00
|
|
|
|
2007-01-18 09:34:07 +03:00
|
|
|
#ifndef nsAppShell_h_
|
|
|
|
#define nsAppShell_h_
|
2005-06-02 05:14:02 +04:00
|
|
|
|
2009-03-19 01:51:40 +03:00
|
|
|
class nsCocoaWindow;
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsBaseAppShell.h"
|
2009-03-19 01:51:40 +03:00
|
|
|
#include "nsTArray.h"
|
2005-06-02 05:14:02 +04:00
|
|
|
|
2008-10-18 01:58:47 +04:00
|
|
|
typedef struct _nsCocoaAppModalWindowListItem {
|
2009-03-19 01:51:40 +03:00
|
|
|
_nsCocoaAppModalWindowListItem(NSWindow *aWindow, NSModalSession aSession) :
|
2012-07-30 18:20:58 +04:00
|
|
|
mWindow(aWindow), mSession(aSession), mWidget(nullptr) {}
|
2009-03-19 01:51:40 +03:00
|
|
|
_nsCocoaAppModalWindowListItem(NSWindow *aWindow, nsCocoaWindow *aWidget) :
|
|
|
|
mWindow(aWindow), mSession(nil), mWidget(aWidget) {}
|
2008-10-18 01:58:47 +04:00
|
|
|
NSWindow *mWindow; // Weak
|
|
|
|
NSModalSession mSession; // Weak (not retainable)
|
2009-03-19 01:51:40 +03:00
|
|
|
nsCocoaWindow *mWidget; // Weak
|
2008-10-18 01:58:47 +04:00
|
|
|
} nsCocoaAppModalWindowListItem;
|
|
|
|
|
|
|
|
class nsCocoaAppModalWindowList {
|
|
|
|
public:
|
2009-03-19 01:51:40 +03: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-18 01:58:47 +04:00
|
|
|
NSModalSession CurrentSession();
|
2009-03-19 01:51:40 +03:00
|
|
|
// Has a Gecko modal dialog popped up over a Cocoa app-modal dialog?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GeckoModalAboveCocoaModal();
|
2008-10-18 01:58:47 +04:00
|
|
|
private:
|
2009-03-19 01:51:40 +03:00
|
|
|
nsTArray<nsCocoaAppModalWindowListItem> mList;
|
2008-10-18 01:58:47 +04:00
|
|
|
};
|
|
|
|
|
2012-06-07 04:26:45 +04:00
|
|
|
// GeckoNSApplication
|
|
|
|
//
|
|
|
|
// Subclass of NSApplication for filtering out certain events.
|
|
|
|
@interface GeckoNSApplication : NSApplication
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
@class AppShellDelegate;
|
2005-06-02 05:14:02 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
class nsAppShell : public nsBaseAppShell
|
|
|
|
{
|
|
|
|
public:
|
2007-09-19 23:17:06 +04:00
|
|
|
NS_IMETHOD ResumeNative(void);
|
2007-03-23 02:04:51 +03:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
nsAppShell();
|
2005-06-02 05:14:02 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
nsresult Init();
|
2005-06-02 05:14:02 +04:00
|
|
|
|
2006-06-01 22:35:47 +04:00
|
|
|
NS_IMETHOD Run(void);
|
2007-09-19 23:17:06 +04:00
|
|
|
NS_IMETHOD Exit(void);
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHOD OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aRecursionDepth);
|
2006-06-07 04:06:11 +04:00
|
|
|
NS_IMETHOD AfterProcessNextEvent(nsIThreadInternal *aThread,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aRecursionDepth);
|
2006-06-01 22:35:47 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
// public only to be visible to Objective-C code that must call it
|
2006-06-15 21:24:25 +04:00
|
|
|
void WillTerminate();
|
2006-05-10 21:30:15 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsAppShell();
|
|
|
|
|
|
|
|
virtual void ScheduleNativeEventCallback();
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool ProcessNextNativeEvent(bool aMayWait);
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool InGeckoMainEventLoop();
|
2007-09-27 20:23:31 +04:00
|
|
|
|
2007-09-19 23:17:06 +04:00
|
|
|
static void ProcessGeckoEvents(void* aInfo);
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
protected:
|
2006-06-07 04:06:11 +04:00
|
|
|
CFMutableArrayRef mAutoreleasePools;
|
2006-05-10 21:30:15 +04:00
|
|
|
|
|
|
|
AppShellDelegate* mDelegate;
|
2007-09-19 23:17:06 +04:00
|
|
|
CFRunLoopRef mCFRunLoop;
|
|
|
|
CFRunLoopSourceRef mCFRunLoopSource;
|
2006-05-17 04:25:35 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mRunningEventLoop;
|
|
|
|
bool mStarted;
|
|
|
|
bool mTerminated;
|
|
|
|
bool mSkippedNativeCallback;
|
|
|
|
bool mRunningCocoaEmbedded;
|
2007-09-19 23:17:06 +04:00
|
|
|
|
|
|
|
// mHadMoreEventsCount and kHadMoreEventsCountMax are used in
|
|
|
|
// ProcessNextNativeEvent().
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mHadMoreEventsCount;
|
2007-09-27 03:05:34 +04: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 19:56:38 +04:00
|
|
|
static const uint32_t kHadMoreEventsCountMax = 3;
|
2007-09-27 20:23:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mRecursionDepth;
|
|
|
|
int32_t mNativeEventCallbackDepth;
|
2009-06-17 19:30:46 +04:00
|
|
|
// Can be set from different threads, so must be modified atomically
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mNativeEventScheduledDepth;
|
2006-05-10 21:30:15 +04:00
|
|
|
};
|
|
|
|
|
2007-01-18 09:34:07 +03:00
|
|
|
#endif // nsAppShell_h_
|