Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends
nsWindowMediator Class Reference

#include <nsWindowMediator.h>

Inheritance diagram for nsWindowMediator:
Inheritance graph
[legend]
Collaboration diagram for nsWindowMediator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsWindowMediator ()
virtual ~nsWindowMediator ()
nsresult Init ()
nsISimpleEnumerator getEnumerator (in wstring aWindowType)
 Return an enumerator which iterates over all windows of type aWindowType from the oldest window to the youngest.
nsISimpleEnumerator getXULWindowEnumerator (in wstring aWindowType)
 Identical to getEnumerator except:
nsISimpleEnumerator getZOrderDOMWindowEnumerator (in wstring aWindowType, in boolean aFrontToBack)
 Return an enumerator which iterates over all windows of type aWindowType in their z (front-to-back) order.
nsISimpleEnumerator getZOrderXULWindowEnumerator (in wstring aWindowType, in boolean aFrontToBack)
 Identical to getZOrderDOMWindowEnumerator except:
nsIDOMWindowInternal getMostRecentWindow (in wstring aWindowType)
 This is a shortcut for simply fetching the first window in front to back order.
void registerWindow (in nsIXULWindow aWindow)
 Add the window to the list of known windows.
void unregisterWindow (in nsIXULWindow aWindow)
 Remove the window from the list of known windows.
void updateWindowTimeStamp (in nsIXULWindow aWindow)
 Call this method when a window gains focus.
void updateWindowTitle (in nsIXULWindow aWindow, in wstring inTitle)
 Call this method when a window's title changes.
boolean calculateZPosition (in nsIXULWindow inWindow, in unsigned long inPosition, in nsIWidget inBelow, out unsigned long outPosition, out nsIWidget outBelow)
 A window wants to be moved in z-order.
void setZPosition (in nsIXULWindow inWindow, in unsigned long inPosition, in nsIXULWindow inBelow)
 A window has been positioned behind another.
PRUint32 getZLevel (in nsIXULWindow aWindow)
 Return the window's Z level (as defined in nsIXULWindow).
void setZLevel (in nsIXULWindow aWindow, in PRUint32 aZLevel)
 Set the window's Z level (as defined in nsIXULWindow).
void addListener (in nsIWindowMediatorListener aListener)
 Register a listener for window status changes.
void removeListener (in nsIWindowMediatorListener aListener)
 Unregister a listener of window status changes.

Public Attributes

const unsigned long zLevelTop = 1
const unsigned long zLevelBottom = 2
const unsigned long zLevelBelow = 3

Private Member Functions

PRInt32 AddEnumerator (nsAppShellWindowEnumerator *inEnumerator)
PRInt32 RemoveEnumerator (nsAppShellWindowEnumerator *inEnumerator)
nsWindowInfoMostRecentWindowInfo (const PRUnichar *inType)
NS_IMETHOD UnregisterWindow (nsWindowInfo *inInfo)
nsWindowInfoGetInfoFor (nsIXULWindow *aWindow)
nsWindowInfoGetInfoFor (nsIWidget *aWindow)
void SortZOrderFrontToBack ()
void SortZOrderBackToFront ()

Private Attributes

nsVoidArray mEnumeratorList
nsWindowInfomOldestWindow
nsWindowInfomTopmostWindow
PRInt32 mTimeStamp
PRBool mSortingZOrder
PRLockmListLock
nsCOMPtr< nsISupportsArraymListeners

Static Private Attributes

static PRInt32 gRefCnt = 0

Friends

class nsAppShellWindowEnumerator
class nsASXULWindowEarlyToLateEnumerator
class nsASDOMWindowEarlyToLateEnumerator
class nsASDOMWindowFrontToBackEnumerator
class nsASXULWindowFrontToBackEnumerator
class nsASDOMWindowBackToFrontEnumerator
class nsASXULWindowBackToFrontEnumerator

Detailed Description

Definition at line 58 of file nsWindowMediator.h.


Constructor & Destructor Documentation

Definition at line 93 of file nsWindowMediator.cpp.

                                   :
  mEnumeratorList(), mOldestWindow(0), mTopmostWindow(0),
  mTimeStamp(0), mSortingZOrder(PR_FALSE), mListLock(0)
{
   // This should really be done in the static constructor fn.
   nsresult rv;
   rv = Init();
   NS_ASSERTION(NS_SUCCEEDED(rv), "uh oh, couldn't Init() for some reason");
}

Here is the call graph for this function:

Definition at line 103 of file nsWindowMediator.cpp.

