2007-12-19 11:40:18 -08:00
|
|
|
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCocoaWindow.h"
|
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIRollupListener.h"
|
|
|
|
#include "nsChildView.h"
|
2008-05-02 03:40:49 -07:00
|
|
|
#include "nsWindowMap.h"
|
2009-03-18 15:51:40 -07:00
|
|
|
#include "nsAppShell.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIXULWindow.h"
|
2007-11-06 23:30:21 -08:00
|
|
|
#include "nsToolkit.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2008-02-13 07:57:12 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2008-03-26 20:42:57 -07:00
|
|
|
#include "nsMenuBarX.h"
|
2008-06-28 00:55:30 -07:00
|
|
|
#include "nsMenuUtilsX.h"
|
2008-10-14 08:33:40 -07:00
|
|
|
#include "nsStyleConsts.h"
|
2008-10-15 06:01:10 -07:00
|
|
|
#include "nsNativeThemeColors.h"
|
2009-04-21 16:53:52 -07:00
|
|
|
#include "nsChildView.h"
|
2012-05-17 00:53:20 -07:00
|
|
|
#include "nsCocoaFeatures.h"
|
2012-05-18 15:16:50 -07:00
|
|
|
#include "nsIScreenManager.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsIWidgetListener.h"
|
2012-10-16 12:41:20 -07:00
|
|
|
#include "nsIPresShell.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-07 13:55:14 -07:00
|
|
|
#include "gfxPlatform.h"
|
2009-04-07 09:02:11 -07:00
|
|
|
#include "qcms.h"
|
2008-04-07 13:55:14 -07:00
|
|
|
|
2011-05-27 01:15:20 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2010-03-01 00:03:49 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
class LayerManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
using namespace mozilla::layers;
|
2011-05-27 01:15:20 -07:00
|
|
|
using namespace mozilla;
|
2010-03-01 00:03:49 -08:00
|
|
|
|
2009-03-18 15:51:40 -07:00
|
|
|
// defined in nsAppShell.mm
|
|
|
|
extern nsCocoaAppModalWindowList *gCocoaAppModalWindowList;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t gXULModalLevel = 0;
|
2009-03-18 15:51:40 -07:00
|
|
|
|
2008-03-23 15:30:56 -07:00
|
|
|
// In principle there should be only one app-modal window at any given time.
|
|
|
|
// But sometimes, despite our best efforts, another window appears above the
|
|
|
|
// current app-modal window. So we need to keep a linked list of app-modal
|
|
|
|
// windows. (A non-sheet window that appears above an app-modal window is
|
|
|
|
// also made app-modal.) See nsCocoaWindow::SetModal().
|
2009-03-18 15:51:40 -07:00
|
|
|
nsCocoaWindowList *gGeckoAppModalWindowList = NULL;
|
2007-09-19 12:17:06 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// defined in nsMenuBarX.mm
|
|
|
|
extern NSMenu* sApplicationMenu; // Application menu shared by all menubars
|
|
|
|
|
|
|
|
// defined in nsChildView.mm
|
|
|
|
extern BOOL gSomeMenuBarPainted;
|
|
|
|
|
2009-12-30 07:24:08 -08:00
|
|
|
extern "C" {
|
|
|
|
// CGSPrivate.h
|
|
|
|
typedef NSInteger CGSConnection;
|
|
|
|
typedef NSInteger CGSWindow;
|
2010-01-13 08:10:25 -08:00
|
|
|
typedef NSUInteger CGSWindowFilterRef;
|
2009-12-30 07:24:08 -08:00
|
|
|
extern CGSConnection _CGSDefaultConnection(void);
|
|
|
|
extern CGError CGSSetWindowShadowAndRimParameters(const CGSConnection cid, CGSWindow wid, float standardDeviation, float density, int offsetX, int offsetY, unsigned int flags);
|
2010-01-13 08:10:25 -08:00
|
|
|
extern CGError CGSNewCIFilterByName(CGSConnection cid, CFStringRef filterName, CGSWindowFilterRef *outFilter);
|
|
|
|
extern CGError CGSSetCIFilterValuesFromDictionary(CGSConnection cid, CGSWindowFilterRef filter, CFDictionaryRef filterValues);
|
|
|
|
extern CGError CGSAddWindowFilter(CGSConnection cid, CGSWindow wid, CGSWindowFilterRef filter, NSInteger flags);
|
|
|
|
extern CGError CGSRemoveWindowFilter(CGSConnection cid, CGSWindow wid, CGSWindowFilterRef filter);
|
|
|
|
extern CGError CGSReleaseCIFilter(CGSConnection cid, CGSWindowFilterRef filter);
|
2009-12-30 07:24:08 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define NS_APPSHELLSERVICE_CONTRACTID "@mozilla.org/appshell/appShellService;1"
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsCocoaWindow, Inherited, nsPIWidgetCocoa)
|
|
|
|
|
2007-09-15 10:01:35 -07:00
|
|
|
// A note on testing to see if your object is a sheet...
|
|
|
|
// |mWindowType == eWindowType_sheet| is true if your gecko nsIWidget is a sheet
|
|
|
|
// widget - whether or not the sheet is showing. |[mWindow isSheet]| will return
|
|
|
|
// true *only when the sheet is actually showing*. Choose your test wisely.
|
|
|
|
|
2007-06-12 13:26:24 -07:00
|
|
|
static void RollUpPopups()
|
|
|
|
{
|
2012-10-26 06:15:22 -07:00
|
|
|
nsIRollupListener* rollupListener = nsBaseWidget::GetActiveRollupListener();
|
2012-12-31 09:27:04 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(rollupListener);
|
2012-10-26 06:15:22 -07:00
|
|
|
nsCOMPtr<nsIWidget> rollupWidget = rollupListener->GetRollupWidget();
|
2012-12-31 09:27:04 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(rollupWidget);
|
|
|
|
rollupListener->Rollup(0, nullptr);
|
2007-06-12 13:26:24 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCocoaWindow::nsCocoaWindow()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mParent(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mWindow(nil)
|
|
|
|
, mDelegate(nil)
|
|
|
|
, mSheetWindowParent(nil)
|
|
|
|
, mPopupContentView(nil)
|
2009-12-30 07:24:08 -08:00
|
|
|
, mShadowStyle(NS_STYLE_WINDOW_SHADOW_DEFAULT)
|
2010-01-13 08:10:25 -08:00
|
|
|
, mWindowFilter(0)
|
2012-09-29 04:36:09 -07:00
|
|
|
, mBackingScaleFactor(0.0)
|
2012-02-16 19:47:39 -08:00
|
|
|
, mAnimationType(nsIWidget::eGenericWindowAnimation)
|
2011-09-30 17:20:33 -07:00
|
|
|
, mWindowMadeHere(false)
|
|
|
|
, mSheetNeedsShow(false)
|
|
|
|
, mFullScreen(false)
|
2012-03-29 12:18:50 -07:00
|
|
|
, mInFullScreenTransition(false)
|
2011-09-30 17:20:33 -07:00
|
|
|
, mModal(false)
|
2012-03-20 16:21:14 -07:00
|
|
|
, mUsesNativeFullScreen(false)
|
2012-02-16 19:47:39 -08:00
|
|
|
, mIsAnimationSuppressed(false)
|
2011-12-13 08:55:16 -08:00
|
|
|
, mInReportMoveEvent(false)
|
2008-03-23 15:30:56 -07:00
|
|
|
, mNumModalDescendents(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-06-24 08:15:32 -07:00
|
|
|
void nsCocoaWindow::DestroyNativeWindow()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return;
|
|
|
|
|
2010-01-13 08:10:25 -08:00
|
|
|
CleanUpWindowFilter();
|
2009-06-24 08:15:32 -07:00
|
|
|
// We want to unhook the delegate here because we don't want events
|
|
|
|
// sent to it after this object has been destroyed.
|
|
|
|
[mWindow setDelegate:nil];
|
|
|
|
[mWindow close];
|
2012-06-18 08:20:02 -07:00
|
|
|
mWindow = nil;
|
2009-06-24 08:15:32 -07:00
|
|
|
[mDelegate autorelease];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCocoaWindow::~nsCocoaWindow()
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-04-23 08:54:50 -07:00
|
|
|
// Notify the children that we're gone. Popup windows (e.g. tooltips) can
|
|
|
|
// have nsChildView children. 'kid' is an nsChildView object if and only if
|
2009-09-24 02:32:20 -07:00
|
|
|
// its 'type' is 'eWindowType_child' or 'eWindowType_plugin'.
|
|
|
|
// childView->ResetParent() can change our list of children while it's
|
|
|
|
// being iterated, so the way we iterate the list must allow for this.
|
2009-07-20 08:02:31 -07:00
|
|
|
for (nsIWidget* kid = mLastChild; kid;) {
|
2009-04-23 08:54:50 -07:00
|
|
|
nsWindowType kidType;
|
|
|
|
kid->GetWindowType(kidType);
|
2009-09-24 02:32:20 -07:00
|
|
|
if (kidType == eWindowType_child || kidType == eWindowType_plugin) {
|
2009-04-23 08:54:50 -07:00
|
|
|
nsChildView* childView = static_cast<nsChildView*>(kid);
|
2009-07-20 08:02:31 -07:00
|
|
|
kid = kid->GetPrevSibling();
|
2009-04-23 08:54:50 -07:00
|
|
|
childView->ResetParent();
|
|
|
|
} else {
|
|
|
|
nsCocoaWindow* childWindow = static_cast<nsCocoaWindow*>(kid);
|
2012-07-30 07:20:58 -07:00
|
|
|
childWindow->mParent = nullptr;
|
2009-07-20 08:02:31 -07:00
|
|
|
kid = kid->GetPrevSibling();
|
2009-04-23 08:54:50 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-15 14:56:44 -07:00
|
|
|
if (mWindow && mWindowMadeHere) {
|
|
|
|
DestroyNativeWindow();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mPopupContentView);
|
2007-09-19 12:17:06 -07:00
|
|
|
|
|
|
|
// Deal with the possiblity that we're being destroyed while running modal.
|
|
|
|
NS_ASSERTION(!mModal, "Widget destroyed while running modal!");
|
|
|
|
if (mModal) {
|
|
|
|
--gXULModalLevel;
|
|
|
|
NS_ASSERTION(gXULModalLevel >= 0, "Wierdness setting modality!");
|
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-16 12:41:20 -07:00
|
|
|
// Find the screen that overlaps aRect the most,
|
|
|
|
// if none are found default to the mainScreen.
|
|
|
|
static NSScreen *FindTargetScreenForRect(const nsIntRect& aRect)
|
|
|
|
{
|
|
|
|
NSScreen *targetScreen = [NSScreen mainScreen];
|
|
|
|
NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator];
|
|
|
|
int largestIntersectArea = 0;
|
|
|
|
while (NSScreen *screen = [screenEnum nextObject]) {
|
|
|
|
nsIntRect screenRect(nsCocoaUtils::CocoaRectToGeckoRect([screen visibleFrame]));
|
|
|
|
screenRect = screenRect.Intersect(aRect);
|
|
|
|
int area = screenRect.width * screenRect.height;
|
|
|
|
if (area > largestIntersectArea) {
|
|
|
|
largestIntersectArea = area;
|
|
|
|
targetScreen = screen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return targetScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fits the rect to the screen that contains the largest area of it,
|
|
|
|
// or to aScreen if a screen is passed in
|
2012-10-18 03:38:26 -07:00
|
|
|
// NB: this operates with aRect in global display pixels
|
2012-09-29 04:36:09 -07:00
|
|
|
static void FitRectToVisibleAreaForScreen(nsIntRect &aRect, NSScreen *aScreen)
|
2007-12-03 08:25:36 -08:00
|
|
|
{
|
2012-09-29 04:36:09 -07:00
|
|
|
if (!aScreen) {
|
2012-10-16 12:41:20 -07:00
|
|
|
aScreen = FindTargetScreenForRect(aRect);
|
2012-09-29 04:36:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect screenBounds(nsCocoaUtils::CocoaRectToGeckoRect([aScreen visibleFrame]));
|
|
|
|
|
2010-10-24 18:32:12 -07:00
|
|
|
if (aRect.width > screenBounds.width) {
|
|
|
|
aRect.width = screenBounds.width;
|
2007-12-03 08:25:36 -08:00
|
|
|
}
|
2010-10-24 18:32:12 -07:00
|
|
|
if (aRect.height > screenBounds.height) {
|
|
|
|
aRect.height = screenBounds.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRect.x - screenBounds.x + aRect.width > screenBounds.width) {
|
|
|
|
aRect.x += screenBounds.width - (aRect.x - screenBounds.x + aRect.width);
|
|
|
|
}
|
|
|
|
if (aRect.y - screenBounds.y + aRect.height > screenBounds.height) {
|
|
|
|
aRect.y += screenBounds.height - (aRect.y - screenBounds.y + aRect.height);
|
2007-12-03 08:25:36 -08:00
|
|
|
}
|
2011-08-19 12:52:26 -07:00
|
|
|
|
|
|
|
// If the left/top edge of the window is off the screen in either direction,
|
|
|
|
// then set the window to start at the left/top edge of the screen.
|
|
|
|
if (aRect.x < screenBounds.x || aRect.x > (screenBounds.x + screenBounds.width)) {
|
|
|
|
aRect.x = screenBounds.x;
|
|
|
|
}
|
|
|
|
if (aRect.y < screenBounds.y || aRect.y > (screenBounds.y + screenBounds.height)) {
|
|
|
|
aRect.y = screenBounds.y;
|
|
|
|
}
|
2007-12-03 08:25:36 -08:00
|
|
|
}
|
|
|
|
|
2009-06-24 08:15:32 -07:00
|
|
|
// Some applications like Camino use native popup windows
|
|
|
|
// (native context menus, native tooltips)
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool UseNativePopupWindows()
|
2009-06-24 08:15:32 -07:00
|
|
|
{
|
2011-06-21 14:00:47 -07:00
|
|
|
#ifdef MOZ_USE_NATIVE_POPUP_WINDOWS
|
2011-09-30 17:20:33 -07:00
|
|
|
return true;
|
2011-06-21 14:00:47 -07:00
|
|
|
#else
|
2011-09-30 17:20:33 -07:00
|
|
|
return false;
|
2011-06-21 14:00:47 -07:00
|
|
|
#endif /* MOZ_USE_NATIVE_POPUP_WINDOWS */
|
2009-06-24 08:15:32 -07:00
|
|
|
}
|
|
|
|
|
2012-10-18 03:38:26 -07:00
|
|
|
// aRect here is specified in global display pixels
|
2009-09-23 23:18:10 -07:00
|
|
|
nsresult nsCocoaWindow::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2009-09-23 23:18:10 -07:00
|
|
|
nsWidgetInitData *aInitData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2010-04-13 13:36:03 -07:00
|
|
|
// Because the hidden window is created outside of an event loop,
|
|
|
|
// we have to provide an autorelease pool (see bug 559075).
|
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2010-10-24 18:32:12 -07:00
|
|
|
nsIntRect newBounds = aRect;
|
2012-10-16 12:41:20 -07:00
|
|
|
FitRectToVisibleAreaForScreen(newBounds, nullptr);
|
2007-12-03 08:25:36 -08:00
|
|
|
|
2009-09-24 02:32:20 -07:00
|
|
|
// Set defaults which can be overriden from aInitData in BaseCreate
|
|
|
|
mWindowType = eWindowType_toplevel;
|
|
|
|
mBorderStyle = eBorderStyle_default;
|
|
|
|
|
2011-10-25 08:05:32 -07:00
|
|
|
// Ensure that the toolkit is created.
|
|
|
|
nsToolkit::GetToolkit();
|
|
|
|
|
2012-10-18 03:38:26 -07:00
|
|
|
// newBounds is still display (global screen) pixels at this point;
|
|
|
|
// fortunately, BaseCreate doesn't actually use it so we don't
|
|
|
|
// need to worry about trying to convert it to device pixels
|
|
|
|
// when we don't have a window (or dev context, perhaps) yet
|
2012-08-15 11:53:09 -07:00
|
|
|
Inherited::BaseCreate(aParent, newBounds, aContext, aInitData);
|
2009-06-24 08:15:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mParent = aParent;
|
2007-03-30 12:51:51 -07:00
|
|
|
|
2009-09-23 23:18:10 -07:00
|
|
|
// Applications that use native popups don't want us to create popup windows.
|
|
|
|
if ((mWindowType == eWindowType_popup) && UseNativePopupWindows())
|
|
|
|
return NS_OK;
|
2009-06-24 08:15:32 -07:00
|
|
|
|
2012-10-18 03:38:26 -07:00
|
|
|
nsresult rv =
|
|
|
|
CreateNativeWindow(nsCocoaUtils::GeckoRectToCocoaRect(newBounds),
|
|
|
|
mBorderStyle, false);
|
2009-09-23 23:18:10 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-04-25 18:37:20 -07:00
|
|
|
if (mWindowType == eWindowType_popup) {
|
|
|
|
if (aInitData->mIsDragPopup) {
|
|
|
|
[mWindow setIgnoresMouseEvents:YES];
|
|
|
|
}
|
2012-10-18 03:38:26 -07:00
|
|
|
// now we can convert newBounds to device pixels for the window we created,
|
|
|
|
// as the child view expects a rect expressed in the dev pix of its parent
|
|
|
|
double scale = BackingScaleFactor();
|
|
|
|
newBounds.x *= scale;
|
|
|
|
newBounds.y *= scale;
|
|
|
|
newBounds.width *= scale;
|
|
|
|
newBounds.height *= scale;
|
2012-08-15 11:53:09 -07:00
|
|
|
return CreatePopupContentView(newBounds, aContext);
|
2011-04-25 18:37:20 -07:00
|
|
|
}
|
2007-03-30 12:51:51 -07:00
|
|
|
|
2012-02-16 19:47:39 -08:00
|
|
|
mIsAnimationSuppressed = aInitData->mIsAnimationSuppressed;
|
|
|
|
|
2009-06-24 08:15:32 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2009-06-27 06:58:03 -07:00
|
|
|
static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle)
|
2009-06-24 08:15:32 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allOrDefault = (aBorderStyle == eBorderStyle_all ||
|
2009-06-27 06:58:03 -07:00
|
|
|
aBorderStyle == eBorderStyle_default);
|
2009-06-24 08:15:32 -07:00
|
|
|
|
2009-06-27 06:58:03 -07:00
|
|
|
/* Apple's docs on NSWindow styles say that "a window's style mask should
|
|
|
|
* include NSTitledWindowMask if it includes any of the others [besides
|
|
|
|
* NSBorderlessWindowMask]". This implies that a borderless window
|
|
|
|
* shouldn't have any other styles than NSBorderlessWindowMask.
|
|
|
|
*/
|
|
|
|
if (!allOrDefault && !(aBorderStyle & eBorderStyle_title))
|
|
|
|
return NSBorderlessWindowMask;
|
2009-06-24 08:15:32 -07:00
|
|
|
|
2009-10-17 21:05:42 -07:00
|
|
|
unsigned int mask = NSTitledWindowMask;
|
2009-06-27 06:58:03 -07:00
|
|
|
if (allOrDefault || aBorderStyle & eBorderStyle_close)
|
|
|
|
mask |= NSClosableWindowMask;
|
2009-10-17 21:05:42 -07:00
|
|
|
if (allOrDefault || aBorderStyle & eBorderStyle_minimize)
|
|
|
|
mask |= NSMiniaturizableWindowMask;
|
2009-06-27 06:58:03 -07:00
|
|
|
if (allOrDefault || aBorderStyle & eBorderStyle_resizeh)
|
|
|
|
mask |= NSResizableWindowMask;
|
2009-06-24 08:15:32 -07:00
|
|
|
|
2009-06-27 06:58:03 -07:00
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2010-09-18 04:28:50 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::ReparentNativeWidget(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
// If aRectIsFrameRect, aRect specifies the frame rect of the new window.
|
|
|
|
// Otherwise, aRect.x/y specify the position of the window's frame relative to
|
|
|
|
// the bottom of the menubar and aRect.width/height specify the size of the
|
|
|
|
// content rect.
|
|
|
|
nsresult nsCocoaWindow::CreateNativeWindow(const NSRect &aRect,
|
|
|
|
nsBorderStyle aBorderStyle,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRectIsFrameRect)
|
2009-06-27 06:58:03 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
2009-06-24 08:15:32 -07:00
|
|
|
|
2009-06-27 06:58:03 -07:00
|
|
|
// We default to NSBorderlessWindowMask, add features if needed.
|
2009-06-24 08:15:32 -07:00
|
|
|
unsigned int features = NSBorderlessWindowMask;
|
|
|
|
|
2009-06-27 06:58:03 -07:00
|
|
|
// Configure the window we will create based on the window type.
|
2009-06-24 08:15:32 -07:00
|
|
|
switch (mWindowType)
|
|
|
|
{
|
|
|
|
case eWindowType_invisible:
|
|
|
|
case eWindowType_child:
|
2009-09-24 02:32:20 -07:00
|
|
|
case eWindowType_plugin:
|
2010-07-27 06:38:03 -07:00
|
|
|
break;
|
2009-06-27 06:58:03 -07:00
|
|
|
case eWindowType_popup:
|
2010-07-27 06:38:03 -07:00
|
|
|
if (aBorderStyle != eBorderStyle_default && mBorderStyle & eBorderStyle_title) {
|
|
|
|
features |= NSTitledWindowMask;
|
2010-07-27 06:38:04 -07:00
|
|
|
if (aBorderStyle & eBorderStyle_close) {
|
|
|
|
features |= NSClosableWindowMask;
|
|
|
|
}
|
2010-07-27 06:38:03 -07:00
|
|
|
}
|
2009-06-24 08:15:32 -07:00
|
|
|
break;
|
2009-06-27 06:58:03 -07:00
|
|
|
case eWindowType_toplevel:
|
2009-06-24 08:15:32 -07:00
|
|
|
case eWindowType_dialog:
|
2009-06-27 06:58:03 -07:00
|
|
|
features = WindowMaskForBorderStyle(aBorderStyle);
|
2009-06-24 08:15:32 -07:00
|
|
|
break;
|
|
|
|
case eWindowType_sheet:
|
|
|
|
nsWindowType parentType;
|
|
|
|
mParent->GetWindowType(parentType);
|
|
|
|
if (parentType != eWindowType_invisible &&
|
|
|
|
aBorderStyle & eBorderStyle_resizeh) {
|
|
|
|
features = NSResizableWindowMask;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
features = NSMiniaturizableWindowMask;
|
|
|
|
}
|
|
|
|
features |= NSTitledWindowMask;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unhandled window type!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-10-19 08:47:58 -07:00
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
NSRect contentRect;
|
2009-06-24 08:15:32 -07:00
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
if (aRectIsFrameRect) {
|
|
|
|
contentRect = [NSWindow contentRectForFrameRect:aRect styleMask:features];
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We pass a content area rect to initialize the native Cocoa window. The
|
|
|
|
* content rect we give is the same size as the size we're given by gecko.
|
|
|
|
* The origin we're given for non-popup windows is moved down by the height
|
|
|
|
* of the menu bar so that an origin of (0,100) from gecko puts the window
|
|
|
|
* 100 pixels below the top of the available desktop area. We also move the
|
|
|
|
* origin down by the height of a title bar if it exists. This is so the
|
|
|
|
* origin that gecko gives us for the top-left of the window turns out to
|
|
|
|
* be the top-left of the window we create. This is how it was done in
|
|
|
|
* Carbon. If it ought to be different we'll probably need to look at all
|
|
|
|
* the callers.
|
|
|
|
*
|
|
|
|
* Note: This means that if you put a secondary screen on top of your main
|
|
|
|
* screen and open a window in the top screen, it'll be incorrectly shifted
|
|
|
|
* down by the height of the menu bar. Same thing would happen in Carbon.
|
|
|
|
*
|
|
|
|
* Note: If you pass a rect with 0,0 for an origin, the window ends up in a
|
|
|
|
* weird place for some reason. This stops that without breaking popups.
|
|
|
|
*/
|
|
|
|
// Compensate for difference between frame and content area height (e.g. title bar).
|
|
|
|
NSRect newWindowFrame = [NSWindow frameRectForContentRect:aRect styleMask:features];
|
|
|
|
|
|
|
|
contentRect = aRect;
|
|
|
|
contentRect.origin.y -= (newWindowFrame.size.height - aRect.size.height);
|
|
|
|
|
|
|
|
if (mWindowType != eWindowType_popup)
|
2009-08-12 15:32:41 -07:00
|
|
|
contentRect.origin.y -= [[NSApp mainMenu] menuBarHeight];
|
2009-07-22 01:57:39 -07:00
|
|
|
}
|
2009-06-24 08:15:32 -07:00
|
|
|
|
|
|
|
// NSLog(@"Top-level window being created at Cocoa rect: %f, %f, %f, %f\n",
|
|
|
|
// rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
Class windowClass = [BaseWindow class];
|
2009-06-24 08:15:32 -07:00
|
|
|
// If we have a titlebar on a top-level window, we want to be able to control the
|
|
|
|
// titlebar color (for unified windows), so use the special ToolbarWindow class.
|
|
|
|
// Note that we need to check the window type because we mark sheets as
|
|
|
|
// having titlebars.
|
2009-08-03 15:39:45 -07:00
|
|
|
if ((mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog) &&
|
2009-06-24 08:15:32 -07:00
|
|
|
(features & NSTitledWindowMask))
|
|
|
|
windowClass = [ToolbarWindow class];
|
|
|
|
// If we're a popup window we need to use the PopupWindow class.
|
|
|
|
else if (mWindowType == eWindowType_popup)
|
|
|
|
windowClass = [PopupWindow class];
|
|
|
|
// If we're a non-popup borderless window we need to use the
|
|
|
|
// BorderlessWindow class.
|
|
|
|
else if (features == NSBorderlessWindowMask)
|
|
|
|
windowClass = [BorderlessWindow class];
|
|
|
|
|
|
|
|
// Create the window
|
2009-07-22 01:57:39 -07:00
|
|
|
mWindow = [[windowClass alloc] initWithContentRect:contentRect styleMask:features
|
2009-06-24 08:15:32 -07:00
|
|
|
backing:NSBackingStoreBuffered defer:YES];
|
|
|
|
|
2012-10-16 12:41:20 -07:00
|
|
|
// setup our notification delegate. Note that setDelegate: does NOT retain.
|
|
|
|
mDelegate = [[WindowDelegate alloc] initWithGeckoWindow:this];
|
|
|
|
[mWindow setDelegate:mDelegate];
|
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
// Make sure that the content rect we gave has been honored.
|
|
|
|
NSRect wantedFrame = [mWindow frameRectForContentRect:contentRect];
|
|
|
|
if (!NSEqualRects([mWindow frame], wantedFrame)) {
|
|
|
|
// This can happen when the window is not on the primary screen.
|
|
|
|
[mWindow setFrame:wantedFrame display:NO];
|
|
|
|
}
|
2010-12-21 03:42:47 -08:00
|
|
|
UpdateBounds();
|
2009-07-22 01:57:39 -07:00
|
|
|
|
2009-06-24 08:15:32 -07:00
|
|
|
if (mWindowType == eWindowType_invisible) {
|
|
|
|
[mWindow setLevel:kCGDesktopWindowLevelKey];
|
2009-06-30 11:41:56 -07:00
|
|
|
} else if (mWindowType == eWindowType_popup) {
|
2010-07-27 06:38:03 -07:00
|
|
|
SetPopupWindowLevel();
|
2009-06-30 11:41:56 -07:00
|
|
|
[mWindow setHasShadow:YES];
|
2009-06-24 08:15:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-08 15:06:15 -07:00
|
|
|
[mWindow setBackgroundColor:[NSColor clearColor]];
|
|
|
|
[mWindow setOpaque:NO];
|
2009-06-24 08:15:32 -07:00
|
|
|
[mWindow setContentMinSize:NSMakeSize(60, 60)];
|
2009-07-21 05:36:56 -07:00
|
|
|
[mWindow disableCursorRects];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
[[WindowDataMap sharedWindowDataMap] ensureDataForWindow:mWindow];
|
2011-09-30 17:20:33 -07:00
|
|
|
mWindowMadeHere = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-06-24 08:15:32 -07:00
|
|
|
return NS_OK;
|
2007-10-29 21:03:42 -07:00
|
|
|
|
2009-06-24 08:15:32 -07:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
2009-06-17 11:13:12 -07:00
|
|
|
|
2009-06-24 08:15:32 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::CreatePopupContentView(const nsIntRect &aRect,
|
2011-10-25 08:05:32 -07:00
|
|
|
nsDeviceContext *aContext)
|
2009-06-24 08:15:32 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
// We need to make our content view a ChildView.
|
|
|
|
mPopupContentView = new nsChildView();
|
|
|
|
if (!mPopupContentView)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ADDREF(mPopupContentView);
|
|
|
|
|
|
|
|
nsIWidget* thisAsWidget = static_cast<nsIWidget*>(this);
|
2012-08-15 11:53:09 -07:00
|
|
|
mPopupContentView->Create(thisAsWidget, nullptr, aRect, aContext, nullptr);
|
2009-06-24 08:15:32 -07:00
|
|
|
|
|
|
|
ChildView* newContentView = (ChildView*)mPopupContentView->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
[mWindow setContentView:newContentView];
|
2009-06-17 11:13:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::Destroy()
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->Destroy();
|
|
|
|
|
|
|
|
nsBaseWidget::Destroy();
|
2009-03-09 09:59:29 -07:00
|
|
|
nsBaseWidget::OnDestroy();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (mFullScreen) {
|
|
|
|
// On Lion we don't have to mess with the OS chrome when in Full Screen
|
|
|
|
// mode. But we do have to destroy the native window here (and not wait
|
|
|
|
// for that to happen in our destructor). We don't switch away from the
|
|
|
|
// native window's space until the window is destroyed, and otherwise this
|
|
|
|
// might not happen for several seconds (because at least one object
|
|
|
|
// holding a reference to ourselves is usually waiting to be garbage-
|
|
|
|
// collected). See bug 757618.
|
|
|
|
if (mUsesNativeFullScreen) {
|
|
|
|
DestroyNativeWindow();
|
|
|
|
} else if (mWindow) {
|
|
|
|
nsCocoaUtils::HideOSChromeOnScreen(false, [mWindow screen]);
|
|
|
|
}
|
2011-02-09 13:27:24 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-05-02 04:32:50 -07:00
|
|
|
nsIWidget* nsCocoaWindow::GetSheetWindowParent(void)
|
|
|
|
{
|
|
|
|
if (mWindowType != eWindowType_sheet)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-05-02 04:32:50 -07:00
|
|
|
nsCocoaWindow *parent = static_cast<nsCocoaWindow*>(mParent);
|
|
|
|
while (parent && (parent->mWindowType == eWindowType_sheet))
|
|
|
|
parent = static_cast<nsCocoaWindow*>(parent->mParent);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void* nsCocoaWindow::GetNativeData(uint32_t aDataType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSNULL;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
void* retVal = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aDataType) {
|
|
|
|
// to emulate how windows works, we always have to return a NSView
|
|
|
|
// for NS_NATIVE_WIDGET
|
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
case NS_NATIVE_DISPLAY:
|
|
|
|
retVal = [mWindow contentView];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
retVal = mWindow;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_GRAPHIC:
|
|
|
|
// There isn't anything that makes sense to return here,
|
2012-07-30 07:20:58 -07:00
|
|
|
// and it doesn't matter so just return nullptr.
|
2009-08-14 07:09:00 -07:00
|
|
|
NS_ERROR("Requesting NS_NATIVE_GRAPHIC on a top-level window!");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-19 01:57:50 -07:00
|
|
|
bool nsCocoaWindow::IsVisible() const
|
2011-01-17 23:24:19 -08:00
|
|
|
{
|
2012-07-19 01:57:50 -07:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
2011-01-26 22:54:58 -08:00
|
|
|
|
2012-07-19 01:57:50 -07:00
|
|
|
return (mWindow && ([mWindow isVisible] || mSheetNeedsShow));
|
2011-01-26 22:54:58 -08:00
|
|
|
|
2012-07-19 01:57:50 -07:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetModal(bool aState)
|
2007-09-19 12:17:06 -07:00
|
|
|
{
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-04-14 13:13:56 -07:00
|
|
|
// This is used during startup (outside the event loop) when creating
|
|
|
|
// the add-ons compatibility checking dialog and the profile manager UI;
|
|
|
|
// therefore, it needs to provide an autorelease pool to avoid cocoa
|
|
|
|
// objects leaking.
|
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2007-09-19 12:17:06 -07:00
|
|
|
mModal = aState;
|
2008-03-23 15:30:56 -07:00
|
|
|
nsCocoaWindow *aParent = static_cast<nsCocoaWindow*>(mParent);
|
2007-09-19 12:17:06 -07:00
|
|
|
if (aState) {
|
|
|
|
++gXULModalLevel;
|
2009-03-18 15:51:40 -07:00
|
|
|
if (gCocoaAppModalWindowList)
|
|
|
|
gCocoaAppModalWindowList->PushGecko(mWindow, this);
|
2008-05-01 08:50:23 -07:00
|
|
|
// When a non-sheet window gets "set modal", make the window(s) that it
|
|
|
|
// appears over behave as they should. We can't rely on native methods to
|
|
|
|
// do this, for the following reason: The OS runs modal non-sheet windows
|
|
|
|
// in an event loop (using [NSApplication runModalForWindow:] or similar
|
|
|
|
// methods) that's incompatible with the modal event loop in nsXULWindow::
|
|
|
|
// ShowModal() (each of these event loops is "exclusive", and can't run at
|
|
|
|
// the same time as other (similar) event loops).
|
|
|
|
if (mWindowType != eWindowType_sheet) {
|
|
|
|
while (aParent) {
|
|
|
|
if (aParent->mNumModalDescendents++ == 0) {
|
|
|
|
NSWindow *aWindow = aParent->GetCocoaWindow();
|
|
|
|
if (aParent->mWindowType != eWindowType_invisible) {
|
|
|
|
[[aWindow standardWindowButton:NSWindowCloseButton] setEnabled:NO];
|
|
|
|
[[aWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled:NO];
|
|
|
|
[[aWindow standardWindowButton:NSWindowZoomButton] setEnabled:NO];
|
|
|
|
}
|
2008-03-23 15:30:56 -07:00
|
|
|
}
|
2008-05-01 08:50:23 -07:00
|
|
|
aParent = static_cast<nsCocoaWindow*>(aParent->mParent);
|
2008-03-23 15:30:56 -07:00
|
|
|
}
|
|
|
|
[mWindow setLevel:NSModalPanelWindowLevel];
|
|
|
|
nsCocoaWindowList *windowList = new nsCocoaWindowList;
|
|
|
|
if (windowList) {
|
|
|
|
windowList->window = this; // Don't ADDREF
|
2009-03-18 15:51:40 -07:00
|
|
|
windowList->prev = gGeckoAppModalWindowList;
|
|
|
|
gGeckoAppModalWindowList = windowList;
|
2008-03-23 15:30:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-09-19 12:17:06 -07:00
|
|
|
--gXULModalLevel;
|
2011-09-30 17:20:33 -07:00
|
|
|
NS_ASSERTION(gXULModalLevel >= 0, "Mismatched call to nsCocoaWindow::SetModal(false)!");
|
2009-03-18 15:51:40 -07:00
|
|
|
if (gCocoaAppModalWindowList)
|
|
|
|
gCocoaAppModalWindowList->PopGecko(mWindow, this);
|
2008-05-01 08:50:23 -07:00
|
|
|
if (mWindowType != eWindowType_sheet) {
|
|
|
|
while (aParent) {
|
|
|
|
if (--aParent->mNumModalDescendents == 0) {
|
|
|
|
NSWindow *aWindow = aParent->GetCocoaWindow();
|
|
|
|
if (aParent->mWindowType != eWindowType_invisible) {
|
|
|
|
[[aWindow standardWindowButton:NSWindowCloseButton] setEnabled:YES];
|
|
|
|
[[aWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled:YES];
|
|
|
|
[[aWindow standardWindowButton:NSWindowZoomButton] setEnabled:YES];
|
|
|
|
}
|
2008-03-23 15:30:56 -07:00
|
|
|
}
|
2008-05-01 08:50:23 -07:00
|
|
|
NS_ASSERTION(aParent->mNumModalDescendents >= 0, "Widget hierarchy changed while modal!");
|
|
|
|
aParent = static_cast<nsCocoaWindow*>(aParent->mParent);
|
2008-03-23 15:30:56 -07:00
|
|
|
}
|
2009-03-18 15:51:40 -07:00
|
|
|
if (gGeckoAppModalWindowList) {
|
|
|
|
NS_ASSERTION(gGeckoAppModalWindowList->window == this, "Widget hierarchy changed while modal!");
|
|
|
|
nsCocoaWindowList *saved = gGeckoAppModalWindowList;
|
|
|
|
gGeckoAppModalWindowList = gGeckoAppModalWindowList->prev;
|
2008-03-23 15:30:56 -07:00
|
|
|
delete saved; // "window" not ADDREFed
|
|
|
|
}
|
|
|
|
if (mWindowType == eWindowType_popup)
|
2010-07-27 06:38:03 -07:00
|
|
|
SetPopupWindowLevel();
|
2008-03-23 15:30:56 -07:00
|
|
|
else
|
|
|
|
[mWindow setLevel:NSNormalWindowLevel];
|
|
|
|
}
|
2007-09-19 12:17:06 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Hide or show this window
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Show(bool bState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-02-26 11:32:19 -08:00
|
|
|
// We need to re-execute sometimes in order to bring already-visible
|
|
|
|
// windows forward.
|
2011-01-26 22:54:58 -08:00
|
|
|
if (!mSheetNeedsShow && !bState && ![mWindow isVisible])
|
2008-02-19 18:30:24 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIWidget* parentWidget = mParent;
|
|
|
|
nsCOMPtr<nsPIWidgetCocoa> piParentWidget(do_QueryInterface(parentWidget));
|
|
|
|
NSWindow* nativeParentWindow = (parentWidget) ?
|
|
|
|
(NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW) : nil;
|
2008-02-19 18:30:24 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (bState && !mBounds.IsEmpty()) {
|
|
|
|
if (mWindowType == eWindowType_sheet) {
|
|
|
|
// bail if no parent window (its basically what we do in Carbon)
|
2011-01-26 22:54:58 -08:00
|
|
|
if (!nativeParentWindow || !piParentWidget)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NSWindow* topNonSheetWindow = nativeParentWindow;
|
|
|
|
|
|
|
|
// If this sheet is the child of another sheet, hide the parent so that
|
|
|
|
// this sheet can be displayed. Leave the parent mSheetNeedsShow alone,
|
|
|
|
// that is only used to handle sibling sheet contention. The parent will
|
|
|
|
// return once there are no more child sheets.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool parentIsSheet = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(piParentWidget->GetIsSheet(&parentIsSheet)) &&
|
|
|
|
parentIsSheet) {
|
|
|
|
piParentWidget->GetSheetWindowParent(&topNonSheetWindow);
|
|
|
|
[NSApp endSheet:nativeParentWindow];
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsCocoaWindow* sheetShown = nullptr;
|
2011-09-30 17:20:33 -07:00
|
|
|
if (NS_SUCCEEDED(piParentWidget->GetChildSheet(true, &sheetShown)) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(!sheetShown || sheetShown == this)) {
|
|
|
|
// If this sheet is already the sheet actually being shown, don't
|
|
|
|
// tell it to show again. Otherwise the number of calls to
|
|
|
|
// [NSApp beginSheet...] won't match up with [NSApp endSheet...].
|
2008-02-21 17:47:14 -08:00
|
|
|
if (![mWindow isVisible]) {
|
2011-09-30 17:20:33 -07:00
|
|
|
mSheetNeedsShow = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
mSheetWindowParent = topNonSheetWindow;
|
2008-05-07 14:15:57 -07:00
|
|
|
// Only set contextInfo if our parent isn't a sheet.
|
|
|
|
NSWindow* contextInfo = parentIsSheet ? nil : mSheetWindowParent;
|
2008-05-02 03:40:49 -07:00
|
|
|
[TopLevelWindowData deactivateInWindow:mSheetWindowParent];
|
2007-03-22 10:30:00 -07:00
|
|
|
[NSApp beginSheet:mWindow
|
|
|
|
modalForWindow:mSheetWindowParent
|
|
|
|
modalDelegate:mDelegate
|
|
|
|
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
2008-05-07 14:15:57 -07:00
|
|
|
contextInfo:contextInfo];
|
2008-05-02 03:40:49 -07:00
|
|
|
[TopLevelWindowData activateInWindow:mWindow];
|
2007-03-22 10:30:00 -07:00
|
|
|
SendSetZLevelEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// A sibling of this sheet is active, don't show this sheet yet.
|
|
|
|
// When the active sheet hides, its brothers and sisters that have
|
|
|
|
// mSheetNeedsShow set will have their opportunities to display.
|
2011-09-30 17:20:33 -07:00
|
|
|
mSheetNeedsShow = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mWindowType == eWindowType_popup) {
|
2007-07-17 13:29:39 -07:00
|
|
|
// If a popup window is shown after being hidden, it needs to be "reset"
|
|
|
|
// for it to receive any mouse events aside from mouse-moved events
|
|
|
|
// (because it was removed from the "window cache" when it was hidden
|
|
|
|
// -- see below). Setting the window number to -1 and then back to its
|
|
|
|
// original value seems to accomplish this. The idea was "borrowed"
|
|
|
|
// from the Java Embedding Plugin.
|
2009-09-24 21:00:28 -07:00
|
|
|
NSInteger windowNumber = [mWindow windowNumber];
|
2007-07-17 13:29:39 -07:00
|
|
|
[mWindow _setWindowNumber:-1];
|
|
|
|
[mWindow _setWindowNumber:windowNumber];
|
2009-01-29 13:57:59 -08:00
|
|
|
// For reasons that aren't yet clear, calls to [NSWindow orderFront:] or
|
|
|
|
// [NSWindow makeKeyAndOrderFront:] can sometimes trigger "Error (1000)
|
|
|
|
// creating CGSWindow", which in turn triggers an internal inconsistency
|
|
|
|
// NSException. These errors shouldn't be fatal. So we need to wrap
|
|
|
|
// calls to ...orderFront: in LOGONLY blocks. See bmo bug 470864.
|
|
|
|
NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
[mWindow orderFront:nil];
|
2009-01-29 13:57:59 -08:00
|
|
|
NS_OBJC_END_TRY_LOGONLY_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
SendSetZLevelEvent();
|
2009-12-30 07:24:08 -08:00
|
|
|
AdjustWindowShadow();
|
2010-01-13 08:10:25 -08:00
|
|
|
SetUpWindowFilter();
|
2007-07-17 13:29:39 -07:00
|
|
|
// If our popup window is a non-native context menu, tell the OS (and
|
|
|
|
// other programs) that a menu has opened. This is how the OS knows to
|
|
|
|
// close other programs' context menus when ours open.
|
|
|
|
if ([mWindow isKindOfClass:[PopupWindow class]] &&
|
|
|
|
[(PopupWindow*) mWindow isContextMenu]) {
|
|
|
|
[[NSDistributedNotificationCenter defaultCenter]
|
|
|
|
postNotificationName:@"com.apple.HIToolbox.beginMenuTrackingNotification"
|
|
|
|
object:@"org.mozilla.gecko.PopupWindow"];
|
|
|
|
}
|
2007-11-28 12:18:11 -08:00
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// If a parent window was supplied and this is a popup at the parent
|
|
|
|
// level, set its child window. This will cause the child window to
|
|
|
|
// appear above the parent and move when the parent does. Setting this
|
|
|
|
// needs to happen after the _setWindowNumber calls above, otherwise the
|
|
|
|
// window doesn't focus properly.
|
|
|
|
if (nativeParentWindow && mPopupLevel == ePopupLevelParent)
|
2007-11-28 12:18:11 -08:00
|
|
|
[nativeParentWindow addChildWindow:mWindow
|
|
|
|
ordered:NSWindowAbove];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2009-01-29 13:57:59 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK;
|
2012-02-16 19:47:39 -08:00
|
|
|
if (mWindowType == eWindowType_toplevel &&
|
|
|
|
[mWindow respondsToSelector:@selector(setAnimationBehavior:)]) {
|
|
|
|
NSWindowAnimationBehavior behavior;
|
|
|
|
if (mIsAnimationSuppressed) {
|
|
|
|
behavior = NSWindowAnimationBehaviorNone;
|
|
|
|
} else {
|
|
|
|
switch (mAnimationType) {
|
|
|
|
case nsIWidget::eDocumentWindowAnimation:
|
|
|
|
behavior = NSWindowAnimationBehaviorDocumentWindow;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unexpected mAnimationType value");
|
|
|
|
// fall through
|
|
|
|
case nsIWidget::eGenericWindowAnimation:
|
|
|
|
behavior = NSWindowAnimationBehaviorDefault;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[mWindow setAnimationBehavior:behavior];
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
[mWindow makeKeyAndOrderFront:nil];
|
2009-01-29 13:57:59 -08:00
|
|
|
NS_OBJC_END_TRY_LOGONLY_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
SendSetZLevelEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// roll up any popups if a top-level window is going away
|
2009-08-03 15:39:45 -07:00
|
|
|
if (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog)
|
2007-06-12 13:26:24 -07:00
|
|
|
RollUpPopups();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// now get rid of the window/sheet
|
|
|
|
if (mWindowType == eWindowType_sheet) {
|
2008-02-19 18:30:24 -08:00
|
|
|
if (mSheetNeedsShow) {
|
|
|
|
// This is an attempt to hide a sheet that never had a chance to
|
|
|
|
// be shown. There's nothing to do other than make sure that it
|
|
|
|
// won't show.
|
2011-09-30 17:20:33 -07:00
|
|
|
mSheetNeedsShow = false;
|
2008-02-19 18:30:24 -08:00
|
|
|
}
|
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
// get sheet's parent *before* hiding the sheet (which breaks the linkage)
|
|
|
|
NSWindow* sheetParent = mSheetWindowParent;
|
|
|
|
|
|
|
|
// hide the sheet
|
|
|
|
[NSApp endSheet:mWindow];
|
|
|
|
|
2008-05-02 03:40:49 -07:00
|
|
|
[TopLevelWindowData deactivateInWindow:mWindow];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsCocoaWindow* siblingSheetToShow = nullptr;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool parentIsSheet = false;
|
2008-02-19 18:30:24 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nativeParentWindow && piParentWidget &&
|
2011-09-30 17:20:33 -07:00
|
|
|
NS_SUCCEEDED(piParentWidget->GetChildSheet(false, &siblingSheetToShow)) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
siblingSheetToShow) {
|
|
|
|
// First, give sibling sheets an opportunity to show.
|
2011-09-30 17:20:33 -07:00
|
|
|
siblingSheetToShow->Show(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (nativeParentWindow && piParentWidget &&
|
|
|
|
NS_SUCCEEDED(piParentWidget->GetIsSheet(&parentIsSheet)) &&
|
|
|
|
parentIsSheet) {
|
2008-05-07 14:15:57 -07:00
|
|
|
// Only set contextInfo if the parent of the parent sheet we're about
|
|
|
|
// to restore isn't itself a sheet.
|
|
|
|
NSWindow* contextInfo = sheetParent;
|
|
|
|
nsIWidget* grandparentWidget = nil;
|
|
|
|
if (NS_SUCCEEDED(piParentWidget->GetRealParent(&grandparentWidget)) && grandparentWidget) {
|
|
|
|
nsCOMPtr<nsPIWidgetCocoa> piGrandparentWidget(do_QueryInterface(grandparentWidget));
|
2011-09-28 23:19:26 -07:00
|
|
|
bool grandparentIsSheet = false;
|
2008-05-07 14:15:57 -07:00
|
|
|
if (piGrandparentWidget && NS_SUCCEEDED(piGrandparentWidget->GetIsSheet(&grandparentIsSheet)) &&
|
|
|
|
grandparentIsSheet) {
|
|
|
|
contextInfo = nil;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
// If there are no sibling sheets, but the parent is a sheet, restore
|
|
|
|
// it. It wasn't sent any deactivate events when it was hidden, so
|
|
|
|
// don't call through Show, just let the OS put it back up.
|
|
|
|
[NSApp beginSheet:nativeParentWindow
|
|
|
|
modalForWindow:sheetParent
|
|
|
|
modalDelegate:[nativeParentWindow delegate]
|
|
|
|
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
2008-05-07 14:15:57 -07:00
|
|
|
contextInfo:contextInfo];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Sheet, that was hard. No more siblings or parents, going back
|
|
|
|
// to a real window.
|
2009-01-29 13:57:59 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
[sheetParent makeKeyAndOrderFront:nil];
|
2009-01-29 13:57:59 -08:00
|
|
|
NS_OBJC_END_TRY_LOGONLY_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
SendSetZLevelEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-12-05 11:19:08 -08:00
|
|
|
// If the window is a popup window with a parent window we need to
|
|
|
|
// unhook it here before ordering it out. When you order out the child
|
|
|
|
// of a window it hides the parent window.
|
|
|
|
if (mWindowType == eWindowType_popup && nativeParentWindow)
|
|
|
|
[nativeParentWindow removeChildWindow:mWindow];
|
|
|
|
|
2010-01-13 08:10:25 -08:00
|
|
|
CleanUpWindowFilter();
|
2007-03-22 10:30:00 -07:00
|
|
|
[mWindow orderOut:nil];
|
2007-07-17 13:29:39 -07:00
|
|
|
// Unless it's explicitly removed from NSApp's "window cache", a popup
|
|
|
|
// window will keep receiving mouse-moved events even after it's been
|
|
|
|
// "ordered out" (instead of the browser window that was underneath it,
|
|
|
|
// until you click on that window). This is bmo bug 378645, but it's
|
|
|
|
// surely an Apple bug. The "window cache" is an undocumented subsystem,
|
|
|
|
// all of whose methods are included in the NSWindowCache category of
|
|
|
|
// the NSApplication class (in header files generated using class-dump).
|
|
|
|
// This workaround was "borrowed" from the Java Embedding Plugin (which
|
|
|
|
// uses it for a different purpose).
|
2009-07-20 12:44:25 -07:00
|
|
|
if (mWindowType == eWindowType_popup)
|
2007-07-17 13:29:39 -07:00
|
|
|
[NSApp _removeWindowFromCache:mWindow];
|
2007-11-28 12:18:11 -08:00
|
|
|
|
2007-07-17 13:29:39 -07:00
|
|
|
// If our popup window is a non-native context menu, tell the OS (and
|
|
|
|
// other programs) that a menu has closed.
|
|
|
|
if ([mWindow isKindOfClass:[PopupWindow class]] &&
|
|
|
|
[(PopupWindow*) mWindow isContextMenu]) {
|
|
|
|
[[NSDistributedNotificationCenter defaultCenter]
|
|
|
|
postNotificationName:@"com.apple.HIToolbox.endMenuTrackingNotification"
|
|
|
|
object:@"org.mozilla.gecko.PopupWindow"];
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-01-26 22:54:58 -08:00
|
|
|
|
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->Show(bState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-30 07:24:08 -08:00
|
|
|
struct ShadowParams {
|
|
|
|
float standardDeviation;
|
|
|
|
float density;
|
|
|
|
int offsetX;
|
|
|
|
int offsetY;
|
|
|
|
unsigned int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
// These numbers have been determined by looking at the results of
|
|
|
|
// CGSGetWindowShadowAndRimParameters for native window types.
|
|
|
|
static const ShadowParams kWindowShadowParameters[] = {
|
|
|
|
{ 0.0f, 0.0f, 0, 0, 0 }, // none
|
|
|
|
{ 8.0f, 0.5f, 0, 6, 1 }, // default
|
|
|
|
{ 10.0f, 0.44f, 0, 10, 512 }, // menu
|
|
|
|
{ 8.0f, 0.5f, 0, 6, 1 }, // tooltip
|
|
|
|
{ 4.0f, 0.6f, 0, 4, 512 } // sheet
|
|
|
|
};
|
|
|
|
|
|
|
|
// This method will adjust the window shadow style for popup windows after
|
|
|
|
// they have been made visible. Before they're visible, their window number
|
|
|
|
// might be -1, which is not useful.
|
|
|
|
// We won't attempt to change the shadow for windows that can acquire key state
|
|
|
|
// since OS X will reset the shadow whenever that happens.
|
|
|
|
void
|
|
|
|
nsCocoaWindow::AdjustWindowShadow()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow || ![mWindow isVisible] || ![mWindow hasShadow] ||
|
2009-12-30 07:24:08 -08:00
|
|
|
[mWindow canBecomeKeyWindow] || [mWindow windowNumber] == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const ShadowParams& params = kWindowShadowParameters[mShadowStyle];
|
|
|
|
CGSConnection cid = _CGSDefaultConnection();
|
|
|
|
CGSSetWindowShadowAndRimParameters(cid, [mWindow windowNumber],
|
|
|
|
params.standardDeviation, params.density,
|
|
|
|
params.offsetX, params.offsetY,
|
|
|
|
params.flags);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2010-01-13 08:10:25 -08:00
|
|
|
void
|
|
|
|
nsCocoaWindow::SetUpWindowFilter()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow || ![mWindow isVisible] || [mWindow windowNumber] == -1)
|
2010-01-13 08:10:25 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
CleanUpWindowFilter();
|
|
|
|
|
2010-03-08 04:38:17 -08:00
|
|
|
// Only blur the background of menus and fake sheets, but not on PPC
|
|
|
|
// because it results in blank windows (bug 547723).
|
|
|
|
#ifndef __ppc__
|
2010-01-13 08:10:25 -08:00
|
|
|
if (mShadowStyle != NS_STYLE_WINDOW_SHADOW_MENU &&
|
|
|
|
mShadowStyle != NS_STYLE_WINDOW_SHADOW_SHEET)
|
2010-03-08 04:38:17 -08:00
|
|
|
#endif
|
2010-01-13 08:10:25 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a CoreImage filter and set it up
|
|
|
|
CGSConnection cid = _CGSDefaultConnection();
|
|
|
|
CGSNewCIFilterByName(cid, (CFStringRef)@"CIGaussianBlur", &mWindowFilter);
|
|
|
|
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:2.0] forKey:@"inputRadius"];
|
|
|
|
CGSSetCIFilterValuesFromDictionary(cid, mWindowFilter, (CFDictionaryRef)options);
|
|
|
|
|
|
|
|
// Now apply the filter to the window
|
|
|
|
NSInteger compositingType = 1 << 0; // Under the window
|
|
|
|
CGSAddWindowFilter(cid, [mWindow windowNumber], mWindowFilter, compositingType);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCocoaWindow::CleanUpWindowFilter()
|
|
|
|
{
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow || !mWindowFilter || [mWindow windowNumber] == -1)
|
2010-01-13 08:10:25 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
CGSConnection cid = _CGSDefaultConnection();
|
|
|
|
CGSRemoveWindowFilter(cid, [mWindow windowNumber], mWindowFilter);
|
|
|
|
CGSReleaseCIFilter(cid, mWindowFilter);
|
|
|
|
mWindowFilter = 0;
|
|
|
|
}
|
|
|
|
|
2009-07-21 17:44:55 -07:00
|
|
|
nsresult
|
|
|
|
nsCocoaWindow::ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
|
|
|
|
{
|
2009-07-21 17:45:13 -07:00
|
|
|
if (mPopupContentView) {
|
|
|
|
mPopupContentView->ConfigureChildren(aConfigurations);
|
2009-07-21 17:44:55 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2009-07-21 17:45:13 -07:00
|
|
|
}
|
|
|
|
|
2011-03-23 11:46:57 -07:00
|
|
|
LayerManager*
|
2011-08-09 12:38:26 -07:00
|
|
|
nsCocoaWindow::GetLayerManager(PLayersChild* aShadowManager,
|
|
|
|
LayersBackend aBackendHint,
|
|
|
|
LayerManagerPersistence aPersistence,
|
|
|
|
bool* aAllowRetaining)
|
2011-03-23 11:46:57 -07:00
|
|
|
{
|
|
|
|
if (mPopupContentView) {
|
2011-08-09 12:38:26 -07:00
|
|
|
return mPopupContentView->GetLayerManager(aShadowManager,
|
|
|
|
aBackendHint,
|
|
|
|
aPersistence,
|
|
|
|
aAllowRetaining);
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
nsTransparencyMode nsCocoaWindow::GetTransparencyMode()
|
2007-12-19 11:40:18 -08:00
|
|
|
{
|
2008-08-25 17:02:26 -07:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
return (!mWindow || [mWindow isOpaque]) ? eTransparencyOpaque : eTransparencyTransparent;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2008-08-25 17:02:26 -07:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(eTransparencyOpaque);
|
2007-12-19 11:40:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is called from nsMenuPopupFrame when making a popup transparent.
|
2008-08-12 17:44:14 -07:00
|
|
|
// For other window types, nsChildView::SetTransparencyMode is used.
|
|
|
|
void nsCocoaWindow::SetTransparencyMode(nsTransparencyMode aMode)
|
2007-12-19 11:40:18 -08:00
|
|
|
{
|
2008-08-12 17:44:14 -07:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return;
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
BOOL isTransparent = aMode == eTransparencyTransparent;
|
2007-12-19 11:40:18 -08:00
|
|
|
BOOL currentTransparency = ![mWindow isOpaque];
|
2008-08-12 17:44:14 -07:00
|
|
|
if (isTransparent != currentTransparency) {
|
2009-11-13 14:58:15 -08:00
|
|
|
[mWindow setOpaque:!isTransparent];
|
|
|
|
[mWindow setBackgroundColor:(isTransparent ? [NSColor clearColor] : [NSColor whiteColor])];
|
2007-12-19 11:40:18 -08:00
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-12-19 11:40:18 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Enable(bool aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-22 22:19:08 -07:00
|
|
|
bool nsCocoaWindow::IsEnabled() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-22 22:19:08 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-21 14:13:21 -08:00
|
|
|
#define kWindowPositionSlop 20
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::ConstrainPosition(bool aAllowSlop,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t *aX, int32_t *aY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-21 14:13:21 -08:00
|
|
|
if (!mWindow || ![mWindow screen]) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-18 15:16:50 -07:00
|
|
|
nsIntRect screenBounds;
|
|
|
|
|
2012-10-16 12:41:19 -07:00
|
|
|
int32_t width, height;
|
|
|
|
|
|
|
|
NSRect frame = [mWindow frame];
|
|
|
|
|
|
|
|
// zero size rects confuse the screen manager
|
|
|
|
width = NS_MAX<int32_t>(frame.size.width, 1);
|
|
|
|
height = NS_MAX<int32_t>(frame.size.height, 1);
|
|
|
|
|
2012-05-18 15:16:50 -07:00
|
|
|
nsCOMPtr<nsIScreenManager> screenMgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
|
|
|
if (screenMgr) {
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
screenMgr->ScreenForRect(*aX, *aY, width, height, getter_AddRefs(screen));
|
|
|
|
|
|
|
|
if (screen) {
|
2012-10-16 12:41:19 -07:00
|
|
|
screen->GetRectDisplayPix(&(screenBounds.x), &(screenBounds.y),
|
|
|
|
&(screenBounds.width), &(screenBounds.height));
|
2012-05-18 15:16:50 -07:00
|
|
|
}
|
|
|
|
}
|
2011-12-21 14:13:21 -08:00
|
|
|
|
|
|
|
if (aAllowSlop) {
|
2012-10-16 12:41:19 -07:00
|
|
|
if (*aX < screenBounds.x - width + kWindowPositionSlop) {
|
|
|
|
*aX = screenBounds.x - width + kWindowPositionSlop;
|
2011-12-21 14:13:21 -08:00
|
|
|
} else if (*aX >= screenBounds.x + screenBounds.width - kWindowPositionSlop) {
|
|
|
|
*aX = screenBounds.x + screenBounds.width - kWindowPositionSlop;
|
|
|
|
}
|
|
|
|
|
2012-10-16 12:41:19 -07:00
|
|
|
if (*aY < screenBounds.y - height + kWindowPositionSlop) {
|
|
|
|
*aY = screenBounds.y - height + kWindowPositionSlop;
|
2011-12-21 14:13:21 -08:00
|
|
|
} else if (*aY >= screenBounds.y + screenBounds.height - kWindowPositionSlop) {
|
|
|
|
*aY = screenBounds.y + screenBounds.height - kWindowPositionSlop;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (*aX < screenBounds.x) {
|
|
|
|
*aX = screenBounds.x;
|
2012-10-16 12:41:19 -07:00
|
|
|
} else if (*aX >= screenBounds.x + screenBounds.width - width) {
|
|
|
|
*aX = screenBounds.x + screenBounds.width - width;
|
2011-12-21 14:13:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*aY < screenBounds.y) {
|
|
|
|
*aY = screenBounds.y;
|
2012-10-16 12:41:19 -07:00
|
|
|
} else if (*aY >= screenBounds.y + screenBounds.height - height) {
|
|
|
|
*aY = screenBounds.y + screenBounds.height - height;
|
2011-12-21 14:13:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 17:43:29 -07:00
|
|
|
void nsCocoaWindow::SetSizeConstraints(const SizeConstraints& aConstraints)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
// Popups can be smaller than (60, 60)
|
|
|
|
NSRect rect =
|
|
|
|
(mWindowType == eWindowType_popup) ? NSZeroRect : NSMakeRect(0.0, 0.0, 60, 60);
|
|
|
|
rect = [mWindow frameRectForContentRect:rect];
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
CGFloat scaleFactor = BackingScaleFactor();
|
2012-07-30 17:43:29 -07:00
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
SizeConstraints c = aConstraints;
|
|
|
|
c.mMinSize.width =
|
|
|
|
NS_MAX(nsCocoaUtils::CocoaPointsToDevPixels(rect.size.width, scaleFactor),
|
|
|
|
c.mMinSize.width);
|
|
|
|
c.mMinSize.height =
|
|
|
|
NS_MAX(nsCocoaUtils::CocoaPointsToDevPixels(rect.size.height, scaleFactor),
|
|
|
|
c.mMinSize.height);
|
|
|
|
|
|
|
|
NSSize minSize = {
|
|
|
|
nsCocoaUtils::DevPixelsToCocoaPoints(c.mMinSize.width, scaleFactor),
|
|
|
|
nsCocoaUtils::DevPixelsToCocoaPoints(c.mMinSize.height, scaleFactor)
|
|
|
|
};
|
2012-07-30 17:43:29 -07:00
|
|
|
[mWindow setMinSize:minSize];
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
NSSize maxSize = {
|
|
|
|
c.mMaxSize.width == NS_MAXSIZE ?
|
|
|
|
FLT_MAX : nsCocoaUtils::DevPixelsToCocoaPoints(c.mMaxSize.width, scaleFactor),
|
|
|
|
c.mMaxSize.height == NS_MAXSIZE ?
|
|
|
|
FLT_MAX : nsCocoaUtils::DevPixelsToCocoaPoints(c.mMaxSize.height, scaleFactor)
|
|
|
|
};
|
2012-07-30 17:43:29 -07:00
|
|
|
[mWindow setMaxSize:maxSize];
|
|
|
|
|
|
|
|
nsBaseWidget::SetSizeConstraints(c);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
// Coordinates are global display pixels
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Move(double aX, double aY)
|
2007-11-06 23:36:10 -08:00
|
|
|
{
|
2012-12-06 09:31:34 -08:00
|
|
|
if (!mWindow) {
|
2007-11-06 23:36:10 -08:00
|
|
|
return NS_OK;
|
2012-12-06 09:31:34 -08:00
|
|
|
}
|
2007-11-06 23:36:10 -08:00
|
|
|
|
|
|
|
// The point we have is in Gecko coordinates (origin top-left). Convert
|
|
|
|
// it to Cocoa ones (origin bottom-left).
|
2012-09-29 04:36:09 -07:00
|
|
|
NSPoint coord = {
|
2012-12-06 09:31:34 -08:00
|
|
|
static_cast<float>(aX),
|
2012-12-12 01:57:38 -08:00
|
|
|
static_cast<float>(nsCocoaUtils::FlippedScreenY(NSToIntRound(aY)))
|
2012-09-29 04:36:09 -07:00
|
|
|
};
|
2012-12-06 09:31:34 -08:00
|
|
|
|
|
|
|
NSRect frame = [mWindow frame];
|
|
|
|
if (frame.origin.x != coord.x ||
|
|
|
|
frame.origin.y + frame.size.height != coord.y) {
|
|
|
|
[mWindow setFrameTopLeftPoint:coord];
|
|
|
|
}
|
2007-11-06 23:36:10 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position the window behind the given window
|
|
|
|
NS_METHOD nsCocoaWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIWidget *aWidget, bool aActivate)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_METHOD nsCocoaWindow::SetSizeMode(int32_t aMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-01-31 02:40:03 -08:00
|
|
|
// mSizeMode will be updated in DispatchSizeModeEvent, which will be called
|
|
|
|
// from a delegate method that handles the state change during one of the
|
|
|
|
// calls below.
|
|
|
|
nsSizeMode previousMode = mSizeMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aMode == nsSizeMode_Normal) {
|
2008-09-10 09:57:57 -07:00
|
|
|
if ([mWindow isMiniaturized])
|
|
|
|
[mWindow deminiaturize:nil];
|
|
|
|
else if (previousMode == nsSizeMode_Maximized && [mWindow isZoomed])
|
2007-03-22 10:30:00 -07:00
|
|
|
[mWindow zoom:nil];
|
|
|
|
}
|
|
|
|
else if (aMode == nsSizeMode_Minimized) {
|
|
|
|
if (![mWindow isMiniaturized])
|
|
|
|
[mWindow miniaturize:nil];
|
|
|
|
}
|
|
|
|
else if (aMode == nsSizeMode_Maximized) {
|
|
|
|
if ([mWindow isMiniaturized])
|
|
|
|
[mWindow deminiaturize:nil];
|
|
|
|
if (![mWindow isZoomed])
|
|
|
|
[mWindow zoom:nil];
|
|
|
|
}
|
2012-02-08 11:59:18 -08:00
|
|
|
else if (aMode == nsSizeMode_Fullscreen) {
|
|
|
|
if (!mFullScreen)
|
|
|
|
MakeFullScreen(true);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
// This has to preserve the window's frame bounds.
|
|
|
|
// This method requires (as does the Windows impl.) that you call Resize shortly
|
|
|
|
// after calling HideWindowChrome. See bug 498835 for fixing this.
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::HideWindowChrome(bool aShouldHide)
|
2009-07-22 01:57:39 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow || !mWindowMadeHere ||
|
2009-07-22 01:57:39 -07:00
|
|
|
(mWindowType != eWindowType_toplevel && mWindowType != eWindowType_dialog))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
BOOL isVisible = [mWindow isVisible];
|
|
|
|
|
|
|
|
// Remove child windows.
|
|
|
|
NSArray* childWindows = [mWindow childWindows];
|
|
|
|
NSEnumerator* enumerator = [childWindows objectEnumerator];
|
|
|
|
NSWindow* child = nil;
|
|
|
|
while ((child = [enumerator nextObject])) {
|
|
|
|
[mWindow removeChildWindow:child];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the content view.
|
|
|
|
NSView* contentView = [mWindow contentView];
|
|
|
|
[contentView retain];
|
|
|
|
[contentView removeFromSuperviewWithoutNeedingDisplay];
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
// Save state (like window title).
|
|
|
|
NSMutableDictionary* state = [mWindow exportState];
|
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
// Recreate the window with the right border style.
|
|
|
|
NSRect frameRect = [mWindow frame];
|
|
|
|
DestroyNativeWindow();
|
2011-09-30 17:20:33 -07:00
|
|
|
nsresult rv = CreateNativeWindow(frameRect, aShouldHide ? eBorderStyle_none : mBorderStyle, true);
|
2009-07-22 01:57:39 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
// Re-import state.
|
|
|
|
[mWindow importState:state];
|
|
|
|
|
2009-07-22 01:57:39 -07:00
|
|
|
// Reparent the content view.
|
|
|
|
[mWindow setContentView:contentView];
|
|
|
|
[contentView release];
|
|
|
|
|
|
|
|
// Reparent child windows.
|
|
|
|
enumerator = [childWindows objectEnumerator];
|
|
|
|
while ((child = [enumerator nextObject])) {
|
|
|
|
[mWindow addChildWindow:child ordered:NSWindowAbove];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the new window.
|
|
|
|
if (isVisible) {
|
2011-09-30 17:20:33 -07:00
|
|
|
rv = Show(true);
|
2009-07-22 01:57:39 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2012-03-20 16:21:14 -07:00
|
|
|
void nsCocoaWindow::EnteredFullScreen(bool aFullScreen)
|
|
|
|
{
|
2012-03-29 12:18:50 -07:00
|
|
|
mInFullScreenTransition = false;
|
2012-03-20 16:21:14 -07:00
|
|
|
mFullScreen = aFullScreen;
|
|
|
|
DispatchSizeModeEvent();
|
|
|
|
}
|
2009-07-22 01:57:39 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsCocoaWindow::MakeFullScreen(bool aFullScreen)
|
2009-07-22 02:01:37 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-20 16:21:14 -07:00
|
|
|
// We will call into MakeFullScreen redundantly when entering/exiting
|
|
|
|
// fullscreen mode via OS X controls. When that happens we should just handle
|
|
|
|
// it gracefully - no need to ASSERT.
|
|
|
|
if (mFullScreen == aFullScreen) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-20 08:52:13 -07:00
|
|
|
|
|
|
|
// If we're using native fullscreen mode and our native window is invisible,
|
|
|
|
// our attempt to go into fullscreen mode will fail with an assertion in
|
|
|
|
// system code, without [WindowDelegate windowDidFailToEnterFullScreen:]
|
|
|
|
// ever getting called. To pre-empt this we bail here. See bug 752294.
|
|
|
|
if (mUsesNativeFullScreen && aFullScreen && ![mWindow isVisible]) {
|
|
|
|
EnteredFullScreen(false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-29 12:18:50 -07:00
|
|
|
mInFullScreenTransition = true;
|
2009-07-22 02:01:37 -07:00
|
|
|
|
2012-03-20 16:21:14 -07:00
|
|
|
if (mUsesNativeFullScreen) {
|
2012-03-29 12:18:50 -07:00
|
|
|
// Calling toggleFullScreen will result in windowDid(FailTo)?(Enter|Exit)FullScreen
|
2012-03-20 16:21:14 -07:00
|
|
|
// to be called from the OS. We will call EnteredFullScreen from those methods,
|
|
|
|
// where mFullScreen will be set and a sizemode event will be dispatched.
|
|
|
|
[mWindow toggleFullScreen:nil];
|
|
|
|
} else {
|
|
|
|
NSDisableScreenUpdates();
|
|
|
|
// The order here matters. When we exit full screen mode, we need to show the
|
|
|
|
// Dock first, otherwise the newly-created window won't have its minimize
|
|
|
|
// button enabled. See bug 526282.
|
|
|
|
nsCocoaUtils::HideOSChromeOnScreen(aFullScreen, [mWindow screen]);
|
|
|
|
nsresult rv = nsBaseWidget::MakeFullScreen(aFullScreen);
|
|
|
|
NSEnableScreenUpdates();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-07-22 02:01:37 -07:00
|
|
|
|
2012-03-20 16:21:14 -07:00
|
|
|
EnteredFullScreen(aFullScreen);
|
|
|
|
}
|
2009-07-22 02:01:37 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
// Coordinates are global display pixels
|
2012-12-12 01:57:38 -08:00
|
|
|
nsresult nsCocoaWindow::DoResize(double aX, double aY,
|
|
|
|
double aWidth, double aHeight,
|
2012-12-06 09:31:34 -08:00
|
|
|
bool aRepaint,
|
|
|
|
bool aConstrainToCurrentScreen)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
if (!mWindow) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConstrainSize operates in device pixels, so we need to convert using
|
|
|
|
// the backing scale factor here
|
|
|
|
CGFloat scale = BackingScaleFactor();
|
2012-12-12 01:57:38 -08:00
|
|
|
int32_t width = NSToIntRound(aWidth * scale);
|
|
|
|
int32_t height = NSToIntRound(aHeight * scale);
|
|
|
|
ConstrainSize(&width, &height);
|
2012-07-30 17:43:29 -07:00
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
nsIntRect newBounds(aX, aY,
|
|
|
|
NSToIntRound(width / scale),
|
|
|
|
NSToIntRound(height / scale));
|
2012-09-29 04:36:09 -07:00
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
// constrain to the screen that contains the largest area of the new rect
|
|
|
|
FitRectToVisibleAreaForScreen(newBounds, aConstrainToCurrentScreen ?
|
|
|
|
[mWindow screen] : nullptr);
|
2007-12-03 08:25:36 -08:00
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
// convert requested bounds into Cocoa coordinate system
|
|
|
|
NSRect newFrame = nsCocoaUtils::GeckoRectToCocoaRect(newBounds);
|
2012-09-29 04:36:09 -07:00
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
NSRect frame = [mWindow frame];
|
|
|
|
BOOL isMoving = newFrame.origin.x != frame.origin.x ||
|
|
|
|
newFrame.origin.y != frame.origin.y;
|
|
|
|
BOOL isResizing = newFrame.size.width != frame.size.width ||
|
|
|
|
newFrame.size.height != frame.size.height;
|
2007-11-06 23:36:10 -08:00
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
if (!isMoving && !isResizing) {
|
2007-11-06 23:36:10 -08:00
|
|
|
return NS_OK;
|
2012-12-06 09:31:34 -08:00
|
|
|
}
|
2007-11-06 23:36:10 -08:00
|
|
|
|
2007-11-26 16:24:13 -08:00
|
|
|
// We ignore aRepaint -- we have to call display:YES, otherwise the
|
|
|
|
// title bar doesn't immediately get repainted and is displayed in
|
|
|
|
// the wrong place, leading to a visual jump.
|
|
|
|
[mWindow setFrame:newFrame display:YES];
|
2007-11-06 23:36:10 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
// Coordinates are global display pixels
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Resize(double aX, double aY,
|
|
|
|
double aWidth, double aHeight,
|
2012-10-16 12:41:20 -07:00
|
|
|
bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-16 12:41:20 -07:00
|
|
|
return DoResize(aX, aY, aWidth, aHeight, aRepaint, false);
|
|
|
|
}
|
2010-12-21 03:42:47 -08:00
|
|
|
|
2012-12-06 09:31:34 -08:00
|
|
|
// Coordinates are global display pixels
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Resize(double aWidth, double aHeight, bool aRepaint)
|
2012-10-16 12:41:20 -07:00
|
|
|
{
|
2012-12-06 09:31:34 -08:00
|
|
|
double invScale = 1.0 / GetDefaultScale();
|
2012-12-12 01:57:38 -08:00
|
|
|
return DoResize(mBounds.x * invScale, mBounds.y * invScale,
|
2012-12-06 09:31:34 -08:00
|
|
|
aWidth, aHeight, aRepaint, true);
|
2010-12-21 03:42:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetClientBounds(nsIntRect &aRect)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
CGFloat scaleFactor = BackingScaleFactor();
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow) {
|
2012-09-29 04:36:09 -07:00
|
|
|
aRect = nsCocoaUtils::CocoaRectToGeckoRectDevPix(NSZeroRect, scaleFactor);
|
2012-06-18 08:20:02 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
NSRect r;
|
2010-12-21 03:42:47 -08:00
|
|
|
if ([mWindow isKindOfClass:[ToolbarWindow class]] &&
|
|
|
|
[(ToolbarWindow*)mWindow drawsContentsIntoWindowFrame]) {
|
2012-09-29 04:36:09 -07:00
|
|
|
r = [mWindow frame];
|
2010-12-21 03:42:47 -08:00
|
|
|
} else {
|
2012-09-29 04:36:09 -07:00
|
|
|
r = [mWindow contentRectForFrameRect:[mWindow frame]];
|
2010-12-21 03:42:47 -08:00
|
|
|
}
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
aRect = nsCocoaUtils::CocoaRectToGeckoRectDevPix(r, scaleFactor);
|
|
|
|
|
2010-12-21 03:42:47 -08:00
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-12-21 03:42:47 -08:00
|
|
|
void
|
|
|
|
nsCocoaWindow::UpdateBounds()
|
|
|
|
{
|
2012-06-18 08:20:02 -07:00
|
|
|
NSRect frame = NSZeroRect;
|
2012-09-29 04:36:09 -07:00
|
|
|
if (mWindow) {
|
2012-06-18 08:20:02 -07:00
|
|
|
frame = [mWindow frame];
|
2012-09-29 04:36:09 -07:00
|
|
|
}
|
|
|
|
mBounds = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
|
2010-12-21 03:42:47 -08:00
|
|
|
}
|
|
|
|
|
2010-03-25 02:25:00 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(nsIntRect &aRect)
|
|
|
|
{
|
2010-03-25 03:30:40 -07:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix([mWindow frame], BackingScaleFactor());
|
|
|
|
NS_ASSERTION(mWindow && mBounds == r, "mBounds out of sync!");
|
|
|
|
#endif
|
2010-12-21 03:42:47 -08:00
|
|
|
|
|
|
|
aRect = mBounds;
|
2010-03-25 02:25:00 -07:00
|
|
|
return NS_OK;
|
2010-03-25 03:30:40 -07:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
double
|
2012-10-30 17:31:35 -07:00
|
|
|
nsCocoaWindow::GetDefaultScaleInternal()
|
2012-09-29 04:36:09 -07:00
|
|
|
{
|
|
|
|
return BackingScaleFactor();
|
|
|
|
}
|
|
|
|
|
2012-12-14 01:46:16 -08:00
|
|
|
static CGFloat
|
|
|
|
GetBackingScaleFactor(NSWindow* aWindow)
|
|
|
|
{
|
|
|
|
NSRect frame = [aWindow frame];
|
|
|
|
if (frame.size.width > 0 && frame.size.height > 0) {
|
|
|
|
return nsCocoaUtils::GetBackingScaleFactor(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For windows with zero width or height, the backingScaleFactor method
|
|
|
|
// is broken - it will always return 2 on a retina macbook, even when
|
|
|
|
// the window position implies it's on a non-hidpi external display
|
|
|
|
// (to the extent that a zero-area window can be said to be "on" a
|
|
|
|
// display at all!)
|
|
|
|
// And to make matters worse, Cocoa even fires a
|
|
|
|
// windowDidChangeBackingProperties notification with the
|
|
|
|
// NSBackingPropertyOldScaleFactorKey key when a window on an
|
|
|
|
// external display is resized to/from zero height, even though it hasn't
|
|
|
|
// really changed screens.
|
|
|
|
|
|
|
|
// This causes us to handle popup window sizing incorrectly when the
|
|
|
|
// popup is resized to zero height (bug 820327) - nsXULPopupManager
|
|
|
|
// becomes (incorrectly) convinced the popup has been explicitly forced
|
|
|
|
// to a non-default size and needs to have size attributes attached.
|
|
|
|
|
|
|
|
// Workaround: instead of asking the window, we'll find the screen it is on
|
|
|
|
// and ask that for *its* backing scale factor.
|
|
|
|
|
|
|
|
// First, expand the rect so that it actually has a measurable area,
|
|
|
|
// for FindTargetScreenForRect to use.
|
|
|
|
if (frame.size.width == 0) {
|
|
|
|
frame.size.width = 1;
|
|
|
|
}
|
|
|
|
if (frame.size.height == 0) {
|
|
|
|
frame.size.height = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then identify the screen it belongs to, and return its scale factor.
|
|
|
|
NSScreen *screen =
|
|
|
|
FindTargetScreenForRect(nsCocoaUtils::CocoaRectToGeckoRect(frame));
|
|
|
|
return nsCocoaUtils::GetBackingScaleFactor(screen);
|
|
|
|
}
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
CGFloat
|
|
|
|
nsCocoaWindow::BackingScaleFactor()
|
|
|
|
{
|
|
|
|
if (mBackingScaleFactor > 0.0) {
|
|
|
|
return mBackingScaleFactor;
|
|
|
|
}
|
|
|
|
if (!mWindow) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
2012-12-14 01:46:16 -08:00
|
|
|
mBackingScaleFactor = GetBackingScaleFactor(mWindow);
|
2012-09-29 04:36:09 -07:00
|
|
|
return mBackingScaleFactor;
|
|
|
|
}
|
|
|
|
|
2012-10-16 12:41:20 -07:00
|
|
|
void
|
|
|
|
nsCocoaWindow::BackingScaleFactorChanged()
|
|
|
|
{
|
2012-12-14 01:46:16 -08:00
|
|
|
CGFloat newScale = GetBackingScaleFactor(mWindow);
|
2012-10-16 12:41:20 -07:00
|
|
|
|
|
|
|
// ignore notification if it hasn't really changed (or maybe we have
|
|
|
|
// disabled HiDPI mode via prefs)
|
|
|
|
if (mBackingScaleFactor == newScale) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 12:41:20 -07:00
|
|
|
if (mBackingScaleFactor > 0.0) {
|
|
|
|
// convert size constraints to the new device pixel coordinate space
|
|
|
|
double scaleFactor = newScale / mBackingScaleFactor;
|
|
|
|
mSizeConstraints.mMinSize.width =
|
|
|
|
NSToIntRound(mSizeConstraints.mMinSize.width * scaleFactor);
|
|
|
|
mSizeConstraints.mMinSize.height =
|
|
|
|
NSToIntRound(mSizeConstraints.mMinSize.height * scaleFactor);
|
|
|
|
if (mSizeConstraints.mMaxSize.width < NS_MAXSIZE) {
|
|
|
|
mSizeConstraints.mMaxSize.width =
|
|
|
|
NS_MIN(NS_MAXSIZE,
|
|
|
|
NSToIntRound(mSizeConstraints.mMaxSize.width * scaleFactor));
|
|
|
|
}
|
|
|
|
if (mSizeConstraints.mMaxSize.height < NS_MAXSIZE) {
|
|
|
|
mSizeConstraints.mMaxSize.height =
|
|
|
|
NS_MIN(NS_MAXSIZE,
|
|
|
|
NSToIntRound(mSizeConstraints.mMaxSize.height * scaleFactor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 12:41:20 -07:00
|
|
|
mBackingScaleFactor = newScale;
|
|
|
|
|
|
|
|
if (!mWidgetListener || mWidgetListener->GetXULWindow()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* presShell = mWidgetListener->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->BackingScaleFactorChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:04:16 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetCursor(nsCursor aCursor)
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
return mPopupContentView->SetCursor(aCursor);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetCursor(imgIContainer* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aHotspotX, uint32_t aHotspotY)
|
2009-09-27 14:04:16 -07:00
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
return mPopupContentView->SetCursor(aCursor, aHotspotX, aHotspotY);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsString& strTitle = PromiseFlatString(aTitle);
|
|
|
|
NSString* title = [NSString stringWithCharacters:strTitle.get() length:strTitle.Length()];
|
|
|
|
[mWindow setTitle:title];
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:21 -08:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Invalidate(const nsIntRect & aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-29 04:36:09 -07:00
|
|
|
if (mPopupContentView) {
|
2011-12-23 19:52:21 -08:00
|
|
|
return mPopupContentView->Invalidate(aRect);
|
2012-09-29 04:36:09 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass notification of some drag event to Gecko
|
|
|
|
//
|
|
|
|
// The drag manager has let us know that something related to a drag has
|
|
|
|
// occurred in this window. It could be any number of things, ranging from
|
|
|
|
// a drop, to a drag enter/leave, or a drag over event. The actual event
|
|
|
|
// is passed in |aMessage| and is passed along to our event hanlder so Gecko
|
|
|
|
// knows about it.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsCocoaWindow::DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-30 17:20:33 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::SendSetZLevelEvent()
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
nsWindowZ placement = nsWindowZTop;
|
|
|
|
nsIWidget* actualBelow;
|
|
|
|
if (mWidgetListener)
|
|
|
|
mWidgetListener->ZLevelChanged(true, &placement, nullptr, &actualBelow);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetChildSheet(bool aShown, nsCocoaWindow** _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIWidget* child = GetFirstChild();
|
|
|
|
|
|
|
|
while (child) {
|
2008-02-19 18:30:24 -08:00
|
|
|
nsWindowType type;
|
|
|
|
if (NS_SUCCEEDED(child->GetWindowType(type)) && type == eWindowType_sheet) {
|
|
|
|
// if it's a sheet, it must be an nsCocoaWindow
|
|
|
|
nsCocoaWindow* cocoaWindow = static_cast<nsCocoaWindow*>(child);
|
2012-06-18 08:20:02 -07:00
|
|
|
if (cocoaWindow->mWindow &&
|
|
|
|
((aShown && [cocoaWindow->mWindow isVisible]) ||
|
|
|
|
(!aShown && cocoaWindow->mSheetNeedsShow))) {
|
2008-02-19 18:30:24 -08:00
|
|
|
*_retval = cocoaWindow;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
*_retval = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-05-07 14:15:57 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetRealParent(nsIWidget** parent)
|
|
|
|
{
|
|
|
|
*parent = mParent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetIsSheet(bool* isSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-30 17:20:33 -07:00
|
|
|
mWindowType == eWindowType_sheet ? *isSheet = true : *isSheet = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetSheetWindowParent(NSWindow** sheetWindowParent)
|
|
|
|
{
|
|
|
|
*sheetWindowParent = mSheetWindowParent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::ResetInputState()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-19 15:15:48 -07:00
|
|
|
// Invokes callback and ProcessEvent methods on Event Listener object
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCocoaWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus)
|
|
|
|
{
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsIWidget* aWidget = event->widget;
|
|
|
|
NS_IF_ADDREF(aWidget);
|
2007-09-19 15:15:48 -07:00
|
|
|
|
2012-08-15 11:53:09 -07:00
|
|
|
if (mWidgetListener)
|
|
|
|
aStatus = mWidgetListener->HandleEvent(event, mUseAttachedEvents);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IF_RELEASE(aWidget);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-08 11:59:18 -08:00
|
|
|
// aFullScreen should be the window's mFullScreen. We don't have access to that
|
|
|
|
// from here, so we need to pass it in. mFullScreen should be the canonical
|
|
|
|
// indicator that a window is currently full screen and it makes sense to keep
|
|
|
|
// all sizemode logic here.
|
2009-08-13 15:02:54 -07:00
|
|
|
static nsSizeMode
|
2012-02-08 11:59:18 -08:00
|
|
|
GetWindowSizeMode(NSWindow* aWindow, bool aFullScreen) {
|
|
|
|
if (aFullScreen)
|
|
|
|
return nsSizeMode_Fullscreen;
|
2009-08-13 15:02:54 -07:00
|
|
|
if ([aWindow isMiniaturized])
|
|
|
|
return nsSizeMode_Minimized;
|
|
|
|
if (([aWindow styleMask] & NSResizableWindowMask) && [aWindow isZoomed])
|
|
|
|
return nsSizeMode_Maximized;
|
|
|
|
return nsSizeMode_Normal;
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
void
|
|
|
|
nsCocoaWindow::ReportMoveEvent()
|
|
|
|
{
|
2010-12-21 03:42:47 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-12-13 08:55:16 -08:00
|
|
|
// Prevent recursion, which can become infinite (see bug 708278). This
|
|
|
|
// can happen when the call to [NSWindow setFrameTopLeftPoint:] in
|
|
|
|
// nsCocoaWindow::Move() triggers an immediate NSWindowDidMove notification
|
|
|
|
// (and a call to [WindowDelegate windowDidMove:]).
|
|
|
|
if (mInReportMoveEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mInReportMoveEvent = true;
|
|
|
|
|
2010-12-21 03:42:47 -08:00
|
|
|
UpdateBounds();
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
// Dispatch the move event to Gecko
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener)
|
|
|
|
mWidgetListener->WindowMoved(this, mBounds.x, mBounds.y);
|
2010-12-21 03:42:47 -08:00
|
|
|
|
2011-12-13 08:55:16 -08:00
|
|
|
mInReportMoveEvent = false;
|
|
|
|
|
2010-12-21 03:42:47 -08:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2010-07-27 06:38:04 -07:00
|
|
|
}
|
|
|
|
|
2008-09-10 09:57:57 -07:00
|
|
|
void
|
2009-08-13 15:02:54 -07:00
|
|
|
nsCocoaWindow::DispatchSizeModeEvent()
|
2008-09-10 09:57:57 -07:00
|
|
|
{
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-08 11:59:18 -08:00
|
|
|
nsSizeMode newMode = GetWindowSizeMode(mWindow, mFullScreen);
|
2012-03-29 12:18:50 -07:00
|
|
|
|
|
|
|
// Don't dispatch a sizemode event if:
|
|
|
|
// 1. the window is transitioning to fullscreen
|
|
|
|
// 2. the new sizemode is the same as the current sizemode
|
|
|
|
if (mInFullScreenTransition || mSizeMode == newMode) {
|
2012-01-31 02:40:03 -08:00
|
|
|
return;
|
2012-03-29 12:18:50 -07:00
|
|
|
}
|
2012-01-31 02:40:03 -08:00
|
|
|
|
|
|
|
mSizeMode = newMode;
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->SizeModeChanged(newMode);
|
|
|
|
}
|
2008-09-10 09:57:57 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2010-12-21 03:42:47 -08:00
|
|
|
nsCocoaWindow::ReportSizeEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2010-12-21 03:42:47 -08:00
|
|
|
UpdateBounds();
|
2009-10-21 00:05:39 -07:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mWidgetListener) {
|
|
|
|
nsIntRect innerBounds;
|
|
|
|
GetClientBounds(innerBounds);
|
|
|
|
mWidgetListener->WindowResized(this, innerBounds.width, innerBounds.height);
|
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-04-08 11:39:58 -07:00
|
|
|
void nsCocoaWindow::SetMenuBar(nsMenuBarX *aMenuBar)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mMenuBar)
|
2012-07-30 07:20:58 -07:00
|
|
|
mMenuBar->SetParent(nullptr);
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mMenuBar = nullptr;
|
2012-06-18 08:20:02 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-04-08 11:39:58 -07:00
|
|
|
mMenuBar = aMenuBar;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
|
|
|
|
// Only paint for active windows, or paint the hidden window menu bar if no
|
|
|
|
// other menu bar has been painted yet so that some reasonable menu bar is
|
|
|
|
// displayed when the app starts up.
|
|
|
|
id windowDelegate = [mWindow delegate];
|
|
|
|
if (mMenuBar &&
|
|
|
|
((!gSomeMenuBarPainted && nsMenuUtilsX::GetHiddenWindowMenuBar() == mMenuBar) ||
|
|
|
|
(windowDelegate && [windowDelegate toplevelActiveState])))
|
2007-03-22 10:30:00 -07:00
|
|
|
mMenuBar->Paint();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetFocus(bool aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (mPopupContentView) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mPopupContentView->SetFocus(aState);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
}
|
2010-02-03 04:42:12 -08:00
|
|
|
else if (aState && ([mWindow isVisible] || [mWindow isMiniaturized])) {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
[mWindow makeKeyAndOrderFront:nil];
|
|
|
|
SendSetZLevelEvent();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint nsCocoaWindow::WidgetToScreenOffset()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-18 16:11:49 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
2009-02-15 09:41:16 -08:00
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
NSRect rect = NSZeroRect;
|
2012-09-29 04:36:09 -07:00
|
|
|
nsIntRect r;
|
|
|
|
if (mWindow) {
|
2012-06-18 08:20:02 -07:00
|
|
|
rect = [mWindow contentRectForFrameRect:[mWindow frame]];
|
2012-09-29 04:36:09 -07:00
|
|
|
}
|
|
|
|
r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(rect, BackingScaleFactor());
|
2009-02-15 09:41:16 -08:00
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
return r.TopLeft();
|
2009-02-15 09:41:16 -08:00
|
|
|
|
2009-02-18 16:11:49 -08:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0,0));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
nsIntPoint nsCocoaWindow::GetClientOffset()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2010-12-21 03:42:47 -08:00
|
|
|
nsIntRect clientRect;
|
|
|
|
GetClientBounds(clientRect);
|
2010-07-27 06:38:03 -07:00
|
|
|
|
2010-12-21 03:42:47 -08:00
|
|
|
return clientRect.TopLeft() - mBounds.TopLeft();
|
2010-07-27 06:38:03 -07:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntSize nsCocoaWindow::ClientToWindowSize(const nsIntSize& aClientSize)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return nsIntSize(0, 0);
|
|
|
|
|
2012-09-29 04:36:09 -07:00
|
|
|
CGFloat backingScale = BackingScaleFactor();
|
|
|
|
nsIntRect r(0, 0, aClientSize.width, aClientSize.height);
|
|
|
|
NSRect rect = nsCocoaUtils::DevPixelsToCocoaPoints(r, backingScale);
|
2010-07-27 06:38:03 -07:00
|
|
|
|
|
|
|
NSRect inflatedRect = [mWindow frameRectForContentRect:rect];
|
2012-09-29 04:36:09 -07:00
|
|
|
return nsCocoaUtils::CocoaRectToGeckoRectDevPix(inflatedRect, backingScale).Size();
|
2010-07-27 06:38:03 -07:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntSize(0,0));
|
|
|
|
}
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
nsMenuBarX* nsCocoaWindow::GetMenuBar()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mMenuBar;
|
|
|
|
}
|
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
gRollupListener = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aDoCapture) {
|
|
|
|
gRollupListener = aListener;
|
2009-05-14 13:13:22 -07:00
|
|
|
|
2007-10-01 14:39:52 -07:00
|
|
|
// Sometimes more than one popup window can be visible at the same time
|
|
|
|
// (e.g. nested non-native context menus, or the test case (attachment
|
2012-10-26 06:15:22 -07:00
|
|
|
// 276885) for bmo bug 392389, which displays a non-native combo-box in a
|
|
|
|
// non-native popup window). In these cases the "active" popup window should
|
|
|
|
// be the topmost -- the (nested) context menu the mouse is currently over,
|
|
|
|
// or the combo-box's drop-down list (when it's displayed). But (among
|
2007-10-01 14:39:52 -07:00
|
|
|
// windows that have the same "level") OS X makes topmost the window that
|
|
|
|
// last received a mouse-down event, which may be incorrect (in the combo-
|
|
|
|
// box case, it makes topmost the window containing the combo-box). So
|
|
|
|
// here we fiddle with a non-native popup window's level to make sure the
|
|
|
|
// "active" one is always above any other non-native popup windows that
|
|
|
|
// may be visible.
|
|
|
|
if (mWindow && (mWindowType == eWindowType_popup))
|
2010-07-27 06:38:03 -07:00
|
|
|
SetPopupWindowLevel();
|
2007-10-01 14:39:52 -07:00
|
|
|
} else {
|
2010-07-27 06:38:03 -07:00
|
|
|
// XXXndeakin this doesn't make sense.
|
|
|
|
// Why is the new window assumed to be a modal panel?
|
2007-10-01 14:39:52 -07:00
|
|
|
if (mWindow && (mWindowType == eWindowType_popup))
|
|
|
|
[mWindow setLevel:NSModalPanelWindowLevel];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetAttention(int32_t aCycleCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
[NSApp requestUserAttention:NSInformationalRequest];
|
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-04-21 16:53:52 -07:00
|
|
|
nsCocoaWindow::HasPendingInputEvent()
|
|
|
|
{
|
|
|
|
return nsChildView::DoHasPendingInputEvent();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetWindowShadowStyle(int32_t aStyle)
|
2008-10-14 08:33:40 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-12-30 07:24:08 -08:00
|
|
|
mShadowStyle = aStyle;
|
|
|
|
[mWindow setHasShadow:(aStyle != NS_STYLE_WINDOW_SHADOW_NONE)];
|
|
|
|
AdjustWindowShadow();
|
2010-01-13 08:10:25 -08:00
|
|
|
SetUpWindowFilter();
|
2009-12-30 07:24:08 -08:00
|
|
|
|
2008-10-14 08:33:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsCocoaWindow::SetShowsToolbarButton(bool aShow)
|
2009-08-05 13:49:59 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (mWindow)
|
|
|
|
[mWindow setShowsToolbarButton:aShow];
|
2009-08-05 13:49:59 -07:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2012-03-20 16:21:14 -07:00
|
|
|
void nsCocoaWindow::SetShowsFullScreenButton(bool aShow)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow || ![mWindow respondsToSelector:@selector(toggleFullScreen:)] ||
|
2012-03-20 16:21:14 -07:00
|
|
|
mUsesNativeFullScreen == aShow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the window is currently in fullscreen mode, then we're going to
|
|
|
|
// transition out first, then set the collection behavior & toggle
|
|
|
|
// mUsesNativeFullScreen, then transtion back into fullscreen mode. This
|
|
|
|
// prevents us from getting into a conflicting state with MakeFullScreen
|
|
|
|
// where mUsesNativeFullScreen would lead us down the wrong path.
|
|
|
|
bool wasFullScreen = mFullScreen;
|
|
|
|
|
|
|
|
if (wasFullScreen) {
|
|
|
|
MakeFullScreen(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSWindowCollectionBehavior newBehavior = [mWindow collectionBehavior];
|
|
|
|
if (aShow) {
|
|
|
|
newBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
|
|
|
|
} else {
|
|
|
|
newBehavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
|
|
|
|
}
|
|
|
|
[mWindow setCollectionBehavior:newBehavior];
|
|
|
|
mUsesNativeFullScreen = aShow;
|
|
|
|
|
|
|
|
if (wasFullScreen) {
|
|
|
|
MakeFullScreen(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2012-02-16 19:47:39 -08:00
|
|
|
void nsCocoaWindow::SetWindowAnimationType(nsIWidget::WindowAnimationType aType)
|
|
|
|
{
|
|
|
|
mAnimationType = aType;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetWindowTitlebarColor(nscolor aColor, bool aActive)
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
// If they pass a color with a complete transparent alpha component, use the
|
|
|
|
// native titlebar appearance.
|
|
|
|
if (NS_GET_A(aColor) == 0) {
|
2009-11-02 11:07:57 -08:00
|
|
|
[mWindow setTitlebarColor:nil forActiveWindow:(BOOL)aActive];
|
2007-10-29 21:03:42 -07:00
|
|
|
} else {
|
2008-04-07 13:55:14 -07:00
|
|
|
// Transform from sRGBA to monitor RGBA. This seems like it would make trying
|
|
|
|
// to match the system appearance lame, so probably we just shouldn't color
|
|
|
|
// correct chrome.
|
2008-09-10 19:21:03 -07:00
|
|
|
if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform *transform = gfxPlatform::GetCMSRGBATransform();
|
2008-09-10 19:21:03 -07:00
|
|
|
if (transform) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t color[3];
|
2008-09-10 19:21:03 -07:00
|
|
|
color[0] = NS_GET_R(aColor);
|
|
|
|
color[1] = NS_GET_G(aColor);
|
|
|
|
color[2] = NS_GET_B(aColor);
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_transform_data(transform, color, color, 1);
|
2008-09-10 19:21:03 -07:00
|
|
|
aColor = NS_RGB(color[0], color[1], color[2]);
|
|
|
|
}
|
|
|
|
}
|
2008-04-07 13:55:14 -07:00
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
[mWindow setTitlebarColor:[NSColor colorWithDeviceRed:NS_GET_R(aColor)/255.0
|
|
|
|
green:NS_GET_G(aColor)/255.0
|
|
|
|
blue:NS_GET_B(aColor)/255.0
|
|
|
|
alpha:NS_GET_A(aColor)/255.0]
|
|
|
|
forActiveWindow:(BOOL)aActive];
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2009-09-22 19:31:37 -07:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsCocoaWindow::SetDrawsInTitlebar(bool aState)
|
2009-10-21 00:05:39 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-06-18 08:20:02 -07:00
|
|
|
if (mWindow)
|
|
|
|
[mWindow setDrawsContentsIntoWindowFrame:aState];
|
2009-10-21 00:05:39 -07:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2009-09-22 19:31:37 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SynthesizeNativeMouseEvent(nsIntPoint aPoint,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aNativeMessage,
|
|
|
|
uint32_t aModifierFlags)
|
2009-09-22 19:31:37 -07:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
if (mPopupContentView)
|
|
|
|
return mPopupContentView->SynthesizeNativeMouseEvent(aPoint, aNativeMessage,
|
|
|
|
aModifierFlags);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
2007-08-02 11:48:28 -07:00
|
|
|
gfxASurface* nsCocoaWindow::GetThebesSurface()
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
return mPopupContentView->GetThebesSurface();
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-08-02 11:48:28 -07:00
|
|
|
}
|
|
|
|
|
2007-09-27 09:01:32 -07:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::BeginSecureKeyboardInput()
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-09-27 09:01:32 -07:00
|
|
|
nsresult rv = nsBaseWidget::BeginSecureKeyboardInput();
|
2011-02-09 11:00:58 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-09-27 09:01:32 -07:00
|
|
|
::EnableSecureEventInput();
|
2011-02-09 11:00:58 -08:00
|
|
|
}
|
2007-09-27 09:01:32 -07:00
|
|
|
return rv;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-09-27 09:01:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::EndSecureKeyboardInput()
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-09-27 09:01:32 -07:00
|
|
|
nsresult rv = nsBaseWidget::EndSecureKeyboardInput();
|
2011-02-09 11:00:58 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-09-27 09:01:32 -07:00
|
|
|
::DisableSecureEventInput();
|
2011-02-09 11:00:58 -08:00
|
|
|
}
|
2007-09-27 09:01:32 -07:00
|
|
|
return rv;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-09-27 09:01:32 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
void nsCocoaWindow::SetPopupWindowLevel()
|
|
|
|
{
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow)
|
|
|
|
return;
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// Floating popups are at the floating level and hide when the window is
|
|
|
|
// deactivated.
|
|
|
|
if (mPopupLevel == ePopupLevelFloating) {
|
|
|
|
[mWindow setLevel:NSFloatingWindowLevel];
|
|
|
|
[mWindow setHidesOnDeactivate:YES];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Otherwise, this is a top-level or parent popup. Parent popups always
|
|
|
|
// appear just above their parent and essentially ignore the level.
|
|
|
|
[mWindow setLevel:NSPopUpMenuWindowLevel];
|
|
|
|
[mWindow setHidesOnDeactivate:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsCocoaWindow::IsChildInFailingLeftClickThrough(NSView *aChild)
|
2010-11-15 13:12:50 -08:00
|
|
|
{
|
|
|
|
if ([aChild isKindOfClass:[ChildView class]]) {
|
|
|
|
ChildView* childView = (ChildView*) aChild;
|
|
|
|
if ([childView isInFailingLeftClickThrough])
|
2011-09-30 17:20:33 -07:00
|
|
|
return true;
|
2010-11-15 13:12:50 -08:00
|
|
|
}
|
|
|
|
NSArray* subviews = [aChild subviews];
|
|
|
|
if (subviews) {
|
|
|
|
NSUInteger count = [subviews count];
|
|
|
|
for (NSUInteger i = 0; i < count; ++i) {
|
|
|
|
NSView* aView = (NSView*) [subviews objectAtIndex:i];
|
|
|
|
if (IsChildInFailingLeftClickThrough(aView))
|
2011-09-30 17:20:33 -07:00
|
|
|
return true;
|
2010-11-15 13:12:50 -08:00
|
|
|
}
|
|
|
|
}
|
2011-09-30 17:20:33 -07:00
|
|
|
return false;
|
2010-11-15 13:12:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't focus a plugin if we're in a left click-through that will
|
|
|
|
// fail (see [ChildView isInFailingLeftClickThrough]). Called from
|
|
|
|
// [ChildView shouldFocusPlugin].
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsCocoaWindow::ShouldFocusPlugin()
|
2010-11-15 13:12:50 -08:00
|
|
|
{
|
2012-06-18 08:20:02 -07:00
|
|
|
if (!mWindow || IsChildInFailingLeftClickThrough([mWindow contentView]))
|
2011-09-30 17:20:33 -07:00
|
|
|
return false;
|
2010-11-15 13:12:50 -08:00
|
|
|
|
2011-09-30 17:20:33 -07:00
|
|
|
return true;
|
2010-11-15 13:12:50 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
@implementation WindowDelegate
|
|
|
|
|
|
|
|
// We try to find a gecko menu bar to paint. If one does not exist, just paint
|
|
|
|
// the application menu by itself so that a window doesn't have some other
|
|
|
|
// window's menu bar.
|
|
|
|
+ (void)paintMenubarForWindow:(NSWindow*)aWindow
|
2008-02-20 15:47:05 -08:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// make sure we only act on windows that have this kind of
|
|
|
|
// object as a delegate
|
|
|
|
id windowDelegate = [aWindow delegate];
|
|
|
|
if ([windowDelegate class] != [self class])
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCocoaWindow* geckoWidget = [windowDelegate geckoWidget];
|
|
|
|
NS_ASSERTION(geckoWidget, "Window delegate not returning a gecko widget!");
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
nsMenuBarX* geckoMenuBar = geckoWidget->GetMenuBar();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (geckoMenuBar) {
|
|
|
|
geckoMenuBar->Paint();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// sometimes we don't have a native application menu early in launching
|
|
|
|
if (!sApplicationMenu)
|
|
|
|
return;
|
|
|
|
|
2007-11-15 18:54:00 -08:00
|
|
|
NSMenu* mainMenu = [NSApp mainMenu];
|
|
|
|
NS_ASSERTION([mainMenu numberOfItems] > 0, "Main menu does not have any items, something is terribly wrong!");
|
|
|
|
|
2008-04-07 21:38:52 -07:00
|
|
|
// Create a new menu bar.
|
|
|
|
// We create a GeckoNSMenu because all menu bar NSMenu objects should use that subclass for
|
|
|
|
// key handling reasons.
|
|
|
|
GeckoNSMenu* newMenuBar = [[GeckoNSMenu alloc] initWithTitle:@"MainMenuBar"];
|
2007-11-15 18:54:00 -08:00
|
|
|
|
|
|
|
// move the application menu from the existing menu bar to the new one
|
|
|
|
NSMenuItem* firstMenuItem = [[mainMenu itemAtIndex:0] retain];
|
|
|
|
[mainMenu removeItemAtIndex:0];
|
|
|
|
[newMenuBar insertItem:firstMenuItem atIndex:0];
|
|
|
|
[firstMenuItem release];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// set our new menu bar as the main menu
|
|
|
|
[NSApp setMainMenu:newMenuBar];
|
|
|
|
[newMenuBar release];
|
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
[super init];
|
|
|
|
mGeckoWindow = geckoWind;
|
2011-09-30 17:20:33 -07:00
|
|
|
mToplevelActiveState = false;
|
|
|
|
mHasEverBeenZoomed = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return self;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
|
|
|
|
{
|
2007-06-12 13:26:24 -07:00
|
|
|
RollUpPopups();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return proposedFrameSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResize:(NSNotification *)aNotification
|
|
|
|
{
|
2011-08-08 07:43:13 -07:00
|
|
|
BaseWindow* window = [aNotification object];
|
|
|
|
[window updateTrackingArea];
|
|
|
|
|
2010-11-27 05:52:33 -08:00
|
|
|
if (!mGeckoWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2007-09-17 07:41:59 -07:00
|
|
|
|
2009-08-13 15:02:54 -07:00
|
|
|
// Resizing might have changed our zoom state.
|
|
|
|
mGeckoWindow->DispatchSizeModeEvent();
|
2007-09-17 07:41:59 -07:00
|
|
|
mGeckoWindow->ReportSizeEvent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 16:36:20 -08:00
|
|
|
- (void)windowDidChangeScreen:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
if (!mGeckoWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mGeckoWindow->ReportMoveEvent();
|
|
|
|
}
|
|
|
|
|
2012-03-20 16:21:14 -07:00
|
|
|
// Lion's full screen mode will bypass our internal fullscreen tracking, so
|
|
|
|
// we need to catch it when we transition and call our own methods, which in
|
|
|
|
// turn will fire "fullscreen" events.
|
|
|
|
- (void)windowDidEnterFullScreen:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
if (!mGeckoWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGeckoWindow->EnteredFullScreen(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidExitFullScreen:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
if (!mGeckoWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGeckoWindow->EnteredFullScreen(false);
|
|
|
|
}
|
|
|
|
|
2012-03-29 12:18:50 -07:00
|
|
|
- (void)windowDidFailToEnterFullScreen:(NSWindow *)window
|
|
|
|
{
|
|
|
|
if (!mGeckoWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGeckoWindow->EnteredFullScreen(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidFailToExitFullScreen:(NSWindow *)window
|
|
|
|
{
|
|
|
|
if (!mGeckoWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGeckoWindow->EnteredFullScreen(true);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
- (void)windowDidBecomeMain:(NSNotification *)aNotification
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-06-12 13:26:24 -07:00
|
|
|
RollUpPopups();
|
2009-12-11 13:56:59 -08:00
|
|
|
ChildViewMouseTracker::ReEvaluateMouseEnterState();
|
2007-05-17 19:06:59 -07:00
|
|
|
|
2008-03-26 20:42:57 -07:00
|
|
|
// [NSApp _isRunningAppModal] will return true if we're running an OS dialog
|
|
|
|
// app modally. If one of those is up then we want it to retain its menu bar.
|
|
|
|
if ([NSApp _isRunningAppModal])
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
NSWindow* window = [aNotification object];
|
|
|
|
if (window)
|
|
|
|
[WindowDelegate paintMenubarForWindow:window];
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResignMain:(NSNotification *)aNotification
|
|
|
|
{
|
2007-06-12 13:26:24 -07:00
|
|
|
RollUpPopups();
|
2009-12-11 13:56:59 -08:00
|
|
|
ChildViewMouseTracker::ReEvaluateMouseEnterState();
|
2008-03-26 20:42:57 -07:00
|
|
|
|
|
|
|
// [NSApp _isRunningAppModal] will return true if we're running an OS dialog
|
|
|
|
// app modally. If one of those is up then we want it to retain its menu bar.
|
|
|
|
if ([NSApp _isRunningAppModal])
|
|
|
|
return;
|
2008-06-28 00:55:30 -07:00
|
|
|
nsRefPtr<nsMenuBarX> hiddenWindowMenuBar = nsMenuUtilsX::GetHiddenWindowMenuBar();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (hiddenWindowMenuBar) {
|
|
|
|
// printf("painting hidden window menu bar due to window losing main status\n");
|
|
|
|
hiddenWindowMenuBar->Paint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)aNotification
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-10-05 19:59:23 -07:00
|
|
|
RollUpPopups();
|
2009-12-11 13:56:59 -08:00
|
|
|
ChildViewMouseTracker::ReEvaluateMouseEnterState();
|
2009-10-05 19:59:23 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NSWindow* window = [aNotification object];
|
|
|
|
if ([window isSheet])
|
|
|
|
[WindowDelegate paintMenubarForWindow:window];
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)aNotification
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-10-05 19:59:23 -07:00
|
|
|
RollUpPopups();
|
2009-12-11 13:56:59 -08:00
|
|
|
ChildViewMouseTracker::ReEvaluateMouseEnterState();
|
2009-10-05 19:59:23 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If a sheet just resigned key then we should paint the menu bar
|
|
|
|
// for whatever window is now main.
|
|
|
|
NSWindow* window = [aNotification object];
|
|
|
|
if ([window isSheet])
|
|
|
|
[WindowDelegate paintMenubarForWindow:[NSApp mainWindow]];
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowWillMove:(NSNotification *)aNotification
|
|
|
|
{
|
2007-06-12 13:26:24 -07:00
|
|
|
RollUpPopups();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-10 16:54:05 -07:00
|
|
|
- (void)windowDidMove:(NSNotification *)aNotification
|
|
|
|
{
|
2010-07-27 06:38:04 -07:00
|
|
|
if (mGeckoWindow)
|
|
|
|
mGeckoWindow->ReportMoveEvent();
|
2007-05-10 16:54:05 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)sender
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIWidgetListener* listener = mGeckoWindow ? mGeckoWindow->GetWidgetListener() : nullptr;
|
|
|
|
if (listener)
|
|
|
|
listener->RequestWindowClose(mGeckoWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NO; // gecko will do it
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowWillClose:(NSNotification *)aNotification
|
|
|
|
{
|
2007-06-12 13:26:24 -07:00
|
|
|
RollUpPopups();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowWillMiniaturize:(NSNotification *)aNotification
|
|
|
|
{
|
2007-06-12 13:26:24 -07:00
|
|
|
RollUpPopups();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-10 09:57:57 -07:00
|
|
|
- (void)windowDidMiniaturize:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
if (mGeckoWindow)
|
2009-08-13 15:02:54 -07:00
|
|
|
mGeckoWindow->DispatchSizeModeEvent();
|
2008-09-10 09:57:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
if (mGeckoWindow)
|
2009-08-13 15:02:54 -07:00
|
|
|
mGeckoWindow->DispatchSizeModeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)proposedFrame
|
|
|
|
{
|
|
|
|
if (!mHasEverBeenZoomed && [window isZoomed])
|
|
|
|
return NO; // See bug 429954.
|
|
|
|
|
|
|
|
mHasEverBeenZoomed = YES;
|
|
|
|
return YES;
|
2008-09-10 09:57:57 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
- (void)didEndSheet:(NSWindow*)sheet returnCode:(int)returnCode contextInfo:(void*)contextInfo
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2008-05-07 14:15:57 -07:00
|
|
|
// Note: 'contextInfo' (if it is set) is the window that is the parent of
|
|
|
|
// the sheet. The value of contextInfo is determined in
|
|
|
|
// nsCocoaWindow::Show(). If it's set, 'contextInfo' is always the top-
|
|
|
|
// level window, not another sheet itself. But 'contextInfo' is nil if
|
|
|
|
// our parent window is also a sheet -- in that case we shouldn't send
|
|
|
|
// the top-level window any activate events (because it's our parent
|
|
|
|
// window that needs to get these events, not the top-level window).
|
2008-05-02 03:40:49 -07:00
|
|
|
[TopLevelWindowData deactivateInWindow:sheet];
|
2007-03-22 10:30:00 -07:00
|
|
|
[sheet orderOut:self];
|
2008-05-07 14:15:57 -07:00
|
|
|
if (contextInfo)
|
|
|
|
[TopLevelWindowData activateInWindow:(NSWindow*)contextInfo];
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-16 12:41:20 -07:00
|
|
|
- (void)windowDidChangeBackingProperties:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
NSWindow *window = (NSWindow *)[aNotification object];
|
|
|
|
|
|
|
|
if ([window respondsToSelector:@selector(backingScaleFactor)]) {
|
|
|
|
CGFloat oldFactor =
|
|
|
|
[[[aNotification userInfo]
|
|
|
|
objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue];
|
|
|
|
if ([window backingScaleFactor] != oldFactor) {
|
|
|
|
mGeckoWindow->BackingScaleFactorChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2007-04-17 15:32:40 -07:00
|
|
|
- (nsCocoaWindow*)geckoWidget
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mGeckoWindow;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
- (bool)toplevelActiveState
|
2008-05-02 03:40:49 -07:00
|
|
|
{
|
|
|
|
return mToplevelActiveState;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendToplevelActivateEvents
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mToplevelActiveState && mGeckoWindow) {
|
|
|
|
nsIWidgetListener* listener = mGeckoWindow->GetWidgetListener();
|
|
|
|
if (listener)
|
|
|
|
listener->WindowActivated();
|
2011-09-30 17:20:33 -07:00
|
|
|
mToplevelActiveState = true;
|
2008-05-02 03:40:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendToplevelDeactivateEvents
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (mToplevelActiveState && mGeckoWindow) {
|
|
|
|
nsIWidgetListener* listener = mGeckoWindow->GetWidgetListener();
|
|
|
|
if (listener)
|
|
|
|
listener->WindowDeactivated();
|
2011-09-30 17:20:33 -07:00
|
|
|
mToplevelActiveState = false;
|
2008-05-02 03:40:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-30 22:07:18 -07:00
|
|
|
@end
|
|
|
|
|
2010-08-19 02:35:08 -07:00
|
|
|
static float
|
|
|
|
GetDPI(NSWindow* aWindow)
|
|
|
|
{
|
|
|
|
NSScreen* screen = [aWindow screen];
|
|
|
|
if (!screen)
|
|
|
|
return 96.0f;
|
|
|
|
|
|
|
|
CGDirectDisplayID displayID =
|
|
|
|
[[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
|
|
|
|
CGFloat heightMM = ::CGDisplayScreenSize(displayID).height;
|
|
|
|
size_t heightPx = ::CGDisplayPixelsHigh(displayID);
|
|
|
|
CGFloat scaleFactor = [aWindow userSpaceScaleFactor];
|
|
|
|
if (scaleFactor < 0.01 || heightMM < 1 || heightPx < 1) {
|
|
|
|
// Something extremely bogus is going on
|
|
|
|
return 96.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Currently we don't do our own scaling to take account
|
|
|
|
// of userSpaceScaleFactor, so every "pixel" we draw is actually
|
|
|
|
// userSpaceScaleFactor screen pixels. So divide the screen height
|
|
|
|
// by userSpaceScaleFactor to get the number of "device pixels"
|
|
|
|
// available.
|
2012-09-29 04:36:09 -07:00
|
|
|
float dpi = (heightPx / scaleFactor) / (heightMM / MM_PER_INCH_FLOAT);
|
|
|
|
|
|
|
|
// Account for HiDPI mode where Cocoa's "points" do not correspond to real
|
|
|
|
// device pixels
|
2012-12-14 01:46:16 -08:00
|
|
|
CGFloat backingScale = GetBackingScaleFactor(aWindow);
|
2012-09-29 04:36:09 -07:00
|
|
|
|
|
|
|
return dpi * backingScale;
|
2010-08-19 02:35:08 -07:00
|
|
|
}
|
|
|
|
|
2011-08-08 07:43:13 -07:00
|
|
|
@interface BaseWindow(Private)
|
|
|
|
- (void)removeTrackingArea;
|
|
|
|
- (void)cursorUpdated:(NSEvent*)aEvent;
|
|
|
|
@end
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
@implementation BaseWindow
|
2007-10-29 21:03:42 -07:00
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
- (id)initWithContentRect:(NSRect)aContentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)aBufferingType defer:(BOOL)aFlag
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
2009-11-02 11:07:57 -08:00
|
|
|
[super initWithContentRect:aContentRect styleMask:aStyle backing:aBufferingType defer:aFlag];
|
|
|
|
mState = nil;
|
|
|
|
mDrawsIntoWindowFrame = NO;
|
|
|
|
mActiveTitlebarColor = nil;
|
|
|
|
mInactiveTitlebarColor = nil;
|
2009-12-11 13:53:22 -08:00
|
|
|
mScheduledShadowInvalidation = NO;
|
2010-08-19 02:35:08 -07:00
|
|
|
mDPI = GetDPI(self);
|
2011-08-08 07:43:13 -07:00
|
|
|
mTrackingArea = nil;
|
|
|
|
[self updateTrackingArea];
|
2010-08-19 02:35:08 -07:00
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
return self;
|
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[mActiveTitlebarColor release];
|
|
|
|
[mInactiveTitlebarColor release];
|
2011-08-08 07:43:13 -07:00
|
|
|
[self removeTrackingArea];
|
|
|
|
ChildViewMouseTracker::OnDestroyWindow(self);
|
2009-11-02 11:07:57 -08:00
|
|
|
[super dealloc];
|
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
static const NSString* kStateTitleKey = @"title";
|
|
|
|
static const NSString* kStateDrawsContentsIntoWindowFrameKey = @"drawsContentsIntoWindowFrame";
|
|
|
|
static const NSString* kStateActiveTitlebarColorKey = @"activeTitlebarColor";
|
|
|
|
static const NSString* kStateInactiveTitlebarColorKey = @"inactiveTitlebarColor";
|
2009-12-30 07:24:03 -08:00
|
|
|
static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
|
2009-11-02 11:07:57 -08:00
|
|
|
|
|
|
|
- (void)importState:(NSDictionary*)aState
|
|
|
|
{
|
|
|
|
[self setTitle:[aState objectForKey:kStateTitleKey]];
|
|
|
|
[self setDrawsContentsIntoWindowFrame:[[aState objectForKey:kStateDrawsContentsIntoWindowFrameKey] boolValue]];
|
|
|
|
[self setTitlebarColor:[aState objectForKey:kStateActiveTitlebarColorKey] forActiveWindow:YES];
|
|
|
|
[self setTitlebarColor:[aState objectForKey:kStateInactiveTitlebarColorKey] forActiveWindow:NO];
|
2009-12-30 07:24:03 -08:00
|
|
|
[self setShowsToolbarButton:[[aState objectForKey:kStateShowsToolbarButton] boolValue]];
|
2009-11-02 11:07:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary*)exportState
|
|
|
|
{
|
|
|
|
NSMutableDictionary* state = [NSMutableDictionary dictionaryWithCapacity:10];
|
|
|
|
[state setObject:[self title] forKey:kStateTitleKey];
|
|
|
|
[state setObject:[NSNumber numberWithBool:[self drawsContentsIntoWindowFrame]]
|
|
|
|
forKey:kStateDrawsContentsIntoWindowFrameKey];
|
|
|
|
NSColor* activeTitlebarColor = [self titlebarColorForActiveWindow:YES];
|
|
|
|
if (activeTitlebarColor) {
|
|
|
|
[state setObject:activeTitlebarColor forKey:kStateActiveTitlebarColorKey];
|
|
|
|
}
|
|
|
|
NSColor* inactiveTitlebarColor = [self titlebarColorForActiveWindow:NO];
|
|
|
|
if (inactiveTitlebarColor) {
|
|
|
|
[state setObject:inactiveTitlebarColor forKey:kStateInactiveTitlebarColorKey];
|
|
|
|
}
|
2009-12-30 07:24:03 -08:00
|
|
|
[state setObject:[NSNumber numberWithBool:[self showsToolbarButton]]
|
|
|
|
forKey:kStateShowsToolbarButton];
|
2009-11-02 11:07:57 -08:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState
|
|
|
|
{
|
|
|
|
mDrawsIntoWindowFrame = aState;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)drawsContentsIntoWindowFrame
|
|
|
|
{
|
|
|
|
return mDrawsIntoWindowFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass nil here to get the default appearance.
|
|
|
|
- (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive
|
|
|
|
{
|
|
|
|
[aColor retain];
|
|
|
|
if (aActive) {
|
|
|
|
[mActiveTitlebarColor release];
|
|
|
|
mActiveTitlebarColor = aColor;
|
|
|
|
} else {
|
|
|
|
[mInactiveTitlebarColor release];
|
|
|
|
mInactiveTitlebarColor = aColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSColor*)titlebarColorForActiveWindow:(BOOL)aActive
|
|
|
|
{
|
|
|
|
return aActive ? mActiveTitlebarColor : mInactiveTitlebarColor;
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
2009-12-11 13:53:22 -08:00
|
|
|
- (void)deferredInvalidateShadow
|
|
|
|
{
|
|
|
|
if (mScheduledShadowInvalidation || [self isOpaque] || ![self hasShadow])
|
|
|
|
return;
|
|
|
|
|
|
|
|
[self performSelector:@selector(invalidateShadow) withObject:nil afterDelay:0];
|
|
|
|
mScheduledShadowInvalidation = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)invalidateShadow
|
|
|
|
{
|
|
|
|
[super invalidateShadow];
|
|
|
|
mScheduledShadowInvalidation = NO;
|
|
|
|
}
|
|
|
|
|
2010-08-19 02:35:08 -07:00
|
|
|
- (float)getDPI
|
|
|
|
{
|
|
|
|
return mDPI;
|
|
|
|
}
|
|
|
|
|
2011-08-08 07:43:13 -07:00
|
|
|
- (NSView*)trackingAreaView
|
|
|
|
{
|
|
|
|
NSView* contentView = [self contentView];
|
|
|
|
return [contentView superview] ? [contentView superview] : contentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeTrackingArea
|
|
|
|
{
|
|
|
|
if (mTrackingArea) {
|
|
|
|
[[self trackingAreaView] removeTrackingArea:mTrackingArea];
|
|
|
|
[mTrackingArea release];
|
|
|
|
mTrackingArea = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateTrackingArea
|
|
|
|
{
|
|
|
|
[self removeTrackingArea];
|
|
|
|
|
|
|
|
NSView* view = [self trackingAreaView];
|
|
|
|
const NSTrackingAreaOptions options =
|
|
|
|
NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways;
|
|
|
|
mTrackingArea = [[NSTrackingArea alloc] initWithRect:[view bounds]
|
|
|
|
options:options
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
|
|
|
[view addTrackingArea:mTrackingArea];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent*)aEvent
|
|
|
|
{
|
|
|
|
ChildViewMouseTracker::MouseEnteredWindow(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseExited:(NSEvent*)aEvent
|
|
|
|
{
|
|
|
|
ChildViewMouseTracker::MouseExitedWindow(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent*)aEvent
|
|
|
|
{
|
|
|
|
ChildViewMouseTracker::MouseMoved(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cursorUpdated:(NSEvent*)aEvent
|
|
|
|
{
|
|
|
|
// Nothing to do here, but NSTrackingArea wants us to implement this method.
|
|
|
|
}
|
|
|
|
|
2011-01-28 06:11:29 -08:00
|
|
|
- (BOOL)respondsToSelector:(SEL)aSelector
|
|
|
|
{
|
|
|
|
// Claim the window doesn't respond to this so that the system
|
|
|
|
// doesn't steal keyboard equivalents for it. Bug 613710.
|
|
|
|
if (aSelector == @selector(cancelOperation:)) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super respondsToSelector:aSelector];
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:26:17 -07:00
|
|
|
- (void) doCommandBySelector:(SEL)aSelector
|
|
|
|
{
|
|
|
|
// We override this so that it won't beep if it can't act.
|
|
|
|
// We want to control the beeping for missing or disabled
|
|
|
|
// commands ourselves.
|
|
|
|
[self tryToPerform:aSelector with:nil];
|
|
|
|
}
|
|
|
|
|
2011-09-27 08:38:44 -07:00
|
|
|
- (id)accessibilityAttributeValue:(NSString *)attribute
|
|
|
|
{
|
|
|
|
id retval = [super accessibilityAttributeValue:attribute];
|
|
|
|
|
|
|
|
// The following works around a problem with Text-to-Speech on OS X 10.7.
|
|
|
|
// See bug 674612 for more info.
|
|
|
|
//
|
|
|
|
// When accessibility is off, AXUIElementCopyAttributeValue(), when called
|
|
|
|
// on an AXApplication object to get its AXFocusedUIElement attribute,
|
|
|
|
// always returns an AXWindow object (the actual browser window -- never a
|
|
|
|
// mozAccessible object). This also happens with accessibility turned on,
|
|
|
|
// if no other object in the browser window has yet been focused. But if
|
|
|
|
// the browser window has a title bar (as it currently always does), the
|
|
|
|
// AXWindow object will always have four "accessible" children, one of which
|
|
|
|
// is an AXStaticText object (the title bar's "title"; the other three are
|
|
|
|
// the close, minimize and zoom buttons). This means that (for complicated
|
|
|
|
// reasons, for which see bug 674612) Text-to-Speech on OS X 10.7 will often
|
|
|
|
// "speak" the window title, no matter what text is selected, or even if no
|
|
|
|
// text at all is selected. (This always happens when accessibility is off.
|
|
|
|
// It doesn't happen in Firefox releases because Apple has (on OS X 10.7)
|
|
|
|
// special-cased the handling of apps whose CFBundleIdentifier is
|
|
|
|
// org.mozilla.firefox.)
|
|
|
|
//
|
|
|
|
// We work around this problem by only returning AXChildren that are
|
|
|
|
// mozAccessible object or are one of the titlebar's buttons (which
|
|
|
|
// instantiate subclasses of NSButtonCell).
|
2012-05-17 00:53:20 -07:00
|
|
|
if (nsCocoaFeatures::OnLionOrLater() && [retval isKindOfClass:[NSArray class]] &&
|
2011-09-27 08:38:44 -07:00
|
|
|
[attribute isEqualToString:@"AXChildren"]) {
|
|
|
|
NSMutableArray *holder = [NSMutableArray arrayWithCapacity:10];
|
|
|
|
[holder addObjectsFromArray:(NSArray *)retval];
|
|
|
|
NSUInteger count = [holder count];
|
|
|
|
for (NSInteger i = count - 1; i >= 0; --i) {
|
|
|
|
id item = [holder objectAtIndex:i];
|
|
|
|
// Remove anything from holder that isn't one of the titlebar's buttons
|
|
|
|
// (which instantiate subclasses of NSButtonCell) or a mozAccessible
|
|
|
|
// object (or one of its subclasses).
|
|
|
|
if (![item isKindOfClass:[NSButtonCell class]] &&
|
|
|
|
![item respondsToSelector:@selector(hasRepresentedView)]) {
|
|
|
|
[holder removeObjectAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval = [NSArray arrayWithArray:holder];
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
@end
|
|
|
|
|
2012-11-01 06:19:24 -07:00
|
|
|
// This class allows us to have a "unified toolbar" style window. It works like this:
|
2007-10-29 21:03:42 -07:00
|
|
|
// 1) We set the window's style to textured.
|
|
|
|
// 2) Because of this, the background color applies to the entire window, including
|
|
|
|
// the titlebar area. For normal textured windows, the default pattern is a
|
2008-09-16 01:21:06 -07:00
|
|
|
// "brushed metal" image on Tiger and a unified gradient on Leopard.
|
2007-10-29 21:03:42 -07:00
|
|
|
// 3) We set the background color to a custom NSColor subclass that knows how tall the window is.
|
|
|
|
// When -set is called on it, it sets a pattern (with a draw callback) as the fill. In that callback,
|
2008-09-16 01:21:06 -07:00
|
|
|
// it paints the the titlebar and background colors in the correct areas of the context it's given,
|
2007-10-29 21:03:42 -07:00
|
|
|
// which will fill the entire window (CG will tile it horizontally for us).
|
2008-09-16 01:21:06 -07:00
|
|
|
// 4) Whenever the window's main state changes and when [window display] is called,
|
|
|
|
// Cocoa redraws the titlebar using the patternDraw callback function.
|
2007-10-29 21:03:42 -07:00
|
|
|
//
|
|
|
|
// This class also provides us with a pill button to show/hide the toolbar.
|
2008-09-16 01:21:06 -07:00
|
|
|
//
|
|
|
|
// Drawing the unified gradient in the titlebar and the toolbar works like this:
|
|
|
|
// 1) In the style sheet we set the toolbar's -moz-appearance to -moz-mac-unified-toolbar.
|
2010-07-24 02:35:29 -07:00
|
|
|
// 2) When the toolbar is visible and we paint the application chrome
|
2011-01-11 05:03:16 -08:00
|
|
|
// window, the array that Gecko passes nsChildView::UpdateThemeGeometries
|
|
|
|
// will contain an entry for the widget type NS_THEME_TOOLBAR or
|
2010-07-24 02:35:29 -07:00
|
|
|
// NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR.
|
2011-01-11 05:03:16 -08:00
|
|
|
// 3) nsChildView::UpdateThemeGeometries finds the toolbar frame's ToolbarWindow
|
|
|
|
// and passes the toolbar frame's height to setUnifiedToolbarHeight.
|
|
|
|
// 4) If the toolbar height has changed, a titlebar redraw is triggered and the
|
|
|
|
// upper part of the unified gradient is drawn in the titlebar.
|
|
|
|
// 5) The lower part of the unified gradient in the toolbar is drawn during
|
|
|
|
// normal window content painting in nsNativeThemeCocoa::DrawUnifiedToolbar.
|
2008-09-16 01:21:06 -07:00
|
|
|
//
|
|
|
|
// Whenever the unified gradient is drawn in the titlebar or the toolbar, both
|
|
|
|
// titlebar height and toolbar height must be known in order to construct the
|
|
|
|
// correct gradient (which is a linear gradient with the length
|
|
|
|
// titlebarHeight + toolbarHeight - 1). But you can only get from the toolbar frame
|
|
|
|
// to the containing window - the other direction doesn't work. That's why the
|
|
|
|
// toolbar height is cached in the ToolbarWindow but nsNativeThemeCocoa can simply
|
|
|
|
// query the window for its titlebar height when drawing the toolbar.
|
2007-05-30 22:07:18 -07:00
|
|
|
@implementation ToolbarWindow
|
|
|
|
|
2009-08-13 23:35:32 -07:00
|
|
|
- (id)initWithContentRect:(NSRect)aContentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)aBufferingType defer:(BOOL)aFlag
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
aStyle = aStyle | NSTexturedBackgroundWindowMask;
|
|
|
|
if ((self = [super initWithContentRect:aContentRect styleMask:aStyle backing:aBufferingType defer:aFlag])) {
|
2009-11-02 11:07:57 -08:00
|
|
|
mColor = [[TitlebarAndBackgroundColor alloc] initWithWindow:self];
|
|
|
|
// Bypass our guard method below.
|
2007-10-29 21:03:42 -07:00
|
|
|
[super setBackgroundColor:mColor];
|
2012-01-04 11:53:52 -08:00
|
|
|
mBackgroundColor = [[NSColor whiteColor] retain];
|
2007-10-29 21:03:42 -07:00
|
|
|
|
2008-09-16 01:21:06 -07:00
|
|
|
mUnifiedToolbarHeight = 0.0f;
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
// setBottomCornerRounded: is a private API call, so we check to make sure
|
|
|
|
// we respond to it just in case.
|
|
|
|
if ([self respondsToSelector:@selector(setBottomCornerRounded:)])
|
|
|
|
[self setBottomCornerRounded:NO];
|
2009-11-13 14:59:38 -08:00
|
|
|
|
|
|
|
[self setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
|
|
|
|
[self setContentBorderThickness:0.0f forEdge:NSMaxYEdge];
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
return self;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
[mColor release];
|
2009-11-02 11:07:57 -08:00
|
|
|
[mBackgroundColor release];
|
2007-10-29 21:03:42 -07:00
|
|
|
[super dealloc];
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
- (void)setTitlebarColor:(NSColor*)aColor forActiveWindow:(BOOL)aActive
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
2009-11-02 11:07:57 -08:00
|
|
|
[super setTitlebarColor:aColor forActiveWindow:aActive];
|
|
|
|
[self setTitlebarNeedsDisplayInRect:[self titlebarRect]];
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
- (void)setBackgroundColor:(NSColor*)aColor
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
2009-11-02 11:07:57 -08:00
|
|
|
[aColor retain];
|
|
|
|
[mBackgroundColor release];
|
|
|
|
mBackgroundColor = aColor;
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
- (NSColor*)windowBackgroundColor
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
2009-11-02 11:07:57 -08:00
|
|
|
return mBackgroundColor;
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
2009-10-21 00:05:39 -07:00
|
|
|
- (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect
|
|
|
|
{
|
|
|
|
[self setTitlebarNeedsDisplayInRect:aRect sync:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync
|
|
|
|
{
|
|
|
|
NSRect titlebarRect = [self titlebarRect];
|
|
|
|
NSRect rect = NSIntersectionRect(titlebarRect, aRect);
|
|
|
|
if (NSIsEmptyRect(rect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSView* borderView = [[self contentView] superview];
|
|
|
|
if (!borderView)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aSync) {
|
|
|
|
[borderView displayRect:rect];
|
|
|
|
} else {
|
|
|
|
[borderView setNeedsDisplayInRect:rect];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)titlebarRect
|
|
|
|
{
|
|
|
|
return NSMakeRect(0, [[self contentView] bounds].size.height,
|
|
|
|
[self frame].size.width, [self titlebarHeight]);
|
2008-08-27 08:45:24 -07:00
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2008-09-16 01:21:06 -07:00
|
|
|
- (float)unifiedToolbarHeight
|
2008-08-27 08:45:24 -07:00
|
|
|
{
|
2008-09-16 01:21:06 -07:00
|
|
|
return mUnifiedToolbarHeight;
|
|
|
|
}
|
2008-08-27 12:40:25 -07:00
|
|
|
|
2008-09-16 01:21:06 -07:00
|
|
|
- (float)titlebarHeight
|
|
|
|
{
|
|
|
|
NSRect frameRect = [self frame];
|
|
|
|
return frameRect.size.height - [self contentRectForFrameRect:frameRect].size.height;
|
2008-08-27 08:45:24 -07:00
|
|
|
}
|
2007-10-29 21:03:42 -07:00
|
|
|
|
2011-01-11 05:03:16 -08:00
|
|
|
- (void)setUnifiedToolbarHeight:(float)aHeight
|
2010-01-13 08:08:06 -08:00
|
|
|
{
|
2011-01-11 05:03:16 -08:00
|
|
|
if ([self drawsContentsIntoWindowFrame] || aHeight == mUnifiedToolbarHeight)
|
|
|
|
return;
|
2010-01-13 08:08:06 -08:00
|
|
|
|
2011-01-11 05:03:16 -08:00
|
|
|
mUnifiedToolbarHeight = aHeight;
|
2010-07-24 02:35:29 -07:00
|
|
|
|
2011-01-11 05:03:16 -08:00
|
|
|
// Update sheet positioning hint.
|
|
|
|
[self setContentBorderThickness:mUnifiedToolbarHeight forEdge:NSMaxYEdge];
|
2010-07-24 02:35:29 -07:00
|
|
|
|
2011-01-11 05:03:16 -08:00
|
|
|
// Redraw the title bar. If we're inside painting, we'll do it right now,
|
|
|
|
// otherwise we'll just invalidate it.
|
|
|
|
BOOL needSyncRedraw = ([NSView focusView] != nil);
|
|
|
|
[self setTitlebarNeedsDisplayInRect:[self titlebarRect] sync:needSyncRedraw];
|
2010-01-13 08:08:06 -08:00
|
|
|
}
|
|
|
|
|
2009-10-21 00:05:39 -07:00
|
|
|
- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState
|
|
|
|
{
|
2009-11-02 11:07:57 -08:00
|
|
|
BOOL stateChanged = ([self drawsContentsIntoWindowFrame] != aState);
|
|
|
|
[super setDrawsContentsIntoWindowFrame:aState];
|
2010-11-17 13:48:11 -08:00
|
|
|
if (stateChanged && [[self delegate] isKindOfClass:[WindowDelegate class]]) {
|
|
|
|
WindowDelegate *windowDelegate = (WindowDelegate *)[self delegate];
|
|
|
|
nsCocoaWindow *geckoWindow = [windowDelegate geckoWidget];
|
2009-10-21 00:05:39 -07:00
|
|
|
if (geckoWindow) {
|
|
|
|
// Re-layout our contents.
|
|
|
|
geckoWindow->ReportSizeEvent();
|
|
|
|
}
|
2011-08-13 07:25:39 -07:00
|
|
|
|
|
|
|
// Resizing the content area causes a reflow which would send a synthesized
|
|
|
|
// mousemove event to the old mouse position relative to the top left
|
|
|
|
// corner of the content area. But the mouse has shifted relative to the
|
|
|
|
// content area, so that event would have wrong position information. So
|
|
|
|
// we'll send a mouse move event with the correct new position.
|
|
|
|
ChildViewMouseTracker::ResendLastMouseMoveEvent();
|
|
|
|
|
2012-11-01 06:19:24 -07:00
|
|
|
[self setTitlebarNeedsDisplayInRect:[self titlebarRect]];
|
2009-10-21 00:05:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-05 13:49:59 -07:00
|
|
|
// Returning YES here makes the setShowsToolbarButton method work even though
|
|
|
|
// the window doesn't contain an NSToolbar.
|
2007-05-30 22:07:18 -07:00
|
|
|
- (BOOL)_hasToolbar
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
// Dispatch a toolbar pill button clicked message to Gecko.
|
2007-05-30 22:07:18 -07:00
|
|
|
- (void)_toolbarPillButtonClicked:(id)sender
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2010-03-18 12:58:07 -07:00
|
|
|
RollUpPopups();
|
|
|
|
|
2010-11-17 13:48:11 -08:00
|
|
|
if ([[self delegate] isKindOfClass:[WindowDelegate class]]) {
|
|
|
|
WindowDelegate *windowDelegate = (WindowDelegate *)[self delegate];
|
|
|
|
nsCocoaWindow *geckoWindow = [windowDelegate geckoWidget];
|
|
|
|
if (!geckoWindow)
|
|
|
|
return;
|
2012-08-15 11:52:42 -07:00
|
|
|
|
|
|
|
nsIWidgetListener* listener = geckoWindow->GetWidgetListener();
|
|
|
|
if (listener)
|
|
|
|
listener->OSToolbarButtonPressed();
|
2010-11-17 13:48:11 -08:00
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-05-30 22:07:18 -07:00
|
|
|
}
|
|
|
|
|
2007-10-23 11:34:29 -07:00
|
|
|
// Retain and release "self" to avoid crashes when our widget (and its native
|
|
|
|
// window) is closed as a result of processing a key equivalent (e.g.
|
|
|
|
// Command+w or Command+q). This workaround is only needed for a window
|
|
|
|
// that can become key.
|
|
|
|
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-10-23 11:34:29 -07:00
|
|
|
NSWindow *nativeWindow = [self retain];
|
|
|
|
BOOL retval = [super performKeyEquivalent:theEvent];
|
|
|
|
[nativeWindow release];
|
|
|
|
return retval;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2007-10-23 11:34:29 -07:00
|
|
|
}
|
|
|
|
|
2008-03-23 15:30:56 -07:00
|
|
|
- (void)sendEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NSEventType type = [anEvent type];
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case NSScrollWheel:
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
case NSMouseMoved:
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
2008-03-24 22:00:36 -07:00
|
|
|
{
|
2008-03-23 15:30:56 -07:00
|
|
|
// Drop all mouse events if a modal window has appeared above us.
|
|
|
|
// This helps make us behave as if the OS were running a "real" modal
|
|
|
|
// event loop.
|
|
|
|
id delegate = [self delegate];
|
|
|
|
if (delegate && [delegate isKindOfClass:[WindowDelegate class]]) {
|
|
|
|
nsCocoaWindow *widget = [(WindowDelegate *)delegate geckoWidget];
|
|
|
|
if (widget) {
|
2009-03-18 15:51:40 -07:00
|
|
|
if (gGeckoAppModalWindowList && (widget != gGeckoAppModalWindowList->window))
|
2008-03-23 15:30:56 -07:00
|
|
|
return;
|
|
|
|
if (widget->HasModalDescendents())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-03-24 22:00:36 -07:00
|
|
|
}
|
|
|
|
default:
|
2008-03-23 15:30:56 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[super sendEvent:anEvent];
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
@end
|
2007-07-17 13:29:39 -07:00
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
// Custom NSColor subclass where most of the work takes place for drawing in
|
|
|
|
// the titlebar area.
|
|
|
|
@implementation TitlebarAndBackgroundColor
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
- (id)initWithWindow:(ToolbarWindow*)aWindow
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
2007-12-11 11:52:26 -08:00
|
|
|
mWindow = aWindow; // weak ref to avoid a cycle
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-10-21 00:05:39 -07:00
|
|
|
static void
|
2011-08-08 07:42:20 -07:00
|
|
|
DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
|
|
|
|
float aToolbarHeight, BOOL aIsMain)
|
|
|
|
{
|
2012-08-01 08:30:31 -07:00
|
|
|
if (aTitlebarRect.size.width * aTitlebarRect.size.height > CUIDRAW_MAX_AREA) {
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 07:42:20 -07:00
|
|
|
int unifiedHeight = aTitlebarRect.size.height + aToolbarHeight;
|
|
|
|
CUIDraw([NSWindow coreUIRenderer], aTitlebarRect, aContext,
|
|
|
|
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"kCUIWidgetWindowFrame", @"widget",
|
|
|
|
@"regularwin", @"windowtype",
|
|
|
|
(aIsMain ? @"normal" : @"inactive"), @"state",
|
|
|
|
[NSNumber numberWithInt:unifiedHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey",
|
|
|
|
[NSNumber numberWithBool:YES], @"kCUIWindowFrameDrawTitleSeparatorKey",
|
|
|
|
nil],
|
|
|
|
nil);
|
|
|
|
|
2012-05-17 00:53:20 -07:00
|
|
|
if (nsCocoaFeatures::OnLionOrLater()) {
|
2011-08-12 07:25:24 -07:00
|
|
|
// On Lion the call to CUIDraw doesn't draw the top pixel strip at some
|
|
|
|
// window widths. We don't want to have a flickering transparent line, so
|
|
|
|
// we overdraw it.
|
|
|
|
CGContextSetRGBFillColor(aContext, 0.95, 0.95, 0.95, 1);
|
|
|
|
CGContextFillRect(aContext, CGRectMake(0, CGRectGetMaxY(aTitlebarRect) - 1,
|
|
|
|
aTitlebarRect.size.width, 1));
|
|
|
|
}
|
2009-10-21 00:05:39 -07:00
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2009-10-21 00:05:39 -07:00
|
|
|
// Pattern draw callback for standard titlebar gradients and solid titlebar colors
|
|
|
|
static void
|
2011-08-08 07:42:20 -07:00
|
|
|
TitlebarDrawCallback(void* aInfo, CGContextRef aContext)
|
2009-10-21 00:05:39 -07:00
|
|
|
{
|
2009-11-02 11:07:57 -08:00
|
|
|
ToolbarWindow *window = (ToolbarWindow*)aInfo;
|
2011-08-13 07:15:46 -07:00
|
|
|
NSRect titlebarRect = [window titlebarRect];
|
2007-10-29 21:03:42 -07:00
|
|
|
|
2011-08-08 07:42:20 -07:00
|
|
|
if ([window drawsContentsIntoWindowFrame]) {
|
2012-11-01 06:19:24 -07:00
|
|
|
NSView* view = [[[window contentView] subviews] lastObject];
|
|
|
|
if (!view || ![view isKindOfClass:[ChildView class]])
|
2011-08-08 07:42:20 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Gecko drawing assumes flippedness, but the current context isn't flipped
|
|
|
|
// (because we're painting into the window's border view, which is not a
|
2011-08-13 07:15:46 -07:00
|
|
|
// ChildView, so it isn't flipped).
|
2011-08-08 07:42:20 -07:00
|
|
|
// So we need to set a flip transform.
|
|
|
|
CGContextScaleCTM(aContext, 1.0f, -1.0f);
|
|
|
|
CGContextTranslateCTM(aContext, 0.0f, -[window frame].size.height);
|
|
|
|
|
2011-08-13 07:15:46 -07:00
|
|
|
NSRect flippedTitlebarRect = { NSZeroPoint, titlebarRect.size };
|
2012-11-01 06:19:24 -07:00
|
|
|
[(ChildView*)view drawRect:flippedTitlebarRect inTitlebarContext:aContext];
|
2007-10-29 21:03:42 -07:00
|
|
|
} else {
|
2011-08-08 07:42:20 -07:00
|
|
|
BOOL isMain = [window isMainWindow];
|
|
|
|
NSColor *titlebarColor = [window titlebarColorForActiveWindow:isMain];
|
|
|
|
if (!titlebarColor) {
|
|
|
|
// If the titlebar color is nil, draw the default titlebar shading.
|
|
|
|
DrawNativeTitlebar(aContext, NSRectToCGRect(titlebarRect),
|
|
|
|
[window unifiedToolbarHeight], isMain);
|
|
|
|
} else {
|
|
|
|
// If the titlebar color is not nil, just set and draw it normally.
|
2011-08-13 07:15:46 -07:00
|
|
|
[NSGraphicsContext saveGraphicsState];
|
|
|
|
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:aContext flipped:NO]];
|
2011-08-08 07:42:20 -07:00
|
|
|
[titlebarColor set];
|
|
|
|
NSRectFill(titlebarRect);
|
2011-08-13 07:15:46 -07:00
|
|
|
[NSGraphicsContext restoreGraphicsState];
|
2011-08-08 07:42:20 -07:00
|
|
|
}
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
2009-10-21 00:05:39 -07:00
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
- (void)setFill
|
|
|
|
{
|
2011-08-08 07:42:20 -07:00
|
|
|
float patternWidth = [mWindow frame].size.width;
|
2010-10-15 03:34:29 -07:00
|
|
|
|
2011-08-08 07:42:20 -07:00
|
|
|
CGPatternCallbacks callbacks = {0, &TitlebarDrawCallback, NULL};
|
2009-11-02 11:07:57 -08:00
|
|
|
CGPatternRef pattern = CGPatternCreate(mWindow, CGRectMake(0.0f, 0.0f, patternWidth, [mWindow frame].size.height),
|
2009-10-21 00:05:39 -07:00
|
|
|
CGAffineTransformIdentity, patternWidth, [mWindow frame].size.height,
|
2007-10-29 21:03:42 -07:00
|
|
|
kCGPatternTilingConstantSpacing, true, &callbacks);
|
|
|
|
|
|
|
|
// Set the pattern as the fill, which is what we were asked to do. All our
|
|
|
|
// drawing will take place in the patternDraw callback.
|
|
|
|
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
|
2010-10-15 03:34:29 -07:00
|
|
|
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
2007-10-29 21:03:42 -07:00
|
|
|
CGContextSetFillColorSpace(context, patternSpace);
|
|
|
|
CGColorSpaceRelease(patternSpace);
|
2009-08-13 23:35:32 -07:00
|
|
|
CGFloat component = 1.0f;
|
2007-10-29 21:03:42 -07:00
|
|
|
CGContextSetFillPattern(context, pattern, &component);
|
|
|
|
CGPatternRelease(pattern);
|
|
|
|
}
|
|
|
|
|
2009-11-02 11:07:57 -08:00
|
|
|
- (void)set
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
2009-11-02 11:07:57 -08:00
|
|
|
[self setFill];
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)colorSpaceName
|
|
|
|
{
|
|
|
|
return NSDeviceRGBColorSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2007-07-17 13:29:39 -07:00
|
|
|
@implementation PopupWindow
|
|
|
|
|
2009-08-13 23:35:32 -07:00
|
|
|
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
|
2007-07-17 13:29:39 -07:00
|
|
|
backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-07-17 13:29:39 -07:00
|
|
|
mIsContextMenu = false;
|
|
|
|
return [super initWithContentRect:contentRect styleMask:styleMask
|
|
|
|
backing:bufferingType defer:deferCreation];
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-07-17 13:29:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isContextMenu
|
|
|
|
{
|
|
|
|
return mIsContextMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIsContextMenu:(BOOL)flag
|
|
|
|
{
|
|
|
|
mIsContextMenu = flag;
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
- (BOOL)canBecomeMainWindow
|
|
|
|
{
|
|
|
|
// This is overriden because the default is 'yes' when a titlebar is present.
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2007-07-17 13:29:39 -07:00
|
|
|
@end
|
2007-10-19 08:47:58 -07:00
|
|
|
|
|
|
|
// According to Apple's docs on [NSWindow canBecomeKeyWindow] and [NSWindow
|
|
|
|
// canBecomeMainWindow], windows without a title bar or resize bar can't (by
|
|
|
|
// default) become key or main. But if a window can't become key, it can't
|
|
|
|
// accept keyboard input (bmo bug 393250). And it should also be possible for
|
|
|
|
// an otherwise "ordinary" window to become main. We need to override these
|
|
|
|
// two methods to make this happen.
|
|
|
|
@implementation BorderlessWindow
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:30:56 -07:00
|
|
|
- (void)sendEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NSEventType type = [anEvent type];
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case NSScrollWheel:
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
case NSMouseMoved:
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
2008-03-24 22:00:36 -07:00
|
|
|
{
|
2008-03-23 15:30:56 -07:00
|
|
|
// Drop all mouse events if a modal window has appeared above us.
|
|
|
|
// This helps make us behave as if the OS were running a "real" modal
|
|
|
|
// event loop.
|
|
|
|
id delegate = [self delegate];
|
|
|
|
if (delegate && [delegate isKindOfClass:[WindowDelegate class]]) {
|
|
|
|
nsCocoaWindow *widget = [(WindowDelegate *)delegate geckoWidget];
|
|
|
|
if (widget) {
|
2009-03-18 15:51:40 -07:00
|
|
|
if (gGeckoAppModalWindowList && (widget != gGeckoAppModalWindowList->window))
|
2008-03-23 15:30:56 -07:00
|
|
|
return;
|
|
|
|
if (widget->HasModalDescendents())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-03-24 22:00:36 -07:00
|
|
|
}
|
|
|
|
default:
|
2008-03-23 15:30:56 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[super sendEvent:anEvent];
|
|
|
|
}
|
|
|
|
|
2007-10-19 08:47:58 -07:00
|
|
|
// Apple's doc on this method says that the NSWindow class's default is not to
|
|
|
|
// become main if the window isn't "visible" -- so we should replicate that
|
|
|
|
// behavior here. As best I can tell, the [NSWindow isVisible] method is an
|
|
|
|
// accurate test of what Apple means by "visibility".
|
|
|
|
- (BOOL)canBecomeMainWindow
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-10-19 08:47:58 -07:00
|
|
|
if (![self isVisible])
|
|
|
|
return NO;
|
|
|
|
return YES;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2007-10-19 08:47:58 -07:00
|
|
|
}
|
|
|
|
|
2007-10-23 11:34:29 -07:00
|
|
|
// Retain and release "self" to avoid crashes when our widget (and its native
|
|
|
|
// window) is closed as a result of processing a key equivalent (e.g.
|
|
|
|
// Command+w or Command+q). This workaround is only needed for a window
|
|
|
|
// that can become key.
|
|
|
|
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-10-23 11:34:29 -07:00
|
|
|
NSWindow *nativeWindow = [self retain];
|
|
|
|
BOOL retval = [super performKeyEquivalent:theEvent];
|
|
|
|
[nativeWindow release];
|
|
|
|
return retval;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2007-10-23 11:34:29 -07:00
|
|
|
}
|
|
|
|
|
2007-10-19 08:47:58 -07:00
|
|
|
@end
|