2006-07-25 18:51:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-11-06 15:35:24 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-08-25 23:02:50 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
2004-08-25 23:02:50 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
2006-01-05 17:07:01 +00:00
|
|
|
* Contributor(s):
|
|
|
|
* Josh Aas <josh@mozilla.com>
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-08-25 23:02:50 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-11-06 15:35:24 +00:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-08-25 23:02:50 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-11-06 15:35:24 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-08-25 23:02:50 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-11-06 15:35:24 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsCocoaWindow.h"
|
|
|
|
|
2006-04-06 07:41:34 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-11-06 15:35:24 +00:00
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIRollupListener.h"
|
2007-02-22 21:56:50 +00:00
|
|
|
#include "nsCocoaUtils.h"
|
2006-04-07 04:51:16 +00:00
|
|
|
#include "nsChildView.h"
|
2006-04-06 07:41:34 +00:00
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIXULWindow.h"
|
2007-03-30 19:51:51 +00:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
2007-04-06 00:11:41 +00:00
|
|
|
#include "nsIDOMChromeWindow.h"
|
|
|
|
#include "unistd.h"
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-12-19 19:26:41 +00:00
|
|
|
// defined in nsMenuBarX.mm
|
|
|
|
extern NSMenu* sApplicationMenu; // Application menu shared by all menubars
|
|
|
|
|
|
|
|
// defined in nsChildView.mm
|
2001-11-06 15:35:24 +00:00
|
|
|
extern nsIRollupListener * gRollupListener;
|
|
|
|
extern nsIWidget * gRollupWidget;
|
2006-04-07 04:51:16 +00:00
|
|
|
extern BOOL gSomeMenuBarPainted;
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-04-06 07:41:34 +00:00
|
|
|
#define NS_APPSHELLSERVICE_CONTRACTID "@mozilla.org/appshell/appShellService;1"
|
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsCocoaWindow, Inherited, nsPIWidgetCocoa)
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-03-10 20:51:48 +00:00
|
|
|
|
2006-12-23 20:25:51 +00:00
|
|
|
// returns the height of the title bar for a given cocoa NSWindow
|
2007-06-12 20:26:24 +00:00
|
|
|
static float TitleBarHeightForWindow(NSWindow* aWindow)
|
2006-12-23 20:25:51 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aWindow, "Must have a window to calculate a title bar height!");
|
|
|
|
|
|
|
|
NSRect frameRect = [aWindow frame];
|
|
|
|
NSRect contentRect = [aWindow contentRectForFrameRect:frameRect];
|
|
|
|
return (frameRect.size.height - contentRect.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-12 20:26:24 +00:00
|
|
|
// roll up any popup windows
|
|
|
|
static void RollUpPopups()
|
|
|
|
{
|
|
|
|
if (gRollupListener && gRollupWidget)
|
|
|
|
gRollupListener->Rollup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
nsCocoaWindow::nsCocoaWindow()
|
2006-02-07 19:15:42 +00:00
|
|
|
: mParent(nsnull)
|
2006-02-07 21:00:46 +00:00
|
|
|
, mWindow(nil)
|
2006-06-08 17:29:18 +00:00
|
|
|
, mDelegate(nil)
|
|
|
|
, mSheetWindowParent(nil)
|
2006-07-25 18:51:41 +00:00
|
|
|
, mPopupContentView(nil)
|
2007-04-06 00:11:41 +00:00
|
|
|
, mAnimation(nsIDOMChromeWindow::RESIZE_ANIMATION_OFF)
|
2001-11-19 15:02:23 +00:00
|
|
|
, mIsResizing(PR_FALSE)
|
2001-11-06 15:35:24 +00:00
|
|
|
, mWindowMadeHere(PR_FALSE)
|
2006-02-10 21:39:30 +00:00
|
|
|
, mVisible(PR_FALSE)
|
2006-06-08 17:29:18 +00:00
|
|
|
, mSheetNeedsShow(PR_FALSE)
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCocoaWindow::~nsCocoaWindow()
|
|
|
|
{
|
2006-12-12 18:55:24 +00:00
|
|
|
// notify the children that we're gone
|
|
|
|
for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) {
|
2007-07-08 07:08:04 +00:00
|
|
|
nsCocoaWindow* childWindow = static_cast<nsCocoaWindow*>(kid);
|
2006-12-12 18:55:24 +00:00
|
|
|
childWindow->mParent = nsnull;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
if (mWindow && mWindowMadeHere) {
|
2006-06-22 21:34:30 +00: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];
|
2002-03-11 02:39:45 +00:00
|
|
|
[mWindow autorelease];
|
|
|
|
[mDelegate autorelease];
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
2006-07-25 18:51:41 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mPopupContentView);
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-06 07:41:34 +00:00
|
|
|
static nsIMenuBar* GetHiddenWindowMenuBar()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAppShellService> appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
|
|
|
|
if (!appShell) {
|
|
|
|
NS_WARNING("Couldn't get AppShellService in order to get hidden window ref");
|
2006-08-09 01:50:21 +00:00
|
|
|
return nsnull;
|
2006-04-06 07:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULWindow> hiddenWindow;
|
|
|
|
appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
|
|
|
|
if (!hiddenWindow) {
|
2006-11-16 03:25:55 +00:00
|
|
|
// Don't warn, this happens during shutdown, bug 358607.
|
2006-08-09 01:50:21 +00:00
|
|
|
return nsnull;
|
2006-04-06 07:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseHiddenWindow;
|
|
|
|
baseHiddenWindow = do_GetInterface(hiddenWindow);
|
|
|
|
if (!baseHiddenWindow) {
|
|
|
|
NS_WARNING("Couldn't get nsIBaseWindow from hidden window (nsIXULWindow)");
|
2006-08-09 01:50:21 +00:00
|
|
|
return nsnull;
|
2006-04-06 07:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> hiddenWindowWidget;
|
|
|
|
if (NS_FAILED(baseHiddenWindow->GetMainWidget(getter_AddRefs(hiddenWindowWidget)))) {
|
|
|
|
NS_WARNING("Couldn't get nsIWidget from hidden window (nsIBaseWindow)");
|
2006-08-09 01:50:21 +00:00
|
|
|
return nsnull;
|
2006-04-06 07:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget* hiddenWindowWidgetNoCOMPtr = hiddenWindowWidget;
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<nsCocoaWindow*>(hiddenWindowWidgetNoCOMPtr)->GetMenuBar();
|
2006-04-06 07:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
// Utility method for implementing both Create(nsIWidget ...) and
|
|
|
|
// Create(nsNativeWidget...)
|
|
|
|
nsresult nsCocoaWindow::StandardCreate(nsIWidget *aParent,
|
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
nsWidgetInitData *aInitData,
|
2006-02-10 21:39:30 +00:00
|
|
|
nsNativeWidget aNativeWindow)
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
2006-01-11 19:09:20 +00:00
|
|
|
Inherited::BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell,
|
|
|
|
aToolkit, aInitData);
|
2006-02-07 19:15:42 +00:00
|
|
|
|
|
|
|
mParent = aParent;
|
2006-02-08 06:09:44 +00:00
|
|
|
|
2006-02-10 21:39:30 +00:00
|
|
|
// create a window if we aren't given one, always create if this should be a popup
|
|
|
|
if (!aNativeWindow || (aInitData && aInitData->mWindowType == eWindowType_popup)) {
|
|
|
|
// decide on a window type
|
|
|
|
PRBool allOrDefault = PR_FALSE;
|
2005-10-07 23:31:45 +00:00
|
|
|
if (aInitData) {
|
2006-02-10 21:39:30 +00:00
|
|
|
allOrDefault = aInitData->mBorderStyle == eBorderStyle_all ||
|
|
|
|
aInitData->mBorderStyle == eBorderStyle_default;
|
2001-11-19 15:02:23 +00:00
|
|
|
mWindowType = aInitData->mWindowType;
|
2006-02-10 21:39:30 +00:00
|
|
|
// if a toplevel window was requested without a titlebar, use a dialog
|
2006-02-08 06:09:44 +00:00
|
|
|
if (mWindowType == eWindowType_toplevel &&
|
|
|
|
(aInitData->mBorderStyle == eBorderStyle_none ||
|
2006-02-10 21:39:30 +00:00
|
|
|
!allOrDefault &&
|
|
|
|
!(aInitData->mBorderStyle & eBorderStyle_title)))
|
|
|
|
mWindowType = eWindowType_dialog;
|
2006-02-08 06:09:44 +00:00
|
|
|
}
|
2005-10-07 23:31:45 +00:00
|
|
|
else {
|
2006-02-10 21:39:30 +00:00
|
|
|
allOrDefault = PR_TRUE;
|
|
|
|
mWindowType = eWindowType_toplevel;
|
2005-02-16 05:14:59 +00:00
|
|
|
}
|
2007-03-30 19:51:51 +00:00
|
|
|
|
|
|
|
// Some applications like Camino use native popup windows
|
|
|
|
// (native context menus, native tooltips)
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefs) {
|
|
|
|
PRBool useNativeContextMenus;
|
|
|
|
nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows", &useNativeContextMenus);
|
|
|
|
if (NS_SUCCEEDED(rv) && useNativeContextMenus && mWindowType == eWindowType_popup)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-10 21:39:30 +00:00
|
|
|
// we default to NSBorderlessWindowMask, add features if needed
|
|
|
|
unsigned int features = NSBorderlessWindowMask;
|
|
|
|
|
|
|
|
// Configure the window we will create based on the window type
|
|
|
|
switch (mWindowType)
|
|
|
|
{
|
2006-11-27 18:08:30 +00:00
|
|
|
case eWindowType_invisible:
|
2006-02-10 21:39:30 +00:00
|
|
|
case eWindowType_child:
|
|
|
|
break;
|
|
|
|
case eWindowType_dialog:
|
|
|
|
if (aInitData) {
|
|
|
|
switch (aInitData->mBorderStyle)
|
|
|
|
{
|
|
|
|
case eBorderStyle_none:
|
|
|
|
break;
|
|
|
|
case eBorderStyle_default:
|
|
|
|
features |= NSTitledWindowMask;
|
|
|
|
break;
|
|
|
|
case eBorderStyle_all:
|
2007-01-30 17:53:48 +00:00
|
|
|
features |= NSClosableWindowMask;
|
2006-02-10 21:39:30 +00:00
|
|
|
features |= NSTitledWindowMask;
|
|
|
|
features |= NSResizableWindowMask;
|
|
|
|
features |= NSMiniaturizableWindowMask;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (aInitData->mBorderStyle & eBorderStyle_title) {
|
|
|
|
features |= NSTitledWindowMask;
|
|
|
|
features |= NSMiniaturizableWindowMask;
|
|
|
|
}
|
2007-01-30 17:53:48 +00:00
|
|
|
if (aInitData->mBorderStyle & eBorderStyle_resizeh)
|
2006-02-10 21:39:30 +00:00
|
|
|
features |= NSResizableWindowMask;
|
2007-01-30 17:53:48 +00:00
|
|
|
if (aInitData->mBorderStyle & eBorderStyle_close)
|
|
|
|
features |= NSClosableWindowMask;
|
2006-02-10 21:39:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
features |= NSTitledWindowMask;
|
|
|
|
features |= NSMiniaturizableWindowMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eWindowType_sheet:
|
|
|
|
if (aInitData) {
|
|
|
|
nsWindowType parentType;
|
|
|
|
aParent->GetWindowType(parentType);
|
2006-06-08 17:29:18 +00:00
|
|
|
if (parentType != eWindowType_invisible &&
|
|
|
|
aInitData->mBorderStyle & eBorderStyle_resizeh) {
|
|
|
|
features = NSResizableWindowMask;
|
2006-02-10 21:39:30 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
features = NSMiniaturizableWindowMask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
features = NSMiniaturizableWindowMask;
|
|
|
|
}
|
2006-05-11 15:14:29 +00:00
|
|
|
features |= NSTitledWindowMask;
|
2006-02-10 21:39:30 +00:00
|
|
|
break;
|
2006-03-17 23:35:39 +00:00
|
|
|
case eWindowType_popup:
|
|
|
|
features |= NSBorderlessWindowMask;
|
|
|
|
break;
|
2006-02-10 21:39:30 +00:00
|
|
|
case eWindowType_toplevel:
|
|
|
|
features |= NSTitledWindowMask;
|
|
|
|
features |= NSMiniaturizableWindowMask;
|
|
|
|
if (allOrDefault || aInitData->mBorderStyle & eBorderStyle_close)
|
|
|
|
features |= NSClosableWindowMask;
|
|
|
|
if (allOrDefault || aInitData->mBorderStyle & eBorderStyle_resizeh)
|
|
|
|
features |= NSResizableWindowMask;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unhandled window type!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2006-03-10 20:51:48 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
NSRect rect = geckoRectToCocoaRect(aRect);
|
|
|
|
|
|
|
|
// compensate for difference between frame and content area height (e.g. title bar)
|
|
|
|
NSRect newWindowFrame = [NSWindow frameRectForContentRect:rect styleMask:features];
|
2006-03-17 23:35:39 +00:00
|
|
|
|
2006-03-10 20:51:48 +00:00
|
|
|
rect.origin.y -= (newWindowFrame.size.height - rect.size.height);
|
|
|
|
|
|
|
|
if (mWindowType != eWindowType_popup)
|
|
|
|
rect.origin.y -= ::GetMBarHeight();
|
2006-09-06 17:35:02 +00: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);
|
|
|
|
|
2007-07-17 20:29:39 +00:00
|
|
|
// Create the window
|
|
|
|
Class windowClass = [NSWindow class];
|
|
|
|
// If we're a top level window, we want to be able to have the toolbar
|
|
|
|
// pill button, so use the special ToolbarWindow class.
|
|
|
|
if (mWindowType == eWindowType_toplevel)
|
|
|
|
windowClass = [ToolbarWindow class];
|
|
|
|
// If we're a popup window we need to use the PopupWindow class.
|
|
|
|
else if (mWindowType == eWindowType_popup)
|
|
|
|
windowClass = [PopupWindow class];
|
2007-05-31 05:07:18 +00:00
|
|
|
mWindow = [[windowClass alloc] initWithContentRect:rect styleMask:features
|
2007-07-17 20:29:39 +00:00
|
|
|
backing:NSBackingStoreBuffered defer:NO];
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-03-17 23:35:39 +00:00
|
|
|
if (mWindowType == eWindowType_popup) {
|
2006-09-13 17:26:58 +00:00
|
|
|
[mWindow setAlphaValue:0.95];
|
2006-05-17 18:53:58 +00:00
|
|
|
[mWindow setLevel:NSPopUpMenuWindowLevel];
|
|
|
|
[mWindow setHasShadow:YES];
|
2006-07-25 18:51:41 +00:00
|
|
|
|
|
|
|
// we need to make our content view a ChildView
|
|
|
|
mPopupContentView = new nsChildView();
|
|
|
|
if (mPopupContentView) {
|
|
|
|
NS_ADDREF(mPopupContentView);
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsIWidget* thisAsWidget = static_cast<nsIWidget*>(this);
|
2006-07-25 18:51:41 +00:00
|
|
|
mPopupContentView->StandardCreate(thisAsWidget, aRect, aHandleEventFunction,
|
|
|
|
aContext, aAppShell, aToolkit, nsnull, nsnull);
|
|
|
|
|
|
|
|
ChildView* newContentView = (ChildView*)mPopupContentView->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
[mWindow setContentView:newContentView];
|
|
|
|
}
|
2006-03-17 23:35:39 +00:00
|
|
|
}
|
2006-05-23 19:47:43 +00:00
|
|
|
else if (mWindowType == eWindowType_invisible) {
|
|
|
|
[mWindow setLevel:kCGDesktopWindowLevelKey];
|
|
|
|
}
|
|
|
|
|
2006-10-04 20:03:59 +00:00
|
|
|
[mWindow setBackgroundColor:[NSColor whiteColor]];
|
2006-05-23 19:47:43 +00:00
|
|
|
[mWindow setContentMinSize:NSMakeSize(60, 60)];
|
2006-02-10 21:39:30 +00:00
|
|
|
[mWindow setReleasedWhenClosed:NO];
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
// setup our notification delegate. Note that setDelegate: does NOT retain.
|
|
|
|
mDelegate = [[WindowDelegate alloc] initWithGeckoWindow:this];
|
|
|
|
[mWindow setDelegate:mDelegate];
|
|
|
|
|
2006-02-10 21:39:30 +00:00
|
|
|
mWindowMadeHere = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mWindow = (NSWindow*)aNativeWindow;
|
|
|
|
mVisible = PR_TRUE;
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create a nsCocoaWindow using a native window provided by the application
|
2006-02-10 21:39:30 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Create(nsNativeWidget aNativeWindow,
|
2001-11-06 15:35:24 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
nsWidgetInitData *aInitData)
|
|
|
|
{
|
2006-11-27 18:08:30 +00:00
|
|
|
return(StandardCreate(nsnull, aRect, aHandleEventFunction, aContext,
|
|
|
|
aAppShell, aToolkit, aInitData, aNativeWindow));
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-19 15:02:23 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Create(nsIWidget* aParent,
|
2001-11-06 15:35:24 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
nsWidgetInitData *aInitData)
|
|
|
|
{
|
2006-11-27 18:08:30 +00:00
|
|
|
return(StandardCreate(aParent, aRect, aHandleEventFunction, aContext,
|
|
|
|
aAppShell, aToolkit, aInitData, nsnull));
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2006-08-09 01:50:21 +00:00
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Destroy()
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->Destroy();
|
|
|
|
|
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
nsBaseWidget::Destroy();
|
|
|
|
|
2006-07-27 14:42:28 +00:00
|
|
|
return NS_OK;
|
2006-07-25 18:51:41 +00:00
|
|
|
}
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-08-09 01:50:21 +00:00
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
void* nsCocoaWindow::GetNativeData(PRUint32 aDataType)
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
|
|
|
void* retVal = nsnull;
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
switch (aDataType) {
|
2001-11-08 21:47:44 +00:00
|
|
|
// to emulate how windows works, we always have to return a NSView
|
|
|
|
// for NS_NATIVE_WIDGET
|
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
case NS_NATIVE_DISPLAY:
|
2001-11-06 15:35:24 +00:00
|
|
|
retVal = [mWindow contentView];
|
|
|
|
break;
|
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
case NS_NATIVE_WINDOW:
|
2001-11-08 21:47:44 +00:00
|
|
|
retVal = mWindow;
|
2001-11-06 15:35:24 +00:00
|
|
|
break;
|
2001-11-08 21:47:44 +00:00
|
|
|
|
2006-11-27 18:08:30 +00:00
|
|
|
case NS_NATIVE_GRAPHIC:
|
|
|
|
// There isn't anything that makes sense to return here,
|
|
|
|
// and it doesn't matter so just return nsnull.
|
|
|
|
NS_ASSERTION(0, "Requesting NS_NATIVE_GRAPHIC on a top-level window!");
|
2001-11-06 15:35:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::IsVisible(PRBool & aState)
|
2002-02-12 08:30:01 +00:00
|
|
|
{
|
|
|
|
aState = mVisible;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-05-26 19:57:41 +00:00
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
// Hide or show this window
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::Show(PRBool bState)
|
|
|
|
{
|
2006-06-08 17:29:18 +00:00
|
|
|
nsIWidget* parentWidget = mParent;
|
|
|
|
nsCOMPtr<nsPIWidgetCocoa> piParentWidget(do_QueryInterface(parentWidget));
|
|
|
|
NSWindow* nativeParentWindow = (parentWidget) ?
|
|
|
|
(NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW) : nil;
|
|
|
|
|
|
|
|
if (bState && !mBounds.IsEmpty()) {
|
|
|
|
if (mWindowType == eWindowType_sheet) {
|
|
|
|
// bail if no parent window (its basically what we do in Carbon)
|
|
|
|
if (!nativeParentWindow || !piParentWidget)
|
|
|
|
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.
|
|
|
|
PRBool parentIsSheet = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(piParentWidget->GetIsSheet(&parentIsSheet)) &&
|
|
|
|
parentIsSheet) {
|
|
|
|
piParentWidget->GetSheetWindowParent(&topNonSheetWindow);
|
|
|
|
[NSApp endSheet:nativeParentWindow];
|
2006-11-17 09:27:22 +00:00
|
|
|
[nativeParentWindow setAcceptsMouseMovedEvents:NO];
|
2006-06-08 17:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCocoaWindow* sheetShown = nsnull;
|
|
|
|
if (NS_SUCCEEDED(piParentWidget->GetChildSheet(PR_TRUE, &sheetShown)) &&
|
|
|
|
(!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...].
|
|
|
|
if (![mWindow isSheet]) {
|
|
|
|
mVisible = PR_TRUE;
|
|
|
|
mSheetNeedsShow = PR_FALSE;
|
|
|
|
mSheetWindowParent = topNonSheetWindow;
|
|
|
|
[[mSheetWindowParent delegate] sendLostFocusAndDeactivate];
|
2006-11-17 09:27:22 +00:00
|
|
|
[mWindow setAcceptsMouseMovedEvents:YES];
|
2006-06-08 17:29:18 +00:00
|
|
|
[NSApp beginSheet:mWindow
|
|
|
|
modalForWindow:mSheetWindowParent
|
|
|
|
modalDelegate:mDelegate
|
|
|
|
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
|
|
|
contextInfo:mSheetWindowParent];
|
|
|
|
[[mWindow delegate] sendGotFocusAndActivate];
|
2006-10-03 20:38:38 +00:00
|
|
|
SendSetZLevelEvent();
|
2006-06-08 17:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
mSheetNeedsShow = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mWindowType == eWindowType_popup) {
|
|
|
|
mVisible = PR_TRUE;
|
2007-07-17 20:29:39 +00: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.
|
|
|
|
int windowNumber = [mWindow windowNumber];
|
|
|
|
[mWindow _setWindowNumber:-1];
|
|
|
|
[mWindow _setWindowNumber:windowNumber];
|
2006-11-17 09:27:22 +00:00
|
|
|
[mWindow setAcceptsMouseMovedEvents:YES];
|
2006-04-25 19:20:31 +00:00
|
|
|
[mWindow orderFront:nil];
|
2006-10-03 20:38:38 +00:00
|
|
|
SendSetZLevelEvent();
|
2007-07-17 20:29:39 +00: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"];
|
|
|
|
}
|
2006-04-25 19:20:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-06-08 17:29:18 +00:00
|
|
|
mVisible = PR_TRUE;
|
2006-11-17 09:27:22 +00:00
|
|
|
[mWindow setAcceptsMouseMovedEvents:YES];
|
2006-04-25 19:20:31 +00:00
|
|
|
[mWindow makeKeyAndOrderFront:nil];
|
2006-10-03 20:38:38 +00:00
|
|
|
SendSetZLevelEvent();
|
2006-04-25 19:20:31 +00:00
|
|
|
}
|
2006-04-06 07:41:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-06-08 17:29:18 +00:00
|
|
|
// roll up any popups if a top-level window is going away
|
2007-06-12 20:26:24 +00:00
|
|
|
if (mWindowType == eWindowType_toplevel)
|
|
|
|
RollUpPopups();
|
2006-06-08 17:29:18 +00:00
|
|
|
|
|
|
|
// now get rid of the window/sheet
|
|
|
|
if (mWindowType == eWindowType_sheet) {
|
|
|
|
if (mVisible) {
|
|
|
|
mVisible = PR_FALSE;
|
|
|
|
|
|
|
|
// get sheet's parent *before* hiding the sheet (which breaks the linkage)
|
|
|
|
NSWindow* sheetParent = mSheetWindowParent;
|
|
|
|
|
|
|
|
// hide the sheet
|
|
|
|
[NSApp endSheet:mWindow];
|
|
|
|
|
2006-11-17 09:27:22 +00:00
|
|
|
[mWindow setAcceptsMouseMovedEvents:NO];
|
|
|
|
|
2006-06-08 17:29:18 +00:00
|
|
|
[[mWindow delegate] sendLostFocusAndDeactivate];
|
|
|
|
|
|
|
|
nsCocoaWindow* siblingSheetToShow = nsnull;
|
|
|
|
PRBool parentIsSheet = PR_FALSE;
|
|
|
|
|
|
|
|
if (nativeParentWindow && piParentWidget &&
|
|
|
|
NS_SUCCEEDED(piParentWidget->GetChildSheet(PR_FALSE, &siblingSheetToShow)) &&
|
|
|
|
siblingSheetToShow) {
|
|
|
|
// First, give sibling sheets an opportunity to show.
|
|
|
|
siblingSheetToShow->Show(PR_TRUE);
|
|
|
|
}
|
|
|
|
else if (nativeParentWindow && piParentWidget &&
|
|
|
|
NS_SUCCEEDED(piParentWidget->GetIsSheet(&parentIsSheet)) &&
|
|
|
|
parentIsSheet) {
|
|
|
|
// 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.
|
2006-11-17 09:27:22 +00:00
|
|
|
[nativeParentWindow setAcceptsMouseMovedEvents:YES];
|
2006-06-08 17:29:18 +00:00
|
|
|
[NSApp beginSheet:nativeParentWindow
|
|
|
|
modalForWindow:sheetParent
|
|
|
|
modalDelegate:[nativeParentWindow delegate]
|
|
|
|
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
|
|
|
contextInfo:sheetParent];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Sheet, that was hard. No more siblings or parents, going back
|
|
|
|
// to a real window.
|
|
|
|
[sheetParent makeKeyAndOrderFront:nil];
|
2006-11-17 09:27:22 +00:00
|
|
|
[sheetParent setAcceptsMouseMovedEvents:YES];
|
2006-06-08 17:29:18 +00:00
|
|
|
}
|
2006-10-03 20:38:38 +00:00
|
|
|
SendSetZLevelEvent();
|
2006-06-08 17:29:18 +00:00
|
|
|
}
|
|
|
|
else 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.
|
|
|
|
mSheetNeedsShow = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[mWindow orderOut:nil];
|
2007-07-17 20:29:39 +00: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).
|
|
|
|
if (mWindowType == eWindowType_popup)
|
|
|
|
[NSApp _removeWindowFromCache:mWindow];
|
2006-11-17 09:27:22 +00:00
|
|
|
// it's very important to turn off mouse moved events when hiding a window, otherwise
|
|
|
|
// the windows' tracking rects will interfere with each other. (bug 356528)
|
|
|
|
[mWindow setAcceptsMouseMovedEvents:NO];
|
2006-06-08 17:29:18 +00:00
|
|
|
mVisible = PR_FALSE;
|
2007-07-17 20:29:39 +00: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"];
|
|
|
|
}
|
2006-06-08 17:29:18 +00:00
|
|
|
}
|
2006-04-06 07:41:34 +00:00
|
|
|
}
|
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->Show(bState);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-09 01:50:21 +00:00
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_METHOD nsCocoaWindow::AddMouseListener(nsIMouseListener * aListener)
|
|
|
|
{
|
|
|
|
nsBaseWidget::AddMouseListener(aListener);
|
|
|
|
|
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->AddMouseListener(aListener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-09 01:50:21 +00:00
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_METHOD nsCocoaWindow::AddEventListener(nsIEventListener * aListener)
|
|
|
|
{
|
|
|
|
nsBaseWidget::AddEventListener(aListener);
|
|
|
|
|
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->AddEventListener(aListener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD nsCocoaWindow::AddMenuListener(nsIMenuListener * aListener)
|
|
|
|
{
|
|
|
|
nsBaseWidget::AddMenuListener(aListener);
|
|
|
|
|
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->AddMenuListener(aListener);
|
|
|
|
|
2006-04-06 07:41:34 +00:00
|
|
|
return NS_OK;
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-28 23:10:04 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Enable(PRBool aState)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::IsEnabled(PRBool *aState)
|
|
|
|
{
|
|
|
|
if (aState)
|
|
|
|
*aState = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
|
2002-01-09 01:29:18 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::ConstrainPosition(PRBool aAllowSlop,
|
|
|
|
PRInt32 *aX, PRInt32 *aY)
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Move(PRInt32 aX, PRInt32 aY)
|
2001-11-19 15:02:23 +00:00
|
|
|
{
|
2005-10-07 23:31:45 +00:00
|
|
|
if (mWindow) {
|
2001-11-19 15:02:23 +00:00
|
|
|
// if we're a popup, we have to convert from our parent widget's coord
|
|
|
|
// system to the global coord system first because the (x,y) we're given
|
|
|
|
// is in its coordinate system.
|
2006-02-22 23:15:25 +00:00
|
|
|
if (mWindowType == eWindowType_popup) {
|
2001-11-19 15:02:23 +00:00
|
|
|
nsRect localRect, globalRect;
|
|
|
|
localRect.x = aX;
|
|
|
|
localRect.y = aY;
|
2006-02-07 19:15:42 +00:00
|
|
|
if (mParent) {
|
|
|
|
mParent->WidgetToScreen(localRect,globalRect);
|
2001-11-19 15:02:23 +00:00
|
|
|
aX=globalRect.x;
|
|
|
|
aY=globalRect.y;
|
2006-05-17 18:53:58 +00:00
|
|
|
}
|
2001-11-19 15:02:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-22 21:56:50 +00:00
|
|
|
// the point we have is in Gecko coordinates (origin top-left). Convert
|
|
|
|
// it to Cocoa ones (origin bottom-left).
|
2007-07-17 20:29:39 +00:00
|
|
|
NSPoint coord = {aX, CocoaScreenCoordsHeight() - aY};
|
2007-02-22 21:56:50 +00:00
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
//printf("final coords %f %f\n", coord.x, coord.y);
|
|
|
|
//printf("- window coords before %f %f\n", [mWindow frame].origin.x, [mWindow frame].origin.y);
|
2001-11-06 15:35:24 +00:00
|
|
|
[mWindow setFrameTopLeftPoint:coord];
|
2005-10-07 23:31:45 +00:00
|
|
|
//printf("- window coords after %f %f\n", [mWindow frame].origin.x, [mWindow frame].origin.y);
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
//
|
|
|
|
// Position the window behind the given window
|
|
|
|
//
|
2003-10-07 01:19:51 +00:00
|
|
|
NS_METHOD nsCocoaWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget, PRBool aActivate)
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
|
2006-10-13 20:27:56 +00:00
|
|
|
// Note bug 278777, we need to update state when the window is unminimized
|
|
|
|
// from the dock by users.
|
2001-11-06 15:35:24 +00:00
|
|
|
NS_METHOD nsCocoaWindow::SetSizeMode(PRInt32 aMode)
|
|
|
|
{
|
2006-10-13 20:27:56 +00:00
|
|
|
PRInt32 previousMode;
|
|
|
|
nsBaseWidget::GetSizeMode(&previousMode);
|
|
|
|
|
|
|
|
nsresult rv = nsBaseWidget::SetSizeMode(aMode);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aMode == nsSizeMode_Normal) {
|
|
|
|
if (previousMode == nsSizeMode_Maximized && [mWindow isZoomed])
|
|
|
|
[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];
|
|
|
|
}
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
Resize(aWidth, aHeight, aRepaint);
|
2006-07-26 21:08:42 +00:00
|
|
|
Move(aX, aY);
|
2001-11-06 15:35:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
|
|
|
|
{
|
2005-10-07 23:31:45 +00:00
|
|
|
if (mWindow) {
|
2006-08-09 01:50:21 +00:00
|
|
|
NSRect newFrame = [mWindow frame];
|
|
|
|
|
|
|
|
// width is easy, no adjusting necessary
|
|
|
|
newFrame.size.width = aWidth;
|
|
|
|
|
|
|
|
// Adjusting the height is harder.
|
2006-06-08 17:29:18 +00:00
|
|
|
// Note that [mWindow isSheet] is not the same as checking for
|
|
|
|
// |mWindowType == eWindowType_sheet|. If this is a sheet object, the latter
|
|
|
|
// will always be true. The former is true only when the sheet is being shown.
|
|
|
|
// Here we need to know if the sheet is actually being shown because if it is,
|
|
|
|
// the content view and the window's frame are equal, despite the fact that
|
|
|
|
// the native window object has the title bar flag set. If the window is not
|
|
|
|
// being shown as a sheet the content area and window frame differ.
|
2006-08-09 01:50:21 +00:00
|
|
|
float newHeight = (float)aHeight;
|
|
|
|
if (mWindowType != eWindowType_popup && ![mWindow isSheet])
|
2007-06-12 20:26:24 +00:00
|
|
|
newHeight += TitleBarHeightForWindow(mWindow); // add height of title bar
|
2006-08-09 01:50:21 +00:00
|
|
|
// Now we need to adjust for the fact that gecko wants the top of the window
|
|
|
|
// to remain in the same place.
|
2006-08-09 01:51:49 +00:00
|
|
|
newFrame.origin.y += newFrame.size.height - newHeight;
|
2006-08-09 01:50:21 +00:00
|
|
|
newFrame.size.height = newHeight;
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
StartResizing();
|
2007-04-06 00:11:41 +00:00
|
|
|
if (mAnimation == nsIDOMChromeWindow::RESIZE_ANIMATION_SLIDE) {
|
|
|
|
[[mWindow contentView] setHidden:YES];
|
|
|
|
[mWindow setFrame:newFrame display:YES animate:YES];
|
|
|
|
[[mWindow contentView] setHidden:NO];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[mWindow setFrame:newFrame display:NO];
|
|
|
|
}
|
2001-11-06 15:35:24 +00:00
|
|
|
StopResizing();
|
|
|
|
}
|
|
|
|
|
2007-07-07 00:28:29 +00:00
|
|
|
// report the actual size of the window because it can be restricted
|
|
|
|
NSRect finalWindowFrame = [mWindow contentRectForFrameRect:[mWindow frame]];
|
|
|
|
mBounds.width = (nscoord)finalWindowFrame.size.width;
|
|
|
|
mBounds.height = (nscoord)finalWindowFrame.size.height;
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
// tell gecko to update all the child widgets
|
|
|
|
ReportSizeEvent();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
|
2006-04-06 05:31:16 +00:00
|
|
|
// We return the origin for the entire window (title bar and all) but
|
|
|
|
// the size of the content area. I have no idea why it was originally done
|
|
|
|
// this way, but it matches Carbon and makes things work nicely.
|
2005-10-07 23:31:45 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(nsRect &aRect)
|
|
|
|
{
|
2006-04-06 05:31:16 +00:00
|
|
|
nsRect windowFrame = cocoaRectToGeckoRect([mWindow frame]);
|
|
|
|
aRect.x = windowFrame.x;
|
|
|
|
aRect.y = windowFrame.y;
|
|
|
|
aRect.width = mBounds.width;
|
|
|
|
aRect.height = mBounds.height;
|
|
|
|
// printf("GetScreenBounds: output: %d,%d,%d,%d\n", aRect.x, aRect.y, aRect.width, aRect.height);
|
2001-11-06 15:35:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
PRBool nsCocoaWindow::OnPaint(nsPaintEvent &event)
|
|
|
|
{
|
|
|
|
return PR_TRUE; // don't dispatch the update event
|
|
|
|
}
|
|
|
|
|
2006-05-26 19:57:41 +00:00
|
|
|
|
2004-04-18 23:18:23 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetTitle(const nsAString& aTitle)
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
2004-04-18 23:18:23 +00:00
|
|
|
const nsString& strTitle = PromiseFlatString(aTitle);
|
|
|
|
NSString* title = [NSString stringWithCharacters:strTitle.get() length:strTitle.Length()];
|
2001-11-06 15:35:24 +00:00
|
|
|
[mWindow setTitle:title];
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous)
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
return mPopupContentView->Invalidate(aRect, aIsSynchronous);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-09 01:50:21 +00:00
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Invalidate(PRBool aIsSynchronous)
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
return mPopupContentView->Invalidate(aIsSynchronous);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-09 01:50:21 +00:00
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::Update()
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
return mPopupContentView->Update();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
// 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.
|
2007-06-12 20:26:24 +00:00
|
|
|
PRBool nsCocoaWindow::DragEvent(unsigned int aMessage, Point aMouseGlobal, UInt16 aKeyModifiers)
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
|
2006-10-03 20:38:38 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SendSetZLevelEvent()
|
2005-10-07 23:31:45 +00:00
|
|
|
{
|
2006-05-17 18:53:58 +00:00
|
|
|
nsZLevelEvent event(PR_TRUE, NS_SETZLEVEL, this);
|
2006-10-03 20:38:38 +00:00
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
event.refPoint.x = mBounds.x;
|
|
|
|
event.refPoint.y = mBounds.y;
|
|
|
|
event.time = PR_IntervalNow();
|
2006-10-03 20:38:38 +00:00
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
event.mImmediate = PR_TRUE;
|
2006-10-03 20:38:38 +00:00
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
DispatchEvent(&event, status);
|
2006-10-03 20:38:38 +00:00
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetChildSheet(PRBool aShown, nsCocoaWindow** _retval)
|
|
|
|
{
|
2006-06-08 17:29:18 +00:00
|
|
|
nsIWidget* child = GetFirstChild();
|
|
|
|
|
|
|
|
while (child) {
|
|
|
|
// find out if this is a top-level window
|
|
|
|
nsCOMPtr<nsPIWidgetCocoa> piChildWidget(do_QueryInterface(child));
|
|
|
|
if (piChildWidget) {
|
|
|
|
// if it implements nsPIWidgetCocoa, it must be an nsCocoaWindow
|
2007-07-08 07:08:04 +00:00
|
|
|
nsCocoaWindow* window = static_cast<nsCocoaWindow*>(child);
|
2006-06-08 17:29:18 +00:00
|
|
|
nsWindowType type;
|
|
|
|
if (NS_SUCCEEDED(window->GetWindowType(type)) &&
|
|
|
|
type == eWindowType_sheet) {
|
|
|
|
// if it's a sheet, it must be an nsCocoaWindow
|
2007-07-08 07:08:04 +00:00
|
|
|
nsCocoaWindow* cocoaWindow = static_cast<nsCocoaWindow*>(window);
|
2006-06-08 17:29:18 +00:00
|
|
|
if ((aShown && cocoaWindow->mVisible) ||
|
|
|
|
(!aShown && cocoaWindow->mSheetNeedsShow)) {
|
|
|
|
*_retval = cocoaWindow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
*_retval = nsnull;
|
2006-06-08 17:29:18 +00:00
|
|
|
|
2006-05-17 18:53:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetMenuBar(nsIMenuBar** menuBar)
|
|
|
|
{
|
|
|
|
*menuBar = mMenuBar;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetIsSheet(PRBool* isSheet)
|
|
|
|
{
|
2006-06-08 17:29:18 +00:00
|
|
|
mWindowType == eWindowType_sheet ? *isSheet = PR_TRUE : *isSheet = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetSheetWindowParent(NSWindow** sheetWindowParent)
|
|
|
|
{
|
|
|
|
*sheetWindowParent = mSheetWindowParent;
|
2006-05-17 18:53:58 +00:00
|
|
|
return NS_OK;
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::ResetInputState()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
// Invokes callback and ProcessEvent method on Event Listener object
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCocoaWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus)
|
|
|
|
{
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsIWidget* aWidget = event->widget;
|
|
|
|
NS_IF_ADDREF(aWidget);
|
|
|
|
|
|
|
|
if (nsnull != mMenuListener){
|
|
|
|
if(NS_MENU_EVENT == event->eventStructType)
|
2005-10-07 23:31:45 +00:00
|
|
|
aStatus = mMenuListener->MenuSelected(static_cast<nsMenuEvent&>(*event));
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
if (mEventCallback)
|
|
|
|
aStatus = (*mEventCallback)(event);
|
|
|
|
|
|
|
|
// Dispatch to event listener if event was not consumed
|
|
|
|
if ((aStatus != nsEventStatus_eConsumeNoDefault) && (mEventListener != nsnull))
|
|
|
|
aStatus = mEventListener->ProcessEvent(*event);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(aWidget);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCocoaWindow::ReportSizeEvent()
|
|
|
|
{
|
2005-04-28 23:48:28 +00:00
|
|
|
nsSizeEvent sizeEvent(PR_TRUE, NS_SIZE, this);
|
2005-10-07 23:31:45 +00:00
|
|
|
sizeEvent.time = PR_IntervalNow();
|
2001-11-08 21:47:44 +00:00
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
sizeEvent.windowSize = &mBounds;
|
|
|
|
sizeEvent.mWinWidth = mBounds.width;
|
|
|
|
sizeEvent.mWinHeight = mBounds.height;
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2001-11-08 21:47:44 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
DispatchEvent(&sizeEvent, status);
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetMenuBar(nsIMenuBar *aMenuBar)
|
|
|
|
{
|
|
|
|
if (mMenuBar)
|
|
|
|
mMenuBar->SetParent(nsnull);
|
|
|
|
mMenuBar = aMenuBar;
|
2006-04-07 04:51:16 +00:00
|
|
|
|
|
|
|
// We 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.
|
|
|
|
if (!gSomeMenuBarPainted && mMenuBar && (GetHiddenWindowMenuBar() == mMenuBar))
|
|
|
|
mMenuBar->Paint();
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
return NS_OK;
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-25 18:51:41 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetFocus(PRBool aState)
|
|
|
|
{
|
|
|
|
if (mPopupContentView)
|
|
|
|
mPopupContentView->SetFocus(aState);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-09 01:50:21 +00:00
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::ShowMenuBar(PRBool aShow)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-25 19:19:48 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect)
|
|
|
|
{
|
|
|
|
nsRect r = cocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
|
|
|
|
|
|
|
|
aNewRect.x = r.x + aOldRect.x;
|
|
|
|
aNewRect.y = r.y + aOldRect.y;
|
|
|
|
aNewRect.width = aOldRect.width;
|
|
|
|
aNewRect.height = aOldRect.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect)
|
|
|
|
{
|
|
|
|
nsRect r = cocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
|
|
|
|
|
|
|
|
aNewRect.x = aOldRect.x - r.x;
|
|
|
|
aNewRect.y = aOldRect.y - r.y;
|
|
|
|
aNewRect.width = aOldRect.width;
|
|
|
|
aNewRect.height = aOldRect.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
nsIMenuBar* nsCocoaWindow::GetMenuBar()
|
|
|
|
{
|
|
|
|
return mMenuBar;
|
|
|
|
}
|
2001-11-06 15:35:24 +00:00
|
|
|
|
|
|
|
|
2006-03-07 20:02:09 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::CaptureRollupEvents(nsIRollupListener * aListener,
|
|
|
|
PRBool aDoCapture,
|
|
|
|
PRBool aConsumeRollupEvent)
|
|
|
|
{
|
2006-07-31 19:19:39 +00:00
|
|
|
NS_IF_RELEASE(gRollupListener);
|
|
|
|
NS_IF_RELEASE(gRollupWidget);
|
|
|
|
|
2006-03-07 20:02:09 +00:00
|
|
|
if (aDoCapture) {
|
|
|
|
gRollupListener = aListener;
|
|
|
|
NS_ADDREF(aListener);
|
|
|
|
gRollupWidget = this;
|
|
|
|
NS_ADDREF(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-11 19:51:56 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetAttention(PRInt32 aCycleCount)
|
|
|
|
{
|
|
|
|
[NSApp requestUserAttention:NSInformationalRequest];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-06 00:11:41 +00:00
|
|
|
NS_IMETHODIMP nsCocoaWindow::SetAnimatedResize(PRUint16 aAnimation)
|
|
|
|
{
|
|
|
|
mAnimation = aAnimation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCocoaWindow::GetAnimatedResize(PRUint16* aAnimation)
|
|
|
|
{
|
|
|
|
*aAnimation = mAnimation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
@implementation WindowDelegate
|
|
|
|
|
|
|
|
|
2006-12-19 19:26:41 +00:00
|
|
|
// 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
|
|
|
|
{
|
|
|
|
// 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!");
|
|
|
|
|
|
|
|
nsIMenuBar* geckoMenuBar = geckoWidget->GetMenuBar();
|
|
|
|
if (geckoMenuBar) {
|
|
|
|
geckoMenuBar->Paint();
|
|
|
|
}
|
|
|
|
else {
|
2006-12-19 22:54:14 +00:00
|
|
|
// sometimes we don't have a native application menu early in launching
|
|
|
|
if (!sApplicationMenu)
|
|
|
|
return;
|
2006-12-19 19:26:41 +00:00
|
|
|
|
|
|
|
// create a new menu bar with one item
|
|
|
|
NSMenu* newMenuBar = [[NSMenu alloc] init];
|
|
|
|
NSMenuItem* newMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
|
|
|
[newMenuBar addItem:newMenuItem];
|
|
|
|
[newMenuItem release];
|
|
|
|
|
|
|
|
// Attach application menu as submenu for our one menu item. If the application
|
|
|
|
// menu has a supermenu, we need to disconnect it from its parent before hooking
|
|
|
|
// it up to the new menu bar
|
|
|
|
NSMenu* appMenuSupermenu = [sApplicationMenu supermenu];
|
|
|
|
if (appMenuSupermenu) {
|
|
|
|
int appMenuItemIndex = [appMenuSupermenu indexOfItemWithSubmenu:sApplicationMenu];
|
|
|
|
[[appMenuSupermenu itemAtIndex:appMenuItemIndex] setSubmenu:nil];
|
|
|
|
}
|
|
|
|
[newMenuItem setSubmenu:sApplicationMenu];
|
|
|
|
|
|
|
|
// set our new menu bar as the main menu
|
|
|
|
[NSApp setMainMenu:newMenuBar];
|
|
|
|
[newMenuBar release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
- (id)initWithGeckoWindow:(nsCocoaWindow*)geckoWind
|
|
|
|
{
|
|
|
|
[super init];
|
|
|
|
mGeckoWindow = geckoWind;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-02-22 23:15:25 +00:00
|
|
|
|
2006-04-06 19:14:02 +00:00
|
|
|
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
|
|
|
|
{
|
2007-06-12 20:26:24 +00:00
|
|
|
RollUpPopups();
|
2006-04-06 19:14:02 +00:00
|
|
|
|
|
|
|
return proposedFrameSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-06 15:35:24 +00:00
|
|
|
- (void)windowDidResize:(NSNotification *)aNotification
|
|
|
|
{
|
2006-03-07 20:02:09 +00:00
|
|
|
if (mGeckoWindow->IsResizing())
|
|
|
|
return;
|
|
|
|
|
2006-06-02 17:48:34 +00:00
|
|
|
// Gecko already compensates for the title bar, so we have to strip it out here.
|
2006-06-08 17:29:18 +00:00
|
|
|
NSRect frameRect = [[[aNotification object] contentView] frame];
|
2007-07-08 07:08:04 +00:00
|
|
|
mGeckoWindow->Resize(static_cast<PRInt32>(frameRect.size.width),
|
|
|
|
static_cast<PRInt32>(frameRect.size.height), PR_TRUE);
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)windowDidBecomeMain:(NSNotification *)aNotification
|
|
|
|
{
|
2007-06-12 20:26:24 +00:00
|
|
|
RollUpPopups();
|
2007-05-18 02:06:59 +00:00
|
|
|
|
2006-12-19 19:26:41 +00:00
|
|
|
NSWindow* window = [aNotification object];
|
|
|
|
if (window)
|
|
|
|
[WindowDelegate paintMenubarForWindow:window];
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)windowDidResignMain:(NSNotification *)aNotification
|
|
|
|
{
|
2007-06-12 20:26:24 +00:00
|
|
|
RollUpPopups();
|
2006-03-07 20:02:09 +00:00
|
|
|
|
2006-04-06 07:41:34 +00:00
|
|
|
nsCOMPtr<nsIMenuBar> hiddenWindowMenuBar = GetHiddenWindowMenuBar();
|
|
|
|
if (hiddenWindowMenuBar) {
|
2006-04-21 20:35:00 +00:00
|
|
|
// printf("painting hidden window menu bar due to window losing main status\n");
|
2006-04-06 07:41:34 +00:00
|
|
|
hiddenWindowMenuBar->Paint();
|
|
|
|
}
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-19 19:26:41 +00:00
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSWindow* window = [aNotification object];
|
|
|
|
if ([window isSheet])
|
|
|
|
[WindowDelegate paintMenubarForWindow:window];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
// 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]];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-07 20:02:09 +00:00
|
|
|
- (void)windowWillMove:(NSNotification *)aNotification
|
2001-11-06 15:35:24 +00:00
|
|
|
{
|
2007-06-12 20:26:24 +00:00
|
|
|
RollUpPopups();
|
2001-11-06 15:35:24 +00:00
|
|
|
}
|
|
|
|
|
2007-05-10 23:54:05 +00:00
|
|
|
- (void)windowDidMove:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
// Dispatch the move event to Gecko
|
|
|
|
nsGUIEvent guiEvent(PR_TRUE, NS_MOVE, mGeckoWindow);
|
|
|
|
nsRect rect;
|
|
|
|
mGeckoWindow->GetScreenBounds(rect);
|
|
|
|
guiEvent.refPoint.x = rect.x;
|
|
|
|
guiEvent.refPoint.y = rect.y;
|
|
|
|
guiEvent.time = PR_IntervalNow();
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mGeckoWindow->DispatchEvent(&guiEvent, status);
|
|
|
|
}
|
2001-11-06 15:35:24 +00:00
|
|
|
|
2006-03-17 05:16:59 +00:00
|
|
|
- (BOOL)windowShouldClose:(id)sender
|
2006-02-22 23:15:25 +00:00
|
|
|
{
|
2006-03-17 05:16:59 +00:00
|
|
|
// We only want to send NS_XUL_CLOSE and let gecko close the window
|
2006-02-22 23:15:25 +00:00
|
|
|
nsGUIEvent guiEvent(PR_TRUE, NS_XUL_CLOSE, mGeckoWindow);
|
|
|
|
guiEvent.time = PR_IntervalNow();
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mGeckoWindow->DispatchEvent(&guiEvent, status);
|
2006-03-17 05:16:59 +00:00
|
|
|
return NO; // gecko will do it
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-25 19:20:31 +00:00
|
|
|
- (void)windowWillClose:(NSNotification *)aNotification
|
2006-03-17 05:16:59 +00:00
|
|
|
{
|
2007-06-12 20:26:24 +00:00
|
|
|
RollUpPopups();
|
2006-02-22 23:15:25 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:31:45 +00:00
|
|
|
|
2006-03-07 20:02:09 +00:00
|
|
|
- (void)windowWillMiniaturize:(NSNotification *)aNotification
|
|
|
|
{
|
2007-06-12 20:26:24 +00:00
|
|
|
RollUpPopups();
|
2006-03-07 20:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-25 19:20:31 +00:00
|
|
|
- (void)sendGotFocusAndActivate
|
|
|
|
{
|
|
|
|
if (!mGeckoWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsGUIEvent focusGuiEvent(PR_TRUE, NS_GOTFOCUS, mGeckoWindow);
|
|
|
|
focusGuiEvent.time = PR_IntervalNow();
|
|
|
|
mGeckoWindow->DispatchEvent(&focusGuiEvent, status);
|
|
|
|
|
|
|
|
nsGUIEvent activateGuiEvent(PR_TRUE, NS_ACTIVATE, mGeckoWindow);
|
|
|
|
activateGuiEvent.time = PR_IntervalNow();
|
|
|
|
mGeckoWindow->DispatchEvent(&activateGuiEvent, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)sendLostFocusAndDeactivate
|
|
|
|
{
|
|
|
|
if (!mGeckoWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsGUIEvent deactivateGuiEvent(PR_TRUE, NS_DEACTIVATE, mGeckoWindow);
|
|
|
|
deactivateGuiEvent.time = PR_IntervalNow();
|
|
|
|
mGeckoWindow->DispatchEvent(&deactivateGuiEvent, status);
|
|
|
|
|
|
|
|
nsGUIEvent lostfocusGuiEvent(PR_TRUE, NS_LOSTFOCUS, mGeckoWindow);
|
|
|
|
lostfocusGuiEvent.time = PR_IntervalNow();
|
|
|
|
mGeckoWindow->DispatchEvent(&lostfocusGuiEvent, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-08 17:29:18 +00:00
|
|
|
- (void)didEndSheet:(NSWindow*)sheet returnCode:(int)returnCode contextInfo:(void*)contextInfo
|
|
|
|
{
|
|
|
|
// Note: 'contextInfo' is the window that is the parent of the sheet,
|
|
|
|
// we set that in nsCocoaWindow::Show. 'contextInfo' is always the top-level
|
|
|
|
// window, not another sheet itself.
|
|
|
|
[[sheet delegate] sendLostFocusAndDeactivate];
|
|
|
|
[sheet orderOut:self];
|
|
|
|
[[(NSWindow*)contextInfo delegate] sendGotFocusAndActivate];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-17 22:32:40 +00:00
|
|
|
- (nsCocoaWindow*)geckoWidget
|
2006-12-19 19:26:41 +00:00
|
|
|
{
|
|
|
|
return mGeckoWindow;
|
|
|
|
}
|
|
|
|
|
2007-05-31 05:07:18 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ToolbarWindow
|
|
|
|
|
|
|
|
// The carbon widget code was saying we want a toolbar for all top level
|
|
|
|
// windows, and since we're only using this class for top level windows, we
|
|
|
|
// always want to return yes from here.
|
|
|
|
- (BOOL)_hasToolbar
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch a toolbar pill button clicked message to Gecko
|
|
|
|
- (void)_toolbarPillButtonClicked:(id)sender
|
|
|
|
{
|
|
|
|
nsCocoaWindow *geckoWindow = [[self delegate] geckoWidget];
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsGUIEvent guiEvent(PR_TRUE, NS_OS_TOOLBAR, geckoWindow);
|
|
|
|
guiEvent.time = PR_IntervalNow();
|
|
|
|
geckoWindow->DispatchEvent(&guiEvent, status);
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:29:18 +00:00
|
|
|
@end
|
2007-07-17 20:29:39 +00:00
|
|
|
|
|
|
|
@implementation PopupWindow
|
|
|
|
|
|
|
|
// The OS treats our custom popup windows very strangely -- many mouse events
|
|
|
|
// sent to them never reach their target NSView objects. (That these windows
|
|
|
|
// are borderless and of level NSPopUpMenuWindowLevel may have something to do
|
|
|
|
// with it.) The best solution is to pre-empt the OS, as follows. (All
|
|
|
|
// events for a given NSWindow object go through its sendEvent: method.)
|
|
|
|
- (void)sendEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NSView *target = nil, *contentView = nil;
|
|
|
|
NSWindow *window = [anEvent window];
|
|
|
|
NSEventType type = [anEvent type];
|
|
|
|
if (window) {
|
|
|
|
switch (type) {
|
|
|
|
case NSScrollWheel:
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
case NSMouseMoved:
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
|
|
|
if ((contentView = [window contentView]) != nil) {
|
|
|
|
target = [contentView hitTest:[contentView convertPoint:
|
|
|
|
[anEvent locationInWindow] fromView:nil]];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (target) {
|
|
|
|
switch (type) {
|
|
|
|
case NSScrollWheel:
|
|
|
|
[target scrollWheel:anEvent];
|
|
|
|
break;
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
[target mouseDown:anEvent];
|
|
|
|
// If we're in a context menu we don't want the OS to send the coming
|
|
|
|
// leftMouseUp event to NSApp via the window server, but we do want
|
|
|
|
// our ChildView to receive a leftMouseUp event (and to send a Gecko
|
|
|
|
// NS_MOUSE_BUTTON_UP event to the corresponding nsChildView object).
|
|
|
|
// If our NSApp isn't active (i.e. if we're in a context menu raised
|
|
|
|
// by a rightMouseDown event) when it receives the coming leftMouseUp
|
|
|
|
// via the window server, our browser will (in effect) become partially
|
|
|
|
// activated, which has strange side effects: For example, if another
|
|
|
|
// app's window had the focus, that window will lose the focus and the
|
|
|
|
// other app's main menu will be completely disabled (though it will
|
|
|
|
// continue to be displayed).
|
|
|
|
// A side effect of not allowing the coming leftMouseUp event to be
|
|
|
|
// sent to NSApp via the window server is that our custom context
|
|
|
|
// menus will roll up whenever the user left-clicks on them, whether
|
|
|
|
// or not the left-click hit an active menu item. This is how native
|
|
|
|
// context menus behave, but wasn't how our custom context menus
|
|
|
|
// behaved previously (on the trunk or e.g. in Firefox 2.0.0.4).
|
|
|
|
// If our ChildView's corresponding nsChildView object doesn't
|
|
|
|
// dispatch an NS_MOUSE_BUTTON_UP event, none of our active menu items
|
|
|
|
// will "work" on a leftMouseDown.
|
|
|
|
if (mIsContextMenu) {
|
|
|
|
NSEvent *newEvent = [NSEvent mouseEventWithType:NSLeftMouseUp
|
|
|
|
location:[anEvent locationInWindow]
|
|
|
|
modifierFlags:[anEvent modifierFlags]
|
|
|
|
timestamp:GetCurrentEventTime()
|
|
|
|
windowNumber:[[anEvent window] windowNumber]
|
|
|
|
context:nil
|
|
|
|
eventNumber:0
|
|
|
|
clickCount:1
|
|
|
|
pressure:0.0];
|
|
|
|
[target mouseUp:newEvent];
|
|
|
|
RollUpPopups();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
[target mouseUp:anEvent];
|
|
|
|
break;
|
|
|
|
case NSRightMouseDown:
|
|
|
|
[target rightMouseDown:anEvent];
|
|
|
|
break;
|
|
|
|
case NSRightMouseUp:
|
|
|
|
[target rightMouseUp:anEvent];
|
|
|
|
break;
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
[target otherMouseDown:anEvent];
|
|
|
|
break;
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
[target otherMouseUp:anEvent];
|
|
|
|
break;
|
|
|
|
case NSMouseMoved:
|
|
|
|
[target mouseMoved:anEvent];
|
|
|
|
break;
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
[target mouseDragged:anEvent];
|
|
|
|
break;
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
[target rightMouseDragged:anEvent];
|
|
|
|
break;
|
|
|
|
case NSOtherMouseDragged:
|
|
|
|
[target otherMouseDragged:anEvent];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
[super sendEvent:anEvent];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[super sendEvent:anEvent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
|
|
|
|
backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
|
|
|
|
{
|
|
|
|
mIsContextMenu = false;
|
|
|
|
return [super initWithContentRect:contentRect styleMask:styleMask
|
|
|
|
backing:bufferingType defer:deferCreation];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isContextMenu
|
|
|
|
{
|
|
|
|
return mIsContextMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIsContextMenu:(BOOL)flag
|
|
|
|
{
|
|
|
|
mIsContextMenu = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|