Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsAppShellService Class Reference

#include <nsAppShellService.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIAPPSHELLSERVICE
NS_DECL_NSIOBSERVER 
nsAppShellService ()
nsIXULWindow createTopLevelWindow (in nsIXULWindow aParent, in nsIURI aUrl, in PRUint32 aChromeMask, in long aInitialWidth, in long aInitialHeight, in nsIAppShell aAppShell)
void createHiddenWindow (in nsIAppShell aAppShell)
void destroyHiddenWindow ()
void getHiddenWindowAndJSContext (out nsIDOMWindowInternal aHiddenDOMWindow, out JSContext aJSContext)
 Return the (singleton) application hidden window as an nsIDOMWindowInternal, and, the corresponding JavaScript context pointer.
void registerTopLevelWindow (in nsIXULWindow aWindow)
 Add a window to the application's registry of windows.
void unregisterTopLevelWindow (in nsIXULWindow aWindow)
 Remove a window from the application's window registry.
void topLevelWindowIsModal (in nsIXULWindow aWindow, in boolean aModal)
 The appshell service needs to be informed of modal XUL windows currently open.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Public Attributes

const long SIZE_TO_CONTENT = -1
 Create a window, which will be initially invisible.
readonly attribute nsIXULWindow hiddenWindow
 Return the (singleton) application hidden window, automatically created and maintained by this AppShellService.
readonly attribute
nsIDOMWindowInternal 
hiddenDOMWindow
 Return the (singleton) application hidden window, automatically created and maintained by this AppShellService.

Protected Member Functions

 ~nsAppShellService ()
nsresult JustCreateTopWindow (nsIXULWindow *aParent, nsIURI *aUrl, PRUint32 aChromeMask, PRInt32 aInitialWidth, PRInt32 aInitialHeight, PRBool aIsHiddenWindow, nsIAppShell *aAppShell, nsWebShellWindow **aResult)
PRUint32 CalculateWindowZLevel (nsIXULWindow *aParent, PRUint32 aChromeMask)
nsresult SetXPConnectSafeContext ()
nsresult ClearXPConnectSafeContext ()

Protected Attributes

nsRefPtr< nsWebShellWindowmHiddenWindow
PRPackedBool mXPCOMShuttingDown
PRUint16 mModalWindowCount

Detailed Description

Definition at line 53 of file nsAppShellService.h.


Constructor & Destructor Documentation

Definition at line 84 of file nsAppShellService.cpp.

                                     : 
  mXPCOMShuttingDown(PR_FALSE),
  mModalWindowCount(0)
{
  nsCOMPtr<nsIObserverService> obs
    (do_GetService("@mozilla.org/observer-service;1"));

  if (obs)
    obs->AddObserver(this, "xpcom-shutdown", PR_FALSE);
}

Here is the call graph for this function:

Definition at line 95 of file nsAppShellService.cpp.

{
}

Member Function Documentation

PRUint32 nsAppShellService::CalculateWindowZLevel ( nsIXULWindow aParent,
PRUint32  aChromeMask 
) [protected]

Definition at line 247 of file nsAppShellService.cpp.

{
  PRUint32 zLevel;

  zLevel = nsIXULWindow::normalZ;
  if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RAISED)
    zLevel = nsIXULWindow::raisedZ;
  else if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_LOWERED)
    zLevel = nsIXULWindow::loweredZ;

#if defined(XP_MAC) || defined(XP_MACOSX)
  /* Platforms on which modal windows are always application-modal, not
     window-modal (that's just the Mac, right?) want modal windows to
     be stacked on top of everyone else.

     On Mac OS X, bind modality to parent window instead of app (ala Mac OS 9)
  */
  PRUint32 modalDepMask = nsIWebBrowserChrome::CHROME_MODAL |
                          nsIWebBrowserChrome::CHROME_DEPENDENT;
  if (aParent && (aChromeMask & modalDepMask)) {
    aParent->GetZLevel(&zLevel);
  }
#else
  /* Platforms with native support for dependent windows (that's everyone
      but pre-Mac OS X, right?) know how to stack dependent windows. On these
      platforms, give the dependent window the same level as its parent,
      so we won't try to override the normal platform behaviour. */
  if ((aChromeMask & nsIWebBrowserChrome::CHROME_DEPENDENT) && aParent)
    aParent->GetZLevel(&zLevel);
#endif

  return zLevel;
}

Definition at line 124 of file nsAppShellService.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIThreadJSContextStack> cxstack =
    do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
  if (NS_FAILED(rv)) {
    NS_ERROR("XPConnect ContextStack gone before XPCOM shutdown?");
    return rv;
  }

  nsCOMPtr<nsIDOMWindowInternal> junk;
  JSContext *cx;
  rv = GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx);
  NS_ENSURE_SUCCESS(rv, rv);

  JSContext *safe_cx;
  rv = cxstack->GetSafeJSContext(&safe_cx);
  NS_ENSURE_SUCCESS(rv, rv);

  if (cx == safe_cx)
    rv = cxstack->SetSafeJSContext(nsnull);

  return rv;
}

Here is the call graph for this function:

nsIXULWindow nsIAppShellService::createTopLevelWindow ( in nsIXULWindow  aParent,
in nsIURI  aUrl,
in PRUint32  aChromeMask,
in long  aInitialWidth,
in long  aInitialHeight,
in nsIAppShell  aAppShell 
) [inherited]
void nsIAppShellService::getHiddenWindowAndJSContext ( out nsIDOMWindowInternal  aHiddenDOMWindow,
out JSContext  aJSContext 
) [inherited]

Return the (singleton) application hidden window as an nsIDOMWindowInternal, and, the corresponding JavaScript context pointer.

