Clean up window mediator code. b=450576 sr=roc

This commit is contained in:
Josh Aas 2009-01-02 22:06:52 -06:00
parent cbb1b6e85c
commit c474ff07a9
4 changed files with 191 additions and 250 deletions

View File

@ -51,12 +51,12 @@
#include "nsAppShellWindowEnumerator.h"
#include "nsWindowMediator.h"
/********************************************************************/
/************************ static helper functions *******************/
/********************************************************************/
//
// static helper functions
//
static nsresult GetDOMWindow(nsIXULWindow* inWindow,
nsCOMPtr<nsIDOMWindowInternal> &outDOMWindow);
nsCOMPtr<nsIDOMWindowInternal> &outDOMWindow);
static nsCOMPtr<nsIDOMNode> GetDOMNodeFromDocShell(nsIDocShell *aShell);
static void GetAttribute(nsIXULWindow *inWindow, const nsAString &inAttribute,
nsAString &outValue);
@ -72,8 +72,6 @@ nsresult GetDOMWindow(nsIXULWindow *aWindow, nsCOMPtr<nsIDOMWindowInternal> &aDO
return aDOMWindow ? NS_OK : NS_ERROR_FAILURE;
}
// QueryInterface fu
nsCOMPtr<nsIDOMNode> GetDOMNodeFromDocShell(nsIDocShell *aShell)
{
nsCOMPtr<nsIDOMNode> node;
@ -106,7 +104,6 @@ void GetAttribute(nsIXULWindow *inWindow, const nsAString &inAttribute,
{
nsCOMPtr<nsIDocShell> shell;
if (inWindow && NS_SUCCEEDED(inWindow->GetDocShell(getter_AddRefs(shell)))) {
nsCOMPtr<nsIDOMNode> node(GetDOMNodeFromDocShell(shell));
if (node) {
nsCOMPtr<nsIDOMElement> webshellElement(do_QueryInterface(node));
@ -123,9 +120,9 @@ void GetWindowType(nsIXULWindow* aWindow, nsString &outType)
GetAttribute(aWindow, NS_LITERAL_STRING("windowtype"), outType);
}
/********************************************************************/
/**************************** nsWindowInfo **************************/
/********************************************************************/
//
// nsWindowInfo
//
nsWindowInfo::nsWindowInfo(nsIXULWindow* inWindow, PRInt32 inTimeStamp) :
mWindow(inWindow),mTimeStamp(inTimeStamp),mZLevel(nsIXULWindow::normalZ)
@ -136,7 +133,7 @@ nsWindowInfo::nsWindowInfo(nsIXULWindow* inWindow, PRInt32 inTimeStamp) :
nsWindowInfo::~nsWindowInfo()
{
}
// return true if the window described by this WindowInfo has a type
// equal to the given type
PRBool nsWindowInfo::TypeEquals(const nsAString &aType)
@ -148,7 +145,8 @@ PRBool nsWindowInfo::TypeEquals(const nsAString &aType)
// insert the struct into their two linked lists, in position after the
// given (independent) method arguments
void nsWindowInfo::InsertAfter(nsWindowInfo *inOlder , nsWindowInfo *inHigher) {
void nsWindowInfo::InsertAfter(nsWindowInfo *inOlder , nsWindowInfo *inHigher)
{
if (inOlder) {
mOlder = inOlder;
mYounger = inOlder->mYounger;
@ -172,8 +170,8 @@ void nsWindowInfo::InsertAfter(nsWindowInfo *inOlder , nsWindowInfo *inHigher) {
}
// remove the struct from its linked lists
void nsWindowInfo::Unlink(PRBool inAge, PRBool inZ) {
void nsWindowInfo::Unlink(PRBool inAge, PRBool inZ)
{
if (inAge) {
mOlder->mYounger = mYounger;
mYounger->mOlder = mOlder;
@ -182,12 +180,12 @@ void nsWindowInfo::Unlink(PRBool inAge, PRBool inZ) {
mLower->mHigher = mHigher;
mHigher->mLower = mLower;
}
ReferenceSelf( inAge, inZ );
ReferenceSelf(inAge, inZ);
}
// initialize the struct to be a valid linked list of one element
void nsWindowInfo::ReferenceSelf(PRBool inAge, PRBool inZ) {
void nsWindowInfo::ReferenceSelf(PRBool inAge, PRBool inZ)
{
if (inAge) {
mYounger = this;
mOlder = this;
@ -198,33 +196,31 @@ void nsWindowInfo::ReferenceSelf(PRBool inAge, PRBool inZ) {
}
}
/********************************************************************/
/*********************** nsAppShellWindowEnumerator *****************/
/********************************************************************/
//
// nsAppShellWindowEnumerator
//
NS_IMPL_ISUPPORTS1(nsAppShellWindowEnumerator, nsISimpleEnumerator)
nsAppShellWindowEnumerator::nsAppShellWindowEnumerator (
nsAppShellWindowEnumerator::nsAppShellWindowEnumerator(
const PRUnichar* aTypeString,
nsWindowMediator& aMediator) :
mWindowMediator(&aMediator), mType(aTypeString),
mCurrentPosition(0)
mWindowMediator(&aMediator), mType(aTypeString), mCurrentPosition(nsnull)
{
mWindowMediator->AddEnumerator(this);
NS_ADDREF(mWindowMediator);
}
nsAppShellWindowEnumerator::~nsAppShellWindowEnumerator() {
nsAppShellWindowEnumerator::~nsAppShellWindowEnumerator()
{
mWindowMediator->RemoveEnumerator(this);
NS_RELEASE(mWindowMediator);
}
// after mCurrentPosition has been initialized to point to the beginning
// of the appropriate list, adjust it if necessary
void nsAppShellWindowEnumerator::AdjustInitialPosition() {
void nsAppShellWindowEnumerator::AdjustInitialPosition()
{
if (!mType.IsEmpty() && mCurrentPosition && !mCurrentPosition->TypeEquals(mType))
mCurrentPosition = FindNext();
}
@ -237,35 +233,35 @@ NS_IMETHODIMP nsAppShellWindowEnumerator::HasMoreElements(PRBool *retval)
*retval = mCurrentPosition ? PR_TRUE : PR_FALSE;
return NS_OK;
}
// if a window is being removed adjust the iterator's current position
void nsAppShellWindowEnumerator::WindowRemoved(nsWindowInfo *inInfo) {
// if a window is being removed adjust the iterator's current position
void nsAppShellWindowEnumerator::WindowRemoved(nsWindowInfo *inInfo)
{
if (mCurrentPosition == inInfo)
mCurrentPosition = FindNext();
}
/********************************************************************/
/*********************** nsASDOMWindowEnumerator ********************/
/********************************************************************/
//
// nsASDOMWindowEnumerator
//
nsASDOMWindowEnumerator::nsASDOMWindowEnumerator(
const PRUnichar* aTypeString,
nsWindowMediator& aMediator) :
nsAppShellWindowEnumerator(aTypeString, aMediator) {
nsAppShellWindowEnumerator(aTypeString, aMediator)
{
}
nsASDOMWindowEnumerator::~nsASDOMWindowEnumerator() {
nsASDOMWindowEnumerator::~nsASDOMWindowEnumerator()
{
}
NS_IMETHODIMP nsASDOMWindowEnumerator::GetNext(nsISupports **retval) {
NS_IMETHODIMP nsASDOMWindowEnumerator::GetNext(nsISupports **retval)
{
if (!retval)
return NS_ERROR_INVALID_ARG;
*retval = NULL;
*retval = nsnull;
if (mCurrentPosition) {
nsCOMPtr<nsIDOMWindowInternal> domWindow;
GetDOMWindow(mCurrentPosition->mWindow, domWindow);
@ -275,27 +271,27 @@ NS_IMETHODIMP nsASDOMWindowEnumerator::GetNext(nsISupports **retval) {
return NS_OK;
}
/********************************************************************/
/*********************** nsASXULWindowEnumerator ********************/
/********************************************************************/
//
// nsASXULWindowEnumerator
//
nsASXULWindowEnumerator::nsASXULWindowEnumerator(
const PRUnichar* aTypeString,
nsWindowMediator& aMediator) :
nsAppShellWindowEnumerator(aTypeString, aMediator) {
nsAppShellWindowEnumerator(aTypeString, aMediator)
{
}
nsASXULWindowEnumerator::~nsASXULWindowEnumerator() {
nsASXULWindowEnumerator::~nsASXULWindowEnumerator()
{
}
NS_IMETHODIMP nsASXULWindowEnumerator::GetNext(nsISupports **retval) {
NS_IMETHODIMP nsASXULWindowEnumerator::GetNext(nsISupports **retval)
{
if (!retval)
return NS_ERROR_INVALID_ARG;
*retval = NULL;
*retval = nsnull;
if (mCurrentPosition) {
CallQueryInterface(mCurrentPosition->mWindow, retval);
mCurrentPosition = FindNext();
@ -303,32 +299,32 @@ NS_IMETHODIMP nsASXULWindowEnumerator::GetNext(nsISupports **retval) {
return NS_OK;
}
/********************************************************************/
/****************** nsASDOMWindowEarlyToLateEnumerator **************/
/********************************************************************/
//
// nsASDOMWindowEarlyToLateEnumerator
//
nsASDOMWindowEarlyToLateEnumerator::nsASDOMWindowEarlyToLateEnumerator(
const PRUnichar *aTypeString,
nsWindowMediator &aMediator) :
nsASDOMWindowEnumerator(aTypeString, aMediator) {
nsASDOMWindowEnumerator(aTypeString, aMediator)
{
mCurrentPosition = aMediator.mOldestWindow;
AdjustInitialPosition();
}
nsASDOMWindowEarlyToLateEnumerator::~nsASDOMWindowEarlyToLateEnumerator() {
nsASDOMWindowEarlyToLateEnumerator::~nsASDOMWindowEarlyToLateEnumerator()
{
}
nsWindowInfo *nsASDOMWindowEarlyToLateEnumerator::FindNext() {
nsWindowInfo *nsASDOMWindowEarlyToLateEnumerator::FindNext()
{
nsWindowInfo *info,
*listEnd;
PRBool allWindows = mType.IsEmpty();
// see nsXULWindowEarlyToLateEnumerator::FindNext
if (!mCurrentPosition)
return 0;
return nsnull;
info = mCurrentPosition->mYounger;
listEnd = mWindowMediator->mOldestWindow;
@ -339,28 +335,28 @@ nsWindowInfo *nsASDOMWindowEarlyToLateEnumerator::FindNext() {
info = info->mYounger;
}
return 0;
return nsnull;
}
/********************************************************************/
/****************** nsASXULWindowEarlyToLateEnumerator **************/
/********************************************************************/
//
// nsASXULWindowEarlyToLateEnumerator
//
nsASXULWindowEarlyToLateEnumerator::nsASXULWindowEarlyToLateEnumerator(
const PRUnichar *aTypeString,
nsWindowMediator &aMediator) :
nsASXULWindowEnumerator(aTypeString, aMediator) {
nsASXULWindowEnumerator(aTypeString, aMediator)
{
mCurrentPosition = aMediator.mOldestWindow;
AdjustInitialPosition();
}
nsASXULWindowEarlyToLateEnumerator::~nsASXULWindowEarlyToLateEnumerator() {
nsASXULWindowEarlyToLateEnumerator::~nsASXULWindowEarlyToLateEnumerator()
{
}
nsWindowInfo *nsASXULWindowEarlyToLateEnumerator::FindNext() {
nsWindowInfo *nsASXULWindowEarlyToLateEnumerator::FindNext()
{
nsWindowInfo *info,
*listEnd;
PRBool allWindows = mType.IsEmpty();
@ -373,7 +369,7 @@ nsWindowInfo *nsASXULWindowEarlyToLateEnumerator::FindNext() {
pick up newly added windows anyway (if they occurred previous to our
current position) so we just don't worry about that. */
if (!mCurrentPosition)
return 0;
return nsnull;
info = mCurrentPosition->mYounger;
listEnd = mWindowMediator->mOldestWindow;
@ -384,35 +380,35 @@ nsWindowInfo *nsASXULWindowEarlyToLateEnumerator::FindNext() {
info = info->mYounger;
}
return 0;
return nsnull;
}
/********************************************************************/
/****************** nsASDOMWindowFrontToBackEnumerator **************/
/********************************************************************/
//
// nsASDOMWindowFrontToBackEnumerator
//
nsASDOMWindowFrontToBackEnumerator::nsASDOMWindowFrontToBackEnumerator(
const PRUnichar *aTypeString,
nsWindowMediator &aMediator) :
nsASDOMWindowEnumerator(aTypeString, aMediator) {
nsASDOMWindowEnumerator(aTypeString, aMediator)
{
mCurrentPosition = aMediator.mTopmostWindow;
AdjustInitialPosition();
}
nsASDOMWindowFrontToBackEnumerator::~nsASDOMWindowFrontToBackEnumerator() {
nsASDOMWindowFrontToBackEnumerator::~nsASDOMWindowFrontToBackEnumerator()
{
}
nsWindowInfo *nsASDOMWindowFrontToBackEnumerator::FindNext() {
nsWindowInfo *nsASDOMWindowFrontToBackEnumerator::FindNext()
{
nsWindowInfo *info,
*listEnd;
PRBool allWindows = mType.IsEmpty();
// see nsXULWindowEarlyToLateEnumerator::FindNext
if (!mCurrentPosition)
return 0;
return nsnull;
info = mCurrentPosition->mLower;
listEnd = mWindowMediator->mTopmostWindow;
@ -423,19 +419,18 @@ nsWindowInfo *nsASDOMWindowFrontToBackEnumerator::FindNext() {
info = info->mLower;
}
return 0;
return nsnull;
}
/********************************************************************/
/****************** nsASXULWindowFrontToBackEnumerator **************/
/********************************************************************/
//
// nsASXULWindowFrontToBackEnumerator
//
nsASXULWindowFrontToBackEnumerator::nsASXULWindowFrontToBackEnumerator(
const PRUnichar *aTypeString,
nsWindowMediator &aMediator) :
nsASXULWindowEnumerator(aTypeString, aMediator) {
nsASXULWindowEnumerator(aTypeString, aMediator)
{
mCurrentPosition = aMediator.mTopmostWindow;
AdjustInitialPosition();
}
@ -444,15 +439,15 @@ nsASXULWindowFrontToBackEnumerator::~nsASXULWindowFrontToBackEnumerator()
{
}
nsWindowInfo *nsASXULWindowFrontToBackEnumerator::FindNext() {
nsWindowInfo *nsASXULWindowFrontToBackEnumerator::FindNext()
{
nsWindowInfo *info,
*listEnd;
PRBool allWindows = mType.IsEmpty();
// see nsXULWindowEarlyToLateEnumerator::FindNext
if (!mCurrentPosition)
return 0;
return nsnull;
info = mCurrentPosition->mLower;
listEnd = mWindowMediator->mTopmostWindow;
@ -463,36 +458,36 @@ nsWindowInfo *nsASXULWindowFrontToBackEnumerator::FindNext() {
info = info->mLower;
}
return 0;
return nsnull;
}
/********************************************************************/
/****************** nsASDOMWindowBackToFrontEnumerator **************/
/********************************************************************/
//
// nsASDOMWindowBackToFrontEnumerator
//
nsASDOMWindowBackToFrontEnumerator::nsASDOMWindowBackToFrontEnumerator(
const PRUnichar *aTypeString,
nsWindowMediator &aMediator) :
nsASDOMWindowEnumerator(aTypeString, aMediator) {
nsASDOMWindowEnumerator(aTypeString, aMediator)
{
mCurrentPosition = aMediator.mTopmostWindow ?
aMediator.mTopmostWindow->mHigher : 0;
aMediator.mTopmostWindow->mHigher : nsnull;
AdjustInitialPosition();
}
nsASDOMWindowBackToFrontEnumerator::~nsASDOMWindowBackToFrontEnumerator() {
nsASDOMWindowBackToFrontEnumerator::~nsASDOMWindowBackToFrontEnumerator()
{
}
nsWindowInfo *nsASDOMWindowBackToFrontEnumerator::FindNext() {
nsWindowInfo *nsASDOMWindowBackToFrontEnumerator::FindNext()
{
nsWindowInfo *info,
*listEnd;
PRBool allWindows = mType.IsEmpty();
// see nsXULWindowEarlyToLateEnumerator::FindNext
if (!mCurrentPosition)
return 0;
return nsnull;
info = mCurrentPosition->mHigher;
listEnd = mWindowMediator->mTopmostWindow;
@ -505,21 +500,20 @@ nsWindowInfo *nsASDOMWindowBackToFrontEnumerator::FindNext() {
info = info->mHigher;
}
return 0;
return nsnull;
}
/********************************************************************/
/****************** nsASXULWindowBackToFrontEnumerator **************/
/********************************************************************/
//
// nsASXULWindowBackToFrontEnumerator
//
nsASXULWindowBackToFrontEnumerator::nsASXULWindowBackToFrontEnumerator(
const PRUnichar *aTypeString,
nsWindowMediator &aMediator) :
nsASXULWindowEnumerator(aTypeString, aMediator) {
nsASXULWindowEnumerator(aTypeString, aMediator)
{
mCurrentPosition = aMediator.mTopmostWindow ?
aMediator.mTopmostWindow->mHigher : 0;
aMediator.mTopmostWindow->mHigher : nsnull;
AdjustInitialPosition();
}
@ -527,15 +521,15 @@ nsASXULWindowBackToFrontEnumerator::~nsASXULWindowBackToFrontEnumerator()
{
}
nsWindowInfo *nsASXULWindowBackToFrontEnumerator::FindNext() {
nsWindowInfo *nsASXULWindowBackToFrontEnumerator::FindNext()
{
nsWindowInfo *info,
*listEnd;
PRBool allWindows = mType.IsEmpty();
// see nsXULWindowEarlyToLateEnumerator::FindNext
if (!mCurrentPosition)
return 0;
return nsnull;
info = mCurrentPosition->mHigher;
listEnd = mWindowMediator->mTopmostWindow;
@ -548,6 +542,5 @@ nsWindowInfo *nsASXULWindowBackToFrontEnumerator::FindNext() {
info = info->mHigher;
}
return 0;
return nsnull;
}

View File

@ -43,9 +43,9 @@
class nsWindowMediator;
/********************************************************************/
/**************************** nsWindowInfo **************************/
/********************************************************************/
//
// nsWindowInfo
//
struct nsWindowInfo
{
@ -68,10 +68,9 @@ struct nsWindowInfo
void ReferenceSelf(PRBool inAge, PRBool inZ);
};
/********************************************************************/
/************************ virtual enumerators ***********************/
/********************************************************************/
//
// virtual enumerators
//
class nsAppShellWindowEnumerator : public nsISimpleEnumerator {
@ -116,9 +115,9 @@ public:
NS_IMETHOD GetNext(nsISupports **retval);
};
/********************************************************************/
/*********************** concrete enumerators ***********************/
/********************************************************************/
//
// concrete enumerators
//
class nsASDOMWindowEarlyToLateEnumerator : public nsASDOMWindowEnumerator {
@ -197,5 +196,3 @@ public:
protected:
virtual nsWindowInfo *FindNext();
};

View File

@ -57,15 +57,13 @@
#include "nsIWindowMediatorListener.h"
#include "nsXPIDLString.h"
// Interfaces Needed
#include "nsIDocShell.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIXULWindow.h"
static nsresult GetDOMWindow( nsIXULWindow* inWindow,
nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow);
static nsresult GetDOMWindow(nsIXULWindow* inWindow,
nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow);
static PRBool notifyOpenWindow(nsISupports *aElement, void* aData);
static PRBool notifyCloseWindow(nsISupports *aElement, void* aData);
@ -77,9 +75,8 @@ struct windowData {
const PRUnichar *mTitle;
};
nsresult
GetDOMWindow( nsIXULWindow* inWindow, nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow)
GetDOMWindow(nsIXULWindow* inWindow, nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow)
{
nsCOMPtr<nsIDocShell> docShell;
@ -88,11 +85,11 @@ GetDOMWindow( nsIXULWindow* inWindow, nsCOMPtr< nsIDOMWindowInternal>& outDOMWin
return outDOMWindow ? NS_OK : NS_ERROR_FAILURE;
}
PRInt32 nsWindowMediator::gRefCnt = 0;
PRInt32 nsWindowMediator::gRefCnt = 0;
nsWindowMediator::nsWindowMediator() :
mEnumeratorList(), mOldestWindow(0), mTopmostWindow(0),
mTimeStamp(0), mSortingZOrder(PR_FALSE), mListLock(0)
mEnumeratorList(), mOldestWindow(nsnull), mTopmostWindow(nsnull),
mTimeStamp(0), mSortingZOrder(PR_FALSE), mListLock(nsnull)
{
// This should really be done in the static constructor fn.
nsresult rv;
@ -103,7 +100,6 @@ nsWindowMediator::nsWindowMediator() :
nsWindowMediator::~nsWindowMediator()
{
if (--gRefCnt == 0) {
// Delete data
while (mOldestWindow)
UnregisterWindow(mOldestWindow);
@ -113,8 +109,6 @@ nsWindowMediator::~nsWindowMediator()
}
}
NS_IMETHODIMP nsWindowMediator::RegisterWindow(nsIXULWindow* inWindow)
{
if (GetInfoFor(inWindow)) {
@ -126,7 +120,7 @@ NS_IMETHODIMP nsWindowMediator::RegisterWindow(nsIXULWindow* inWindow)
// Create window info struct and add to list of windows
nsWindowInfo* windowInfo = new nsWindowInfo (inWindow, mTimeStamp);
if (windowInfo == NULL)
if (!windowInfo)
return NS_ERROR_OUT_OF_MEMORY;
if (mListeners) {
@ -136,15 +130,13 @@ NS_IMETHODIMP nsWindowMediator::RegisterWindow(nsIXULWindow* inWindow)
nsAutoLock lock(mListLock);
if (mOldestWindow)
windowInfo->InsertAfter(mOldestWindow->mOlder, 0);
windowInfo->InsertAfter(mOldestWindow->mOlder, nsnull);
else
mOldestWindow = windowInfo;
return NS_OK;
}
NS_IMETHODIMP
nsWindowMediator::UnregisterWindow(nsIXULWindow* inWindow)
{
@ -155,9 +147,7 @@ nsWindowMediator::UnregisterWindow(nsIXULWindow* inWindow)
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
nsresult
nsWindowMediator::UnregisterWindow(nsWindowInfo *inInfo)
{
// Inform the iterators
@ -177,45 +167,45 @@ nsWindowMediator::UnregisterWindow(nsWindowInfo *inInfo)
mTopmostWindow = inInfo->mLower;
inInfo->Unlink(PR_TRUE, PR_TRUE);
if (inInfo == mOldestWindow)
mOldestWindow = 0;
mOldestWindow = nsnull;
if (inInfo == mTopmostWindow)
mTopmostWindow = 0;
mTopmostWindow = nsnull;
delete inInfo;
return NS_OK;
}
nsWindowInfo *
nsWindowInfo*
nsWindowMediator::GetInfoFor(nsIXULWindow *aWindow)
{
nsWindowInfo *info,
*listEnd;
if (!aWindow)
return 0;
return nsnull;
info = mOldestWindow;
listEnd = 0;
listEnd = nsnull;
while (info != listEnd) {
if (info->mWindow.get() == aWindow)
return info;
info = info->mYounger;
listEnd = mOldestWindow;
}
return 0;
return nsnull;
}
nsWindowInfo *
nsWindowInfo*
nsWindowMediator::GetInfoFor(nsIWidget *aWindow)
{
nsWindowInfo *info,
*listEnd;
if (!aWindow)
return 0;
return nsnull;
info = mOldestWindow;
listEnd = 0;
listEnd = nsnull;
nsCOMPtr<nsIWidget> scanWidget;
while (info != listEnd) {
@ -227,13 +217,13 @@ nsWindowMediator::GetInfoFor(nsIWidget *aWindow)
info = info->mYounger;
listEnd = mOldestWindow;
}
return 0;
return nsnull;
}
NS_METHOD
nsWindowMediator::GetEnumerator( const PRUnichar* inType, nsISimpleEnumerator** outEnumerator)
NS_IMETHODIMP
nsWindowMediator::GetEnumerator(const PRUnichar* inType, nsISimpleEnumerator** outEnumerator)
{
if (outEnumerator == NULL)
if (!outEnumerator)
return NS_ERROR_INVALID_ARG;
nsAutoLock lock(mListLock);
@ -244,25 +234,21 @@ nsWindowMediator::GetEnumerator( const PRUnichar* inType, nsISimpleEnumerator**
return NS_ERROR_OUT_OF_MEMORY;
}
NS_METHOD
NS_IMETHODIMP
nsWindowMediator::GetXULWindowEnumerator(const PRUnichar* inType, nsISimpleEnumerator** outEnumerator)
{
if (outEnumerator == NULL)
if (!outEnumerator)
return NS_ERROR_INVALID_ARG;
nsAutoLock lock(mListLock);
nsAppShellWindowEnumerator *enumerator = new nsASXULWindowEarlyToLateEnumerator(inType, *this);
if (enumerator)
return enumerator->QueryInterface( NS_GET_IID(nsISimpleEnumerator) , (void**)outEnumerator);
return enumerator->QueryInterface(NS_GET_IID(nsISimpleEnumerator) , (void**)outEnumerator);
return NS_ERROR_OUT_OF_MEMORY;
}
}
NS_METHOD
NS_IMETHODIMP
nsWindowMediator::GetZOrderDOMWindowEnumerator(
const PRUnichar *aWindowType, PRBool aFrontToBack,
nsISimpleEnumerator **_retval)
@ -282,9 +268,7 @@ nsWindowMediator::GetZOrderDOMWindowEnumerator(
return NS_ERROR_OUT_OF_MEMORY;
}
NS_METHOD
NS_IMETHODIMP
nsWindowMediator::GetZOrderXULWindowEnumerator(
const PRUnichar *aWindowType, PRBool aFrontToBack,
nsISimpleEnumerator **_retval)
@ -304,33 +288,25 @@ nsWindowMediator::GetZOrderXULWindowEnumerator(
return NS_ERROR_OUT_OF_MEMORY;
}
PRInt32
nsWindowMediator::AddEnumerator(nsAppShellWindowEnumerator * inEnumerator)
{
return mEnumeratorList.AppendElement(inEnumerator);
}
PRInt32
nsWindowMediator::RemoveEnumerator( nsAppShellWindowEnumerator * inEnumerator)
nsWindowMediator::RemoveEnumerator(nsAppShellWindowEnumerator * inEnumerator)
{
return mEnumeratorList.RemoveElement(inEnumerator);
}
/*
Returns the window of type inType ( if null return any window type ) which has the most recent
time stamp
*/
// Returns the window of type inType ( if null return any window type ) which has the most recent
// time stamp
NS_IMETHODIMP
nsWindowMediator::GetMostRecentWindow( const PRUnichar* inType, nsIDOMWindowInternal** outWindow)
nsWindowMediator::GetMostRecentWindow(const PRUnichar* inType, nsIDOMWindowInternal** outWindow)
{
NS_ENSURE_ARG_POINTER(outWindow);
*outWindow = NULL;
*outWindow = nsnull;
// Find the most window with the highest time stamp that matches
// the requested type
@ -351,9 +327,7 @@ nsWindowMediator::GetMostRecentWindow( const PRUnichar* inType, nsIDOMWindowInte
return NS_OK;
}
nsWindowInfo *
nsWindowInfo*
nsWindowMediator::MostRecentWindowInfo(const PRUnichar* inType)
{
PRInt32 lastTimeStamp = -1;
@ -364,10 +338,10 @@ nsWindowMediator::MostRecentWindowInfo(const PRUnichar* inType)
// the requested type
nsWindowInfo *searchInfo,
*listEnd,
*foundInfo = 0;
*foundInfo = nsnull;
searchInfo = mOldestWindow;
listEnd = 0;
listEnd = nsnull;
while (searchInfo != listEnd) {
if ((allWindows || searchInfo->TypeEquals(typeString)) &&
searchInfo->mTimeStamp >= lastTimeStamp) {
@ -381,10 +355,8 @@ nsWindowMediator::MostRecentWindowInfo(const PRUnichar* inType)
return foundInfo;
}
NS_IMETHODIMP
nsWindowMediator::UpdateWindowTimeStamp( nsIXULWindow* inWindow)
nsWindowMediator::UpdateWindowTimeStamp(nsIXULWindow* inWindow)
{
nsAutoLock lock(mListLock);
nsWindowInfo *info = GetInfoFor(inWindow);
@ -396,11 +368,9 @@ nsWindowMediator::UpdateWindowTimeStamp( nsIXULWindow* inWindow)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsWindowMediator::UpdateWindowTitle( nsIXULWindow* inWindow,
const PRUnichar* inTitle )
nsWindowMediator::UpdateWindowTitle(nsIXULWindow* inWindow,
const PRUnichar* inTitle)
{
nsAutoLock lock(mListLock);
if (mListeners && GetInfoFor(inWindow)) {
@ -411,8 +381,6 @@ nsWindowMediator::UpdateWindowTitle( nsIXULWindow* inWindow,
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
@ -427,11 +395,10 @@ nsWindowMediator::CalculateZPosition(
PRUint32 *outPosition,
nsIWidget **outBelow,
PRBool *outAltered) {
if (!outBelow)
return NS_ERROR_NULL_POINTER;
*outBelow = 0;
*outBelow = nsnull;
if (!inWindow || !outPosition || !outAltered)
return NS_ERROR_NULL_POINTER;
@ -439,14 +406,13 @@ nsWindowMediator::CalculateZPosition(
if (inPosition != nsIWindowMediator::zLevelTop &&
inPosition != nsIWindowMediator::zLevelBottom &&
inPosition != nsIWindowMediator::zLevelBelow)
return NS_ERROR_INVALID_ARG;
nsWindowInfo *info = mTopmostWindow;
nsIXULWindow *belowWindow = 0;
nsIXULWindow *belowWindow = nsnull;
PRBool found = PR_FALSE;
nsresult result = NS_OK;
*outPosition = inPosition;
*outAltered = PR_FALSE;
@ -462,7 +428,6 @@ nsWindowMediator::CalculateZPosition(
nsAutoLock lock(mListLock);
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);
@ -483,7 +448,6 @@ nsWindowMediator::CalculateZPosition(
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)
@ -494,11 +458,9 @@ nsWindowMediator::CalculateZPosition(
*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;
@ -511,7 +473,6 @@ nsWindowMediator::CalculateZPosition(
*outAltered = PR_TRUE;
}
} else {
unsigned long relativeZ;
// check that we're in the right z-plane
@ -519,10 +480,8 @@ nsWindowMediator::CalculateZPosition(
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;
@ -533,7 +492,6 @@ nsWindowMediator::CalculateZPosition(
*outAltered = PR_TRUE;
}
} else if (relativeZ < inZ) {
// nope. look for a higher window to be behind.
do {
info = info->mHigher;
@ -546,7 +504,6 @@ nsWindowMediator::CalculateZPosition(
else
*outPosition = nsIWindowMediator::zLevelTop;
*outAltered = PR_TRUE;
} // else they're equal, so it's OK
}
}
@ -562,26 +519,20 @@ nsWindowMediator::CalculateZPosition(
return result;
}
NS_IMETHODIMP
nsWindowMediator::SetZPosition(
nsIXULWindow *inWindow,
PRUint32 inPosition,
nsIXULWindow *inBelow) {
nsWindowInfo *inInfo,
*belowInfo;
if (inPosition != nsIWindowMediator::zLevelTop &&
inPosition != nsIWindowMediator::zLevelBottom &&
inPosition != nsIWindowMediator::zLevelBelow ||
!inWindow)
// inPosition == nsIWindowMediator::zLevelBelow && !inBelow)
!inWindow) {
return NS_ERROR_INVALID_ARG;
}
if (mSortingZOrder) // don't fight SortZOrder()
return NS_OK;
@ -601,21 +552,23 @@ nsWindowMediator::SetZPosition(
belowInfo = GetInfoFor(inBelow);
// it had better also be in the z-order list
if (belowInfo &&
belowInfo->mYounger != belowInfo && belowInfo->mLower == belowInfo)
belowInfo = 0;
if (!belowInfo)
belowInfo->mYounger != belowInfo && belowInfo->mLower == belowInfo) {
belowInfo = nsnull;
}
if (!belowInfo) {
if (inBelow)
return NS_ERROR_INVALID_ARG;
else
inPosition = nsIWindowMediator::zLevelTop;
}
}
if (inPosition == nsIWindowMediator::zLevelTop ||
inPosition == nsIWindowMediator::zLevelBottom)
belowInfo = mTopmostWindow ? mTopmostWindow->mHigher : 0;
belowInfo = mTopmostWindow ? mTopmostWindow->mHigher : nsnull;
if (inInfo != belowInfo) {
inInfo->Unlink(PR_FALSE, PR_TRUE);
inInfo->InsertAfter(0, belowInfo);
inInfo->InsertAfter(nsnull, belowInfo);
}
if (inPosition == nsIWindowMediator::zLevelTop)
mTopmostWindow = inInfo;
@ -704,7 +657,7 @@ nsWindowMediator::SortZOrderFrontToBack() {
if (scan == mTopmostWindow)
mTopmostWindow = scan->mLower;
scan->Unlink(PR_FALSE, PR_TRUE);
scan->InsertAfter(0, prev);
scan->InsertAfter(nsnull, prev);
// fix actual window order
nsCOMPtr<nsIBaseWindow> base;
@ -753,14 +706,14 @@ nsWindowMediator::SortZOrderBackToFront() {
PRUint32 scanZ = scan->mZLevel;
if (scanZ > scan->mHigher->mZLevel) { // out of order
search = scan;
do
do {
search = search->mHigher;
while (search != lowest && scanZ > search->mZLevel);
} while (search != lowest && scanZ > search->mZLevel);
// reposition |scan| within the list
if (scan != search && scan != search->mLower) {
scan->Unlink(PR_FALSE, PR_TRUE);
scan->InsertAfter(0, search);
scan->InsertAfter(nsnull, search);
}
if (search == lowest)
mTopmostWindow = scan;
@ -779,7 +732,6 @@ nsWindowMediator::SortZOrderBackToFront() {
}
if (scanWidget)
scanWidget->PlaceBehind(eZPlacementBelow, searchWidget, PR_FALSE);
finished = PR_FALSE;
break;
}
@ -790,19 +742,17 @@ nsWindowMediator::SortZOrderBackToFront() {
mSortingZOrder = PR_FALSE;
}
// COM
NS_IMPL_ADDREF( nsWindowMediator )
NS_IMPL_ADDREF(nsWindowMediator)
NS_IMPL_QUERY_INTERFACE1(nsWindowMediator, nsIWindowMediator)
NS_IMPL_RELEASE(nsWindowMediator)
nsresult
nsWindowMediator::Init()
{
if (gRefCnt++ == 0)
{
if (gRefCnt++ == 0) {
mListLock = PR_NewLock();
if (!mListLock)
return NS_ERROR_OUT_OF_MEMORY;
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
@ -829,14 +779,16 @@ nsWindowMediator::RemoveListener(nsIWindowMediatorListener* aListener)
{
NS_ENSURE_ARG_POINTER(aListener);
if (!mListeners) return NS_OK;
if (!mListeners)
return NS_OK;
mListeners->RemoveElement(aListener);
return NS_OK;
}
PRBool notifyOpenWindow(nsISupports *aElement, void* aData)
PRBool
notifyOpenWindow(nsISupports *aElement, void* aData)
{
nsIWindowMediatorListener* listener =
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
@ -846,7 +798,8 @@ PRBool notifyOpenWindow(nsISupports *aElement, void* aData)
return PR_TRUE;
}
PRBool notifyCloseWindow(nsISupports *aElement, void* aData)
PRBool
notifyCloseWindow(nsISupports *aElement, void* aData)
{
nsIWindowMediatorListener* listener =
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
@ -856,7 +809,8 @@ PRBool notifyCloseWindow(nsISupports *aElement, void* aData)
return PR_TRUE;
}
PRBool notifyWindowTitleChange(nsISupports *aElement, void* aData)
PRBool
notifyWindowTitleChange(nsISupports *aElement, void* aData)
{
nsIWindowMediatorListener* listener =
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
@ -868,4 +822,3 @@ PRBool notifyWindowTitleChange(nsISupports *aElement, void* aData)
return PR_TRUE;
}

View File

@ -35,8 +35,8 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef __nsWindowMediator_h
#define __nsWindowMediator_h
#ifndef nsWindowMediator_h_
#define nsWindowMediator_h_
#include "nsCOMPtr.h"
#include "nsIWindowMediator.h"
@ -71,17 +71,14 @@ public:
nsresult Init();
NS_DECL_NSIWINDOWMEDIATOR
// COM
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
private:
// Helper functions
PRInt32 AddEnumerator( nsAppShellWindowEnumerator* inEnumerator );
PRInt32 RemoveEnumerator( nsAppShellWindowEnumerator* inEnumerator);
nsWindowInfo *MostRecentWindowInfo(const PRUnichar* inType);
NS_IMETHOD UnregisterWindow(nsWindowInfo *inInfo);
nsresult UnregisterWindow(nsWindowInfo *inInfo);
nsWindowInfo *GetInfoFor(nsIXULWindow *aWindow);
nsWindowInfo *GetInfoFor(nsIWidget *aWindow);
void SortZOrderFrontToBack();
@ -93,6 +90,7 @@ private:
PRInt32 mTimeStamp;
PRBool mSortingZOrder;
PRLock *mListLock;
nsCOMPtr<nsISupportsArray> mListeners;
static PRInt32 gRefCnt;