{
  if (--gRefCnt == 0) {

    // Delete data
    while (mOldestWindow)
      UnregisterWindow(mOldestWindow);

    if (mListLock)
      PR_DestroyLock(mListLock);
  }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 310 of file nsWindowMediator.cpp.

{
  return mEnumeratorList.AppendElement(inEnumerator);
}

Register a listener for window status changes.

keeps strong ref? (to be decided)

Parameters:
aListenerthe listener to register
boolean nsIWindowMediator::calculateZPosition ( in nsIXULWindow  inWindow,
in unsigned long  inPosition,
in nsIWidget  inBelow,
out unsigned long  outPosition,
out nsIWidget  outBelow 
) [inherited]

A window wants to be moved in z-order.

Calculate whether and how it should be constrained. Note this method is advisory only: it changes nothing either in WindowMediator's internal state or with the window. Note it compares the nsIXULWindow to nsIWidgets. A pure interface would use all nsIXULWindows. But we expect this to be called from callbacks originating in native window code. They are expected to hand us comparison values which are pulled from general storage in the native widget, and may not correspond to an nsIWidget at all. For that reason this interface requires only objects one step removed from the native window (nsIWidgets), and its implementation must be very understanding of what may be completely invalid pointers in those parameters.

Parameters:
inWindowthe window in question
inPositionrequested position values: zLevelTop: topmost window. zLevelBottom: bottom. zLevelBelow: below ioBelow. (the value of ioBelow will be ignored for zLevelTop and Bottom.)
inBelowif inPosition==zLevelBelow, the window below which inWindow wants to be placed. Otherwise this variable is ignored.
outPositionconstrained position, values like inPosition.
outBelowif outPosition==zLevelBelow, the window below which inWindow should be placed. Otherwise this this value will be null.
Returns:
PR_TRUE if the position returned is different from the position given.
nsISimpleEnumerator nsIWindowMediator::getEnumerator ( in wstring  aWindowType) [inherited]

Return an enumerator which iterates over all windows of type aWindowType from the oldest window to the youngest.

Parameters:
aWindowTypethe returned enumerator will enumerate only windows of this type. ("type" is the |windowtype| attribute of the XML <window> element.) If null, all windows will be enumerated.
Returns:
an enumerator of nsIDOMWindows

Definition at line 189 of file nsWindowMediator.cpp.

{
  nsWindowInfo *info,
               *listEnd;

  if (!aWindow)
    return 0;

  info = mOldestWindow;
  listEnd = 0;
  while (info != listEnd) {
    if (info->mWindow.get() == aWindow)
      return info;
    info = info->mYounger;
    listEnd = mOldestWindow;
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 209 of file nsWindowMediator.cpp.

{
  nsWindowInfo *info,
               *listEnd;

  if (!aWindow)
    return 0;

  info = mOldestWindow;
  listEnd = 0;

  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;
  }
  return 0;
}

Here is the call graph for this function:

nsIDOMWindowInternal nsIWindowMediator::getMostRecentWindow ( in wstring  aWindowType) [inherited]

This is a shortcut for simply fetching the first window in front to back order.

Parameters:
aWindowTypereturn the topmost window of this type. ("type" is the |windowtype| attribute of the XML <window> element.) If null, return the topmost window of any type.
Returns:
the topmost window

Identical to getEnumerator except:

Returns:
an enumerator of nsIXULWindows

Return the window's Z level (as defined in nsIXULWindow).

Parameters:
aWindowthe window in question
Returns:
aWindow's z level
nsISimpleEnumerator nsIWindowMediator::getZOrderDOMWindowEnumerator ( in wstring  aWindowType,
in boolean  aFrontToBack 
) [inherited]

Return an enumerator which iterates over all windows of type aWindowType in their z (front-to-back) order.

Note this interface makes no requirement that a window couldn't be revisited if windows are re-ordered while z-order enumerators are active.

Parameters:
aWindowTypethe returned enumerator will enumerate only windows of this type. ("type" is the |windowtype| attribute of the XML <window> element.) If null, all windows will be enumerated.
aFrontToBackif true, the enumerator enumerates windows in order from front to back. back to front if false.
Returns:
an enumerator of nsIDOMWindows
nsISimpleEnumerator nsIWindowMediator::getZOrderXULWindowEnumerator ( in wstring  aWindowType,
in boolean  aFrontToBack 
) [inherited]

Identical to getZOrderDOMWindowEnumerator except:

Returns:
an enumerator of nsIXULWindows

Definition at line 799 of file nsWindowMediator.cpp.

{
  if (gRefCnt++ == 0)
  {
    mListLock = PR_NewLock();
    if (!mListLock)
        return NS_ERROR_OUT_OF_MEMORY;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 357 of file nsWindowMediator.cpp.

{
  PRInt32       lastTimeStamp = -1;
  nsAutoString  typeString(inType);
  PRBool        allWindows = !inType || typeString.IsEmpty();

  // Find the most window with the highest time stamp that matches
  // the requested type
  nsWindowInfo *searchInfo,
               *listEnd,
               *foundInfo = 0;

  searchInfo = mOldestWindow;
  listEnd = 0;
  while (searchInfo != listEnd) {
    if ((allWindows || searchInfo->TypeEquals(typeString)) &&
        searchInfo->mTimeStamp >= lastTimeStamp) {

      foundInfo = searchInfo;
      lastTimeStamp = searchInfo->mTimeStamp;
    }
    searchInfo = searchInfo->mYounger;
    listEnd = mOldestWindow;
  }
  return foundInfo;
}

Here is the call graph for this function:

Add the window to the list of known windows.

Listeners (see addListener) will be notified through their onOpenWindow method.

Parameters:
aWindowthe window to add

Definition at line 318 of file nsWindowMediator.cpp.

{
  return mEnumeratorList.RemoveElement(inEnumerator);
}

Here is the caller graph for this function:

Unregister a listener of window status changes.

Parameters:
aListenerthe listener to unregister
void nsIWindowMediator::setZLevel ( in nsIXULWindow  aWindow,
in PRUint32  aZLevel 
) [inherited]

Set the window's Z level (as defined in nsIXULWindow).

The implementation will reposition the window as necessary to match its new Z level. The implementation will assume a window's Z level to be nsIXULWindow::normalZ until it has been informed of a different level.

Parameters:
aWindowthe window in question
aZLevelthe window's new Z level
void nsIWindowMediator::setZPosition ( in nsIXULWindow  inWindow,
in unsigned long  inPosition,
in nsIXULWindow  inBelow 
) [inherited]

A window has been positioned behind another.

Inform WindowMediator

Parameters:
inWindowthe window in question
inPositionnew position. values: zLevelTop: topmost window. zLevelBottom: bottom. zLevelBelow: below inBelow. (inBelow is ignored for other values of inPosition.)
inBelowthe window inWindow is behind, if zLevelBelow

Definition at line 734 of file nsWindowMediator.cpp.

                                        {

  nsWindowInfo *scan,   // scans list looking for problems
               *search, // searches for correct placement for scan window
               *lowest; // bottom-most window in list
  PRBool       finished;

  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;
        do
          search = search->mHigher;
        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);
        }
        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;
}

Here is the call graph for this function:

Definition at line 675 of file nsWindowMediator.cpp.

                                        {

  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
  PRBool       finished;

  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);
        scan->InsertAfter(0, prev);

        // 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;
}

Here is the call graph for this function:

Definition at line 149 of file nsWindowMediator.cpp.

{
  nsAutoLock lock(mListLock);
  nsWindowInfo *info = GetInfoFor(inWindow);
  if (info)
    return UnregisterWindow(info);
  return NS_ERROR_INVALID_ARG;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Remove the window from the list of known windows.

Listeners (see addListener) will be be notified through their onCloseWindow method.

Parameters:
aWindowthe window to remove

Call this method when a window gains focus.

It's a primitive means of determining the most recent window. It's no longer necessary and it really should be removed.

Parameters:
aWindowthe window which has gained focus
void nsIWindowMediator::updateWindowTitle ( in nsIXULWindow  aWindow,
in wstring  inTitle 
) [inherited]

Call this method when a window's title changes.

Listeners (see addListener) will be notified through their onWindowTitleChange method.

Parameters:
aWindowthe window whose title has changed
inTitlethe window's new title

Friends And Related Function Documentation

friend class nsAppShellWindowEnumerator [friend]

Definition at line 60 of file nsWindowMediator.h.

friend class nsASDOMWindowBackToFrontEnumerator [friend]

Definition at line 65 of file nsWindowMediator.h.

friend class nsASDOMWindowEarlyToLateEnumerator [friend]

Definition at line 62 of file nsWindowMediator.h.

friend class nsASDOMWindowFrontToBackEnumerator [friend]

Definition at line 63 of file nsWindowMediator.h.

friend class nsASXULWindowBackToFrontEnumerator [friend]

Definition at line 66 of file nsWindowMediator.h.

friend class nsASXULWindowEarlyToLateEnumerator [friend]

Definition at line 61 of file nsWindowMediator.h.

friend class nsASXULWindowFrontToBackEnumerator [friend]

Definition at line 64 of file nsWindowMediator.h.


Member Data Documentation

PRInt32 nsWindowMediator::gRefCnt = 0 [static, private]

Definition at line 98 of file nsWindowMediator.h.

Definition at line 90 of file nsWindowMediator.h.

Definition at line 96 of file nsWindowMediator.h.

Definition at line 95 of file nsWindowMediator.h.

Definition at line 91 of file nsWindowMediator.h.

Definition at line 94 of file nsWindowMediator.h.

Definition at line 93 of file nsWindowMediator.h.

Definition at line 91 of file nsWindowMediator.h.

const unsigned long nsIWindowMediator::zLevelBelow = 3 [inherited]

Definition at line 134 of file nsIWindowMediator.idl.

const unsigned long nsIWindowMediator::zLevelBottom = 2 [inherited]

Definition at line 133 of file nsIWindowMediator.idl.

const unsigned long nsIWindowMediator::zLevelTop = 1 [inherited]

Definition at line 132 of file nsIWindowMediator.idl.


The documentation for this class was generated from the following files: