2006-05-10 17:30:15 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 ci et: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2013-02-16 03:55:36 +00:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
|
|
|
|
2000-01-22 03:15:41 +00:00
|
|
|
// Local includes
|
|
|
|
#include "nsXULWindow.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2000-01-22 03:15:41 +00:00
|
|
|
|
|
|
|
// Helper classes
|
2012-07-25 01:35:32 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2000-01-22 03:15:41 +00:00
|
|
|
#include "nsString.h"
|
2000-02-08 13:40:10 +00:00
|
|
|
#include "nsWidgetsCID.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsNetCID.h"
|
2015-04-15 16:47:03 +00:00
|
|
|
#include "nsQueryObject.h"
|
2016-08-15 06:43:21 +00:00
|
|
|
#include "mozilla/Sprintf.h"
|
2000-01-22 03:15:41 +00:00
|
|
|
|
|
|
|
//Interfaces needed to be included
|
2000-02-08 13:40:10 +00:00
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIAppShellService.h"
|
2000-01-22 03:15:41 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2011-10-15 07:33:26 +00:00
|
|
|
#include "nsIContentViewer.h"
|
2000-01-22 03:15:41 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2003-09-08 19:06:11 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
2007-07-26 17:52:26 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2001-01-29 23:47:36 +00:00
|
|
|
#include "nsIDOMScreen.h"
|
2002-01-16 00:11:06 +00:00
|
|
|
#include "nsIEmbeddingSiteWindow.h"
|
2000-02-08 13:40:10 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-02-08 13:40:10 +00:00
|
|
|
#include "nsIIOService.h"
|
2015-01-13 22:24:52 +00:00
|
|
|
#include "nsILoadContext.h"
|
2000-02-14 06:13:12 +00:00
|
|
|
#include "nsIObserverService.h"
|
2000-01-22 03:15:41 +00:00
|
|
|
#include "nsIWindowMediator.h"
|
2000-04-13 20:07:28 +00:00
|
|
|
#include "nsIScreenManager.h"
|
|
|
|
#include "nsIScreen.h"
|
2000-08-11 03:43:44 +00:00
|
|
|
#include "nsIScrollable.h"
|
2003-10-07 01:20:16 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2001-04-10 18:30:25 +00:00
|
|
|
#include "nsIWindowWatcher.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIURI.h"
|
2004-10-29 19:28:38 +00:00
|
|
|
#include "nsAppShellCID.h"
|
2002-08-07 01:59:22 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2000-08-11 03:43:44 +00:00
|
|
|
#include "nsStyleConsts.h"
|
2008-11-17 06:59:45 +00:00
|
|
|
#include "nsPresContext.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsContentUtils.h"
|
2000-04-01 22:13:46 +00:00
|
|
|
#include "nsWebShellWindow.h" // get rid of this one, too...
|
2013-06-01 08:53:00 +00:00
|
|
|
#include "nsGlobalWindow.h"
|
2018-01-31 19:49:28 +00:00
|
|
|
#include "XULDocument.h"
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2010-07-01 21:45:14 +00:00
|
|
|
#include "prenv.h"
|
2013-08-14 06:56:25 +00:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2011-06-20 03:00:16 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-04-29 17:31:06 +00:00
|
|
|
#include "mozilla/Services.h"
|
2013-06-01 08:53:00 +00:00
|
|
|
#include "mozilla/dom/BarProps.h"
|
2012-10-02 08:24:10 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "mozilla/dom/Event.h"
|
2013-12-12 01:51:58 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2016-07-14 20:31:41 +00:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2011-06-20 03:00:16 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-04-15 03:27:00 +00:00
|
|
|
using dom::AutoNoJSAPI;
|
2011-06-20 03:00:16 +00:00
|
|
|
|
2009-07-08 16:13:13 +00:00
|
|
|
#define SIZEMODE_NORMAL NS_LITERAL_STRING("normal")
|
|
|
|
#define SIZEMODE_MAXIMIZED NS_LITERAL_STRING("maximized")
|
|
|
|
#define SIZEMODE_MINIMIZED NS_LITERAL_STRING("minimized")
|
|
|
|
#define SIZEMODE_FULLSCREEN NS_LITERAL_STRING("fullscreen")
|
2000-12-14 22:42:48 +00:00
|
|
|
|
2001-02-03 23:08:19 +00:00
|
|
|
#define WINDOWTYPE_ATTRIBUTE NS_LITERAL_STRING("windowtype")
|
|
|
|
|
2001-06-04 22:22:07 +00:00
|
|
|
#define PERSIST_ATTRIBUTE NS_LITERAL_STRING("persist")
|
|
|
|
#define SCREENX_ATTRIBUTE NS_LITERAL_STRING("screenX")
|
|
|
|
#define SCREENY_ATTRIBUTE NS_LITERAL_STRING("screenY")
|
|
|
|
#define WIDTH_ATTRIBUTE NS_LITERAL_STRING("width")
|
|
|
|
#define HEIGHT_ATTRIBUTE NS_LITERAL_STRING("height")
|
|
|
|
#define MODE_ATTRIBUTE NS_LITERAL_STRING("sizemode")
|
2003-10-07 01:20:16 +00:00
|
|
|
#define ZLEVEL_ATTRIBUTE NS_LITERAL_STRING("zlevel")
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2009-02-10 08:29:53 +00:00
|
|
|
|
2000-01-22 03:15:41 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsXULWindow: Object Management
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXULWindow::nsXULWindow(uint32_t aChromeFlags)
|
2017-07-06 12:00:35 +00:00
|
|
|
: mChromeTreeOwner(nullptr),
|
2012-07-30 14:20:58 +00:00
|
|
|
mContentTreeOwner(nullptr),
|
|
|
|
mPrimaryContentTreeOwner(nullptr),
|
2006-05-10 17:30:15 +00:00
|
|
|
mModalStatus(NS_OK),
|
2011-10-17 14:59:28 +00:00
|
|
|
mContinueModalLoop(false),
|
|
|
|
mDebuting(false),
|
2017-07-06 12:00:35 +00:00
|
|
|
mChromeLoaded(false),
|
2011-10-17 14:59:28 +00:00
|
|
|
mShowAfterLoad(false),
|
|
|
|
mIntrinsicallySized(false),
|
|
|
|
mCenterAfterLoad(false),
|
|
|
|
mIsHiddenWindow(false),
|
|
|
|
mLockedUntilChromeLoad(false),
|
|
|
|
mIgnoreXULSize(false),
|
|
|
|
mIgnoreXULPosition(false),
|
|
|
|
mChromeFlagsFrozen(false),
|
|
|
|
mIgnoreXULSizeMode(false),
|
2012-11-15 16:28:40 +00:00
|
|
|
mDestroying(false),
|
2016-06-02 17:28:28 +00:00
|
|
|
mRegistered(false),
|
2006-05-10 17:30:15 +00:00
|
|
|
mPersistentAttributesDirty(0),
|
|
|
|
mPersistentAttributesMask(0),
|
2017-04-16 22:52:02 +00:00
|
|
|
mChromeFlags(aChromeFlags),
|
|
|
|
mNextTabParentId(0)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXULWindow::~nsXULWindow()
|
|
|
|
{
|
2001-03-30 02:27:50 +00:00
|
|
|
Destroy();
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsXULWindow::nsISupports
|
2005-02-19 22:42:01 +00:00
|
|
|
//*****************************************************************************
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2013-07-19 02:31:36 +00:00
|
|
|
NS_IMPL_ADDREF(nsXULWindow)
|
|
|
|
NS_IMPL_RELEASE(nsXULWindow)
|
2000-01-22 03:15:41 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsXULWindow)
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULWindow)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULWindow)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsXULWindow)))
|
2007-07-08 07:08:04 +00:00
|
|
|
foundInterface = reinterpret_cast<nsISupports*>(this);
|
2006-05-10 17:30:15 +00:00
|
|
|
else
|
2000-01-22 03:15:41 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2000-02-08 13:40:10 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsXULWindow::nsIIntefaceRequestor
|
2017-07-06 12:00:35 +00:00
|
|
|
//*****************************************************************************
|
2000-02-08 13:40:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::GetInterface(const nsIID& aIID, void** aSink)
|
|
|
|
{
|
2000-05-16 05:35:23 +00:00
|
|
|
nsresult rv;
|
2002-01-05 02:22:45 +00:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aSink);
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIPrompt))) {
|
|
|
|
rv = EnsurePrompter();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
return mPrompter->QueryInterface(aIID, aSink);
|
2017-07-06 12:00:35 +00:00
|
|
|
}
|
2002-01-05 02:22:45 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIAuthPrompt))) {
|
|
|
|
rv = EnsureAuthPrompter();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
return mAuthPrompter->QueryInterface(aIID, aSink);
|
|
|
|
}
|
2016-01-30 17:05:36 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(mozIDOMWindowProxy))) {
|
|
|
|
return GetWindowDOMWindow(reinterpret_cast<mozIDOMWindowProxy**>(aSink));
|
|
|
|
}
|
2011-07-15 10:31:34 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) {
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> window = nullptr;
|
|
|
|
rv = GetWindowDOMWindow(getter_AddRefs(window));
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(window);
|
|
|
|
domWindow.forget(aSink);
|
|
|
|
return rv;
|
2011-08-14 17:22:29 +00:00
|
|
|
}
|
2017-07-06 12:00:35 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIWebBrowserChrome)) &&
|
2002-01-05 02:22:45 +00:00
|
|
|
NS_SUCCEEDED(EnsureContentTreeOwner()) &&
|
|
|
|
NS_SUCCEEDED(mContentTreeOwner->QueryInterface(aIID, aSink)))
|
|
|
|
return NS_OK;
|
|
|
|
|
2017-07-06 12:00:35 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIEmbeddingSiteWindow)) &&
|
2002-01-16 00:11:06 +00:00
|
|
|
NS_SUCCEEDED(EnsureContentTreeOwner()) &&
|
|
|
|
NS_SUCCEEDED(mContentTreeOwner->QueryInterface(aIID, aSink)))
|
|
|
|
return NS_OK;
|
2002-01-05 02:22:45 +00:00
|
|
|
|
|
|
|
return QueryInterface(aIID, aSink);
|
2000-02-08 13:40:10 +00:00
|
|
|
}
|
|
|
|
|
2000-01-22 03:15:41 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsXULWindow::nsIXULWindow
|
2017-07-06 12:00:35 +00:00
|
|
|
//*****************************************************************************
|
2000-01-22 03:15:41 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::GetDocShell(nsIDocShell** aDocShell)
|
|
|
|
{
|
2003-10-07 01:20:16 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDocShell);
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
*aDocShell = mDocShell;
|
|
|
|
NS_IF_ADDREF(*aDocShell);
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetZLevel(uint32_t *outLevel)
|
2000-04-01 22:13:46 +00:00
|
|
|
{
|
2007-09-05 13:04:54 +00:00
|
|
|
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2003-10-07 01:20:16 +00:00
|
|
|
if (mediator)
|
|
|
|
mediator->GetZLevel(this, outLevel);
|
|
|
|
else
|
|
|
|
*outLevel = normalZ;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetZLevel(uint32_t aLevel)
|
2003-10-07 01:20:16 +00:00
|
|
|
{
|
2007-09-05 13:04:54 +00:00
|
|
|
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2003-10-07 01:20:16 +00:00
|
|
|
if (!mediator)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t zLevel;
|
2003-10-07 01:20:16 +00:00
|
|
|
mediator->GetZLevel(this, &zLevel);
|
|
|
|
if (zLevel == aLevel)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
/* refuse to raise a maximized window above the normal browser level,
|
|
|
|
for fear it could hide newly opened browser windows */
|
2013-04-26 06:49:47 +00:00
|
|
|
if (aLevel > nsIXULWindow::normalZ && mWindow) {
|
2015-08-29 01:12:41 +00:00
|
|
|
nsSizeMode sizeMode = mWindow->SizeMode();
|
2013-04-26 06:49:47 +00:00
|
|
|
if (sizeMode == nsSizeMode_Maximized || sizeMode == nsSizeMode_Fullscreen) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-10-07 01:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do it
|
|
|
|
mediator->SetZLevel(this, aLevel);
|
2015-10-14 01:33:51 +00:00
|
|
|
PersistentAttributesDirty(PAD_MISC);
|
|
|
|
SavePersistentAttributes();
|
2003-10-07 01:20:16 +00:00
|
|
|
|
2009-07-06 05:24:56 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(cv));
|
2010-01-23 11:41:41 +00:00
|
|
|
if (cv) {
|
2013-04-22 01:25:28 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = cv->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
ErrorResult rv;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<dom::Event> event =
|
2017-04-20 12:45:37 +00:00
|
|
|
doc->CreateEvent(NS_LITERAL_STRING("Events"), dom::CallerType::System,
|
|
|
|
rv);
|
2009-07-06 05:24:56 +00:00
|
|
|
if (event) {
|
2011-10-17 14:59:28 +00:00
|
|
|
event->InitEvent(NS_LITERAL_STRING("windowZLevel"), true, false);
|
2009-07-06 05:24:56 +00:00
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
event->SetTrusted(true);
|
2009-07-06 05:24:56 +00:00
|
|
|
|
2013-04-22 01:25:28 +00:00
|
|
|
bool defaultActionEnabled;
|
|
|
|
doc->DispatchEvent(event, &defaultActionEnabled);
|
2009-07-06 05:24:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-07 01:20:16 +00:00
|
|
|
return NS_OK;
|
2000-04-01 22:13:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetChromeFlags(uint32_t *aChromeFlags)
|
2005-02-02 09:39:30 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChromeFlags);
|
|
|
|
*aChromeFlags = mChromeFlags;
|
|
|
|
/* mChromeFlags is kept up to date, except for scrollbar visibility.
|
|
|
|
That can be changed directly by the content DOM window, which
|
|
|
|
doesn't know to update the chrome window. So that we must check
|
|
|
|
separately. */
|
|
|
|
|
|
|
|
// however, it's pointless to ask if the window isn't set up yet
|
|
|
|
if (!mChromeLoaded)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (GetContentScrollbarVisibility())
|
|
|
|
*aChromeFlags |= nsIWebBrowserChrome::CHROME_SCROLLBARS;
|
|
|
|
else
|
|
|
|
*aChromeFlags &= ~nsIWebBrowserChrome::CHROME_SCROLLBARS;
|
2002-09-11 02:27:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetChromeFlags(uint32_t aChromeFlags)
|
2005-02-02 09:39:30 +00:00
|
|
|
{
|
2010-07-19 18:33:33 +00:00
|
|
|
NS_ASSERTION(!mChromeFlagsFrozen,
|
|
|
|
"SetChromeFlags() after AssumeChromeFlagsAreFrozen()!");
|
|
|
|
|
2005-02-02 09:39:30 +00:00
|
|
|
mChromeFlags = aChromeFlags;
|
2018-03-16 09:26:31 +00:00
|
|
|
if (mChromeLoaded)
|
|
|
|
NS_ENSURE_SUCCESS(ApplyChromeFlags(), NS_ERROR_FAILURE);
|
2005-02-02 09:39:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-19 18:33:33 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::AssumeChromeFlagsAreFrozen()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mChromeFlagsFrozen = true;
|
2010-07-19 18:33:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetIntrinsicallySized(bool aIntrinsicallySized)
|
2000-02-14 06:13:12 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
mIntrinsicallySized = aIntrinsicallySized;
|
|
|
|
return NS_OK;
|
2000-02-14 06:13:12 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetIntrinsicallySized(bool* aIntrinsicallySized)
|
2000-02-14 06:13:12 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aIntrinsicallySized);
|
2000-02-14 06:13:12 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
*aIntrinsicallySized = mIntrinsicallySized;
|
|
|
|
return NS_OK;
|
2000-02-14 06:13:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 12:00:35 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetPrimaryContentShell(nsIDocShellTreeItem**
|
2000-01-22 03:15:41 +00:00
|
|
|
aDocShellTreeItem)
|
|
|
|
{
|
2001-10-22 23:37:33 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDocShellTreeItem);
|
2005-02-22 00:17:35 +00:00
|
|
|
NS_IF_ADDREF(*aDocShellTreeItem = mPrimaryContentShell);
|
2001-10-22 23:37:33 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 17:06:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULWindow::TabParentAdded(nsITabParent* aTab, bool aPrimary)
|
|
|
|
{
|
|
|
|
if (aPrimary) {
|
|
|
|
mPrimaryTabParent = aTab;
|
|
|
|
mPrimaryContentShell = nullptr;
|
|
|
|
} else if (mPrimaryTabParent == aTab) {
|
|
|
|
mPrimaryTabParent = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULWindow::TabParentRemoved(nsITabParent* aTab)
|
|
|
|
{
|
|
|
|
if (aTab == mPrimaryTabParent) {
|
|
|
|
mPrimaryTabParent = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULWindow::GetPrimaryTabParent(nsITabParent** aTab)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITabParent> tab = mPrimaryTabParent;
|
|
|
|
tab.forget(aTab);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-02-01 15:38:16 +00:00
|
|
|
nsTArray<RefPtr<mozilla::LiveResizeListener>>
|
|
|
|
nsXULWindow::GetLiveResizeListeners()
|
|
|
|
{
|
|
|
|
nsTArray<RefPtr<mozilla::LiveResizeListener>> listeners;
|
|
|
|
if (mPrimaryTabParent) {
|
|
|
|
TabParent* parent = static_cast<TabParent*>(mPrimaryTabParent.get());
|
|
|
|
listeners.AppendElement(parent);
|
|
|
|
}
|
|
|
|
return listeners;
|
|
|
|
}
|
|
|
|
|
2001-03-30 02:27:50 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::AddChildWindow(nsIXULWindow *aChild)
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
// we're not really keeping track of this right now
|
|
|
|
return NS_OK;
|
2001-03-30 02:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::RemoveChildWindow(nsIXULWindow *aChild)
|
|
|
|
{
|
|
|
|
// we're not really keeping track of this right now
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-29 00:20:55 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::ShowModal()
|
|
|
|
{
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
AUTO_PROFILER_LABEL("nsXULWindow::ShowModal", OTHER);
|
2016-01-15 10:38:03 +00:00
|
|
|
|
2002-02-28 23:23:43 +00:00
|
|
|
// Store locally so it doesn't die on us
|
|
|
|
nsCOMPtr<nsIWidget> window = mWindow;
|
2017-07-06 12:00:35 +00:00
|
|
|
nsCOMPtr<nsIXULWindow> tempRef = this;
|
2002-02-28 23:23:43 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
window->SetModal(true);
|
|
|
|
mContinueModalLoop = true;
|
|
|
|
EnableParent(false);
|
2002-02-28 23:23:43 +00:00
|
|
|
|
2013-04-18 15:36:03 +00:00
|
|
|
{
|
2014-04-15 03:27:00 +00:00
|
|
|
AutoNoJSAPI nojsapi;
|
2017-05-15 13:34:19 +00:00
|
|
|
SpinEventLoopUntil([&]() { return !mContinueModalLoop; });
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
2002-02-28 23:23:43 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mContinueModalLoop = false;
|
|
|
|
window->SetModal(false);
|
|
|
|
/* Note there's no EnableParent(true) here to match the false one
|
2002-03-06 22:26:58 +00:00
|
|
|
above. That's done in ExitModalLoop. It's important that the parent
|
|
|
|
be re-enabled before this window is made invisible; to do otherwise
|
|
|
|
causes bizarre z-ordering problems. At this point, the window is
|
|
|
|
already invisible.
|
|
|
|
No known current implementation of Enable would have a problem with
|
|
|
|
re-enabling the parent twice, so we could do it again here without
|
|
|
|
breaking any current implementation. But that's unnecessary if the
|
|
|
|
modal loop is always exited using ExitModalLoop (the other way would be
|
|
|
|
to change the protected member variable directly.)
|
|
|
|
*/
|
2002-02-28 23:23:43 +00:00
|
|
|
|
|
|
|
return mModalStatus;
|
2000-02-29 00:20:55 +00:00
|
|
|
}
|
|
|
|
|
2000-01-22 03:15:41 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsXULWindow::nsIBaseWindow
|
2017-07-06 12:00:35 +00:00
|
|
|
//*****************************************************************************
|
2000-01-22 03:15:41 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::InitWindow(nativeWindow aParentNativeWindow,
|
2017-07-06 12:00:35 +00:00
|
|
|
nsIWidget* parentWidget, int32_t x, int32_t y, int32_t cx, int32_t cy)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
//XXX First Check In
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(false, "Not Yet Implemented");
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::Create()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
//XXX First Check In
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(false, "Not Yet Implemented");
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::Destroy()
|
|
|
|
{
|
2009-01-06 22:25:49 +00:00
|
|
|
if (!mWindow)
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2012-11-15 16:28:40 +00:00
|
|
|
// Ensure we don't reenter this code
|
|
|
|
if (mDestroying)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mozilla::AutoRestore<bool> guard(mDestroying);
|
|
|
|
mDestroying = true;
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIAppShellService> appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
|
|
|
|
NS_ASSERTION(appShell, "Couldn't get appShell... xpcom shutdown?");
|
|
|
|
if (appShell)
|
2007-07-08 07:08:04 +00:00
|
|
|
appShell->UnregisterTopLevelWindow(static_cast<nsIXULWindow*>(this));
|
2002-08-24 18:57:55 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIXULWindow> parentWindow(do_QueryReferent(mParentWindow));
|
|
|
|
if (parentWindow)
|
|
|
|
parentWindow->RemoveChildWindow(this);
|
2001-03-30 02:27:50 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// let's make sure the window doesn't get deleted out from under us
|
|
|
|
// while we are trying to close....this can happen if the docshell
|
|
|
|
// we close ends up being the last owning reference to this xulwindow
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// XXXTAB This shouldn't be an issue anymore because the ownership model
|
|
|
|
// only goes in one direction. When webshell container is fully removed
|
|
|
|
// try removing this...
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIXULWindow> placeHolder = this;
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// Remove modality (if any) and hide while destroying. More than
|
|
|
|
// a convenience, the hide prevents user interaction with the partially
|
|
|
|
// destroyed window. This is especially necessary when the eldest window
|
|
|
|
// in a stack of modal windows is destroyed first. It happens.
|
|
|
|
ExitModalLoop(NS_OK);
|
2015-08-26 23:48:07 +00:00
|
|
|
// XXX: Skip unmapping the window on Linux due to GLX hangs on the compositor
|
|
|
|
// thread with NVIDIA driver 310.32. We don't need to worry about user
|
|
|
|
// interactions with destroyed windows on X11 either.
|
|
|
|
#ifndef MOZ_WIDGET_GTK
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mWindow)
|
2011-10-17 14:59:28 +00:00
|
|
|
mWindow->Show(false);
|
2015-08-26 23:48:07 +00:00
|
|
|
#endif
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2014-02-10 22:57:01 +00:00
|
|
|
#if defined(XP_WIN)
|
2017-07-06 12:00:35 +00:00
|
|
|
// We need to explicitly set the focus on Windows, but
|
2008-08-01 17:32:32 +00:00
|
|
|
// only if the parent is visible.
|
2003-02-22 19:50:38 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> parent(do_QueryReferent(mParentWindow));
|
|
|
|
if (parent) {
|
2008-08-01 17:32:32 +00:00
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
|
|
|
parent->GetMainWidget(getter_AddRefs(parentWidget));
|
2012-07-19 08:57:50 +00:00
|
|
|
if (!parentWidget || parentWidget->IsVisible()) {
|
2008-08-01 17:32:32 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> baseHiddenWindow;
|
|
|
|
if (appShell) {
|
|
|
|
nsCOMPtr<nsIXULWindow> hiddenWindow;
|
|
|
|
appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
|
|
|
|
if (hiddenWindow)
|
|
|
|
baseHiddenWindow = do_GetInterface(hiddenWindow);
|
|
|
|
}
|
|
|
|
// somebody screwed up somewhere. hiddenwindow shouldn't be anybody's
|
|
|
|
// parent. still, when it happens, skip activating it.
|
|
|
|
if (baseHiddenWindow != parent) {
|
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
|
|
|
parent->GetMainWidget(getter_AddRefs(parentWidget));
|
|
|
|
if (parentWidget)
|
2011-10-17 14:59:28 +00:00
|
|
|
parentWidget->PlaceBehind(eZPlacementTop, 0, true);
|
2008-08-01 17:32:32 +00:00
|
|
|
}
|
2003-11-07 02:13:32 +00:00
|
|
|
}
|
2003-02-22 19:50:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mDOMWindow = nullptr;
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mDocShell) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
|
|
|
|
shellAsWin->Destroy();
|
2012-07-30 14:20:58 +00:00
|
|
|
mDocShell = nullptr; // this can cause reentrancy of this function
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrimaryContentShell = nullptr;
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2009-01-06 22:25:49 +00:00
|
|
|
if (mContentTreeOwner) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mContentTreeOwner->XULWindow(nullptr);
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_RELEASE(mContentTreeOwner);
|
|
|
|
}
|
2009-01-06 22:25:49 +00:00
|
|
|
if (mPrimaryContentTreeOwner) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrimaryContentTreeOwner->XULWindow(nullptr);
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_RELEASE(mPrimaryContentTreeOwner);
|
|
|
|
}
|
2009-01-06 22:25:49 +00:00
|
|
|
if (mChromeTreeOwner) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mChromeTreeOwner->XULWindow(nullptr);
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_RELEASE(mChromeTreeOwner);
|
|
|
|
}
|
2009-01-06 22:25:49 +00:00
|
|
|
if (mWindow) {
|
2012-08-15 18:52:42 +00:00
|
|
|
mWindow->SetWidgetListener(nullptr); // nsWebShellWindow hackery
|
2010-06-02 13:02:05 +00:00
|
|
|
mWindow->Destroy();
|
2012-07-30 14:20:58 +00:00
|
|
|
mWindow = nullptr;
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 17:28:28 +00:00
|
|
|
if (!mIsHiddenWindow && mRegistered) {
|
2006-05-10 17:30:15 +00:00
|
|
|
/* Inform appstartup we've destroyed this window and it could
|
|
|
|
quit now if it wanted. This must happen at least after mDocShell
|
|
|
|
is destroyed, because onunload handlers fire then, and those being
|
|
|
|
script, anything could happen. A new window could open, even.
|
|
|
|
See bug 130719. */
|
2014-04-29 17:31:06 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obssvc = services::GetObserverService();
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ASSERTION(obssvc, "Couldn't get observer service?");
|
|
|
|
|
|
|
|
if (obssvc)
|
2012-07-30 14:20:58 +00:00
|
|
|
obssvc->NotifyObservers(nullptr, "xul-window-destroyed", nullptr);
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2015-11-25 19:12:07 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetDevicePixelsPerDesktopPixel(double *aScale)
|
|
|
|
{
|
|
|
|
*aScale = mWindow ? mWindow->GetDesktopToDeviceScale().scale : 1.0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-16 19:41:19 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
|
|
|
|
{
|
2013-09-18 00:45:19 +00:00
|
|
|
*aScale = mWindow ? mWindow->GetDefaultScale().scale : 1.0;
|
2012-10-16 19:41:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-18 10:46:16 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetPositionDesktopPix(int32_t aX, int32_t aY)
|
|
|
|
{
|
2016-12-19 09:54:03 +00:00
|
|
|
mWindow->Move(aX, aY);
|
2016-02-18 10:46:16 +00:00
|
|
|
if (!mChromeLoaded) {
|
|
|
|
// If we're called before the chrome is loaded someone obviously wants this
|
|
|
|
// window at this position. We don't persist this one-time position.
|
|
|
|
mIgnoreXULPosition = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
PersistentAttributesDirty(PAD_POSITION);
|
|
|
|
SavePersistentAttributes();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-18 10:47:14 +00:00
|
|
|
// The parameters here are device pixels; do the best we can to convert to
|
|
|
|
// desktop px, using the window's current scale factor (if available).
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetPosition(int32_t aX, int32_t aY)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2009-11-02 19:10:07 +00:00
|
|
|
// Don't reset the window's size mode here - platforms that don't want to move
|
|
|
|
// maximized windows should reset it in their respective Move implementation.
|
2016-02-18 10:47:14 +00:00
|
|
|
DesktopToLayoutDeviceScale currScale = mWindow->GetDesktopToDeviceScale();
|
|
|
|
DesktopPoint pos = LayoutDeviceIntPoint(aX, aY) / currScale;
|
|
|
|
return SetPositionDesktopPix(pos.x, pos.y);
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetPosition(int32_t* aX, int32_t* aY)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return GetPositionAndSize(aX, aY, nullptr, nullptr);
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetSize(int32_t aCX, int32_t aCY, bool aRepaint)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2001-09-12 00:19:25 +00:00
|
|
|
/* any attempt to set the window's size or position overrides the window's
|
|
|
|
zoom state. this is important when these two states are competing while
|
|
|
|
the window is being opened. but it should probably just always be so. */
|
|
|
|
mWindow->SetSizeMode(nsSizeMode_Normal);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mIntrinsicallySized = false;
|
2009-02-10 08:29:53 +00:00
|
|
|
|
2015-12-03 13:19:50 +00:00
|
|
|
DesktopToLayoutDeviceScale scale = mWindow->GetDesktopToDeviceScale();
|
|
|
|
DesktopSize size = LayoutDeviceIntSize(aCX, aCY) / scale;
|
2016-12-19 09:54:03 +00:00
|
|
|
mWindow->Resize(size.width, size.height, aRepaint);
|
2009-10-16 09:03:20 +00:00
|
|
|
if (!mChromeLoaded) {
|
|
|
|
// If we're called before the chrome is loaded someone obviously wants this
|
2011-07-05 08:12:05 +00:00
|
|
|
// window at this size & in the normal size mode (since it is the only mode
|
|
|
|
// in which setting dimensions makes sense). We don't persist this one-time
|
|
|
|
// size.
|
2011-10-17 14:59:28 +00:00
|
|
|
mIgnoreXULSize = true;
|
|
|
|
mIgnoreXULSizeMode = true;
|
2009-10-16 09:03:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
PersistentAttributesDirty(PAD_SIZE);
|
|
|
|
SavePersistentAttributes();
|
2001-09-12 00:19:25 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetSize(int32_t* aCX, int32_t* aCY)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return GetPositionAndSize(nullptr, nullptr, aCX, aCY);
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 12:00:35 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetPositionAndSize(int32_t aX, int32_t aY,
|
2016-05-12 00:07:45 +00:00
|
|
|
int32_t aCX, int32_t aCY, uint32_t aFlags)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2001-09-12 00:19:25 +00:00
|
|
|
/* any attempt to set the window's size or position overrides the window's
|
|
|
|
zoom state. this is important when these two states are competing while
|
|
|
|
the window is being opened. but it should probably just always be so. */
|
|
|
|
mWindow->SetSizeMode(nsSizeMode_Normal);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mIntrinsicallySized = false;
|
2001-09-12 00:19:25 +00:00
|
|
|
|
2015-12-03 13:19:50 +00:00
|
|
|
DesktopToLayoutDeviceScale scale = mWindow->GetDesktopToDeviceScale();
|
|
|
|
DesktopRect rect = LayoutDeviceIntRect(aX, aY, aCX, aCY) / scale;
|
2018-01-10 16:15:22 +00:00
|
|
|
mWindow->Resize(rect.X(), rect.Y(), rect.Width(), rect.Height(),
|
2016-12-19 09:54:03 +00:00
|
|
|
!!(aFlags & nsIBaseWindow::eRepaint));
|
2009-10-16 09:03:20 +00:00
|
|
|
if (!mChromeLoaded) {
|
|
|
|
// If we're called before the chrome is loaded someone obviously wants this
|
|
|
|
// window at this size and position. We don't persist this one-time setting.
|
2011-10-17 14:59:28 +00:00
|
|
|
mIgnoreXULPosition = true;
|
|
|
|
mIgnoreXULSize = true;
|
|
|
|
mIgnoreXULSizeMode = true;
|
2009-10-16 09:03:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
PersistentAttributesDirty(PAD_POSITION | PAD_SIZE);
|
|
|
|
SavePersistentAttributes();
|
2001-09-12 00:19:25 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetPositionAndSize(int32_t* x, int32_t* y, int32_t* cx,
|
|
|
|
int32_t* cy)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
|
|
|
|
2002-01-24 22:30:39 +00:00
|
|
|
if (!mWindow)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2016-08-18 23:03:04 +00:00
|
|
|
LayoutDeviceIntRect rect = mWindow->GetScreenBounds();
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2009-01-06 22:25:49 +00:00
|
|
|
if (x)
|
2018-01-10 16:15:22 +00:00
|
|
|
*x = rect.X();
|
2009-01-06 22:25:49 +00:00
|
|
|
if (y)
|
2018-01-10 16:15:22 +00:00
|
|
|
*y = rect.Y();
|
2009-01-06 22:25:49 +00:00
|
|
|
if (cx)
|
2018-01-10 16:15:22 +00:00
|
|
|
*cx = rect.Width();
|
2009-01-06 22:25:49 +00:00
|
|
|
if (cy)
|
2018-01-10 16:15:22 +00:00
|
|
|
*cy = rect.Height();
|
2002-01-24 22:30:39 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::Center(nsIXULWindow *aRelative, bool aScreen, bool aAlert)
|
2009-01-06 22:25:49 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t left, top, width, height,
|
2000-04-13 20:07:28 +00:00
|
|
|
ourWidth, ourHeight;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool screenCoordinates = false,
|
2011-10-17 14:59:28 +00:00
|
|
|
windowCoordinates = false;
|
2000-04-13 20:07:28 +00:00
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (!mChromeLoaded) {
|
|
|
|
// note we lose the parameters. at time of writing, this isn't a problem.
|
2011-10-17 14:59:28 +00:00
|
|
|
mCenterAfterLoad = true;
|
2000-04-13 20:07:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aScreen && !aRelative)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
nsCOMPtr<nsIScreenManager> screenmgr = do_GetService("@mozilla.org/gfx/screenmanager;1", &result);
|
2000-04-13 20:07:28 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
|
|
|
|
if (aRelative) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(aRelative, &result));
|
2002-01-09 01:31:24 +00:00
|
|
|
if (base) {
|
2002-01-24 22:30:39 +00:00
|
|
|
// get window rect
|
|
|
|
result = base->GetPositionAndSize(&left, &top, &width, &height);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2012-10-16 19:41:19 +00:00
|
|
|
double scale;
|
2015-12-03 13:19:50 +00:00
|
|
|
if (NS_SUCCEEDED(base->GetDevicePixelsPerDesktopPixel(&scale))) {
|
2012-10-16 19:41:19 +00:00
|
|
|
left = NSToIntRound(left / scale);
|
|
|
|
top = NSToIntRound(top / scale);
|
|
|
|
width = NSToIntRound(width / scale);
|
|
|
|
height = NSToIntRound(height / scale);
|
|
|
|
}
|
2002-01-24 22:30:39 +00:00
|
|
|
// if centering on screen, convert that to the corresponding screen
|
|
|
|
if (aScreen)
|
|
|
|
screenmgr->ScreenForRect(left, top, width, height, getter_AddRefs(screen));
|
|
|
|
else
|
2011-10-17 14:59:28 +00:00
|
|
|
windowCoordinates = true;
|
2002-01-24 22:30:39 +00:00
|
|
|
} else {
|
|
|
|
// something's wrong with the reference window.
|
|
|
|
// fall back to the primary screen
|
|
|
|
aRelative = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
aScreen = true;
|
2002-01-24 22:30:39 +00:00
|
|
|
}
|
2000-04-13 20:07:28 +00:00
|
|
|
}
|
2002-01-24 22:30:39 +00:00
|
|
|
}
|
2009-09-29 02:20:46 +00:00
|
|
|
if (!aRelative) {
|
|
|
|
if (!mOpenerScreenRect.IsEmpty()) {
|
2012-10-16 19:41:19 +00:00
|
|
|
// FIXME - check if these are device or display pixels
|
2018-01-10 16:15:22 +00:00
|
|
|
screenmgr->ScreenForRect(mOpenerScreenRect.X(), mOpenerScreenRect.Y(),
|
|
|
|
mOpenerScreenRect.Width(), mOpenerScreenRect.Height(),
|
2009-09-29 02:20:46 +00:00
|
|
|
getter_AddRefs(screen));
|
|
|
|
} else {
|
|
|
|
screenmgr->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
}
|
|
|
|
}
|
2000-04-13 20:07:28 +00:00
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
if (aScreen && screen) {
|
2012-10-16 19:41:19 +00:00
|
|
|
screen->GetAvailRectDisplayPix(&left, &top, &width, &height);
|
2011-10-17 14:59:28 +00:00
|
|
|
screenCoordinates = true;
|
2002-01-09 01:31:24 +00:00
|
|
|
}
|
2000-04-13 20:07:28 +00:00
|
|
|
|
2002-01-11 01:53:23 +00:00
|
|
|
if (screenCoordinates || windowCoordinates) {
|
2012-10-16 19:41:19 +00:00
|
|
|
NS_ASSERTION(mWindow, "what, no window?");
|
2015-12-03 13:19:50 +00:00
|
|
|
double scale = mWindow->GetDesktopToDeviceScale().scale;
|
2002-01-09 01:31:24 +00:00
|
|
|
GetSize(&ourWidth, &ourHeight);
|
2015-12-03 13:19:50 +00:00
|
|
|
int32_t scaledWidth, scaledHeight;
|
|
|
|
scaledWidth = NSToIntRound(ourWidth / scale);
|
|
|
|
scaledHeight = NSToIntRound(ourHeight / scale);
|
|
|
|
left += (width - scaledWidth) / 2;
|
|
|
|
top += (height - scaledHeight) / (aAlert ? 3 : 2);
|
2012-10-16 19:41:19 +00:00
|
|
|
if (windowCoordinates) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mWindow->ConstrainPosition(false, &left, &top);
|
2012-10-16 19:41:19 +00:00
|
|
|
}
|
2015-12-03 13:19:50 +00:00
|
|
|
SetPosition(left * scale, top * scale);
|
|
|
|
|
|
|
|
// If moving the window caused it to change size,
|
|
|
|
// re-do the centering.
|
|
|
|
int32_t newWidth, newHeight;
|
|
|
|
GetSize(&newWidth, &newHeight);
|
|
|
|
if (newWidth != ourWidth || newHeight != ourHeight) {
|
|
|
|
return Center(aRelative, aScreen, aAlert);
|
|
|
|
}
|
2002-01-09 01:31:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-12-03 13:19:50 +00:00
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-04-13 20:07:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::Repaint(bool aForce)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
//XXX First Check In
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(false, "Not Yet Implemented");
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::GetParentWidget(nsIWidget** aParentWidget)
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aParentWidget);
|
|
|
|
NS_ENSURE_STATE(mWindow);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_IF_ADDREF(*aParentWidget = mWindow->GetParent());
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::SetParentWidget(nsIWidget* aParentWidget)
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
//XXX First Check In
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(false, "Not Yet Implemented");
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::GetParentNativeWindow(nativeWindow* aParentNativeWindow)
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aParentNativeWindow);
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
|
|
|
NS_ENSURE_SUCCESS(GetParentWidget(getter_AddRefs(parentWidget)), NS_ERROR_FAILURE);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2009-10-09 07:05:08 +00:00
|
|
|
if (parentWidget) {
|
|
|
|
*aParentNativeWindow = parentWidget->GetNativeData(NS_NATIVE_WIDGET);
|
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::SetParentNativeWindow(nativeWindow aParentNativeWindow)
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
//XXX First Check In
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(false, "Not Yet Implemented");
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2012-07-25 01:35:32 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetNativeHandle(nsAString& aNativeHandle)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
NS_ENSURE_SUCCESS(GetMainWidget(getter_AddRefs(mainWidget)), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (mainWidget) {
|
|
|
|
nativeWindow nativeWindowPtr = mainWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
/* the nativeWindow pointer is converted to and exposed as a string. This
|
|
|
|
is a more reliable way not to lose information (as opposed to JS
|
|
|
|
|Number| for instance) */
|
|
|
|
aNativeHandle = NS_ConvertASCIItoUTF16(nsPrintfCString("0x%p", nativeWindowPtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetVisibility(bool* aVisibility)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aVisibility);
|
|
|
|
|
2005-10-19 02:59:30 +00:00
|
|
|
// Always claim to be visible for now. See bug
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=306245.
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aVisibility = true;
|
2005-10-19 02:59:30 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetVisibility(bool aVisibility)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
if (!mChromeLoaded) {
|
|
|
|
mShowAfterLoad = aVisibility;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mDebuting) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mDebuting = true; // (Show / Focus is recursive)
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2017-07-06 12:00:35 +00:00
|
|
|
//XXXTAB Do we really need to show docshell and the window? Isn't
|
2006-05-10 17:30:15 +00:00
|
|
|
// the window good enough?
|
|
|
|
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
|
|
|
|
shellAsWin->SetVisibility(aVisibility);
|
2009-11-11 10:29:29 +00:00
|
|
|
// Store locally so it doesn't die on us. 'Show' can result in the window
|
|
|
|
// being closed with nsXULWindow::Destroy being called. That would set
|
|
|
|
// mWindow to null and posibly destroy the nsIWidget while its Show method
|
|
|
|
// is on the stack. We need to keep it alive until Show finishes.
|
|
|
|
nsCOMPtr<nsIWidget> window = mWindow;
|
|
|
|
window->Show(aVisibility);
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2007-09-05 13:04:54 +00:00
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2006-05-10 17:30:15 +00:00
|
|
|
if (windowMediator)
|
2007-07-08 07:08:04 +00:00
|
|
|
windowMediator->UpdateWindowTimeStamp(static_cast<nsIXULWindow*>(this));
|
2006-05-10 17:30:15 +00:00
|
|
|
|
|
|
|
// notify observers so that we can hide the splash screen if possible
|
2014-04-29 17:31:06 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obssvc = services::GetObserverService();
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ASSERTION(obssvc, "Couldn't get observer service.");
|
|
|
|
if (obssvc) {
|
2017-07-06 12:00:35 +00:00
|
|
|
obssvc->NotifyObservers(nullptr, "xul-window-visible", nullptr);
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
2004-10-29 19:28:38 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mDebuting = false;
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetEnabled(bool *aEnabled)
|
2002-02-28 23:23:43 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEnabled);
|
2012-07-23 05:19:08 +00:00
|
|
|
|
|
|
|
if (mWindow) {
|
|
|
|
*aEnabled = mWindow->IsEnabled();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-03-04 22:50:11 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aEnabled = true; // better guess than most
|
2002-03-04 22:50:11 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-02-28 23:23:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetEnabled(bool aEnable)
|
2002-02-28 23:23:43 +00:00
|
|
|
{
|
|
|
|
if (mWindow) {
|
|
|
|
mWindow->Enable(aEnable);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-01-22 03:15:41 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetMainWidget(nsIWidget** aMainWidget)
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aMainWidget);
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
*aMainWidget = mWindow;
|
|
|
|
NS_IF_ADDREF(*aMainWidget);
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::SetFocus()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
//XXX First Check In
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(false, "Not Yet Implemented");
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 03:10:51 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetTitle(nsAString& aTitle)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2017-09-25 03:10:51 +00:00
|
|
|
aTitle = mTitle;
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 03:10:51 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SetTitle(const nsAString& aTitle)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
|
|
|
mTitle.Assign(aTitle);
|
2017-05-10 17:12:36 +00:00
|
|
|
mTitle.StripCRLF();
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(mWindow->SetTitle(mTitle), NS_ERROR_FAILURE);
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2001-04-11 23:04:28 +00:00
|
|
|
|
2000-01-22 03:15:41 +00:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsXULWindow: Helpers
|
2017-07-06 12:00:35 +00:00
|
|
|
//*****************************************************************************
|
2000-01-22 03:15:41 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::EnsureChromeTreeOwner()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mChromeTreeOwner)
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
mChromeTreeOwner = new nsChromeTreeOwner();
|
|
|
|
NS_ADDREF(mChromeTreeOwner);
|
|
|
|
mChromeTreeOwner->XULWindow(this);
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::EnsureContentTreeOwner()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mContentTreeOwner)
|
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mContentTreeOwner = new nsContentTreeOwner(false);
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ADDREF(mContentTreeOwner);
|
|
|
|
mContentTreeOwner->XULWindow(this);
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 07:29:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::EnsurePrimaryContentTreeOwner()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mPrimaryContentTreeOwner)
|
|
|
|
return NS_OK;
|
2000-01-30 07:29:38 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrimaryContentTreeOwner = new nsContentTreeOwner(true);
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ADDREF(mPrimaryContentTreeOwner);
|
|
|
|
mPrimaryContentTreeOwner->XULWindow(this);
|
2000-01-30 07:29:38 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-01-30 07:29:38 +00:00
|
|
|
}
|
|
|
|
|
2001-04-10 18:30:25 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::EnsurePrompter()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mPrompter)
|
|
|
|
return NS_OK;
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> ourWindow;
|
2006-05-10 17:30:15 +00:00
|
|
|
nsresult rv = GetWindowDOMWindow(getter_AddRefs(ourWindow));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2017-07-06 12:00:35 +00:00
|
|
|
nsCOMPtr<nsIWindowWatcher> wwatch =
|
2006-05-10 17:30:15 +00:00
|
|
|
do_GetService(NS_WINDOWWATCHER_CONTRACTID);
|
|
|
|
if (wwatch)
|
|
|
|
wwatch->GetNewPrompter(ourWindow, getter_AddRefs(mPrompter));
|
|
|
|
}
|
|
|
|
return mPrompter ? NS_OK : NS_ERROR_FAILURE;
|
2001-04-10 18:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::EnsureAuthPrompter()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mAuthPrompter)
|
|
|
|
return NS_OK;
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> ourWindow;
|
2006-05-10 17:30:15 +00:00
|
|
|
nsresult rv = GetWindowDOMWindow(getter_AddRefs(ourWindow));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
|
|
|
if (wwatch)
|
|
|
|
wwatch->GetNewAuthPrompter(ourWindow, getter_AddRefs(mAuthPrompter));
|
|
|
|
}
|
|
|
|
return mAuthPrompter ? NS_OK : NS_ERROR_FAILURE;
|
2001-04-10 18:30:25 +00:00
|
|
|
}
|
2017-03-29 07:43:54 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::GetAvailScreenSize(int32_t* aAvailWidth, int32_t* aAvailHeight)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWindow;
|
|
|
|
GetWindowDOMWindow(getter_AddRefs(domWindow));
|
|
|
|
NS_ENSURE_STATE(domWindow);
|
|
|
|
|
|
|
|
auto* window = nsPIDOMWindowOuter::From(domWindow);
|
|
|
|
NS_ENSURE_STATE(window);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMScreen> screen = window->GetScreen();
|
|
|
|
NS_ENSURE_STATE(screen);
|
|
|
|
|
|
|
|
rv = screen->GetAvailWidth(aAvailWidth);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = screen->GetAvailHeight(aAvailHeight);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rounds window size to 1000x1000, or, if there isn't enough available
|
|
|
|
// screen space, to a multiple of 200x100.
|
|
|
|
NS_IMETHODIMP nsXULWindow::ForceRoundedDimensions()
|
|
|
|
{
|
|
|
|
if (mIsHiddenWindow) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-29 07:43:56 +00:00
|
|
|
int32_t availWidthCSS = 0;
|
|
|
|
int32_t availHeightCSS = 0;
|
|
|
|
int32_t contentWidthCSS = 0;
|
|
|
|
int32_t contentHeightCSS = 0;
|
|
|
|
int32_t windowWidthCSS = 0;
|
|
|
|
int32_t windowHeightCSS = 0;
|
2017-03-29 07:43:54 +00:00
|
|
|
double devicePerCSSPixels = 1.0;
|
|
|
|
|
|
|
|
GetUnscaledDevicePixelsPerCSSPixel(&devicePerCSSPixels);
|
|
|
|
|
|
|
|
GetAvailScreenSize(&availWidthCSS, &availHeightCSS);
|
|
|
|
|
|
|
|
// To get correct chrome size, we have to resize the window to a proper
|
|
|
|
// size first. So, here, we size it to its available size.
|
|
|
|
SetSpecifiedSize(availWidthCSS, availHeightCSS);
|
|
|
|
|
2017-03-29 07:43:56 +00:00
|
|
|
// Get the current window size for calculating chrome UI size.
|
|
|
|
GetSize(&windowWidthCSS, &windowHeightCSS); // device pixels
|
|
|
|
windowWidthCSS = NSToIntRound(windowWidthCSS / devicePerCSSPixels);
|
|
|
|
windowHeightCSS = NSToIntRound(windowHeightCSS / devicePerCSSPixels);
|
2017-03-29 07:43:54 +00:00
|
|
|
|
2017-03-29 07:43:56 +00:00
|
|
|
// Get the content size for calculating chrome UI size.
|
2017-03-29 07:43:54 +00:00
|
|
|
GetPrimaryContentSize(&contentWidthCSS, &contentHeightCSS);
|
|
|
|
|
2017-03-29 07:43:56 +00:00
|
|
|
// Calculate the chrome UI size.
|
|
|
|
int32_t chromeWidth = 0, chromeHeight = 0;
|
|
|
|
chromeWidth = windowWidthCSS - contentWidthCSS;
|
|
|
|
chromeHeight = windowHeightCSS - contentHeightCSS;
|
|
|
|
|
|
|
|
int32_t targetContentWidth = 0, targetContentHeight = 0;
|
|
|
|
|
|
|
|
// Here, we use the available screen dimensions as the input dimensions to
|
|
|
|
// force the window to be rounded as the maximum available content size.
|
|
|
|
nsContentUtils::CalcRoundedWindowSizeForResistingFingerprinting(
|
|
|
|
chromeWidth,
|
|
|
|
chromeHeight,
|
|
|
|
availWidthCSS,
|
|
|
|
availHeightCSS,
|
|
|
|
availWidthCSS,
|
|
|
|
availHeightCSS,
|
|
|
|
false, // aSetOuterWidth
|
|
|
|
false, // aSetOuterHeight
|
|
|
|
&targetContentWidth,
|
|
|
|
&targetContentHeight
|
|
|
|
);
|
|
|
|
|
|
|
|
targetContentWidth = NSToIntRound(targetContentWidth * devicePerCSSPixels);
|
|
|
|
targetContentHeight = NSToIntRound(targetContentHeight * devicePerCSSPixels);
|
2017-03-29 07:43:54 +00:00
|
|
|
|
|
|
|
SetPrimaryContentSize(targetContentWidth, targetContentHeight);
|
|
|
|
|
|
|
|
mIgnoreXULSize = true;
|
|
|
|
mIgnoreXULSizeMode = true;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-06 12:00:35 +00:00
|
|
|
|
Bug 1442521 - Make width/height attr on <window> mean the inner size in nsXULWindow. r=bz
It seems that the layout system assumes those attributes are for size of
the <window> element, i.e. inner window size, not outer window size.
See for example nsContainerFrame::SyncWindowProperties. It reads
{min,max}{width,height} attributes from the element via
nsIFrame::GetXUL{Min,Max}Size, and passes them into SetSizeConstraints.
The latter inflates the sizes with window decoration size before calling
into widget code. It can also be seen that various XUL size related
methods on nsBox and nsIFrame put the same assumption.
The test test_windowminmaxsize.xul apparently puts the same assumption
as the layout system on the meaning of those properties.
(Another test test_resize_move_windows.xul, which tests effectiveness of
features of window.open, also fails if we size the window earlier than
current in bug 1439875, and doesn't fail with this patch on top. It may
indicate that it makes use of the same assumption, but I can't really
figure out how it does so.)
MozReview-Commit-ID: IdMwDc59Ltg
--HG--
extra : rebase_source : ae46c23e450f556cc4608b512890c4e27cf8623e
2018-03-02 11:42:57 +00:00
|
|
|
static LayoutDeviceIntSize
|
|
|
|
GetWindowOuterInnerDiff(nsIWidget* aWindow)
|
|
|
|
{
|
|
|
|
if (!aWindow) {
|
|
|
|
return LayoutDeviceIntSize();
|
|
|
|
}
|
|
|
|
LayoutDeviceIntSize baseSize(200, 200);
|
|
|
|
LayoutDeviceIntSize windowSize = aWindow->ClientToWindowSize(baseSize);
|
|
|
|
return windowSize - baseSize;
|
|
|
|
}
|
|
|
|
|
2000-02-08 13:40:10 +00:00
|
|
|
void nsXULWindow::OnChromeLoaded()
|
|
|
|
{
|
2003-01-10 00:41:54 +00:00
|
|
|
nsresult rv = EnsureContentTreeOwner();
|
2001-03-09 02:15:55 +00:00
|
|
|
|
2003-01-10 00:41:54 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mChromeLoaded = true;
|
2005-02-02 09:39:30 +00:00
|
|
|
ApplyChromeFlags();
|
2009-08-05 20:52:08 +00:00
|
|
|
SyncAttributesToWidget();
|
2018-03-16 09:26:31 +00:00
|
|
|
|
|
|
|
int32_t specWidth = -1, specHeight = -1;
|
|
|
|
bool gotSize = false;
|
|
|
|
bool isContent = false;
|
|
|
|
|
|
|
|
GetHasPrimaryContent(&isContent);
|
|
|
|
|
|
|
|
CSSIntSize windowDiff = mWindow
|
|
|
|
? RoundedToInt(GetWindowOuterInnerDiff(mWindow) /
|
|
|
|
mWindow->GetDefaultScale())
|
|
|
|
: CSSIntSize();
|
|
|
|
|
|
|
|
// If this window has a primary content and fingerprinting resistance is
|
|
|
|
// enabled, we enforce this window to rounded dimensions.
|
|
|
|
if (isContent && nsContentUtils::ShouldResistFingerprinting()) {
|
|
|
|
ForceRoundedDimensions();
|
|
|
|
} else if (!mIgnoreXULSize) {
|
|
|
|
gotSize = LoadSizeFromXUL(specWidth, specHeight);
|
|
|
|
specWidth += windowDiff.width;
|
|
|
|
specHeight += windowDiff.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool positionSet = !mIgnoreXULPosition;
|
|
|
|
nsCOMPtr<nsIXULWindow> parentWindow(do_QueryReferent(mParentWindow));
|
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
// don't override WM placement on unix for independent, top-level windows
|
|
|
|
// (however, we think the benefits of intelligent dependent window placement
|
|
|
|
// trump that override.)
|
|
|
|
if (!parentWindow)
|
|
|
|
positionSet = false;
|
|
|
|
#endif
|
|
|
|
if (positionSet) {
|
|
|
|
// We have to do this before sizing the window, because sizing depends
|
|
|
|
// on the resolution of the screen we're on. But positioning needs to
|
|
|
|
// know the size so that it can constrain to screen bounds.... as an
|
|
|
|
// initial guess here, we'll use the specified size (if any).
|
|
|
|
positionSet = LoadPositionFromXUL(specWidth, specHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gotSize) {
|
|
|
|
SetSpecifiedSize(specWidth, specHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIntrinsicallySized) {
|
|
|
|
// (if LoadSizeFromXUL set the size, mIntrinsicallySized will be false)
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (cv) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem = do_QueryInterface(mDocShell);
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
if (treeOwner) {
|
|
|
|
// GetContentSize can fail, so initialise |width| and |height| to be
|
|
|
|
// on the safe side.
|
|
|
|
int32_t width = 0, height = 0;
|
|
|
|
if (NS_SUCCEEDED(cv->GetContentSize(&width, &height))) {
|
|
|
|
treeOwner->SizeShellTo(docShellAsItem, width, height);
|
|
|
|
// Update specified size for the final LoadPositionFromXUL call.
|
|
|
|
specWidth = width + windowDiff.width;
|
|
|
|
specHeight = height + windowDiff.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we have set the window's final size, we can re-do its
|
|
|
|
// positioning so that it is properly constrained to the screen.
|
|
|
|
if (positionSet) {
|
|
|
|
LoadPositionFromXUL(specWidth, specHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadMiscPersistentAttributesFromXUL();
|
|
|
|
|
|
|
|
if (mCenterAfterLoad && !positionSet) {
|
|
|
|
Center(parentWindow, parentWindow ? false : true, false);
|
|
|
|
}
|
2003-01-10 00:41:54 +00:00
|
|
|
|
2009-11-11 10:29:29 +00:00
|
|
|
if (mShowAfterLoad) {
|
2011-10-17 14:59:28 +00:00
|
|
|
SetVisibility(true);
|
2009-11-11 10:29:29 +00:00
|
|
|
// At this point the window may have been closed during Show(), so
|
|
|
|
// nsXULWindow::Destroy may already have been called. Take care!
|
|
|
|
}
|
2003-01-10 00:41:54 +00:00
|
|
|
}
|
2003-10-07 01:20:16 +00:00
|
|
|
mPersistentAttributesMask |= PAD_POSITION | PAD_SIZE | PAD_MISC;
|
2000-02-08 13:40:10 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:05:10 +00:00
|
|
|
// If aSpecWidth and/or aSpecHeight are > 0, we will use these CSS px sizes
|
|
|
|
// to fit to the screen when staggering windows; if they're negative,
|
|
|
|
// we use the window's current size instead.
|
|
|
|
bool nsXULWindow::LoadPositionFromXUL(int32_t aSpecWidth, int32_t aSpecHeight)
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotPosition = false;
|
2013-07-18 06:54:08 +00:00
|
|
|
|
2001-04-11 23:04:28 +00:00
|
|
|
// if we're the hidden window, don't try to validate our size/position. We're
|
|
|
|
// special.
|
2002-01-09 01:31:24 +00:00
|
|
|
if (mIsHiddenWindow)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-04-11 23:04:28 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
nsCOMPtr<dom::Element> windowElement = GetWindowDOMElement();
|
2012-10-02 08:24:10 +00:00
|
|
|
NS_ENSURE_TRUE(windowElement, false);
|
2001-01-29 23:47:36 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t currX = 0;
|
|
|
|
int32_t currY = 0;
|
|
|
|
int32_t currWidth = 0;
|
|
|
|
int32_t currHeight = 0;
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult errorCode;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t temp;
|
2001-01-29 23:47:36 +00:00
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
GetPositionAndSize(&currX, &currY, &currWidth, &currHeight);
|
|
|
|
|
2012-10-16 19:41:19 +00:00
|
|
|
// Convert to global display pixels for consistent window management across
|
|
|
|
// screens with diverse resolutions
|
2016-03-01 21:05:10 +00:00
|
|
|
double devToDesktopScale = 1.0 / mWindow->GetDesktopToDeviceScale().scale;
|
|
|
|
currX = NSToIntRound(currX * devToDesktopScale);
|
|
|
|
currY = NSToIntRound(currY * devToDesktopScale);
|
|
|
|
|
|
|
|
// For size, use specified value if > 0, else current value
|
|
|
|
double devToCSSScale = 1.0 / mWindow->GetDefaultScale().scale;
|
|
|
|
int32_t cssWidth =
|
|
|
|
aSpecWidth > 0 ? aSpecWidth : NSToIntRound(currWidth * devToCSSScale);
|
|
|
|
int32_t cssHeight =
|
|
|
|
aSpecHeight > 0 ? aSpecHeight : NSToIntRound(currHeight * devToCSSScale);
|
2012-10-16 19:41:19 +00:00
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
// Obtain the position information from the <xul:window> element.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t specX = currX;
|
|
|
|
int32_t specY = currY;
|
2002-01-09 01:31:24 +00:00
|
|
|
nsAutoString posString;
|
2001-01-29 23:47:36 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(SCREENX_ATTRIBUTE, posString);
|
|
|
|
temp = posString.ToInteger(&errorCode);
|
|
|
|
if (NS_SUCCEEDED(errorCode)) {
|
|
|
|
specX = temp;
|
|
|
|
gotPosition = true;
|
2001-01-29 23:47:36 +00:00
|
|
|
}
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(SCREENY_ATTRIBUTE, posString);
|
|
|
|
temp = posString.ToInteger(&errorCode);
|
|
|
|
if (NS_SUCCEEDED(errorCode)) {
|
|
|
|
specY = temp;
|
|
|
|
gotPosition = true;
|
2001-01-29 23:47:36 +00:00
|
|
|
}
|
2013-07-18 06:54:08 +00:00
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
if (gotPosition) {
|
|
|
|
// our position will be relative to our parent, if any
|
|
|
|
nsCOMPtr<nsIBaseWindow> parent(do_QueryReferent(mParentWindow));
|
|
|
|
if (parent) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t parentX, parentY;
|
2002-01-09 01:31:24 +00:00
|
|
|
if (NS_SUCCEEDED(parent->GetPosition(&parentX, &parentY))) {
|
2012-10-16 19:41:19 +00:00
|
|
|
double scale;
|
2015-12-03 13:19:50 +00:00
|
|
|
if (NS_SUCCEEDED(parent->GetDevicePixelsPerDesktopPixel(&scale))) {
|
2012-10-16 19:41:19 +00:00
|
|
|
parentX = NSToIntRound(parentX / scale);
|
|
|
|
parentY = NSToIntRound(parentY / scale);
|
|
|
|
}
|
2002-01-09 01:31:24 +00:00
|
|
|
specX += parentX;
|
|
|
|
specY += parentY;
|
|
|
|
}
|
2007-09-15 17:01:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-03-01 21:05:10 +00:00
|
|
|
StaggerPosition(specX, specY, cssWidth, cssHeight);
|
2007-09-15 17:01:35 +00:00
|
|
|
}
|
2002-01-09 01:31:24 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mWindow->ConstrainPosition(false, &specX, &specY);
|
2012-10-16 19:41:19 +00:00
|
|
|
if (specX != currX || specY != currY) {
|
2016-02-18 10:47:14 +00:00
|
|
|
SetPositionDesktopPix(specX, specY);
|
2012-10-16 19:41:19 +00:00
|
|
|
}
|
2002-01-09 01:31:24 +00:00
|
|
|
|
|
|
|
return gotPosition;
|
|
|
|
}
|
|
|
|
|
2018-03-01 16:40:23 +00:00
|
|
|
static Maybe<int32_t>
|
|
|
|
ReadIntAttribute(const Element& aElement, nsAtom* aAtom)
|
|
|
|
{
|
|
|
|
nsAutoString attrString;
|
|
|
|
if (!aElement.GetAttr(kNameSpaceID_None, aAtom, attrString)) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
int32_t ret = attrString.ToInteger(&res);
|
|
|
|
return NS_SUCCEEDED(res) ? Some(ret) : Nothing();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Maybe<int32_t>
|
|
|
|
ReadSize(const Element& aElement,
|
|
|
|
nsAtom* aAttr,
|
|
|
|
nsAtom* aMinAttr,
|
|
|
|
nsAtom* aMaxAttr)
|
|
|
|
{
|
|
|
|
Maybe<int32_t> attr = ReadIntAttribute(aElement, aAttr);
|
|
|
|
if (!attr) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t min =
|
|
|
|
std::max(100, ReadIntAttribute(aElement, aMinAttr).valueOr(100));
|
|
|
|
int32_t max = ReadIntAttribute(aElement, aMaxAttr)
|
|
|
|
.valueOr(std::numeric_limits<int32_t>::max());
|
|
|
|
|
|
|
|
return Some(std::min(max, std::max(*attr, min)));
|
|
|
|
}
|
|
|
|
|
2016-03-01 21:05:10 +00:00
|
|
|
bool
|
|
|
|
nsXULWindow::LoadSizeFromXUL(int32_t& aSpecWidth, int32_t& aSpecHeight)
|
2002-01-09 01:31:24 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotSize = false;
|
2013-07-18 06:54:08 +00:00
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
// if we're the hidden window, don't try to validate our size/position. We're
|
|
|
|
// special.
|
2016-03-01 21:05:10 +00:00
|
|
|
if (mIsHiddenWindow) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2016-03-01 21:05:10 +00:00
|
|
|
}
|
2002-01-09 01:31:24 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
nsCOMPtr<dom::Element> windowElement = GetWindowDOMElement();
|
2012-10-02 08:24:10 +00:00
|
|
|
NS_ENSURE_TRUE(windowElement, false);
|
2002-01-09 01:31:24 +00:00
|
|
|
|
2016-03-01 21:05:10 +00:00
|
|
|
// Obtain the sizing information from the <xul:window> element.
|
|
|
|
aSpecWidth = 100;
|
|
|
|
aSpecHeight = 100;
|
2002-01-09 01:31:24 +00:00
|
|
|
|
2018-03-01 16:40:23 +00:00
|
|
|
if (auto width = ReadSize(*windowElement,
|
|
|
|
nsGkAtoms::width,
|
|
|
|
nsGkAtoms::minwidth,
|
|
|
|
nsGkAtoms::maxwidth)) {
|
|
|
|
aSpecWidth = *width;
|
2013-07-18 06:54:08 +00:00
|
|
|
gotSize = true;
|
2001-01-29 23:47:36 +00:00
|
|
|
}
|
2018-03-01 16:40:23 +00:00
|
|
|
|
|
|
|
if (auto height = ReadSize(*windowElement,
|
|
|
|
nsGkAtoms::height,
|
|
|
|
nsGkAtoms::minheight,
|
|
|
|
nsGkAtoms::maxheight)) {
|
|
|
|
aSpecHeight = *height;
|
2013-07-18 06:54:08 +00:00
|
|
|
gotSize = true;
|
2001-01-29 23:47:36 +00:00
|
|
|
}
|
2000-02-10 07:47:24 +00:00
|
|
|
|
2016-03-01 21:05:10 +00:00
|
|
|
return gotSize;
|
|
|
|
}
|
2002-12-14 00:36:29 +00:00
|
|
|
|
2016-03-01 21:05:10 +00:00
|
|
|
void
|
|
|
|
nsXULWindow::SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight)
|
|
|
|
{
|
|
|
|
// constrain to screen size
|
2017-03-29 07:43:54 +00:00
|
|
|
int32_t screenWidth;
|
|
|
|
int32_t screenHeight;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(GetAvailScreenSize(&screenWidth, &screenHeight))) {
|
|
|
|
if (aSpecWidth > screenWidth) {
|
|
|
|
aSpecWidth = screenWidth;
|
|
|
|
}
|
|
|
|
if (aSpecHeight > screenHeight) {
|
|
|
|
aSpecHeight = screenHeight;
|
2012-10-16 19:41:19 +00:00
|
|
|
}
|
2002-01-11 01:08:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 21:05:10 +00:00
|
|
|
NS_ASSERTION(mWindow, "we expected to have a window already");
|
|
|
|
|
|
|
|
int32_t currWidth = 0;
|
|
|
|
int32_t currHeight = 0;
|
|
|
|
GetSize(&currWidth, &currHeight); // returns device pixels
|
|
|
|
|
|
|
|
// convert specified values to device pixels, and resize if needed
|
|
|
|
double cssToDevPx = mWindow ? mWindow->GetDefaultScale().scale : 1.0;
|
|
|
|
aSpecWidth = NSToIntRound(aSpecWidth * cssToDevPx);
|
|
|
|
aSpecHeight = NSToIntRound(aSpecHeight * cssToDevPx);
|
|
|
|
mIntrinsicallySized = false;
|
|
|
|
if (aSpecWidth != currWidth || aSpecHeight != currHeight) {
|
|
|
|
SetSize(aSpecWidth, aSpecHeight, false);
|
|
|
|
}
|
2002-01-11 01:08:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
/* Miscellaneous persistent attributes are attributes named in the
|
|
|
|
|persist| attribute, other than size and position. Those are special
|
|
|
|
because it's important to load those before one of the misc
|
|
|
|
attributes (sizemode) and they require extra processing. */
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsXULWindow::LoadMiscPersistentAttributesFromXUL()
|
2002-01-11 01:08:49 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotState = false;
|
2013-07-18 06:54:08 +00:00
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
/* There are no misc attributes of interest to the hidden window.
|
|
|
|
It's especially important not to try to validate that window's
|
|
|
|
size or position, because some platforms (Mac OS X) need to
|
|
|
|
make it visible and offscreen. */
|
2002-01-11 01:08:49 +00:00
|
|
|
if (mIsHiddenWindow)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2002-01-11 01:08:49 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
nsCOMPtr<dom::Element> windowElement = GetWindowDOMElement();
|
2012-10-02 08:24:10 +00:00
|
|
|
NS_ENSURE_TRUE(windowElement, false);
|
2001-09-06 18:35:55 +00:00
|
|
|
|
2002-01-11 01:08:49 +00:00
|
|
|
nsAutoString stateString;
|
2003-10-07 01:20:16 +00:00
|
|
|
|
|
|
|
// sizemode
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(MODE_ATTRIBUTE, stateString);
|
2015-08-29 01:12:41 +00:00
|
|
|
nsSizeMode sizeMode = nsSizeMode_Normal;
|
2013-07-18 06:54:08 +00:00
|
|
|
/* ignore request to minimize, to not confuse novices
|
|
|
|
if (stateString.Equals(SIZEMODE_MINIMIZED))
|
|
|
|
sizeMode = nsSizeMode_Minimized;
|
|
|
|
*/
|
|
|
|
if (!mIgnoreXULSizeMode &&
|
|
|
|
(stateString.Equals(SIZEMODE_MAXIMIZED) || stateString.Equals(SIZEMODE_FULLSCREEN))) {
|
|
|
|
/* Honor request to maximize only if the window is sizable.
|
|
|
|
An unsizable, unmaximizable, yet maximized window confuses
|
|
|
|
Windows OS and is something of a travesty, anyway. */
|
|
|
|
if (mChromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) {
|
|
|
|
mIntrinsicallySized = false;
|
|
|
|
|
|
|
|
if (stateString.Equals(SIZEMODE_MAXIMIZED))
|
|
|
|
sizeMode = nsSizeMode_Maximized;
|
|
|
|
else
|
|
|
|
sizeMode = nsSizeMode_Fullscreen;
|
2009-07-01 19:01:11 +00:00
|
|
|
}
|
2013-07-18 06:54:08 +00:00
|
|
|
}
|
2011-05-27 15:19:58 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
// If we are told to ignore the size mode attribute update the
|
|
|
|
// document so the attribute and window are in sync.
|
|
|
|
if (mIgnoreXULSizeMode) {
|
|
|
|
nsAutoString sizeString;
|
|
|
|
if (sizeMode == nsSizeMode_Maximized)
|
|
|
|
sizeString.Assign(SIZEMODE_MAXIMIZED);
|
|
|
|
else if (sizeMode == nsSizeMode_Fullscreen)
|
|
|
|
sizeString.Assign(SIZEMODE_FULLSCREEN);
|
|
|
|
else if (sizeMode == nsSizeMode_Normal)
|
|
|
|
sizeString.Assign(SIZEMODE_NORMAL);
|
|
|
|
if (!sizeString.IsEmpty()) {
|
|
|
|
ErrorResult rv;
|
|
|
|
windowElement->SetAttribute(MODE_ATTRIBUTE, sizeString, rv);
|
2011-05-27 15:19:58 +00:00
|
|
|
}
|
2013-07-18 06:54:08 +00:00
|
|
|
}
|
2011-05-27 15:19:58 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
if (sizeMode == nsSizeMode_Fullscreen) {
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> ourWindow;
|
2013-07-18 06:54:08 +00:00
|
|
|
GetWindowDOMWindow(getter_AddRefs(ourWindow));
|
2016-01-30 17:05:36 +00:00
|
|
|
auto* piWindow = nsPIDOMWindowOuter::From(ourWindow);
|
2015-10-26 21:37:32 +00:00
|
|
|
piWindow->SetFullScreen(true);
|
2013-07-18 06:54:08 +00:00
|
|
|
} else {
|
2018-02-08 11:29:02 +00:00
|
|
|
// For maximized windows, ignore the XUL size attributes, as setting the
|
|
|
|
// size would set the window back to the normal sizemode.
|
|
|
|
if (sizeMode == nsSizeMode_Maximized) {
|
|
|
|
mIgnoreXULSize = true;
|
|
|
|
}
|
2013-07-18 06:54:08 +00:00
|
|
|
mWindow->SetSizeMode(sizeMode);
|
2001-01-29 23:47:36 +00:00
|
|
|
}
|
2013-07-18 06:54:08 +00:00
|
|
|
gotState = true;
|
2001-09-06 18:35:55 +00:00
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
// zlevel
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(ZLEVEL_ATTRIBUTE, stateString);
|
|
|
|
if (!stateString.IsEmpty()) {
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult errorCode;
|
2013-05-03 23:48:20 +00:00
|
|
|
int32_t zLevel = stateString.ToInteger(&errorCode);
|
2003-10-07 01:20:16 +00:00
|
|
|
if (NS_SUCCEEDED(errorCode) && zLevel >= lowestZ && zLevel <= highestZ)
|
|
|
|
SetZLevel(zLevel);
|
|
|
|
}
|
|
|
|
|
2002-01-11 01:08:49 +00:00
|
|
|
return gotState;
|
2000-02-10 07:47:24 +00:00
|
|
|
}
|
|
|
|
|
2001-01-31 03:25:07 +00:00
|
|
|
/* Stagger windows of the same type so they don't appear on top of each other.
|
|
|
|
This code does have a scary double loop -- it'll keep passing through
|
|
|
|
the entire list of open windows until it finds a non-collision. Doesn't
|
|
|
|
seem to be a problem, but it deserves watching.
|
2016-03-01 21:05:10 +00:00
|
|
|
The aRequested{X,Y} parameters here are in desktop pixels;
|
|
|
|
the aSpec{Width,Height} parameters are CSS pixel dimensions.
|
2001-01-31 03:25:07 +00:00
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
void nsXULWindow::StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY,
|
|
|
|
int32_t aSpecWidth, int32_t aSpecHeight)
|
2001-01-31 03:25:07 +00:00
|
|
|
{
|
2016-03-01 21:05:10 +00:00
|
|
|
// These "constants" will be converted from CSS to desktop pixels
|
|
|
|
// for the appropriate screen, assuming we find a screen to use...
|
|
|
|
// hence they're not actually declared const here.
|
|
|
|
int32_t kOffset = 22;
|
|
|
|
uint32_t kSlop = 4;
|
2012-09-29 11:36:09 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool keepTrying;
|
2003-10-07 01:20:16 +00:00
|
|
|
int bouncedX = 0, // bounced off vertical edge of screen
|
|
|
|
bouncedY = 0; // bounced off horizontal edge
|
2001-01-31 03:25:07 +00:00
|
|
|
|
|
|
|
// look for any other windows of this type
|
2002-04-30 01:36:59 +00:00
|
|
|
nsCOMPtr<nsIWindowMediator> wm(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2001-01-31 03:25:07 +00:00
|
|
|
if (!wm)
|
|
|
|
return;
|
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
nsCOMPtr<dom::Element> windowElement = GetWindowDOMElement();
|
2012-10-02 08:24:10 +00:00
|
|
|
if (!windowElement)
|
|
|
|
return;
|
|
|
|
|
2001-01-31 03:25:07 +00:00
|
|
|
nsCOMPtr<nsIXULWindow> ourXULWindow(this);
|
|
|
|
|
|
|
|
nsAutoString windowType;
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(WINDOWTYPE_ATTRIBUTE, windowType);
|
2001-01-31 03:25:07 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t screenTop = 0, // it's pointless to initialize these ...
|
2003-11-09 16:33:14 +00:00
|
|
|
screenRight = 0, // ... but to prevent oversalubrious and ...
|
|
|
|
screenBottom = 0, // ... underbright compilers from ...
|
|
|
|
screenLeft = 0; // ... issuing warnings.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gotScreen = false;
|
2003-10-07 01:20:16 +00:00
|
|
|
|
|
|
|
{ // fetch screen coordinates
|
|
|
|
nsCOMPtr<nsIScreenManager> screenMgr(do_GetService(
|
|
|
|
"@mozilla.org/gfx/screenmanager;1"));
|
|
|
|
if (screenMgr) {
|
|
|
|
nsCOMPtr<nsIScreen> ourScreen;
|
2012-10-16 19:41:19 +00:00
|
|
|
// the coordinates here are already display pixels
|
2003-10-07 01:20:16 +00:00
|
|
|
screenMgr->ScreenForRect(aRequestedX, aRequestedY,
|
|
|
|
aSpecWidth, aSpecHeight,
|
|
|
|
getter_AddRefs(ourScreen));
|
|
|
|
if (ourScreen) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t screenWidth, screenHeight;
|
2012-10-16 19:41:19 +00:00
|
|
|
ourScreen->GetAvailRectDisplayPix(&screenLeft, &screenTop,
|
|
|
|
&screenWidth, &screenHeight);
|
2003-10-07 01:20:16 +00:00
|
|
|
screenBottom = screenTop + screenHeight;
|
|
|
|
screenRight = screenLeft + screenWidth;
|
2016-03-01 21:05:10 +00:00
|
|
|
// Get the screen's scaling factors and convert staggering constants
|
|
|
|
// from CSS px to desktop pixel units
|
|
|
|
double desktopToDeviceScale = 1.0, cssToDeviceScale = 1.0;
|
|
|
|
ourScreen->GetContentsScaleFactor(&desktopToDeviceScale);
|
|
|
|
ourScreen->GetDefaultCSSScaleFactor(&cssToDeviceScale);
|
|
|
|
double cssToDesktopFactor = cssToDeviceScale / desktopToDeviceScale;
|
|
|
|
kOffset = NSToIntRound(kOffset * cssToDesktopFactor);
|
|
|
|
kSlop = NSToIntRound(kSlop * cssToDesktopFactor);
|
|
|
|
// Convert dimensions from CSS to desktop pixels
|
|
|
|
aSpecWidth = NSToIntRound(aSpecWidth * cssToDesktopFactor);
|
|
|
|
aSpecHeight = NSToIntRound(aSpecHeight * cssToDesktopFactor);
|
2011-10-17 14:59:28 +00:00
|
|
|
gotScreen = true;
|
2003-10-07 01:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-01-31 03:25:07 +00:00
|
|
|
|
2007-09-15 17:01:35 +00:00
|
|
|
// One full pass through all windows of this type, repeat until no collisions.
|
2001-01-31 03:25:07 +00:00
|
|
|
do {
|
2011-10-17 14:59:28 +00:00
|
|
|
keepTrying = false;
|
2001-01-31 03:25:07 +00:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowList;
|
2001-06-30 11:02:25 +00:00
|
|
|
wm->GetXULWindowEnumerator(windowType.get(), getter_AddRefs(windowList));
|
2001-01-31 03:25:07 +00:00
|
|
|
|
|
|
|
if (!windowList)
|
|
|
|
break;
|
|
|
|
|
2007-09-15 17:01:35 +00:00
|
|
|
// One full pass through all windows of this type, offset and stop on collision.
|
2001-01-31 03:25:07 +00:00
|
|
|
do {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool more;
|
2001-01-31 03:25:07 +00:00
|
|
|
windowList->HasMoreElements(&more);
|
|
|
|
if (!more)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supportsWindow;
|
|
|
|
windowList->GetNext(getter_AddRefs(supportsWindow));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULWindow> listXULWindow(do_QueryInterface(supportsWindow));
|
2001-01-31 04:37:37 +00:00
|
|
|
if (listXULWindow != ourXULWindow) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t listX, listY;
|
2007-09-15 17:01:35 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> listBaseWindow(do_QueryInterface(supportsWindow));
|
2001-01-31 03:25:07 +00:00
|
|
|
listBaseWindow->GetPosition(&listX, &listY);
|
2012-10-16 19:41:19 +00:00
|
|
|
double scale;
|
2016-03-01 21:05:10 +00:00
|
|
|
if (NS_SUCCEEDED(listBaseWindow->GetDevicePixelsPerDesktopPixel(&scale))) {
|
2012-10-16 19:41:19 +00:00
|
|
|
listX = NSToIntRound(listX / scale);
|
|
|
|
listY = NSToIntRound(listY / scale);
|
|
|
|
}
|
2001-01-31 03:25:07 +00:00
|
|
|
|
2013-03-05 23:43:53 +00:00
|
|
|
if (Abs(listX - aRequestedX) <= kSlop && Abs(listY - aRequestedY) <= kSlop) {
|
2003-10-07 01:20:16 +00:00
|
|
|
// collision! offset and start over
|
|
|
|
if (bouncedX & 0x1)
|
|
|
|
aRequestedX -= kOffset;
|
|
|
|
else
|
|
|
|
aRequestedX += kOffset;
|
2001-01-31 03:25:07 +00:00
|
|
|
aRequestedY += kOffset;
|
2003-10-07 01:20:16 +00:00
|
|
|
|
|
|
|
if (gotScreen) {
|
2007-09-15 17:01:35 +00:00
|
|
|
// if we're moving to the right and we need to bounce...
|
|
|
|
if (!(bouncedX & 0x1) && ((aRequestedX + aSpecWidth) > screenRight)) {
|
2003-10-07 01:20:16 +00:00
|
|
|
aRequestedX = screenRight - aSpecWidth;
|
|
|
|
++bouncedX;
|
|
|
|
}
|
2007-09-15 17:01:35 +00:00
|
|
|
|
|
|
|
// if we're moving to the left and we need to bounce...
|
2003-10-07 01:20:16 +00:00
|
|
|
if ((bouncedX & 0x1) && aRequestedX < screenLeft) {
|
|
|
|
aRequestedX = screenLeft;
|
|
|
|
++bouncedX;
|
|
|
|
}
|
2007-09-15 17:01:35 +00:00
|
|
|
|
|
|
|
// if we hit the bottom then bounce to the top
|
2003-10-07 01:20:16 +00:00
|
|
|
if (aRequestedY + aSpecHeight > screenBottom) {
|
|
|
|
aRequestedY = screenTop;
|
|
|
|
++bouncedY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop around again,
|
|
|
|
but it's time to give up once we've covered the screen.
|
|
|
|
there's a potential infinite loop with lots of windows. */
|
|
|
|
keepTrying = bouncedX < 2 || bouncedY == 0;
|
2001-01-31 03:25:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(1);
|
|
|
|
} while (keepTrying);
|
|
|
|
}
|
|
|
|
|
2009-08-05 20:52:08 +00:00
|
|
|
void nsXULWindow::SyncAttributesToWidget()
|
2002-08-07 01:59:22 +00:00
|
|
|
{
|
2013-07-18 06:54:08 +00:00
|
|
|
nsCOMPtr<dom::Element> windowElement = GetWindowDOMElement();
|
2009-08-05 20:52:08 +00:00
|
|
|
if (!windowElement)
|
|
|
|
return;
|
2002-07-08 07:11:59 +00:00
|
|
|
|
2009-08-05 20:52:08 +00:00
|
|
|
nsAutoString attr;
|
2002-07-08 07:11:59 +00:00
|
|
|
|
2009-08-05 20:52:08 +00:00
|
|
|
// "hidechrome" attribute
|
2013-07-18 06:54:08 +00:00
|
|
|
if (windowElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidechrome,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mWindow->HideWindowChrome(true);
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
2002-07-08 07:11:59 +00:00
|
|
|
|
2010-06-25 02:01:07 +00:00
|
|
|
// "chromemargin" attribute
|
|
|
|
nsIntMargin margins;
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(NS_LITERAL_STRING("chromemargin"), attr);
|
|
|
|
if (nsContentUtils::ParseIntMarginValue(attr, margins)) {
|
2015-11-12 07:05:04 +00:00
|
|
|
LayoutDeviceIntMargin tmp = LayoutDeviceIntMargin::FromUnknownMargin(margins);
|
|
|
|
mWindow->SetNonClientMargins(tmp);
|
2010-06-25 02:01:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-05 20:52:08 +00:00
|
|
|
// "windowtype" attribute
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(WINDOWTYPE_ATTRIBUTE, attr);
|
|
|
|
if (!attr.IsEmpty()) {
|
2009-08-05 20:52:08 +00:00
|
|
|
mWindow->SetWindowClass(attr);
|
|
|
|
}
|
2001-04-14 00:57:30 +00:00
|
|
|
|
2009-08-05 20:52:08 +00:00
|
|
|
// "id" attribute for icon
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(NS_LITERAL_STRING("id"), attr);
|
|
|
|
if (attr.IsEmpty()) {
|
2009-08-05 20:52:08 +00:00
|
|
|
attr.AssignLiteral("default");
|
|
|
|
}
|
|
|
|
mWindow->SetIcon(attr);
|
|
|
|
|
2013-12-17 16:11:13 +00:00
|
|
|
// "drawtitle" attribute
|
|
|
|
windowElement->GetAttribute(NS_LITERAL_STRING("drawtitle"), attr);
|
|
|
|
mWindow->SetDrawsTitle(attr.LowerCaseEqualsLiteral("true"));
|
|
|
|
|
2009-08-05 20:52:08 +00:00
|
|
|
// "toggletoolbar" attribute
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(NS_LITERAL_STRING("toggletoolbar"), attr);
|
|
|
|
mWindow->SetShowsToolbarButton(attr.LowerCaseEqualsLiteral("true"));
|
2012-02-17 03:47:39 +00:00
|
|
|
|
2012-03-20 23:21:14 +00:00
|
|
|
// "fullscreenbutton" attribute
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(NS_LITERAL_STRING("fullscreenbutton"), attr);
|
|
|
|
mWindow->SetShowsFullScreenButton(attr.LowerCaseEqualsLiteral("true"));
|
2012-03-20 23:21:14 +00:00
|
|
|
|
2012-02-17 03:47:39 +00:00
|
|
|
// "macanimationtype" attribute
|
2013-07-18 06:54:08 +00:00
|
|
|
windowElement->GetAttribute(NS_LITERAL_STRING("macanimationtype"), attr);
|
|
|
|
if (attr.EqualsLiteral("document")) {
|
2012-02-17 03:47:39 +00:00
|
|
|
mWindow->SetWindowAnimationType(nsIWidget::eDocumentWindowAnimation);
|
|
|
|
}
|
2009-08-05 20:49:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 01:33:51 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
|
2000-01-22 03:15:41 +00:00
|
|
|
{
|
2001-06-04 22:22:07 +00:00
|
|
|
// can happen when the persistence timer fires at an inopportune time
|
|
|
|
// during window shutdown
|
2015-10-14 01:33:51 +00:00
|
|
|
if (!mDocShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-27 22:34:18 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
nsCOMPtr<dom::Element> docShellElement = GetWindowDOMElement();
|
2015-10-14 01:33:51 +00:00
|
|
|
if (!docShellElement)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsAutoString persistString;
|
|
|
|
docShellElement->GetAttribute(PERSIST_ATTRIBUTE, persistString);
|
|
|
|
if (persistString.IsEmpty()) { // quick check which sometimes helps
|
|
|
|
mPersistentAttributesDirty = 0;
|
|
|
|
return NS_OK;
|
2003-10-07 01:20:16 +00:00
|
|
|
}
|
2000-01-22 03:15:41 +00:00
|
|
|
|
2015-10-22 00:08:35 +00:00
|
|
|
bool isFullscreen = false;
|
2016-01-30 17:05:36 +00:00
|
|
|
if (nsPIDOMWindowOuter* domWindow = mDocShell->GetWindow()) {
|
2015-10-26 21:37:32 +00:00
|
|
|
isFullscreen = domWindow->GetFullScreen();
|
2015-10-22 00:08:35 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
// get our size, position and mode to persist
|
2015-11-10 05:37:32 +00:00
|
|
|
LayoutDeviceIntRect rect;
|
2014-05-20 07:32:17 +00:00
|
|
|
bool gotRestoredBounds = NS_SUCCEEDED(mWindow->GetRestoredBounds(rect));
|
2013-04-26 06:49:47 +00:00
|
|
|
|
2015-12-03 13:19:50 +00:00
|
|
|
// we use CSS pixels for size, but desktop pixels for position
|
|
|
|
CSSToLayoutDeviceScale sizeScale = mWindow->GetDefaultScale();
|
|
|
|
DesktopToLayoutDeviceScale posScale = mWindow->GetDesktopToDeviceScale();
|
2000-03-09 02:00:20 +00:00
|
|
|
|
2002-01-09 01:31:24 +00:00
|
|
|
// make our position relative to our parent, if any
|
|
|
|
nsCOMPtr<nsIBaseWindow> parent(do_QueryReferent(mParentWindow));
|
2014-05-20 07:32:17 +00:00
|
|
|
if (parent && gotRestoredBounds) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t parentX, parentY;
|
2002-01-09 01:31:24 +00:00
|
|
|
if (NS_SUCCEEDED(parent->GetPosition(&parentX, &parentY))) {
|
2018-01-10 16:15:22 +00:00
|
|
|
rect.MoveBy(-parentX, -parentY);
|
2002-01-09 01:31:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-08 19:06:11 +00:00
|
|
|
char sizeBuf[10];
|
|
|
|
nsAutoString sizeString;
|
2015-10-14 01:33:51 +00:00
|
|
|
nsAutoString windowElementId;
|
2018-01-31 19:49:28 +00:00
|
|
|
RefPtr<dom::XULDocument> ownerXULDoc;
|
2015-10-14 01:33:51 +00:00
|
|
|
|
|
|
|
// fetch docShellElement's ID and XUL owner document
|
2018-01-31 19:49:28 +00:00
|
|
|
ownerXULDoc = docShellElement->OwnerDoc()->AsXULDocument();
|
2015-10-14 01:33:51 +00:00
|
|
|
if (docShellElement->IsXULElement()) {
|
|
|
|
docShellElement->GetId(windowElementId);
|
|
|
|
}
|
2001-06-04 22:22:07 +00:00
|
|
|
|
2015-10-22 00:08:35 +00:00
|
|
|
bool shouldPersist = !isFullscreen && ownerXULDoc;
|
2013-07-18 06:54:08 +00:00
|
|
|
ErrorResult rv;
|
2001-06-04 22:22:07 +00:00
|
|
|
// (only for size elements which are persisted)
|
2014-05-20 07:32:17 +00:00
|
|
|
if ((mPersistentAttributesDirty & PAD_POSITION) && gotRestoredBounds) {
|
2015-10-14 01:33:51 +00:00
|
|
|
if (persistString.Find("screenX") >= 0) {
|
2018-01-10 16:15:22 +00:00
|
|
|
SprintfLiteral(sizeBuf, "%d", NSToIntRound(rect.X() / posScale.scale));
|
2017-07-24 17:23:52 +00:00
|
|
|
CopyASCIItoUTF16(sizeBuf, sizeString);
|
2015-10-14 01:33:51 +00:00
|
|
|
docShellElement->SetAttribute(SCREENX_ATTRIBUTE, sizeString, rv);
|
2015-10-22 00:08:35 +00:00
|
|
|
if (shouldPersist) {
|
2018-01-31 19:49:28 +00:00
|
|
|
IgnoredErrorResult err;
|
|
|
|
ownerXULDoc->Persist(windowElementId, SCREENX_ATTRIBUTE, err);
|
2015-10-22 00:08:35 +00:00
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
}
|
|
|
|
if (persistString.Find("screenY") >= 0) {
|
2018-01-10 16:15:22 +00:00
|
|
|
SprintfLiteral(sizeBuf, "%d", NSToIntRound(rect.Y() / posScale.scale));
|
2017-07-24 17:23:52 +00:00
|
|
|
CopyASCIItoUTF16(sizeBuf, sizeString);
|
2015-10-14 01:33:51 +00:00
|
|
|
docShellElement->SetAttribute(SCREENY_ATTRIBUTE, sizeString, rv);
|
2015-10-22 00:08:35 +00:00
|
|
|
if (shouldPersist) {
|
2018-01-31 19:49:28 +00:00
|
|
|
IgnoredErrorResult err;
|
|
|
|
ownerXULDoc->Persist(windowElementId, SCREENY_ATTRIBUTE, err);
|
2015-10-22 00:08:35 +00:00
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
}
|
2001-06-04 22:22:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-20 07:32:17 +00:00
|
|
|
if ((mPersistentAttributesDirty & PAD_SIZE) && gotRestoredBounds) {
|
Bug 1442521 - Make width/height attr on <window> mean the inner size in nsXULWindow. r=bz
It seems that the layout system assumes those attributes are for size of
the <window> element, i.e. inner window size, not outer window size.
See for example nsContainerFrame::SyncWindowProperties. It reads
{min,max}{width,height} attributes from the element via
nsIFrame::GetXUL{Min,Max}Size, and passes them into SetSizeConstraints.
The latter inflates the sizes with window decoration size before calling
into widget code. It can also be seen that various XUL size related
methods on nsBox and nsIFrame put the same assumption.
The test test_windowminmaxsize.xul apparently puts the same assumption
as the layout system on the meaning of those properties.
(Another test test_resize_move_windows.xul, which tests effectiveness of
features of window.open, also fails if we size the window earlier than
current in bug 1439875, and doesn't fail with this patch on top. It may
indicate that it makes use of the same assumption, but I can't really
figure out how it does so.)
MozReview-Commit-ID: IdMwDc59Ltg
--HG--
extra : rebase_source : ae46c23e450f556cc4608b512890c4e27cf8623e
2018-03-02 11:42:57 +00:00
|
|
|
LayoutDeviceIntSize winDiff = GetWindowOuterInnerDiff(mWindow);
|
2015-10-14 01:33:51 +00:00
|
|
|
if (persistString.Find("width") >= 0) {
|
Bug 1442521 - Make width/height attr on <window> mean the inner size in nsXULWindow. r=bz
It seems that the layout system assumes those attributes are for size of
the <window> element, i.e. inner window size, not outer window size.
See for example nsContainerFrame::SyncWindowProperties. It reads
{min,max}{width,height} attributes from the element via
nsIFrame::GetXUL{Min,Max}Size, and passes them into SetSizeConstraints.
The latter inflates the sizes with window decoration size before calling
into widget code. It can also be seen that various XUL size related
methods on nsBox and nsIFrame put the same assumption.
The test test_windowminmaxsize.xul apparently puts the same assumption
as the layout system on the meaning of those properties.
(Another test test_resize_move_windows.xul, which tests effectiveness of
features of window.open, also fails if we size the window earlier than
current in bug 1439875, and doesn't fail with this patch on top. It may
indicate that it makes use of the same assumption, but I can't really
figure out how it does so.)
MozReview-Commit-ID: IdMwDc59Ltg
--HG--
extra : rebase_source : ae46c23e450f556cc4608b512890c4e27cf8623e
2018-03-02 11:42:57 +00:00
|
|
|
auto width = rect.Width() - winDiff.width;
|
|
|
|
SprintfLiteral(sizeBuf, "%d", NSToIntRound(width / sizeScale.scale));
|
2017-07-24 17:23:52 +00:00
|
|
|
CopyASCIItoUTF16(sizeBuf, sizeString);
|
2015-10-14 01:33:51 +00:00
|
|
|
docShellElement->SetAttribute(WIDTH_ATTRIBUTE, sizeString, rv);
|
2015-10-22 00:08:35 +00:00
|
|
|
if (shouldPersist) {
|
2018-01-31 19:49:28 +00:00
|
|
|
IgnoredErrorResult err;
|
|
|
|
ownerXULDoc->Persist(windowElementId, WIDTH_ATTRIBUTE, err);
|
2015-10-22 00:08:35 +00:00
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
}
|
|
|
|
if (persistString.Find("height") >= 0) {
|
Bug 1442521 - Make width/height attr on <window> mean the inner size in nsXULWindow. r=bz
It seems that the layout system assumes those attributes are for size of
the <window> element, i.e. inner window size, not outer window size.
See for example nsContainerFrame::SyncWindowProperties. It reads
{min,max}{width,height} attributes from the element via
nsIFrame::GetXUL{Min,Max}Size, and passes them into SetSizeConstraints.
The latter inflates the sizes with window decoration size before calling
into widget code. It can also be seen that various XUL size related
methods on nsBox and nsIFrame put the same assumption.
The test test_windowminmaxsize.xul apparently puts the same assumption
as the layout system on the meaning of those properties.
(Another test test_resize_move_windows.xul, which tests effectiveness of
features of window.open, also fails if we size the window earlier than
current in bug 1439875, and doesn't fail with this patch on top. It may
indicate that it makes use of the same assumption, but I can't really
figure out how it does so.)
MozReview-Commit-ID: IdMwDc59Ltg
--HG--
extra : rebase_source : ae46c23e450f556cc4608b512890c4e27cf8623e
2018-03-02 11:42:57 +00:00
|
|
|
auto height = rect.Height() - winDiff.height;
|
|
|
|
SprintfLiteral(sizeBuf, "%d", NSToIntRound(height / sizeScale.scale));
|
2017-07-24 17:23:52 +00:00
|
|
|
CopyASCIItoUTF16(sizeBuf, sizeString);
|
2015-10-14 01:33:51 +00:00
|
|
|
docShellElement->SetAttribute(HEIGHT_ATTRIBUTE, sizeString, rv);
|
2015-10-22 00:08:35 +00:00
|
|
|
if (shouldPersist) {
|
2018-01-31 19:49:28 +00:00
|
|
|
IgnoredErrorResult err;
|
|
|
|
ownerXULDoc->Persist(windowElementId, HEIGHT_ATTRIBUTE, err);
|
2015-10-22 00:08:35 +00:00
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
}
|
2001-06-04 22:22:07 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
if (mPersistentAttributesDirty & PAD_MISC) {
|
2015-08-29 01:12:41 +00:00
|
|
|
nsSizeMode sizeMode = mWindow->SizeMode();
|
2014-05-20 07:32:17 +00:00
|
|
|
|
2012-03-23 15:58:27 +00:00
|
|
|
if (sizeMode != nsSizeMode_Minimized) {
|
2003-10-07 01:20:16 +00:00
|
|
|
if (sizeMode == nsSizeMode_Maximized)
|
|
|
|
sizeString.Assign(SIZEMODE_MAXIMIZED);
|
2012-03-23 15:58:27 +00:00
|
|
|
else if (sizeMode == nsSizeMode_Fullscreen)
|
|
|
|
sizeString.Assign(SIZEMODE_FULLSCREEN);
|
2003-10-07 01:20:16 +00:00
|
|
|
else
|
|
|
|
sizeString.Assign(SIZEMODE_NORMAL);
|
2013-07-18 06:54:08 +00:00
|
|
|
docShellElement->SetAttribute(MODE_ATTRIBUTE, sizeString, rv);
|
2015-10-22 00:08:35 +00:00
|
|
|
if (shouldPersist && persistString.Find("sizemode") >= 0) {
|
2018-01-31 19:49:28 +00:00
|
|
|
IgnoredErrorResult err;
|
|
|
|
ownerXULDoc->Persist(windowElementId, MODE_ATTRIBUTE, err);
|
2015-10-22 00:08:35 +00:00
|
|
|
}
|
2003-10-07 01:20:16 +00:00
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
if (persistString.Find("zlevel") >= 0) {
|
|
|
|
uint32_t zLevel;
|
|
|
|
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
|
|
|
if (mediator) {
|
|
|
|
mediator->GetZLevel(this, &zLevel);
|
2016-08-15 06:44:00 +00:00
|
|
|
SprintfLiteral(sizeBuf, "%" PRIu32, zLevel);
|
2017-07-24 17:23:52 +00:00
|
|
|
CopyASCIItoUTF16(sizeBuf, sizeString);
|
2015-10-14 01:33:51 +00:00
|
|
|
docShellElement->SetAttribute(ZLEVEL_ATTRIBUTE, sizeString, rv);
|
2015-10-22 00:08:35 +00:00
|
|
|
if (shouldPersist) {
|
2018-01-31 19:49:28 +00:00
|
|
|
IgnoredErrorResult err;
|
|
|
|
ownerXULDoc->Persist(windowElementId, ZLEVEL_ATTRIBUTE, err);
|
2015-10-22 00:08:35 +00:00
|
|
|
}
|
2015-10-14 01:33:51 +00:00
|
|
|
}
|
2003-10-07 01:20:16 +00:00
|
|
|
}
|
2001-06-04 22:22:07 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
mPersistentAttributesDirty = 0;
|
2015-10-14 01:33:51 +00:00
|
|
|
return NS_OK;
|
2000-01-22 03:15:41 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetWindowDOMWindow(mozIDOMWindowProxy** aDOMWindow)
|
2000-03-24 03:46:15 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_STATE(mDocShell);
|
2000-03-24 03:46:15 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
if (!mDOMWindow)
|
2014-01-10 02:03:47 +00:00
|
|
|
mDOMWindow = mDocShell->GetWindow();
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_TRUE(mDOMWindow, NS_ERROR_FAILURE);
|
2000-03-24 03:46:15 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
*aDOMWindow = mDOMWindow;
|
|
|
|
NS_ADDREF(*aDOMWindow);
|
|
|
|
return NS_OK;
|
2000-03-24 03:46:15 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
dom::Element*
|
2012-10-02 08:24:10 +00:00
|
|
|
nsXULWindow::GetWindowDOMElement() const
|
2000-02-10 07:47:24 +00:00
|
|
|
{
|
2012-10-02 08:24:10 +00:00
|
|
|
NS_ENSURE_TRUE(mDocShell, nullptr);
|
2000-02-10 07:47:24 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(cv));
|
2012-10-02 08:24:10 +00:00
|
|
|
NS_ENSURE_TRUE(cv, nullptr);
|
2000-02-10 07:47:24 +00:00
|
|
|
|
2012-10-02 08:24:10 +00:00
|
|
|
const nsIDocument* document = cv->GetDocument();
|
|
|
|
NS_ENSURE_TRUE(document, nullptr);
|
2000-02-10 07:47:24 +00:00
|
|
|
|
2013-07-18 06:54:08 +00:00
|
|
|
return document->GetRootElement();
|
2000-02-10 07:47:24 +00:00
|
|
|
}
|
|
|
|
|
2006-02-22 03:58:48 +00:00
|
|
|
nsresult nsXULWindow::ContentShellAdded(nsIDocShellTreeItem* aContentShell,
|
2016-12-08 21:12:36 +00:00
|
|
|
bool aPrimary)
|
|
|
|
{
|
2005-02-02 09:39:30 +00:00
|
|
|
// Set the default content tree owner
|
|
|
|
if (aPrimary) {
|
|
|
|
NS_ENSURE_SUCCESS(EnsurePrimaryContentTreeOwner(), NS_ERROR_FAILURE);
|
|
|
|
aContentShell->SetTreeOwner(mPrimaryContentTreeOwner);
|
2005-02-22 00:17:35 +00:00
|
|
|
mPrimaryContentShell = aContentShell;
|
2015-10-01 17:06:51 +00:00
|
|
|
mPrimaryTabParent = nullptr;
|
2005-02-02 09:39:30 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ENSURE_SUCCESS(EnsureContentTreeOwner(), NS_ERROR_FAILURE);
|
|
|
|
aContentShell->SetTreeOwner(mContentTreeOwner);
|
2005-02-22 00:17:35 +00:00
|
|
|
if (mPrimaryContentShell == aContentShell)
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrimaryContentShell = nullptr;
|
2000-05-27 22:00:07 +00:00
|
|
|
}
|
2000-01-27 05:59:42 +00:00
|
|
|
|
2006-02-22 03:58:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsXULWindow::ContentShellRemoved(nsIDocShellTreeItem* aContentShell)
|
|
|
|
{
|
|
|
|
if (mPrimaryContentShell == aContentShell) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mPrimaryContentShell = nullptr;
|
2006-02-22 03:58:48 +00:00
|
|
|
}
|
2000-05-27 22:00:07 +00:00
|
|
|
return NS_OK;
|
2000-01-27 05:59:42 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 20:31:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULWindow::GetPrimaryContentSize(int32_t* aWidth,
|
|
|
|
int32_t* aHeight)
|
|
|
|
{
|
|
|
|
if (mPrimaryTabParent) {
|
|
|
|
return GetPrimaryTabParentSize(aWidth, aHeight);
|
|
|
|
} else if (mPrimaryContentShell) {
|
|
|
|
return GetPrimaryContentShellSize(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULWindow::GetPrimaryTabParentSize(int32_t* aWidth,
|
|
|
|
int32_t* aHeight)
|
|
|
|
{
|
|
|
|
TabParent* tabParent = TabParent::GetFrom(mPrimaryTabParent);
|
2017-07-14 03:46:59 +00:00
|
|
|
// Need strong ref, since Client* can run script.
|
|
|
|
nsCOMPtr<Element> element = tabParent->GetOwnerElement();
|
2016-07-14 20:31:41 +00:00
|
|
|
NS_ENSURE_STATE(element);
|
|
|
|
|
|
|
|
*aWidth = element->ClientWidth();
|
|
|
|
*aHeight = element->ClientHeight();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULWindow::GetPrimaryContentShellSize(int32_t* aWidth,
|
|
|
|
int32_t* aHeight)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(mPrimaryContentShell);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> shellWindow(do_QueryInterface(mPrimaryContentShell));
|
|
|
|
NS_ENSURE_STATE(shellWindow);
|
|
|
|
|
|
|
|
int32_t devicePixelWidth, devicePixelHeight;
|
|
|
|
double shellScale = 1.0;
|
|
|
|
// We want to return CSS pixels. First, we get device pixels
|
|
|
|
// from the content area...
|
|
|
|
shellWindow->GetSize(&devicePixelWidth, &devicePixelHeight);
|
|
|
|
// And then get the device pixel scaling factor. Dividing device
|
|
|
|
// pixels by this scaling factor gives us CSS pixels.
|
|
|
|
shellWindow->GetUnscaledDevicePixelsPerCSSPixel(&shellScale);
|
|
|
|
*aWidth = NSToIntRound(devicePixelWidth / shellScale);
|
|
|
|
*aHeight = NSToIntRound(devicePixelHeight / shellScale);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULWindow::SetPrimaryContentSize(int32_t aWidth,
|
|
|
|
int32_t aHeight)
|
|
|
|
{
|
|
|
|
if (mPrimaryTabParent) {
|
|
|
|
return SetPrimaryTabParentSize(aWidth, aHeight);
|
|
|
|
} else if (mPrimaryContentShell) {
|
|
|
|
return SizeShellTo(mPrimaryContentShell, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULWindow::SetPrimaryTabParentSize(int32_t aWidth,
|
|
|
|
int32_t aHeight)
|
|
|
|
{
|
|
|
|
int32_t shellWidth, shellHeight;
|
|
|
|
GetPrimaryTabParentSize(&shellWidth, &shellHeight);
|
|
|
|
|
|
|
|
double scale = 1.0;
|
|
|
|
GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
|
|
|
|
|
|
|
SizeShellToWithLimit(aWidth, aHeight,
|
|
|
|
shellWidth * scale, shellHeight * scale);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULWindow::GetRootShellSize(int32_t* aWidth,
|
|
|
|
int32_t* aHeight)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIBaseWindow> shellAsWin = do_QueryInterface(mDocShell);
|
|
|
|
NS_ENSURE_TRUE(shellAsWin, NS_ERROR_FAILURE);
|
|
|
|
return shellAsWin->GetSize(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULWindow::SetRootShellSize(int32_t aWidth,
|
|
|
|
int32_t aHeight)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem = do_QueryInterface(mDocShell);
|
|
|
|
return SizeShellTo(docShellAsItem, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
2000-02-05 03:26:35 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::SizeShellTo(nsIDocShellTreeItem* aShellItem,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aCX, int32_t aCY)
|
2000-02-05 03:26:35 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
// XXXTAB This is wrong, we should actually reflow based on the passed in
|
|
|
|
// shell. For now we are hacking and doing delta sizing. This is bad
|
|
|
|
// because it assumes all size we add will go to the shell which probably
|
|
|
|
// won't happen.
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(aShellItem));
|
|
|
|
NS_ENSURE_TRUE(shellAsWin, NS_ERROR_FAILURE);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t width = 0;
|
|
|
|
int32_t height = 0;
|
2006-05-10 17:30:15 +00:00
|
|
|
shellAsWin->GetSize(&width, &height);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2016-05-11 09:44:57 +00:00
|
|
|
SizeShellToWithLimit(aCX, aCY, width, height);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
2000-02-05 03:26:35 +00:00
|
|
|
}
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2000-07-12 23:56:14 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::ExitModalLoop(nsresult aStatus)
|
2000-02-08 13:40:10 +00:00
|
|
|
{
|
2002-03-06 22:26:58 +00:00
|
|
|
if (mContinueModalLoop)
|
2011-10-17 14:59:28 +00:00
|
|
|
EnableParent(true);
|
|
|
|
mContinueModalLoop = false;
|
2002-02-28 23:23:43 +00:00
|
|
|
mModalStatus = aStatus;
|
|
|
|
return NS_OK;
|
2000-02-08 13:40:10 +00:00
|
|
|
}
|
|
|
|
|
2001-11-06 01:19:39 +00:00
|
|
|
// top-level function to create a new window
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::CreateNewWindow(int32_t aChromeFlags,
|
2014-06-06 02:51:14 +00:00
|
|
|
nsITabParent *aOpeningTab,
|
2016-10-07 18:59:59 +00:00
|
|
|
mozIDOMWindowProxy *aOpener,
|
2017-04-16 22:52:02 +00:00
|
|
|
uint64_t aNextTabParentId,
|
2014-06-06 02:51:14 +00:00
|
|
|
nsIXULWindow **_retval)
|
2000-02-08 13:40:10 +00:00
|
|
|
{
|
2001-11-06 01:19:39 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2017-04-16 22:52:02 +00:00
|
|
|
if (aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) {
|
|
|
|
MOZ_RELEASE_ASSERT(aNextTabParentId == 0,
|
|
|
|
"Unexpected next tab parent ID, should never have a non-zero nextTabParentId when creating a new chrome window");
|
2016-10-07 18:59:59 +00:00
|
|
|
return CreateNewChromeWindow(aChromeFlags, aOpeningTab, aOpener, _retval);
|
2017-04-16 22:52:02 +00:00
|
|
|
}
|
|
|
|
return CreateNewContentWindow(aChromeFlags, aOpeningTab, aOpener, aNextTabParentId, _retval);
|
2000-02-05 03:26:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::CreateNewChromeWindow(int32_t aChromeFlags,
|
2014-06-06 02:51:14 +00:00
|
|
|
nsITabParent *aOpeningTab,
|
2016-10-07 18:59:59 +00:00
|
|
|
mozIDOMWindowProxy *aOpener,
|
2011-10-14 13:06:39 +00:00
|
|
|
nsIXULWindow **_retval)
|
2000-02-05 03:26:35 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIAppShellService> appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// Just do a normal create of a window and return.
|
|
|
|
nsCOMPtr<nsIXULWindow> newWindow;
|
2012-07-30 14:20:58 +00:00
|
|
|
appShell->CreateTopLevelWindow(this, nullptr, aChromeFlags,
|
2006-05-10 17:30:15 +00:00
|
|
|
nsIAppShellService::SIZE_TO_CONTENT,
|
|
|
|
nsIAppShellService::SIZE_TO_CONTENT,
|
2016-10-07 18:59:59 +00:00
|
|
|
aOpeningTab, aOpener,
|
2011-10-14 13:06:39 +00:00
|
|
|
getter_AddRefs(newWindow));
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_TRUE(newWindow, NS_ERROR_FAILURE);
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
*_retval = newWindow;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-05 03:26:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(int32_t aChromeFlags,
|
2014-06-06 02:51:14 +00:00
|
|
|
nsITabParent *aOpeningTab,
|
2016-10-07 18:59:59 +00:00
|
|
|
mozIDOMWindowProxy *aOpener,
|
2017-04-16 22:52:02 +00:00
|
|
|
uint64_t aNextTabParentId,
|
2011-10-14 13:06:39 +00:00
|
|
|
nsIXULWindow **_retval)
|
2000-02-08 13:40:10 +00:00
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIAppShellService> appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// We need to create a new top level window and then enter a nested
|
|
|
|
// loop. Eventually the new window will be told that it has loaded,
|
|
|
|
// at which time we know it is safe to spin out of the nested loop
|
|
|
|
// and allow the opening code to proceed.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
2017-07-31 04:28:48 +00:00
|
|
|
nsAutoCString urlStr;
|
|
|
|
Preferences::GetCString("browser.chromeURL", urlStr);
|
2011-06-20 03:00:16 +00:00
|
|
|
if (urlStr.IsEmpty()) {
|
|
|
|
urlStr.AssignLiteral("chrome://navigator/content/navigator.xul");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIOService> service(do_GetService(NS_IOSERVICE_CONTRACTID));
|
|
|
|
if (service) {
|
2012-07-30 14:20:58 +00:00
|
|
|
service->NewURI(urlStr, nullptr, nullptr, getter_AddRefs(uri));
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
|
|
|
|
|
2012-10-11 17:44:20 +00:00
|
|
|
// We need to create a chrome window to contain the content window we're about
|
|
|
|
// to pass back. The subject principal needs to be system while we're creating
|
2013-12-12 01:51:58 +00:00
|
|
|
// it to make things work right, so force a system caller. See bug 799348
|
|
|
|
// comment 13 for a description of what happens when we don't.
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIXULWindow> newWindow;
|
2013-12-12 01:51:58 +00:00
|
|
|
{
|
2014-04-15 03:27:00 +00:00
|
|
|
AutoNoJSAPI nojsapi;
|
2016-10-07 18:59:59 +00:00
|
|
|
// We actually want this toplevel window which we are creating to have a
|
|
|
|
// null opener, as we will be creating the content xul:browser window inside
|
|
|
|
// of it, so we pass nullptr as our aOpener.
|
2013-12-12 01:51:58 +00:00
|
|
|
appShell->CreateTopLevelWindow(this, uri,
|
|
|
|
aChromeFlags, 615, 480,
|
2016-10-07 18:59:59 +00:00
|
|
|
aOpeningTab, nullptr,
|
2013-12-12 01:51:58 +00:00
|
|
|
getter_AddRefs(newWindow));
|
|
|
|
NS_ENSURE_TRUE(newWindow, NS_ERROR_FAILURE);
|
|
|
|
}
|
2000-02-08 13:40:10 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// Specify that we want the window to remain locked until the chrome has loaded.
|
2007-07-08 07:08:04 +00:00
|
|
|
nsXULWindow *xulWin = static_cast<nsXULWindow*>
|
|
|
|
(static_cast<nsIXULWindow*>
|
|
|
|
(newWindow));
|
2001-11-06 01:19:39 +00:00
|
|
|
|
2017-04-16 22:52:02 +00:00
|
|
|
if (aNextTabParentId) {
|
|
|
|
xulWin->mNextTabParentId = aNextTabParentId;
|
|
|
|
}
|
|
|
|
|
2016-10-07 18:59:59 +00:00
|
|
|
if (aOpener) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
xulWin->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
MOZ_ASSERT(docShell);
|
2017-11-21 22:24:57 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = docShell->GetWindow();
|
|
|
|
MOZ_ASSERT(window);
|
|
|
|
window->SetOpenerForInitialContentBrowser(nsPIDOMWindowOuter::From(aOpener));
|
2016-10-07 18:59:59 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
xulWin->LockUntilChromeLoad();
|
|
|
|
|
2013-04-18 15:36:03 +00:00
|
|
|
{
|
2014-04-15 03:27:00 +00:00
|
|
|
AutoNoJSAPI nojsapi;
|
2017-05-15 13:34:19 +00:00
|
|
|
SpinEventLoopUntil([&]() { return !xulWin->IsLocked(); });
|
2014-06-06 02:51:14 +00:00
|
|
|
}
|
2011-03-03 05:43:09 +00:00
|
|
|
|
2016-06-08 21:03:42 +00:00
|
|
|
NS_ENSURE_STATE(xulWin->mPrimaryContentShell || xulWin->mPrimaryTabParent);
|
2017-04-16 22:52:02 +00:00
|
|
|
MOZ_ASSERT_IF(xulWin->mPrimaryContentShell, aNextTabParentId == 0);
|
2015-01-13 22:24:52 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
*_retval = newWindow;
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-08 13:40:10 +00:00
|
|
|
}
|
2000-02-05 03:26:35 +00:00
|
|
|
|
2016-07-14 20:31:41 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetHasPrimaryContent(bool* aResult)
|
|
|
|
{
|
|
|
|
*aResult = mPrimaryTabParent || mPrimaryContentShell;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsXULWindow::EnableParent(bool aEnable)
|
2000-02-25 03:11:21 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIBaseWindow> parentWindow;
|
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
|
|
|
|
|
|
|
parentWindow = do_QueryReferent(mParentWindow);
|
|
|
|
if (parentWindow)
|
|
|
|
parentWindow->GetMainWidget(getter_AddRefs(parentWidget));
|
|
|
|
if (parentWidget)
|
|
|
|
parentWidget->Enable(aEnable);
|
|
|
|
}
|
|
|
|
|
2000-04-01 22:13:46 +00:00
|
|
|
// Constrain the window to its proper z-level
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsXULWindow::ConstrainToZLevel(bool aImmediate,
|
2009-01-06 22:25:49 +00:00
|
|
|
nsWindowZ *aPlacement,
|
|
|
|
nsIWidget *aReqBelow,
|
|
|
|
nsIWidget **aActualBelow)
|
|
|
|
{
|
2000-04-01 22:13:46 +00:00
|
|
|
#if 0
|
|
|
|
/* Do we have a parent window? This means our z-order is already constrained,
|
|
|
|
since we're a dependent window. Our window list isn't hierarchical,
|
|
|
|
so we can't properly calculate placement for such a window.
|
|
|
|
Should we just abort? */
|
|
|
|
nsCOMPtr<nsIBaseWindow> parentWindow = do_QueryReferent(mParentWindow);
|
|
|
|
if (parentWindow)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-04-01 22:13:46 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-05 13:04:54 +00:00
|
|
|
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2009-01-06 22:25:49 +00:00
|
|
|
if (!mediator)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-04-01 22:13:46 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool altered;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t position,
|
2003-10-07 01:20:16 +00:00
|
|
|
newPosition,
|
|
|
|
zLevel;
|
|
|
|
nsIXULWindow *us = this;
|
2000-04-01 22:13:46 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
altered = false;
|
2003-10-07 01:20:16 +00:00
|
|
|
mediator->GetZLevel(this, &zLevel);
|
2000-04-01 22:13:46 +00:00
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
// translate from WidgetGUIEvent to nsIWindowMediator constants
|
2000-04-01 22:13:46 +00:00
|
|
|
position = nsIWindowMediator::zLevelTop;
|
2003-10-07 01:20:16 +00:00
|
|
|
if (*aPlacement == nsWindowZBottom || zLevel == nsIXULWindow::lowestZ)
|
2000-04-01 22:13:46 +00:00
|
|
|
position = nsIWindowMediator::zLevelBottom;
|
|
|
|
else if (*aPlacement == nsWindowZRelative)
|
|
|
|
position = nsIWindowMediator::zLevelBelow;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mediator->CalculateZPosition(us, position, aReqBelow,
|
|
|
|
&newPosition, aActualBelow, &altered))) {
|
2003-09-24 14:31:03 +00:00
|
|
|
/* If we were asked to move to the top but constrained to remain
|
|
|
|
below one of our other windows, first move all windows in that
|
|
|
|
window's layer and above to the top. This allows the user to
|
|
|
|
click a window which can't be topmost and still bring mozilla
|
|
|
|
to the foreground. */
|
|
|
|
if (altered &&
|
|
|
|
(position == nsIWindowMediator::zLevelTop ||
|
2009-02-10 08:29:53 +00:00
|
|
|
(position == nsIWindowMediator::zLevelBelow && aReqBelow == 0)))
|
2009-01-06 22:25:49 +00:00
|
|
|
PlaceWindowLayersBehind(zLevel + 1, nsIXULWindow::highestZ, 0);
|
2003-09-24 14:31:03 +00:00
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
if (*aPlacement != nsWindowZBottom &&
|
|
|
|
position == nsIWindowMediator::zLevelBottom)
|
2011-10-17 14:59:28 +00:00
|
|
|
altered = true;
|
2000-04-05 02:30:59 +00:00
|
|
|
if (altered || aImmediate) {
|
2000-04-01 22:13:46 +00:00
|
|
|
if (newPosition == nsIWindowMediator::zLevelTop)
|
|
|
|
*aPlacement = nsWindowZTop;
|
|
|
|
else if (newPosition == nsIWindowMediator::zLevelBottom)
|
|
|
|
*aPlacement = nsWindowZBottom;
|
|
|
|
else
|
|
|
|
*aPlacement = nsWindowZRelative;
|
|
|
|
|
|
|
|
if (aImmediate) {
|
2011-08-30 21:45:31 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> ourBase = do_QueryObject(this);
|
2000-04-01 22:13:46 +00:00
|
|
|
if (ourBase) {
|
|
|
|
nsCOMPtr<nsIWidget> ourWidget;
|
|
|
|
ourBase->GetMainWidget(getter_AddRefs(ourWidget));
|
2003-10-07 01:20:16 +00:00
|
|
|
ourWidget->PlaceBehind(*aPlacement == nsWindowZBottom ?
|
|
|
|
eZPlacementBottom : eZPlacementBelow,
|
2011-10-17 14:59:28 +00:00
|
|
|
*aActualBelow, false);
|
2000-04-01 22:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-06 22:25:49 +00:00
|
|
|
/* CalculateZPosition can tell us to be below nothing, because it tries
|
2000-04-01 22:13:46 +00:00
|
|
|
not to change something it doesn't recognize. A request to verify
|
|
|
|
being below an unrecognized window, then, is treated as a request
|
|
|
|
to come to the top (below null) */
|
|
|
|
nsCOMPtr<nsIXULWindow> windowAbove;
|
|
|
|
if (newPosition == nsIWindowMediator::zLevelBelow && *aActualBelow) {
|
2012-08-15 18:52:42 +00:00
|
|
|
windowAbove = (*aActualBelow)->GetWidgetListener()->GetXULWindow();
|
2000-04-01 22:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mediator->SetZPosition(us, newPosition, windowAbove);
|
|
|
|
}
|
|
|
|
|
|
|
|
return altered;
|
|
|
|
}
|
|
|
|
|
2003-09-24 14:31:03 +00:00
|
|
|
/* Re-z-position all windows in the layers from aLowLevel to aHighLevel,
|
|
|
|
inclusive, to be behind aBehind. aBehind of null means on top.
|
|
|
|
Note this method actually does nothing to our relative window positions.
|
|
|
|
(And therefore there's no need to inform WindowMediator we're moving
|
|
|
|
things, because we aren't.) This method is useful for, say, moving
|
|
|
|
a range of layers of our own windows relative to windows belonging to
|
|
|
|
external applications.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
void nsXULWindow::PlaceWindowLayersBehind(uint32_t aLowLevel,
|
|
|
|
uint32_t aHighLevel,
|
2009-01-06 22:25:49 +00:00
|
|
|
nsIXULWindow *aBehind)
|
|
|
|
{
|
2003-09-24 14:31:03 +00:00
|
|
|
// step through windows in z-order from top to bottommost window
|
|
|
|
|
2007-09-05 13:04:54 +00:00
|
|
|
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2009-01-06 22:25:49 +00:00
|
|
|
if (!mediator)
|
2003-09-24 14:31:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
2011-10-17 14:59:28 +00:00
|
|
|
mediator->GetZOrderXULWindowEnumerator(0, true,
|
2003-09-24 14:31:03 +00:00
|
|
|
getter_AddRefs(windowEnumerator));
|
|
|
|
if (!windowEnumerator)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// each window will be moved behind previousHighWidget, itself
|
|
|
|
// a moving target. initialize it.
|
|
|
|
nsCOMPtr<nsIWidget> previousHighWidget;
|
|
|
|
if (aBehind) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> highBase(do_QueryInterface(aBehind));
|
|
|
|
if (highBase)
|
|
|
|
highBase->GetMainWidget(getter_AddRefs(previousHighWidget));
|
|
|
|
}
|
|
|
|
|
|
|
|
// get next lower window
|
2011-09-29 06:19:26 +00:00
|
|
|
bool more;
|
2017-04-08 07:59:47 +00:00
|
|
|
while (NS_SUCCEEDED(windowEnumerator->HasMoreElements(&more)) && more) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t nextZ; // z-level of nextWindow
|
2003-09-24 14:31:03 +00:00
|
|
|
nsCOMPtr<nsISupports> nextWindow;
|
|
|
|
windowEnumerator->GetNext(getter_AddRefs(nextWindow));
|
|
|
|
nsCOMPtr<nsIXULWindow> nextXULWindow(do_QueryInterface(nextWindow));
|
2003-10-07 01:20:16 +00:00
|
|
|
nextXULWindow->GetZLevel(&nextZ);
|
2003-09-24 14:31:03 +00:00
|
|
|
if (nextZ < aLowLevel)
|
|
|
|
break; // we've processed all windows through aLowLevel
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2003-09-24 14:31:03 +00:00
|
|
|
// move it just below its next higher window
|
|
|
|
nsCOMPtr<nsIBaseWindow> nextBase(do_QueryInterface(nextXULWindow));
|
|
|
|
if (nextBase) {
|
|
|
|
nsCOMPtr<nsIWidget> nextWidget;
|
|
|
|
nextBase->GetMainWidget(getter_AddRefs(nextWidget));
|
|
|
|
if (nextZ <= aHighLevel)
|
2011-10-17 14:59:28 +00:00
|
|
|
nextWidget->PlaceBehind(eZPlacementBelow, previousHighWidget, false);
|
2003-09-24 14:31:03 +00:00
|
|
|
previousHighWidget = nextWidget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsXULWindow::SetContentScrollbarVisibility(bool aVisible)
|
2006-05-10 17:30:15 +00:00
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> contentWin(do_GetInterface(mPrimaryContentShell));
|
2015-07-17 05:10:35 +00:00
|
|
|
if (!contentWin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-11 23:10:13 +00:00
|
|
|
nsContentUtils::SetScrollbarsVisibility(contentWin->GetDocShell(), aVisible);
|
2002-02-16 01:15:52 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nsXULWindow::GetContentScrollbarVisibility()
|
2006-05-10 17:30:15 +00:00
|
|
|
{
|
2007-11-12 05:48:24 +00:00
|
|
|
// This code already exists in dom/src/base/nsBarProp.cpp, but we
|
|
|
|
// can't safely get to that from here as this function is called
|
|
|
|
// while the DOM window is being set up, and we need the DOM window
|
|
|
|
// to get to that code.
|
|
|
|
nsCOMPtr<nsIScrollable> scroller(do_QueryInterface(mPrimaryContentShell));
|
|
|
|
|
|
|
|
if (scroller) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t prefValue;
|
2007-11-12 05:48:24 +00:00
|
|
|
scroller->GetDefaultScrollbarPreferences(
|
|
|
|
nsIScrollable::ScrollOrientation_Y, &prefValue);
|
|
|
|
if (prefValue == nsIScrollable::Scrollbar_Never) // try the other way
|
|
|
|
scroller->GetDefaultScrollbarPreferences(
|
|
|
|
nsIScrollable::ScrollOrientation_X, &prefValue);
|
|
|
|
|
|
|
|
if (prefValue == nsIScrollable::Scrollbar_Never)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-08-11 03:43:44 +00:00
|
|
|
}
|
2007-11-12 05:48:24 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2000-08-11 03:43:44 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 01:20:16 +00:00
|
|
|
// during spinup, attributes that haven't been loaded yet can't be dirty
|
2015-10-14 01:33:51 +00:00
|
|
|
void nsXULWindow::PersistentAttributesDirty(uint32_t aDirtyFlags)
|
2006-05-10 17:30:15 +00:00
|
|
|
{
|
2003-10-07 01:20:16 +00:00
|
|
|
mPersistentAttributesDirty |= aDirtyFlags & mPersistentAttributesMask;
|
|
|
|
}
|
|
|
|
|
2018-03-16 09:26:31 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::ApplyChromeFlags()
|
2005-02-02 09:39:30 +00:00
|
|
|
{
|
2013-07-18 06:54:08 +00:00
|
|
|
nsCOMPtr<dom::Element> window = GetWindowDOMElement();
|
2018-03-16 09:26:31 +00:00
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
2005-02-02 09:39:30 +00:00
|
|
|
|
2006-07-25 00:20:33 +00:00
|
|
|
if (mChromeLoaded) {
|
|
|
|
// The two calls in this block don't need to happen early because they
|
|
|
|
// don't cause a global restyle on the document. Not only that, but the
|
|
|
|
// scrollbar stuff needs a content area to toggle the scrollbars on anyway.
|
|
|
|
// So just don't do these until mChromeLoaded is true.
|
2013-07-18 06:54:08 +00:00
|
|
|
|
2006-07-25 00:20:33 +00:00
|
|
|
// Scrollbars have their own special treatment.
|
|
|
|
SetContentScrollbarVisibility(mChromeFlags &
|
2005-02-02 09:39:30 +00:00
|
|
|
nsIWebBrowserChrome::CHROME_SCROLLBARS ?
|
2011-10-17 14:59:28 +00:00
|
|
|
true : false);
|
2006-07-25 00:20:33 +00:00
|
|
|
}
|
2005-02-02 09:39:30 +00:00
|
|
|
|
|
|
|
/* the other flags are handled together. we have style rules
|
|
|
|
in navigator.css that trigger visibility based on
|
|
|
|
the 'chromehidden' attribute of the <window> tag. */
|
|
|
|
nsAutoString newvalue;
|
|
|
|
|
|
|
|
if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_MENUBAR))
|
|
|
|
newvalue.AppendLiteral("menubar ");
|
|
|
|
|
|
|
|
if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_TOOLBAR))
|
|
|
|
newvalue.AppendLiteral("toolbar ");
|
|
|
|
|
|
|
|
if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_LOCATIONBAR))
|
|
|
|
newvalue.AppendLiteral("location ");
|
|
|
|
|
|
|
|
if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR))
|
|
|
|
newvalue.AppendLiteral("directories ");
|
|
|
|
|
|
|
|
if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_STATUSBAR))
|
|
|
|
newvalue.AppendLiteral("status ");
|
|
|
|
|
|
|
|
if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_EXTRA))
|
|
|
|
newvalue.AppendLiteral("extrachrome ");
|
|
|
|
|
2006-07-25 00:20:33 +00:00
|
|
|
// Note that if we're not actually changing the value this will be a no-op,
|
|
|
|
// so no need to compare to the old value.
|
2018-03-16 09:26:31 +00:00
|
|
|
ErrorResult rv;
|
2013-07-18 06:54:08 +00:00
|
|
|
window->SetAttribute(NS_LITERAL_STRING("chromehidden"), newvalue, rv);
|
2005-02-02 09:39:30 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-21 14:47:51 +00:00
|
|
|
NS_IMETHODIMP nsXULWindow::GetXULBrowserWindow(nsIXULBrowserWindow * *aXULBrowserWindow)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aXULBrowserWindow = mXULBrowserWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULWindow::SetXULBrowserWindow(nsIXULBrowserWindow * aXULBrowserWindow)
|
|
|
|
{
|
|
|
|
mXULBrowserWindow = aXULBrowserWindow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-14 20:31:41 +00:00
|
|
|
void nsXULWindow::SizeShellToWithLimit(int32_t aDesiredWidth,
|
|
|
|
int32_t aDesiredHeight,
|
|
|
|
int32_t shellItemWidth,
|
|
|
|
int32_t shellItemHeight)
|
2016-05-11 09:44:57 +00:00
|
|
|
{
|
2016-07-14 20:31:41 +00:00
|
|
|
int32_t widthDelta = aDesiredWidth - shellItemWidth;
|
|
|
|
int32_t heightDelta = aDesiredHeight - shellItemHeight;
|
2016-05-11 09:44:57 +00:00
|
|
|
|
|
|
|
if (widthDelta || heightDelta) {
|
2016-07-14 20:31:41 +00:00
|
|
|
int32_t winWidth = 0;
|
|
|
|
int32_t winHeight = 0;
|
2016-05-11 09:44:57 +00:00
|
|
|
|
2016-07-14 20:31:41 +00:00
|
|
|
GetSize(&winWidth, &winHeight);
|
2016-05-11 09:44:57 +00:00
|
|
|
// There's no point in trying to make the window smaller than the
|
2016-07-14 20:31:41 +00:00
|
|
|
// desired content area size --- that's not likely to work. This whole
|
2016-05-11 09:44:57 +00:00
|
|
|
// function assumes that the outer docshell is adding some constant
|
2016-07-14 20:31:41 +00:00
|
|
|
// "border" chrome to the content area.
|
|
|
|
winWidth = std::max(winWidth + widthDelta, aDesiredWidth);
|
|
|
|
winHeight = std::max(winHeight + heightDelta, aDesiredHeight);
|
|
|
|
SetSize(winWidth, winHeight, true);
|
2016-05-11 09:44:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 02:41:45 +00:00
|
|
|
nsresult
|
|
|
|
nsXULWindow::GetTabCount(uint32_t* aResult)
|
|
|
|
{
|
|
|
|
if (mXULBrowserWindow) {
|
|
|
|
return mXULBrowserWindow->GetTabCount(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-04-16 22:52:02 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULWindow::GetNextTabParentId(uint64_t* aNextTabParentId)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNextTabParentId);
|
|
|
|
*aNextTabParentId = mNextTabParentId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|