2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2009-03-08 01:38:59 -08:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2009-10-16 23:20:08 -07:00
|
|
|
#include "nsIObserverService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsAppShellWindowEnumerator.h"
|
|
|
|
#include "nsWindowMediator.h"
|
|
|
|
#include "nsIWindowMediatorListener.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#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-03-31 21:29:02 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
static nsresult GetDOMWindow(nsIXULWindow* inWindow,
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr< nsIDOMWindow>& outDOMWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool notifyOpenWindow(nsISupports *aElement, void* aData);
|
|
|
|
static bool notifyCloseWindow(nsISupports *aElement, void* aData);
|
|
|
|
static bool notifyWindowTitleChange(nsISupports *aElement, void* aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// for notifyWindowTitleChange
|
2009-01-04 21:22:36 -08:00
|
|
|
struct WindowTitleData {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIXULWindow* mWindow;
|
|
|
|
const PRUnichar *mTitle;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
2011-07-15 03:31:34 -07:00
|
|
|
GetDOMWindow(nsIXULWindow* inWindow, nsCOMPtr<nsIDOMWindow>& outDOMWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
|
|
|
|
inWindow->GetDocShell(getter_AddRefs(docShell));
|
2009-01-04 21:22:36 -08:00
|
|
|
outDOMWindow = do_GetInterface(docShell);
|
|
|
|
return outDOMWindow ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowMediator::nsWindowMediator() :
|
2009-01-02 20:06:52 -08:00
|
|
|
mEnumeratorList(), mOldestWindow(nsnull), mTopmostWindow(nsnull),
|
2009-10-16 23:20:08 -07:00
|
|
|
mTimeStamp(0), mSortingZOrder(PR_FALSE), mReady(PR_FALSE),
|
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-03-31 21:29:02 -07:00
|
|
|
mListLock("nsWindowMediator.mListLock")
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowMediator::~nsWindowMediator()
|
|
|
|
{
|
2009-01-04 21:22:36 -08:00
|
|
|
while (mOldestWindow)
|
|
|
|
UnregisterWindow(mOldestWindow);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-04 21:22:36 -08:00
|
|
|
nsresult nsWindowMediator::Init()
|
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
do_GetService("@mozilla.org/observer-service;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = obsSvc->AddObserver(this, "xpcom-shutdown", PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mReady = PR_TRUE;
|
2009-01-04 21:22:36 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsWindowMediator::RegisterWindow(nsIXULWindow* inWindow)
|
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_STATE(mReady);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (GetInfoFor(inWindow)) {
|
|
|
|
NS_ERROR("multiple window registration");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimeStamp++;
|
|
|
|
|
|
|
|
// Create window info struct and add to list of windows
|
2009-01-05 10:58:59 -08:00
|
|
|
nsWindowInfo* windowInfo = new nsWindowInfo(inWindow, mTimeStamp);
|
2009-01-02 20:06:52 -08:00
|
|
|
if (!windowInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (mListeners) {
|
2009-01-04 21:22:36 -08:00
|
|
|
WindowTitleData winData = { inWindow, nsnull };
|
2007-03-22 10:30:00 -07:00
|
|
|
mListeners->EnumerateForwards(notifyOpenWindow, (void*)&winData);
|
|
|
|
}
|
|
|
|
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mOldestWindow)
|
2009-01-02 20:06:52 -08:00
|
|
|
windowInfo->InsertAfter(mOldestWindow->mOlder, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
mOldestWindow = windowInfo;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::UnregisterWindow(nsIXULWindow* inWindow)
|
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowInfo *info = GetInfoFor(inWindow);
|
|
|
|
if (info)
|
|
|
|
return UnregisterWindow(info);
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowMediator::UnregisterWindow(nsWindowInfo *inInfo)
|
|
|
|
{
|
|
|
|
// Inform the iterators
|
2009-03-08 01:38:59 -08:00
|
|
|
PRUint32 index = 0;
|
|
|
|
while (index < mEnumeratorList.Length()) {
|
|
|
|
mEnumeratorList[index]->WindowRemoved(inInfo);
|
|
|
|
index++;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mListeners) {
|
2009-01-05 10:58:59 -08:00
|
|
|
WindowTitleData winData = { inInfo->mWindow.get(), nsnull };
|
2007-03-22 10:30:00 -07:00
|
|
|
mListeners->EnumerateForwards(notifyCloseWindow, (void*)&winData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from the lists and free up
|
|
|
|
if (inInfo == mOldestWindow)
|
|
|
|
mOldestWindow = inInfo->mYounger;
|
|
|
|
if (inInfo == mTopmostWindow)
|
|
|
|
mTopmostWindow = inInfo->mLower;
|
|
|
|
inInfo->Unlink(PR_TRUE, PR_TRUE);
|
|
|
|
if (inInfo == mOldestWindow)
|
2009-01-02 20:06:52 -08:00
|
|
|
mOldestWindow = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (inInfo == mTopmostWindow)
|
2009-01-02 20:06:52 -08:00
|
|
|
mTopmostWindow = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
delete inInfo;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
nsWindowInfo*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowMediator::GetInfoFor(nsIXULWindow *aWindow)
|
|
|
|
{
|
|
|
|
nsWindowInfo *info,
|
|
|
|
*listEnd;
|
|
|
|
|
|
|
|
if (!aWindow)
|
2009-01-02 20:06:52 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
info = mOldestWindow;
|
2009-01-02 20:06:52 -08:00
|
|
|
listEnd = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (info != listEnd) {
|
|
|
|
if (info->mWindow.get() == aWindow)
|
|
|
|
return info;
|
|
|
|
info = info->mYounger;
|
|
|
|
listEnd = mOldestWindow;
|
|
|
|
}
|
2009-01-02 20:06:52 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
nsWindowInfo*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowMediator::GetInfoFor(nsIWidget *aWindow)
|
|
|
|
{
|
|
|
|
nsWindowInfo *info,
|
|
|
|
*listEnd;
|
|
|
|
|
|
|
|
if (!aWindow)
|
2009-01-02 20:06:52 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
info = mOldestWindow;
|
2009-01-02 20:06:52 -08:00
|
|
|
listEnd = nsnull;
|
2007-03-22 10:30:00 -07: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;
|
|
|
|
}
|
2009-01-02 20:06:52 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::GetEnumerator(const PRUnichar* inType, nsISimpleEnumerator** outEnumerator)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(outEnumerator);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAppShellWindowEnumerator *enumerator = new nsASDOMWindowEarlyToLateEnumerator(inType, *this);
|
|
|
|
if (enumerator)
|
|
|
|
return enumerator->QueryInterface(NS_GET_IID(nsISimpleEnumerator) , (void**)outEnumerator);
|
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
NS_IMETHODIMP
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowMediator::GetXULWindowEnumerator(const PRUnichar* inType, nsISimpleEnumerator** outEnumerator)
|
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(outEnumerator);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAppShellWindowEnumerator *enumerator = new nsASXULWindowEarlyToLateEnumerator(inType, *this);
|
|
|
|
if (enumerator)
|
2009-01-02 20:06:52 -08:00
|
|
|
return enumerator->QueryInterface(NS_GET_IID(nsISimpleEnumerator) , (void**)outEnumerator);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-01-02 20:06:52 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
NS_IMETHODIMP
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowMediator::GetZOrderDOMWindowEnumerator(
|
2011-09-28 23:19:26 -07:00
|
|
|
const PRUnichar *aWindowType, bool aFrontToBack,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISimpleEnumerator **_retval)
|
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAppShellWindowEnumerator *enumerator;
|
|
|
|
if (aFrontToBack)
|
|
|
|
enumerator = new nsASDOMWindowFrontToBackEnumerator(aWindowType, *this);
|
|
|
|
else
|
|
|
|
enumerator = new nsASDOMWindowBackToFrontEnumerator(aWindowType, *this);
|
|
|
|
if (enumerator)
|
2009-01-04 21:22:36 -08:00
|
|
|
return CallQueryInterface(enumerator, _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
NS_IMETHODIMP
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowMediator::GetZOrderXULWindowEnumerator(
|
2011-09-28 23:19:26 -07:00
|
|
|
const PRUnichar *aWindowType, bool aFrontToBack,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISimpleEnumerator **_retval)
|
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAppShellWindowEnumerator *enumerator;
|
|
|
|
if (aFrontToBack)
|
|
|
|
enumerator = new nsASXULWindowFrontToBackEnumerator(aWindowType, *this);
|
|
|
|
else
|
|
|
|
enumerator = new nsASXULWindowBackToFrontEnumerator(aWindowType, *this);
|
|
|
|
if (enumerator)
|
2009-01-04 21:22:36 -08:00
|
|
|
return CallQueryInterface(enumerator, _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsWindowMediator::AddEnumerator(nsAppShellWindowEnumerator * inEnumerator)
|
|
|
|
{
|
2009-03-08 01:38:59 -08:00
|
|
|
return mEnumeratorList.AppendElement(inEnumerator) != nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2009-01-02 20:06:52 -08:00
|
|
|
nsWindowMediator::RemoveEnumerator(nsAppShellWindowEnumerator * inEnumerator)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mEnumeratorList.RemoveElement(inEnumerator);
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
// Returns the window of type inType ( if null return any window type ) which has the most recent
|
|
|
|
// time stamp
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-07-15 03:31:34 -07:00
|
|
|
nsWindowMediator::GetMostRecentWindow(const PRUnichar* inType, nsIDOMWindow** outWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outWindow);
|
2009-01-02 20:06:52 -08:00
|
|
|
*outWindow = nsnull;
|
2009-10-16 23:20:08 -07:00
|
|
|
if (!mReady)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Find the most window with the highest time stamp that matches
|
|
|
|
// the requested type
|
|
|
|
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowInfo *info = MostRecentWindowInfo(inType);
|
|
|
|
|
|
|
|
if (info && info->mWindow) {
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> DOMWindow;
|
2009-01-06 14:25:49 -08:00
|
|
|
if (NS_SUCCEEDED(GetDOMWindow(info->mWindow, DOMWindow))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*outWindow = DOMWindow;
|
|
|
|
NS_ADDREF(*outWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
nsWindowInfo*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowMediator::MostRecentWindowInfo(const PRUnichar* inType)
|
|
|
|
{
|
|
|
|
PRInt32 lastTimeStamp = -1;
|
|
|
|
nsAutoString typeString(inType);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allWindows = !inType || typeString.IsEmpty();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Find the most window with the highest time stamp that matches
|
|
|
|
// the requested type
|
|
|
|
nsWindowInfo *searchInfo,
|
|
|
|
*listEnd,
|
2009-01-02 20:06:52 -08:00
|
|
|
*foundInfo = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
searchInfo = mOldestWindow;
|
2009-01-02 20:06:52 -08:00
|
|
|
listEnd = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (searchInfo != listEnd) {
|
|
|
|
if ((allWindows || searchInfo->TypeEquals(typeString)) &&
|
|
|
|
searchInfo->mTimeStamp >= lastTimeStamp) {
|
|
|
|
|
|
|
|
foundInfo = searchInfo;
|
|
|
|
lastTimeStamp = searchInfo->mTimeStamp;
|
|
|
|
}
|
|
|
|
searchInfo = searchInfo->mYounger;
|
|
|
|
listEnd = mOldestWindow;
|
|
|
|
}
|
|
|
|
return foundInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-02 20:06:52 -08:00
|
|
|
nsWindowMediator::UpdateWindowTimeStamp(nsIXULWindow* inWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowInfo *info = GetInfoFor(inWindow);
|
|
|
|
if (info) {
|
|
|
|
// increment the window's time stamp
|
|
|
|
info->mTimeStamp = ++mTimeStamp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-02 20:06:52 -08:00
|
|
|
nsWindowMediator::UpdateWindowTitle(nsIXULWindow* inWindow,
|
|
|
|
const PRUnichar* inTitle)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mListeners && GetInfoFor(inWindow)) {
|
2009-01-04 21:22:36 -08:00
|
|
|
WindowTitleData winData = { inWindow, inTitle };
|
2009-01-06 14:25:49 -08:00
|
|
|
mListeners->EnumerateForwards(notifyWindowTitleChange, (void*)&winData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::CalculateZPosition(
|
|
|
|
nsIXULWindow *inWindow,
|
|
|
|
PRUint32 inPosition,
|
|
|
|
nsIWidget *inBelow,
|
|
|
|
PRUint32 *outPosition,
|
|
|
|
nsIWidget **outBelow,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *outAltered)
|
2009-01-05 10:58:59 -08:00
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(outBelow);
|
|
|
|
NS_ENSURE_STATE(mReady);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
*outBelow = nsnull;
|
2007-03-22 10:30:00 -07: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;
|
|
|
|
|
|
|
|
nsWindowInfo *info = mTopmostWindow;
|
2009-01-02 20:06:52 -08:00
|
|
|
nsIXULWindow *belowWindow = nsnull;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool found = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult result = NS_OK;
|
2009-01-02 20:06:52 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*outPosition = inPosition;
|
|
|
|
*outAltered = PR_FALSE;
|
|
|
|
|
|
|
|
if (mSortingZOrder) { // don't fight SortZOrder()
|
|
|
|
*outBelow = inBelow;
|
|
|
|
NS_IF_ADDREF(*outBelow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 inZ;
|
|
|
|
GetZLevel(inWindow, &inZ);
|
|
|
|
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (inPosition == nsIWindowMediator::zLevelBelow) {
|
|
|
|
// locate inBelow. use topmost if it can't be found or isn't in the
|
|
|
|
// z-order list
|
|
|
|
info = GetInfoFor(inBelow);
|
|
|
|
if (!info || info->mYounger != info && info->mLower == info)
|
|
|
|
info = mTopmostWindow;
|
|
|
|
else
|
|
|
|
found = PR_TRUE;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (mTopmostWindow && mTopmostWindow->mZLevel > inZ) {
|
|
|
|
// asked for topmost, can't have it. locate highest allowed position.
|
|
|
|
do {
|
|
|
|
if (info->mZLevel <= inZ)
|
|
|
|
break;
|
|
|
|
info = info->mLower;
|
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
|
|
|
*outPosition = nsIWindowMediator::zLevelBelow;
|
|
|
|
belowWindow = info->mHigher->mWindow;
|
|
|
|
*outAltered = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else if (inPosition == nsIWindowMediator::zLevelBottom) {
|
|
|
|
if (mTopmostWindow && mTopmostWindow->mHigher->mZLevel < inZ) {
|
|
|
|
// asked for bottommost, can't have it. locate lowest allowed position.
|
|
|
|
do {
|
|
|
|
info = info->mHigher;
|
|
|
|
if (info->mZLevel >= inZ)
|
|
|
|
break;
|
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
|
|
|
*outPosition = nsIWindowMediator::zLevelBelow;
|
|
|
|
belowWindow = info->mWindow;
|
|
|
|
*outAltered = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned long relativeZ;
|
|
|
|
|
|
|
|
// check that we're in the right z-plane
|
|
|
|
if (found) {
|
|
|
|
belowWindow = info->mWindow;
|
|
|
|
relativeZ = info->mZLevel;
|
|
|
|
if (relativeZ > inZ) {
|
|
|
|
// might be OK. is lower window, if any, lower?
|
|
|
|
if (info->mLower != info && info->mLower->mZLevel > inZ) {
|
|
|
|
do {
|
|
|
|
if (info->mZLevel <= inZ)
|
|
|
|
break;
|
|
|
|
info = info->mLower;
|
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
|
|
|
belowWindow = info->mHigher->mWindow;
|
|
|
|
*outAltered = PR_TRUE;
|
|
|
|
}
|
|
|
|
} else if (relativeZ < inZ) {
|
|
|
|
// nope. look for a higher window to be behind.
|
|
|
|
do {
|
|
|
|
info = info->mHigher;
|
|
|
|
if (info->mZLevel >= inZ)
|
|
|
|
break;
|
|
|
|
} while (info != mTopmostWindow);
|
|
|
|
|
|
|
|
if (info->mZLevel >= inZ)
|
|
|
|
belowWindow = info->mWindow;
|
|
|
|
else
|
|
|
|
*outPosition = nsIWindowMediator::zLevelTop;
|
|
|
|
*outAltered = PR_TRUE;
|
|
|
|
} // 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::SetZPosition(
|
|
|
|
nsIXULWindow *inWindow,
|
|
|
|
PRUint32 inPosition,
|
2009-01-05 10:58:59 -08:00
|
|
|
nsIXULWindow *inBelow)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowInfo *inInfo,
|
|
|
|
*belowInfo;
|
|
|
|
|
|
|
|
if (inPosition != nsIWindowMediator::zLevelTop &&
|
|
|
|
inPosition != nsIWindowMediator::zLevelBottom &&
|
|
|
|
inPosition != nsIWindowMediator::zLevelBelow ||
|
2009-01-02 20:06:52 -08:00
|
|
|
!inWindow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2009-01-02 20:06:52 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mSortingZOrder) // don't fight SortZOrder()
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07: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
|
|
|
|
now may be this window's first exposure to the latter. */
|
|
|
|
inInfo = GetInfoFor(inWindow);
|
|
|
|
if (!inInfo)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// locate inBelow, place inWindow behind it
|
|
|
|
if (inPosition == nsIWindowMediator::zLevelBelow) {
|
|
|
|
belowInfo = GetInfoFor(inBelow);
|
|
|
|
// it had better also be in the z-order list
|
|
|
|
if (belowInfo &&
|
2009-01-02 20:06:52 -08:00
|
|
|
belowInfo->mYounger != belowInfo && belowInfo->mLower == belowInfo) {
|
|
|
|
belowInfo = nsnull;
|
|
|
|
}
|
|
|
|
if (!belowInfo) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (inBelow)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
else
|
|
|
|
inPosition = nsIWindowMediator::zLevelTop;
|
2009-01-02 20:06:52 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (inPosition == nsIWindowMediator::zLevelTop ||
|
|
|
|
inPosition == nsIWindowMediator::zLevelBottom)
|
2009-01-02 20:06:52 -08:00
|
|
|
belowInfo = mTopmostWindow ? mTopmostWindow->mHigher : nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (inInfo != belowInfo) {
|
|
|
|
inInfo->Unlink(PR_FALSE, PR_TRUE);
|
2009-01-02 20:06:52 -08:00
|
|
|
inInfo->InsertAfter(nsnull, belowInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (inPosition == nsIWindowMediator::zLevelTop)
|
|
|
|
mTopmostWindow = inInfo;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-05 10:58:59 -08:00
|
|
|
nsWindowMediator::GetZLevel(nsIXULWindow *aWindow, PRUint32 *_retval)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = nsIXULWindow::normalZ;
|
|
|
|
nsWindowInfo *info = GetInfoFor(aWindow);
|
2009-01-06 14:25:49 -08:00
|
|
|
if (info) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*_retval = info->mZLevel;
|
2009-01-06 14:25:49 -08:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_WARNING("getting z level of unregistered window");
|
|
|
|
// this goes off during window destruction
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-05 10:58:59 -08:00
|
|
|
nsWindowMediator::SetZLevel(nsIXULWindow *aWindow, PRUint32 aZLevel)
|
|
|
|
{
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_ENSURE_STATE(mReady);
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
bool lowered = info->mZLevel > aZLevel;
|
2007-03-22 10:30:00 -07: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
|
|
|
|
done front to back. Assumes caller has locked mListLock.
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void
|
2009-01-05 10:58:59 -08:00
|
|
|
nsWindowMediator::SortZOrderFrontToBack()
|
|
|
|
{
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
bool finished;
|
2007-03-22 10:30:00 -07: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
|
|
|
|
|
|
|
|
mSortingZOrder = PR_TRUE;
|
|
|
|
|
|
|
|
/* 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 {
|
|
|
|
finished = PR_TRUE;
|
|
|
|
lowest = mTopmostWindow->mHigher;
|
|
|
|
scan = mTopmostWindow;
|
|
|
|
while (scan != lowest) {
|
|
|
|
PRUint32 scanZ = scan->mZLevel;
|
|
|
|
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;
|
|
|
|
scan->Unlink(PR_FALSE, PR_TRUE);
|
2009-01-02 20:06:52 -08:00
|
|
|
scan->InsertAfter(nsnull, prev);
|
2007-03-22 10:30:00 -07: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)
|
|
|
|
scanWidget->PlaceBehind(eZPlacementBelow, prevWidget, PR_FALSE);
|
|
|
|
|
|
|
|
finished = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
scan = scan->mLower;
|
|
|
|
}
|
|
|
|
} while (!finished);
|
|
|
|
|
|
|
|
mSortingZOrder = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see comment for SortZOrderFrontToBack
|
|
|
|
void
|
2009-01-05 10:58:59 -08:00
|
|
|
nsWindowMediator::SortZOrderBackToFront()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowInfo *scan, // scans list looking for problems
|
|
|
|
*search, // searches for correct placement for scan window
|
|
|
|
*lowest; // bottom-most window in list
|
2011-09-28 23:19:26 -07:00
|
|
|
bool finished;
|
2007-03-22 10:30:00 -07: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
|
|
|
|
|
|
|
|
mSortingZOrder = PR_TRUE;
|
|
|
|
|
|
|
|
/* 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 {
|
|
|
|
finished = PR_TRUE;
|
|
|
|
lowest = mTopmostWindow->mHigher;
|
|
|
|
scan = lowest;
|
|
|
|
while (scan != mTopmostWindow) {
|
|
|
|
PRUint32 scanZ = scan->mZLevel;
|
|
|
|
if (scanZ > scan->mHigher->mZLevel) { // out of order
|
|
|
|
search = scan;
|
2009-01-02 20:06:52 -08:00
|
|
|
do {
|
2007-03-22 10:30:00 -07:00
|
|
|
search = search->mHigher;
|
2009-01-02 20:06:52 -08:00
|
|
|
} while (search != lowest && scanZ > search->mZLevel);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// reposition |scan| within the list
|
|
|
|
if (scan != search && scan != search->mLower) {
|
|
|
|
scan->Unlink(PR_FALSE, PR_TRUE);
|
2009-01-02 20:06:52 -08:00
|
|
|
scan->InsertAfter(nsnull, search);
|
2007-03-22 10:30:00 -07: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)
|
|
|
|
scanWidget->PlaceBehind(eZPlacementBelow, searchWidget, PR_FALSE);
|
|
|
|
finished = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
scan = scan->mHigher;
|
|
|
|
}
|
|
|
|
} while (!finished);
|
|
|
|
|
|
|
|
mSortingZOrder = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_IMPL_ISUPPORTS3(nsWindowMediator,
|
|
|
|
nsIWindowMediator,
|
|
|
|
nsIObserver,
|
|
|
|
nsISupportsWeakReference)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::AddListener(nsIWindowMediatorListener* aListener)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (!mListeners) {
|
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mListeners));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mListeners->AppendElement(aListener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::RemoveListener(nsIWindowMediatorListener* aListener)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
|
|
|
|
2009-01-02 20:06:52 -08:00
|
|
|
if (!mListeners)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mListeners->RemoveElement(aListener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-16 23:20:08 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowMediator::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown") && mReady) {
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mListLock);
|
2009-10-16 23:20:08 -07:00
|
|
|
while (mOldestWindow)
|
|
|
|
UnregisterWindow(mOldestWindow);
|
|
|
|
mReady = PR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-01-02 20:06:52 -08:00
|
|
|
notifyOpenWindow(nsISupports *aElement, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIWindowMediatorListener* listener =
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
|
2009-01-04 21:22:36 -08:00
|
|
|
WindowTitleData* winData = static_cast<WindowTitleData*>(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
listener->OnOpenWindow(winData->mWindow);
|
2009-01-04 21:22:36 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-01-02 20:06:52 -08:00
|
|
|
notifyCloseWindow(nsISupports *aElement, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIWindowMediatorListener* listener =
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
|
2009-01-04 21:22:36 -08:00
|
|
|
WindowTitleData* winData = static_cast<WindowTitleData*>(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
listener->OnCloseWindow(winData->mWindow);
|
2009-01-04 21:22:36 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-01-02 20:06:52 -08:00
|
|
|
notifyWindowTitleChange(nsISupports *aElement, void* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIWindowMediatorListener* listener =
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
|
2009-01-04 21:22:36 -08:00
|
|
|
WindowTitleData* titleData = reinterpret_cast<WindowTitleData*>(aData);
|
|
|
|
listener->OnWindowTitleChange(titleData->mWindow, titleData->mTitle);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|