2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-05-19 01:44:52 +04:00
|
|
|
|
2000-04-02 02:07:41 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-05-19 01:44:52 +04:00
|
|
|
#include "nsString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2009-03-08 12:38:59 +03:00
|
|
|
#include "nsTArray.h"
|
2000-04-02 02:07:41 +04:00
|
|
|
#include "nsIBaseWindow.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIWidget.h"
|
2001-04-17 00:35:46 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2009-10-17 10:20:08 +04:00
|
|
|
#include "nsIObserverService.h"
|
2000-04-02 02:07:41 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2001-09-05 03:30:41 +04:00
|
|
|
#include "nsAppShellWindowEnumerator.h"
|
2000-02-05 08:38:13 +03:00
|
|
|
#include "nsWindowMediator.h"
|
2002-06-27 02:34:09 +04:00
|
|
|
#include "nsIWindowMediatorListener.h"
|
2013-05-07 20:34:20 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2000-02-05 08:38:13 +03:00
|
|
|
|
2000-02-29 03:20:55 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-02-29 03:20:55 +03:00
|
|
|
#include "nsIXULWindow.h"
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-12-04 02:03:45 +04:00
|
|
|
nsresult nsWindowMediator::GetDOMWindow(
|
2016-01-30 20:05:36 +03:00
|
|
|
nsIXULWindow* inWindow, nsCOMPtr<nsPIDOMWindowOuter>& outDOMWindow) {
|
2002-03-09 05:54:13 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
1999-05-19 01:44:52 +04:00
|
|
|
|
2014-01-10 06:03:47 +04:00
|
|
|
outDOMWindow = nullptr;
|
2002-03-09 05:54:13 +03:00
|
|
|
inWindow->GetDocShell(getter_AddRefs(docShell));
|
2014-01-10 06:03:47 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
outDOMWindow = docShell->GetWindow();
|
2009-01-05 08:22:36 +03:00
|
|
|
return outDOMWindow ? NS_OK : NS_ERROR_FAILURE;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowMediator::nsWindowMediator()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mEnumeratorList(),
|
|
|
|
mOldestWindow(nullptr),
|
|
|
|
mTopmostWindow(nullptr),
|
2014-10-17 02:45:17 +04:00
|
|
|
mTimeStamp(0),
|
|
|
|
mSortingZOrder(false),
|
|
|
|
mReady(false) {}
|
1999-05-19 01:44:52 +04:00
|
|
|
|
|
|
|
nsWindowMediator::~nsWindowMediator() {
|
2009-01-05 08:22:36 +03:00
|
|
|
while (mOldestWindow) UnregisterWindow(mOldestWindow);
|
|
|
|
}
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2009-01-05 08:22:36 +03:00
|
|
|
nsresult nsWindowMediator::Init() {
|
2009-10-17 10:20:08 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
do_GetService("@mozilla.org/observer-service;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = obsSvc->AddObserver(this, "xpcom-shutdown", true);
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mReady = true;
|
2009-01-05 08:22:36 +03:00
|
|
|
return NS_OK;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2001-09-25 02:31:49 +04:00
|
|
|
NS_IMETHODIMP nsWindowMediator::RegisterWindow(nsIXULWindow* inWindow) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_STATE(mReady);
|
|
|
|
|
2003-10-20 19:31:38 +04:00
|
|
|
if (GetInfoFor(inWindow)) {
|
|
|
|
NS_ERROR("multiple window registration");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
mTimeStamp++;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
// Create window info struct and add to list of windows
|
2009-01-05 21:58:59 +03:00
|
|
|
nsWindowInfo* windowInfo = new nsWindowInfo(inWindow, mTimeStamp);
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2017-03-06 04:50:52 +03:00
|
|
|
ListenerArray::ForwardIterator iter(mListeners);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
iter.GetNext()->OnOpenWindow(inWindow);
|
2017-02-24 14:01:42 +03:00
|
|
|
}
|
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
if (mOldestWindow)
|
2012-07-30 18:20:58 +04:00
|
|
|
windowInfo->InsertAfter(mOldestWindow->mOlder, nullptr);
|
2002-03-09 05:54:13 +03:00
|
|
|
else
|
|
|
|
mOldestWindow = windowInfo;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
return NS_OK;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::UnregisterWindow(nsIXULWindow* inWindow) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_STATE(mReady);
|
2003-10-07 05:20:13 +04:00
|
|
|
nsWindowInfo* info = GetInfoFor(inWindow);
|
|
|
|
if (info) return UnregisterWindow(info);
|
2000-04-02 02:07:41 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
nsresult nsWindowMediator::UnregisterWindow(nsWindowInfo* inInfo) {
|
1999-06-22 06:56:58 +04:00
|
|
|
// Inform the iterators
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t index = 0;
|
2009-03-08 12:38:59 +03:00
|
|
|
while (index < mEnumeratorList.Length()) {
|
|
|
|
mEnumeratorList[index]->WindowRemoved(inInfo);
|
|
|
|
index++;
|
|
|
|
}
|
2017-03-06 04:50:52 +03:00
|
|
|
|
|
|
|
nsIXULWindow* window = inInfo->mWindow.get();
|
|
|
|
ListenerArray::ForwardIterator iter(mListeners);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
iter.GetNext()->OnCloseWindow(window);
|
2017-02-24 14:01:42 +03:00
|
|
|
}
|
2002-06-27 02:34:09 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// Remove from the lists and free up
|
2000-04-02 02:07:41 +04:00
|
|
|
if (inInfo == mOldestWindow) mOldestWindow = inInfo->mYounger;
|
|
|
|
if (inInfo == mTopmostWindow) mTopmostWindow = inInfo->mLower;
|
2011-10-17 18:59:28 +04:00
|
|
|
inInfo->Unlink(true, true);
|
2000-04-02 02:07:41 +04:00
|
|
|
if (inInfo == mOldestWindow) mOldestWindow = nullptr;
|
|
|
|
if (inInfo == mTopmostWindow) mTopmostWindow = nullptr;
|
2017-07-06 15:00:35 +03:00
|
|
|
delete inInfo;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
nsWindowInfo* nsWindowMediator::GetInfoFor(nsIXULWindow* aWindow) {
|
|
|
|
nsWindowInfo *info, *listEnd;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!aWindow) return nullptr;
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
info = mOldestWindow;
|
2012-07-30 18:20:58 +04:00
|
|
|
listEnd = nullptr;
|
2003-10-07 05:20:13 +04:00
|
|
|
while (info != listEnd) {
|
|
|
|
if (info->mWindow.get() == aWindow) return info;
|
|
|
|
info = info->mYounger;
|
|
|
|
listEnd = mOldestWindow;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2003-10-07 05:20:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowInfo* nsWindowMediator::GetInfoFor(nsIWidget* aWindow) {
|
|
|
|
nsWindowInfo *info, *listEnd;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!aWindow) return nullptr;
|
1999-05-19 01:44:52 +04:00
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
info = mOldestWindow;
|
2012-07-30 18:20:58 +04:00
|
|
|
listEnd = nullptr;
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> scanWidget;
|
|
|
|
while (info != listEnd) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(info->mWindow));
|
|
|
|
if (base) base->GetMainWidget(getter_AddRefs(scanWidget));
|
|
|
|
if (aWindow == scanWidget.get()) return info;
|
|
|
|
info = info->mYounger;
|
|
|
|
listEnd = mOldestWindow;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2003-10-07 05:20:13 +04:00
|
|
|
}
|
2002-03-09 05:54:13 +03:00
|
|
|
|
2009-01-03 07:06:52 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsWindowMediator::GetEnumerator(const char16_t* inType,
|
|
|
|
nsISimpleEnumerator** outEnumerator) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(outEnumerator);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
2014-10-17 02:45:17 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAppShellWindowEnumerator> enumerator =
|
|
|
|
new nsASDOMWindowEarlyToLateEnumerator(inType, *this);
|
2015-03-12 16:43:50 +03:00
|
|
|
enumerator.forget(outEnumerator);
|
|
|
|
return NS_OK;
|
2000-01-25 05:54:45 +03:00
|
|
|
}
|
2002-03-09 05:54:13 +03:00
|
|
|
|
2009-01-03 07:06:52 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsWindowMediator::GetXULWindowEnumerator(const char16_t* inType,
|
|
|
|
nsISimpleEnumerator** outEnumerator) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(outEnumerator);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
2014-10-17 02:45:17 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAppShellWindowEnumerator> enumerator =
|
|
|
|
new nsASXULWindowEarlyToLateEnumerator(inType, *this);
|
2015-03-12 16:43:50 +03:00
|
|
|
enumerator.forget(outEnumerator);
|
|
|
|
return NS_OK;
|
2009-01-03 07:06:52 +03:00
|
|
|
}
|
2002-03-09 05:54:13 +03:00
|
|
|
|
2009-01-03 07:06:52 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-09 05:54:13 +03:00
|
|
|
nsWindowMediator::GetZOrderXULWindowEnumerator(const char16_t* aWindowType,
|
2014-01-04 19:02:17 +04:00
|
|
|
bool aFrontToBack,
|
2001-09-05 03:30:41 +04:00
|
|
|
nsISimpleEnumerator** _retval) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
2014-10-17 02:45:17 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAppShellWindowEnumerator> enumerator;
|
2001-09-05 03:30:41 +04:00
|
|
|
if (aFrontToBack)
|
|
|
|
enumerator = new nsASXULWindowFrontToBackEnumerator(aWindowType, *this);
|
|
|
|
else
|
|
|
|
enumerator = new nsASXULWindowBackToFrontEnumerator(aWindowType, *this);
|
|
|
|
|
2015-03-12 20:20:29 +03:00
|
|
|
enumerator.forget(_retval);
|
|
|
|
return NS_OK;
|
2001-09-05 03:30:41 +04:00
|
|
|
}
|
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
int32_t nsWindowMediator::AddEnumerator(
|
|
|
|
nsAppShellWindowEnumerator* inEnumerator) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return mEnumeratorList.AppendElement(inEnumerator) != nullptr;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2009-01-03 07:06:52 +03:00
|
|
|
int32_t nsWindowMediator::RemoveEnumerator(
|
|
|
|
nsAppShellWindowEnumerator* inEnumerator) {
|
2000-07-18 02:21:47 +04:00
|
|
|
return mEnumeratorList.RemoveElement(inEnumerator);
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2009-01-03 07:06:52 +03:00
|
|
|
// Returns the window of type inType ( if null return any window type ) which
|
|
|
|
// has the most recent time stamp
|
2002-03-09 05:54:13 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsWindowMediator::GetMostRecentWindow(const char16_t* inType,
|
|
|
|
mozIDOMWindowProxy** outWindow) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2001-04-17 00:35:46 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(outWindow);
|
2012-07-30 18:20:58 +04:00
|
|
|
*outWindow = nullptr;
|
2009-10-17 10:20:08 +04:00
|
|
|
if (!mReady) return NS_OK;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
|
|
|
// Find the most window with the highest time stamp that matches
|
|
|
|
// the requested type
|
2015-12-11 21:32:15 +03:00
|
|
|
nsWindowInfo* info = MostRecentWindowInfo(inType, false);
|
2001-04-17 00:35:46 +04:00
|
|
|
if (info && info->mWindow) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> DOMWindow;
|
2017-07-06 15:00:35 +03:00
|
|
|
if (NS_SUCCEEDED(GetDOMWindow(info->mWindow, DOMWindow))) {
|
2016-01-30 20:05:36 +03:00
|
|
|
DOMWindow.forget(outWindow);
|
2000-04-02 02:07:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2018-12-15 01:53:21 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::GetMostRecentBrowserWindow(mozIDOMWindowProxy** outWindow) {
|
|
|
|
nsresult rv = GetMostRecentWindow(u"navigator:browser", outWindow);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if (!*outWindow) {
|
|
|
|
rv = GetMostRecentWindow(u"navigator:geckoview", outWindow);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-12-11 21:32:15 +03:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsWindowMediator::GetMostRecentNonPBWindow(const char16_t* aType,
|
|
|
|
mozIDOMWindowProxy** aWindow) {
|
2015-12-11 21:32:15 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
*aWindow = nullptr;
|
|
|
|
|
|
|
|
nsWindowInfo* info = MostRecentWindowInfo(aType, true);
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow;
|
2015-12-11 21:32:15 +03:00
|
|
|
if (info && info->mWindow) {
|
|
|
|
GetDOMWindow(info->mWindow, domWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!domWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
domWindow.forget(aWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-12-11 21:32:15 +03:00
|
|
|
nsWindowInfo* nsWindowMediator::MostRecentWindowInfo(
|
|
|
|
const char16_t* inType, bool aSkipPrivateBrowsingOrClosed) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t lastTimeStamp = -1;
|
2001-04-17 00:35:46 +04:00
|
|
|
nsAutoString typeString(inType);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool allWindows = !inType || typeString.IsEmpty();
|
2001-04-17 00:35:46 +04:00
|
|
|
|
2015-12-11 21:32:15 +03:00
|
|
|
// Find the most recent window with the highest time stamp that matches
|
|
|
|
// the requested type and has the correct browsing mode.
|
|
|
|
nsWindowInfo* searchInfo = mOldestWindow;
|
|
|
|
nsWindowInfo* listEnd = nullptr;
|
|
|
|
nsWindowInfo* foundInfo = nullptr;
|
|
|
|
for (; searchInfo != listEnd; searchInfo = searchInfo->mYounger) {
|
|
|
|
listEnd = mOldestWindow;
|
2015-12-04 20:14:44 +03:00
|
|
|
|
2015-12-11 21:32:15 +03:00
|
|
|
if (!allWindows && !searchInfo->TypeEquals(typeString)) {
|
|
|
|
continue;
|
2015-12-05 23:13:41 +03:00
|
|
|
}
|
2015-12-11 21:32:15 +03:00
|
|
|
if (searchInfo->mTimeStamp < lastTimeStamp) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!searchInfo->mWindow) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-11 21:32:15 +03:00
|
|
|
if (aSkipPrivateBrowsingOrClosed) {
|
2015-12-11 21:32:15 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
searchInfo->mWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
|
|
|
|
if (!loadContext || loadContext->UsePrivateBrowsing()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-11 21:32:15 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> piwindow = docShell->GetWindow();
|
2015-12-11 21:32:15 +03:00
|
|
|
if (!piwindow || piwindow->Closed()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-11 21:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
foundInfo = searchInfo;
|
|
|
|
lastTimeStamp = searchInfo->mTimeStamp;
|
2001-04-17 00:35:46 +04:00
|
|
|
}
|
2015-12-11 21:32:15 +03:00
|
|
|
|
2001-04-17 00:35:46 +04:00
|
|
|
return foundInfo;
|
|
|
|
}
|
|
|
|
|
2013-05-07 20:34:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::GetOuterWindowWithId(uint64_t aWindowID,
|
2016-01-30 20:05:36 +03:00
|
|
|
mozIDOMWindowProxy** aWindow) {
|
2017-11-06 21:09:35 +03:00
|
|
|
RefPtr<nsGlobalWindowOuter> window =
|
|
|
|
nsGlobalWindowOuter::GetOuterWindowWithId(aWindowID);
|
2019-04-11 15:12:04 +03:00
|
|
|
window.forget(aWindow);
|
2013-05-07 20:34:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-14 19:34:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::GetCurrentInnerWindowWithId(uint64_t aWindowID,
|
2016-01-30 20:05:36 +03:00
|
|
|
mozIDOMWindow** aWindow) {
|
2017-11-06 21:09:35 +03:00
|
|
|
RefPtr<nsGlobalWindowInner> window =
|
|
|
|
nsGlobalWindowInner::GetInnerWindowWithId(aWindowID);
|
2013-05-14 19:34:12 +04:00
|
|
|
|
|
|
|
// not found
|
|
|
|
if (!window) return NS_OK;
|
|
|
|
|
2019-04-11 17:12:43 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> outer = window->GetOuterWindow();
|
2013-05-14 19:34:12 +04:00
|
|
|
NS_ENSURE_TRUE(outer, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// outer is already using another inner, so it's same as not found
|
2019-04-11 17:12:43 +03:00
|
|
|
if (outer->GetCurrentInnerWindow() != window) return NS_OK;
|
2013-05-14 19:34:12 +04:00
|
|
|
|
2019-04-11 17:12:43 +03:00
|
|
|
window.forget(aWindow);
|
2013-05-14 19:34:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
NS_IMETHODIMP
|
2009-01-03 07:06:52 +03:00
|
|
|
nsWindowMediator::UpdateWindowTimeStamp(nsIXULWindow* inWindow) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_STATE(mReady);
|
2003-10-07 05:20:13 +04:00
|
|
|
nsWindowInfo* info = GetInfoFor(inWindow);
|
|
|
|
if (info) {
|
|
|
|
// increment the window's time stamp
|
|
|
|
info->mTimeStamp = ++mTimeStamp;
|
|
|
|
return NS_OK;
|
2000-04-02 02:07:41 +04:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2000-04-02 02:07:41 +04:00
|
|
|
/* This method's plan is to intervene only when absolutely necessary.
|
|
|
|
We will get requests to place our windows behind unknown windows.
|
|
|
|
For the most part, we need to leave those alone (turning them into
|
|
|
|
explicit requests to be on top breaks Windows.) So generally we
|
|
|
|
calculate a change as seldom as possible.
|
|
|
|
*/
|
2002-03-09 05:54:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::CalculateZPosition(nsIXULWindow* inWindow,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t inPosition, nsIWidget* inBelow,
|
|
|
|
uint32_t* outPosition,
|
2000-04-02 02:07:41 +04:00
|
|
|
nsIWidget** outBelow, bool* outAltered) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(outBelow);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*outBelow = nullptr;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
|
|
|
if (!inWindow || !outPosition || !outAltered) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (inPosition != nsIWindowMediator::zLevelTop &&
|
|
|
|
inPosition != nsIWindowMediator::zLevelBottom &&
|
|
|
|
inPosition != nsIWindowMediator::zLevelBelow)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2002-05-14 01:43:15 +04:00
|
|
|
nsWindowInfo* info = mTopmostWindow;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIXULWindow* belowWindow = nullptr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found = false;
|
2000-04-02 02:07:41 +04:00
|
|
|
nsresult result = NS_OK;
|
2009-01-03 07:06:52 +03:00
|
|
|
|
2000-04-02 02:07:41 +04:00
|
|
|
*outPosition = inPosition;
|
2011-10-17 18:59:28 +04:00
|
|
|
*outAltered = false;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
if (mSortingZOrder) { // don't fight SortZOrder()
|
|
|
|
*outBelow = inBelow;
|
|
|
|
NS_IF_ADDREF(*outBelow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t inZ;
|
2003-10-07 05:20:13 +04:00
|
|
|
GetZLevel(inWindow, &inZ);
|
|
|
|
|
2000-04-02 02:07:41 +04:00
|
|
|
if (inPosition == nsIWindowMediator::zLevelBelow) {
|
2003-10-07 05:20:13 +04:00
|
|
|
// locate inBelow. use topmost if it can't be found or isn't in the
|
|
|
|
// z-order list
|
|
|
|
info = GetInfoFor(inBelow);
|
2011-12-18 10:00:47 +04:00
|
|
|
if (!info || (info->mYounger != info && info->mLower == info))
|
2003-10-07 05:20:13 +04:00
|
|
|
info = mTopmostWindow;
|
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
found = true;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
/* Treat unknown windows as a request to be on top.
|
|
|
|
Not as it should be, but that's what Windows gives us.
|
|
|
|
Note we change inPosition, but not *outPosition. This forces
|
|
|
|
us to go through the "on top" calculation just below, without
|
|
|
|
necessarily changing the output parameters. */
|
|
|
|
inPosition = nsIWindowMediator::zLevelTop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inPosition == nsIWindowMediator::zLevelTop) {
|
2003-10-07 05:20:13 +04:00
|
|
|
if (mTopmostWindow && mTopmostWindow->mZLevel > inZ) {
|
2000-04-02 02:07:41 +04:00
|
|
|
// asked for topmost, can't have it. locate highest allowed position.
|
|
|
|
do {
|
2003-10-07 05:20:13 +04:00
|
|
|
if (info->mZLevel <= inZ) break;
|
2000-04-02 02:07:41 +04:00
|
|
|
info = info->mLower;
|
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
|
|
|
*outPosition = nsIWindowMediator::zLevelBelow;
|
|
|
|
belowWindow = info->mHigher->mWindow;
|
2011-10-17 18:59:28 +04:00
|
|
|
*outAltered = true;
|
2000-04-02 02:07:41 +04:00
|
|
|
}
|
|
|
|
} else if (inPosition == nsIWindowMediator::zLevelBottom) {
|
2003-10-07 05:20:13 +04:00
|
|
|
if (mTopmostWindow && mTopmostWindow->mHigher->mZLevel < inZ) {
|
2000-04-02 02:07:41 +04:00
|
|
|
// asked for bottommost, can't have it. locate lowest allowed position.
|
|
|
|
do {
|
|
|
|
info = info->mHigher;
|
2003-10-07 05:20:13 +04:00
|
|
|
if (info->mZLevel >= inZ) break;
|
2000-04-02 02:07:41 +04:00
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
|
|
|
*outPosition = nsIWindowMediator::zLevelBelow;
|
|
|
|
belowWindow = info->mWindow;
|
2011-10-17 18:59:28 +04:00
|
|
|
*outAltered = true;
|
2000-04-02 02:07:41 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned long relativeZ;
|
|
|
|
|
|
|
|
// check that we're in the right z-plane
|
|
|
|
if (found) {
|
|
|
|
belowWindow = info->mWindow;
|
2003-10-07 05:20:13 +04:00
|
|
|
relativeZ = info->mZLevel;
|
2000-04-02 02:07:41 +04:00
|
|
|
if (relativeZ > inZ) {
|
|
|
|
// might be OK. is lower window, if any, lower?
|
2003-10-07 05:20:13 +04:00
|
|
|
if (info->mLower != info && info->mLower->mZLevel > inZ) {
|
2000-04-02 02:07:41 +04:00
|
|
|
do {
|
2003-10-07 05:20:13 +04:00
|
|
|
if (info->mZLevel <= inZ) break;
|
2000-04-02 02:07:41 +04:00
|
|
|
info = info->mLower;
|
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
|
|
|
belowWindow = info->mHigher->mWindow;
|
2011-10-17 18:59:28 +04:00
|
|
|
*outAltered = true;
|
2000-04-02 02:07:41 +04:00
|
|
|
}
|
|
|
|
} else if (relativeZ < inZ) {
|
|
|
|
// nope. look for a higher window to be behind.
|
|
|
|
do {
|
|
|
|
info = info->mHigher;
|
2003-10-07 05:20:13 +04:00
|
|
|
if (info->mZLevel >= inZ) break;
|
2000-04-02 02:07:41 +04:00
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
if (info->mZLevel >= inZ)
|
2000-04-02 02:07:41 +04:00
|
|
|
belowWindow = info->mWindow;
|
|
|
|
else
|
|
|
|
*outPosition = nsIWindowMediator::zLevelTop;
|
2011-10-17 18:59:28 +04:00
|
|
|
*outAltered = true;
|
2000-04-02 02:07:41 +04:00
|
|
|
} // else they're equal, so it's OK
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result) && belowWindow) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(belowWindow));
|
|
|
|
if (base)
|
|
|
|
base->GetMainWidget(outBelow);
|
|
|
|
else
|
|
|
|
result = NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::SetZPosition(nsIXULWindow* inWindow, uint32_t inPosition,
|
2009-01-05 21:58:59 +03:00
|
|
|
nsIXULWindow* inBelow) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2000-04-02 02:07:41 +04:00
|
|
|
nsWindowInfo *inInfo, *belowInfo;
|
|
|
|
|
2011-12-18 10:00:47 +04:00
|
|
|
if ((inPosition != nsIWindowMediator::zLevelTop &&
|
|
|
|
inPosition != nsIWindowMediator::zLevelBottom &&
|
|
|
|
inPosition != nsIWindowMediator::zLevelBelow) ||
|
2009-01-03 07:06:52 +03:00
|
|
|
!inWindow) {
|
2000-04-02 02:07:41 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2009-01-03 07:06:52 +03:00
|
|
|
}
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
if (mSortingZOrder) // don't fight SortZOrder()
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_STATE(mReady);
|
2000-04-02 02:07:41 +04:00
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
/* Locate inWindow and unlink it from the z-order list.
|
|
|
|
It's important we look for it in the age list, not the z-order list.
|
|
|
|
This is because the former is guaranteed complete, while
|
2000-04-02 02:07:41 +04:00
|
|
|
now may be this window's first exposure to the latter. */
|
2003-10-07 05:20:13 +04:00
|
|
|
inInfo = GetInfoFor(inWindow);
|
2000-04-02 02:07:41 +04:00
|
|
|
if (!inInfo) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
// locate inBelow, place inWindow behind it
|
2000-04-02 02:07:41 +04:00
|
|
|
if (inPosition == nsIWindowMediator::zLevelBelow) {
|
2003-10-07 05:20:13 +04:00
|
|
|
belowInfo = GetInfoFor(inBelow);
|
|
|
|
// it had better also be in the z-order list
|
2009-01-03 07:06:52 +03:00
|
|
|
if (belowInfo && belowInfo->mYounger != belowInfo &&
|
|
|
|
belowInfo->mLower == belowInfo) {
|
2012-07-30 18:20:58 +04:00
|
|
|
belowInfo = nullptr;
|
2009-01-03 07:06:52 +03:00
|
|
|
}
|
|
|
|
if (!belowInfo) {
|
2000-04-02 02:07:41 +04:00
|
|
|
if (inBelow)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
else
|
|
|
|
inPosition = nsIWindowMediator::zLevelTop;
|
2009-01-03 07:06:52 +03:00
|
|
|
}
|
2002-06-01 04:49:46 +04:00
|
|
|
}
|
|
|
|
if (inPosition == nsIWindowMediator::zLevelTop ||
|
|
|
|
inPosition == nsIWindowMediator::zLevelBottom)
|
2012-07-30 18:20:58 +04:00
|
|
|
belowInfo = mTopmostWindow ? mTopmostWindow->mHigher : nullptr;
|
2000-04-02 02:07:41 +04:00
|
|
|
|
|
|
|
if (inInfo != belowInfo) {
|
2011-10-17 18:59:28 +04:00
|
|
|
inInfo->Unlink(false, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
inInfo->InsertAfter(nullptr, belowInfo);
|
2000-04-02 02:07:41 +04:00
|
|
|
}
|
|
|
|
if (inPosition == nsIWindowMediator::zLevelTop) mTopmostWindow = inInfo;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsWindowMediator::GetZLevel(nsIXULWindow* aWindow, uint32_t* _retval) {
|
2003-10-07 05:20:13 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = nsIXULWindow::normalZ;
|
2017-05-24 01:14:07 +03:00
|
|
|
// This can fail during window destruction.
|
2003-10-07 05:20:13 +04:00
|
|
|
nsWindowInfo* info = GetInfoFor(aWindow);
|
2009-01-07 01:25:49 +03:00
|
|
|
if (info) {
|
2003-10-07 05:20:13 +04:00
|
|
|
*_retval = info->mZLevel;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsWindowMediator::SetZLevel(nsIXULWindow* aWindow, uint32_t aZLevel) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_ENSURE_STATE(mReady);
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
nsWindowInfo* info = GetInfoFor(aWindow);
|
|
|
|
NS_ASSERTION(info, "setting z level of unregistered window");
|
|
|
|
if (!info) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (info->mZLevel != aZLevel) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool lowered = info->mZLevel > aZLevel;
|
2003-10-07 05:20:13 +04:00
|
|
|
info->mZLevel = aZLevel;
|
|
|
|
if (lowered)
|
|
|
|
SortZOrderFrontToBack();
|
|
|
|
else
|
|
|
|
SortZOrderBackToFront();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix potentially out-of-order windows by performing an insertion sort
|
|
|
|
on the z-order list. The method will work no matter how broken the
|
|
|
|
list, but its assumed usage is immediately after one window's z level
|
|
|
|
has been changed, so one window is potentially out of place. Such a sort
|
|
|
|
is most efficiently done in a particular direction. Use this one
|
|
|
|
if a window's z level has just been reduced, so the sort is most efficiently
|
2014-10-17 02:45:17 +04:00
|
|
|
done front to back.
|
2003-10-07 05:20:13 +04:00
|
|
|
Note it's hardly worth going to all the trouble to write two versions
|
|
|
|
of this method except that if we choose the inefficient sorting direction,
|
|
|
|
on slow systems windows could visibly bubble around the window that
|
|
|
|
was moved.
|
|
|
|
*/
|
2009-01-05 21:58:59 +03:00
|
|
|
void nsWindowMediator::SortZOrderFrontToBack() {
|
2003-10-07 05:20:13 +04:00
|
|
|
nsWindowInfo *scan, // scans list looking for problems
|
|
|
|
*search, // searches for correct placement for scan window
|
|
|
|
*prev, // previous search element
|
|
|
|
*lowest; // bottom-most window in list
|
2011-09-29 10:19:26 +04:00
|
|
|
bool finished;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-10-07 05:20:13 +04:00
|
|
|
if (!mTopmostWindow) // early during program execution there's no z list yet
|
|
|
|
return; // there's also only one window, so this is not dangerous
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSortingZOrder = true;
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
/* Step through the list from top to bottom. If we find a window which
|
|
|
|
should be moved down in the list, move it to its highest legal position. */
|
|
|
|
do {
|
2011-10-17 18:59:28 +04:00
|
|
|
finished = true;
|
2003-10-07 05:20:13 +04:00
|
|
|
lowest = mTopmostWindow->mHigher;
|
|
|
|
scan = mTopmostWindow;
|
|
|
|
while (scan != lowest) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t scanZ = scan->mZLevel;
|
2003-10-07 05:20:13 +04:00
|
|
|
if (scanZ < scan->mLower->mZLevel) { // out of order
|
|
|
|
search = scan->mLower;
|
|
|
|
do {
|
|
|
|
prev = search;
|
|
|
|
search = search->mLower;
|
|
|
|
} while (prev != lowest && scanZ < search->mZLevel);
|
|
|
|
|
|
|
|
// reposition |scan| within the list
|
|
|
|
if (scan == mTopmostWindow) mTopmostWindow = scan->mLower;
|
2011-10-17 18:59:28 +04:00
|
|
|
scan->Unlink(false, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
scan->InsertAfter(nullptr, prev);
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
// fix actual window order
|
|
|
|
nsCOMPtr<nsIBaseWindow> base;
|
|
|
|
nsCOMPtr<nsIWidget> scanWidget;
|
|
|
|
nsCOMPtr<nsIWidget> prevWidget;
|
|
|
|
base = do_QueryInterface(scan->mWindow);
|
|
|
|
if (base) base->GetMainWidget(getter_AddRefs(scanWidget));
|
|
|
|
base = do_QueryInterface(prev->mWindow);
|
|
|
|
if (base) base->GetMainWidget(getter_AddRefs(prevWidget));
|
|
|
|
if (scanWidget)
|
2011-10-17 18:59:28 +04:00
|
|
|
scanWidget->PlaceBehind(eZPlacementBelow, prevWidget, false);
|
2003-10-07 05:20:13 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
finished = false;
|
2003-10-07 05:20:13 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
scan = scan->mLower;
|
|
|
|
}
|
|
|
|
} while (!finished);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSortingZOrder = false;
|
2003-10-07 05:20:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// see comment for SortZOrderFrontToBack
|
2009-01-05 21:58:59 +03:00
|
|
|
void nsWindowMediator::SortZOrderBackToFront() {
|
2003-10-07 05:20:13 +04:00
|
|
|
nsWindowInfo *scan, // scans list looking for problems
|
|
|
|
*search, // searches for correct placement for scan window
|
|
|
|
*lowest; // bottom-most window in list
|
2011-09-29 10:19:26 +04:00
|
|
|
bool finished;
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
if (!mTopmostWindow) // early during program execution there's no z list yet
|
|
|
|
return; // there's also only one window, so this is not dangerous
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSortingZOrder = true;
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
/* Step through the list from bottom to top. If we find a window which
|
|
|
|
should be moved up in the list, move it to its lowest legal position. */
|
|
|
|
do {
|
2011-10-17 18:59:28 +04:00
|
|
|
finished = true;
|
2003-10-07 05:20:13 +04:00
|
|
|
lowest = mTopmostWindow->mHigher;
|
|
|
|
scan = lowest;
|
|
|
|
while (scan != mTopmostWindow) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t scanZ = scan->mZLevel;
|
2003-10-07 05:20:13 +04:00
|
|
|
if (scanZ > scan->mHigher->mZLevel) { // out of order
|
|
|
|
search = scan;
|
2009-01-03 07:06:52 +03:00
|
|
|
do {
|
2003-10-07 05:20:13 +04:00
|
|
|
search = search->mHigher;
|
2009-01-03 07:06:52 +03:00
|
|
|
} while (search != lowest && scanZ > search->mZLevel);
|
2003-10-07 05:20:13 +04:00
|
|
|
|
|
|
|
// reposition |scan| within the list
|
|
|
|
if (scan != search && scan != search->mLower) {
|
2011-10-17 18:59:28 +04:00
|
|
|
scan->Unlink(false, true);
|
2012-07-30 18:20:58 +04:00
|
|
|
scan->InsertAfter(nullptr, search);
|
2003-10-07 05:20:13 +04:00
|
|
|
}
|
|
|
|
if (search == lowest) mTopmostWindow = scan;
|
|
|
|
|
|
|
|
// fix actual window order
|
|
|
|
nsCOMPtr<nsIBaseWindow> base;
|
|
|
|
nsCOMPtr<nsIWidget> scanWidget;
|
|
|
|
nsCOMPtr<nsIWidget> searchWidget;
|
|
|
|
base = do_QueryInterface(scan->mWindow);
|
|
|
|
if (base) base->GetMainWidget(getter_AddRefs(scanWidget));
|
|
|
|
if (mTopmostWindow != scan) {
|
|
|
|
base = do_QueryInterface(search->mWindow);
|
|
|
|
if (base) base->GetMainWidget(getter_AddRefs(searchWidget));
|
|
|
|
}
|
|
|
|
if (scanWidget)
|
2011-10-17 18:59:28 +04:00
|
|
|
scanWidget->PlaceBehind(eZPlacementBelow, searchWidget, false);
|
|
|
|
finished = false;
|
2003-10-07 05:20:13 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
scan = scan->mHigher;
|
|
|
|
}
|
|
|
|
} while (!finished);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSortingZOrder = false;
|
2003-10-07 05:20:13 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsWindowMediator, nsIWindowMediator, nsIObserver,
|
2009-10-17 10:20:08 +04:00
|
|
|
nsISupportsWeakReference)
|
2002-03-14 02:33:35 +03:00
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-06-27 02:34:09 +04:00
|
|
|
nsWindowMediator::AddListener(nsIWindowMediatorListener* aListener) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-03-06 04:50:52 +03:00
|
|
|
mListeners.AppendElement(aListener);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-06-27 02:34:09 +04:00
|
|
|
nsWindowMediator::RemoveListener(nsIWindowMediatorListener* aListener) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
2002-03-09 05:54:13 +03:00
|
|
|
|
2017-03-06 04:50:52 +03:00
|
|
|
mListeners.RemoveElement(aListener);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2002-03-09 05:54:13 +03:00
|
|
|
return NS_OK;
|
1999-05-19 01:44:52 +04:00
|
|
|
}
|
|
|
|
|
2009-10-17 10:20:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData) {
|
2009-10-17 10:20:08 +04:00
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown") && mReady) {
|
2014-10-17 02:45:17 +04:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
while (mOldestWindow) UnregisterWindow(mOldestWindow);
|
2011-10-17 18:59:28 +04:00
|
|
|
mReady = false;
|
2009-10-17 10:20:08 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|