This is useful if you'd like to subsequently call OpenDialog on the hidden window. the hidden window QI'd to type nsIDOMWindowInternal the corresponding JavaScript context

nsresult nsAppShellService::JustCreateTopWindow ( nsIXULWindow aParent,
nsIURI aUrl,
PRUint32  aChromeMask,
PRInt32  aInitialWidth,
PRInt32  aInitialHeight,
PRBool  aIsHiddenWindow,
nsIAppShell aAppShell,
nsWebShellWindow **  aResult 
) [protected]

Definition at line 286 of file nsAppShellService.cpp.

{
  *aResult = nsnull;

  nsRefPtr<nsWebShellWindow> window = new nsWebShellWindow();
  NS_ENSURE_TRUE(window, NS_ERROR_OUT_OF_MEMORY);

  nsWidgetInitData widgetInitData;

  if (aIsHiddenWindow)
    widgetInitData.mWindowType = eWindowType_invisible;
  else
    widgetInitData.mWindowType = aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG ?
      eWindowType_dialog : eWindowType_toplevel;

  if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_POPUP)
    widgetInitData.mWindowType = eWindowType_popup;

#ifdef XP_MACOSX
  // Mac OS X sheet support
  PRUint32 sheetMask = nsIWebBrowserChrome::CHROME_OPENAS_DIALOG |
    nsIWebBrowserChrome::CHROME_MODAL;
  if (aParent && ((aChromeMask & sheetMask) == sheetMask))
    widgetInitData.mWindowType = eWindowType_sheet;
#endif

  widgetInitData.mContentType = eContentTypeUI;                

  // note default chrome overrides other OS chrome settings, but
  // not internal chrome
  if (aChromeMask & nsIWebBrowserChrome::CHROME_DEFAULT)
    widgetInitData.mBorderStyle = eBorderStyle_default;
  else if ((aChromeMask & nsIWebBrowserChrome::CHROME_ALL) == nsIWebBrowserChrome::CHROME_ALL)
    widgetInitData.mBorderStyle = eBorderStyle_all;
  else {
    widgetInitData.mBorderStyle = eBorderStyle_none; // assumes none == 0x00
    if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_BORDERS)
      widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_border);
    if (aChromeMask & nsIWebBrowserChrome::CHROME_TITLEBAR)
      widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_title);
    if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_CLOSE)
      widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_close);
    if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) {
      widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_resizeh);
      // only resizable windows get the maximize button (but not dialogs)
      if (!(aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
        widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_maximize);
    }
    // all windows (except dialogs) get minimize buttons and the system menu
    if (!(aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
      widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_minimize | eBorderStyle_menu);
    // but anyone can explicitly ask for a minimize button
    if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_MIN) {
      widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_minimize );
    }  
  }

  if (aInitialWidth == nsIAppShellService::SIZE_TO_CONTENT ||
      aInitialHeight == nsIAppShellService::SIZE_TO_CONTENT) {
    aInitialWidth = 1;
    aInitialHeight = 1;
    window->SetIntrinsicallySized(PR_TRUE);
  }

  nsresult rv = window->Initialize(aParent, aAppShell, aUrl,
                                   aInitialWidth, aInitialHeight,
                                   aIsHiddenWindow, widgetInitData);
      
  NS_ENSURE_SUCCESS(rv, rv);

  window.swap(*aResult); // transfer reference
  if (aParent)
    aParent->AddChildWindow(*aResult);

  if (aChromeMask & nsIWebBrowserChrome::CHROME_CENTER_SCREEN)
    rv = (*aResult)->Center(aParent, aParent ? PR_FALSE : PR_TRUE, PR_FALSE);

  return rv;
}

Here is the call graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Add a window to the application's registry of windows.

These windows are generally shown in the Windows taskbar, and the application knows it can't quit until it's out of registered windows.

Parameters:
aWindowthe window to register
Note:
When this method is successful, it fires the global notification "xul-window-registered"

The appshell service needs to be informed of modal XUL windows currently open.

Call this method as a window becomes modal or as it becomes nonmodal.

Parameters:
aWindowno surprises here
aModaltrue if aWindow is becoming modal false if aWindow is becoming nonmodal (or being closed)

Remove a window from the application's window registry.

Note that this method won't automatically attempt to quit the app when the last window is unregistered. For that, see Quit().

Parameters:
aWindowyou see the pattern

Member Data Documentation

Return the (singleton) application hidden window, automatically created and maintained by this AppShellService.

Parameters:
aResultthe hidden window. Do not unhide hidden window. Do not taunt hidden window.

Definition at line 100 of file nsIAppShellService.idl.

Return the (singleton) application hidden window, automatically created and maintained by this AppShellService.

Parameters:
aResultthe hidden window. Do not unhide hidden window. Do not taunt hidden window.

Definition at line 92 of file nsIAppShellService.idl.

Definition at line 76 of file nsAppShellService.h.

Definition at line 78 of file nsAppShellService.h.

Definition at line 77 of file nsAppShellService.h.

Create a window, which will be initially invisible.

Parameters:
aParentthe parent window. Can be null.
aUrlthe contents of the new window.
aChromeMaskchrome flags affecting the kind of OS border given to the window. see nsIBrowserWindow for bit/flag definitions.
aCallbacksinterface providing C++ hooks for window initialization before the window is made visible. Can be null. Deprecated.
aInitialWidthwidth, in pixels, of the window. Width of window at creation. Can be overridden by the "width" tag in the XUL. Set to NS_SIZETOCONTENT to force the window to wrap to its contents.
aInitialHeightlike aInitialWidth, but subtly different.
aAppShella widget "appshell" (event processor) to associate with the new window
aResultthe newly created window is returned here.

Definition at line 73 of file nsIAppShellService.idl.


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