From 890eacaa0753a839ed4ad1270e186f289d6427b6 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Sat, 19 Feb 2005 22:42:01 +0000 Subject: [PATCH] Clean up xpfe/appshell, removing nsIWebShellWindow in the process. Bug 282200, r=danm, sr=bzbarsky. --- mailnews/base/util/nsMsgIncomingServer.cpp | 1 - .../components/startup/src/nsAppStartup.cpp | 8 +- toolkit/xre/nsCommandLineServiceMac.cpp | 1 - xpcom/tests/SizeTest06.cpp | 28 +- xpfe/appshell/public/Makefile.in | 1 - xpfe/appshell/public/nsIAppShellService.idl | 15 +- xpfe/appshell/public/nsIWebShellWindow.h | 0 xpfe/appshell/src/nsAppShellService.cpp | 254 +++--- xpfe/appshell/src/nsAppShellService.h | 18 +- xpfe/appshell/src/nsWebShellWindow.cpp | 863 ++---------------- xpfe/appshell/src/nsWebShellWindow.h | 84 +- xpfe/appshell/src/nsXULWindow.cpp | 34 +- xpfe/appshell/src/nsXULWindow.h | 6 +- xpfe/bootstrap/appleevents/nsWindowUtils.cpp | 1 - xpfe/browser/src/nsBrowserInstance.cpp | 1 - xpfe/components/startup/src/nsAppStartup.cpp | 8 +- .../startup/src/nsCommandLineServiceMac.cpp | 1 - 17 files changed, 241 insertions(+), 1083 deletions(-) delete mode 100644 xpfe/appshell/public/nsIWebShellWindow.h diff --git a/mailnews/base/util/nsMsgIncomingServer.cpp b/mailnews/base/util/nsMsgIncomingServer.cpp index 64f1bcd7833..7144dd24ae8 100644 --- a/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mailnews/base/util/nsMsgIncomingServer.cpp @@ -62,7 +62,6 @@ #include "nsIMsgMailSession.h" #include "nsIPrefService.h" #include "nsIDocShell.h" -#include "nsIWebShellWindow.h" #include "nsIAuthPrompt.h" #include "nsIObserverService.h" #include "nsNetUtil.h" diff --git a/toolkit/components/startup/src/nsAppStartup.cpp b/toolkit/components/startup/src/nsAppStartup.cpp index 289441d1e32..ac2a0a008b4 100644 --- a/toolkit/components/startup/src/nsAppStartup.cpp +++ b/toolkit/components/startup/src/nsAppStartup.cpp @@ -57,7 +57,6 @@ #include "nsISupportsPrimitives.h" #include "nsITimelineService.h" #include "nsIWebBrowserChrome.h" -#include "nsIWebShellWindow.h" #include "nsIWindowMediator.h" #include "nsIWindowWatcher.h" #include "nsIXULWindow.h" @@ -433,9 +432,10 @@ nsAppStartup::CreateChromeWindow2(nsIWebBrowserChrome *aParent, if (!appShell) return NS_ERROR_FAILURE; - appShell->CreateTopLevelWindow(0, 0, PR_FALSE, PR_FALSE, - aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, mAppShell, getter_AddRefs(newWindow)); + appShell->CreateTopLevelWindow(0, 0, aChromeFlags, + nsIAppShellService::SIZE_TO_CONTENT, + nsIAppShellService::SIZE_TO_CONTENT, + mAppShell, getter_AddRefs(newWindow)); } // if anybody gave us anything to work with, use it diff --git a/toolkit/xre/nsCommandLineServiceMac.cpp b/toolkit/xre/nsCommandLineServiceMac.cpp index 7d2263c1618..2aeead84007 100644 --- a/toolkit/xre/nsCommandLineServiceMac.cpp +++ b/toolkit/xre/nsCommandLineServiceMac.cpp @@ -53,7 +53,6 @@ #include "nsIURL.h" #include "nsIServiceManager.h" #include "nsNetCID.h" -#include "nsIWebShellWindow.h" #include "nsIDOMWindow.h" #include "nsXPCOM.h" #include "nsISupportsPrimitives.h" diff --git a/xpcom/tests/SizeTest06.cpp b/xpcom/tests/SizeTest06.cpp index bfc0b97f189..d6eb327b2a4 100644 --- a/xpcom/tests/SizeTest06.cpp +++ b/xpcom/tests/SizeTest06.cpp @@ -3,11 +3,11 @@ #include "nsIDOMWindowInternal.h" #include "nsIScriptGlobalObject.h" #include "nsIDocShell.h" -#include "nsIWebShellWindow.h" +#include "nsIBaseWindow.h" #include "nsCOMPtr.h" NS_DEF_PTR(nsIScriptGlobalObject); -NS_DEF_PTR(nsIWebShellWindow); +NS_DEF_PTR(nsIBaseWindow); /* Windows: @@ -35,7 +35,7 @@ NS_DEF_PTR(nsIWebShellWindow); void // nsresult -Test06_raw(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShellWindow) +Test06_raw(nsIDOMWindowInternal* aDOMWindow, nsIBaseWindow** aBaseWindow) // m388, w214 { // if (!aDOMWindow) @@ -53,12 +53,12 @@ Test06_raw(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShellWindow } void // nsresult -Test06_raw_optimized(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShellWindow) +Test06_raw_optimized(nsIDOMWindowInternal* aDOMWindow, nsIBaseWindow** aBaseWindow) // m332, w191 { // if (!aDOMWindow) // return NS_ERROR_NULL_POINTER; - (*aWebShellWindow) = 0; + (*aBaseWindow) = 0; nsIScriptGlobalObject* scriptGlobalObject; nsresult status = aDOMWindow->QueryInterface(NS_GET_IID(nsIScriptGlobalObject), (void**)&scriptGlobalObject); if (NS_SUCCEEDED(status)) { @@ -73,7 +73,7 @@ Test06_raw_optimized(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebS } void -Test06_nsCOMPtr_as_found(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr* aWebShellWindow) +Test06_nsCOMPtr_as_found(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr* aBaseWindow) // m344, w181/201 { // if (!aDOMWindow) @@ -85,7 +85,7 @@ Test06_nsCOMPtr_as_found(nsIDOMWindowInternal* aDOMWindow, nsCOMPtrGetDocShell(&temp0); nsCOMPtr docShell = dont_AddRef(temp0); - (*aWebShellWindow) = 0; + (*aBaseWindow) = 0; // return status; } void // nsresult -Test06_nsCOMPtr_optimized(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr* aWebShellWindow) +Test06_nsCOMPtr_optimized(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr* aBaseWindow) // m300, w176/182 { // if (!aDOMWindow) @@ -111,17 +111,17 @@ Test06_nsCOMPtr_optimized(nsIDOMWindowInternal* aDOMWindow, nsCOMPtrGetDocShell(&temp0); - (*aWebShellWindow) = do_QueryInterface(nsnull, &status); + (*aBaseWindow) = do_QueryInterface(nsnull, &status); // return status; } void // nsresult -Test06_nsCOMPtr02(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShellWindow) +Test06_nsCOMPtr02(nsIDOMWindowInternal* aDOMWindow, nsIBaseWindow** aBaseWindow) // m320, w187/184 { // if (!aDOMWindow) // return NS_ERROR_NULL_POINTER; - (*aWebShellWindow) = 0; + (*aBaseWindow) = 0; nsresult status; nsCOMPtr scriptGlobalObject = do_QueryInterface(aDOMWindow, &status); if (scriptGlobalObject) { @@ -132,12 +132,12 @@ Test06_nsCOMPtr02(nsIDOMWindowInternal* aDOMWindow, nsIWebShellWindow** aWebShel } void // nsresult -Test06_nsCOMPtr03(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr* aWebShellWindow) +Test06_nsCOMPtr03(nsIDOMWindowInternal* aDOMWindow, nsCOMPtr* aBaseWindow) // m332, w189/188 { // if (!aDOMWindow) // return NS_ERROR_NULL_POINTER; - (*aWebShellWindow) = 0; + (*aBaseWindow) = 0; nsresult status; nsCOMPtr scriptGlobalObject = do_QueryInterface(aDOMWindow, &status); if (scriptGlobalObject) { diff --git a/xpfe/appshell/public/Makefile.in b/xpfe/appshell/public/Makefile.in index 159483eceb1..e755e796881 100644 --- a/xpfe/appshell/public/Makefile.in +++ b/xpfe/appshell/public/Makefile.in @@ -47,7 +47,6 @@ XPIDL_MODULE = appshell GRE_MODULE = 1 EXPORTS = \ - nsIWebShellWindow.h \ nsAppShellCID.h \ $(NULL) diff --git a/xpfe/appshell/public/nsIAppShellService.idl b/xpfe/appshell/public/nsIAppShellService.idl index d20beed3b0b..65416fbf8b3 100644 --- a/xpfe/appshell/public/nsIAppShellService.idl +++ b/xpfe/appshell/public/nsIAppShellService.idl @@ -48,16 +48,13 @@ interface nsIAppShell; struct JSContext; %} -[scriptable, uuid(70c04d53-150f-450b-9106-387487a3c031)] +[scriptable, uuid(93a28ba2-7e22-11d9-9b6f-000a95d535fa)] interface nsIAppShellService : nsISupports { /** - * Create a window. + * Create a window, which will be initially invisible. * @param aParent the parent window. Can be null. * @param aUrl the contents of the new window. - * @param aShowWindow the window remains invisible if PR_FALSE. - * @param aLoadDefaultPage controls whether the window should try to - * load a default content page on its own. * @param aChromeMask chrome flags affecting the kind of OS border * given to the window. see nsIBrowserWindow for * bit/flag definitions. @@ -76,19 +73,11 @@ interface nsIAppShellService : nsISupports const long SIZE_TO_CONTENT = -1; nsIXULWindow createTopLevelWindow(in nsIXULWindow aParent, in nsIURI aUrl, - in boolean aShowWindow, - in boolean aLoadDefaultPage, in PRUint32 aChromeMask, in long aInitialWidth, in long aInitialHeight, in nsIAppShell aAppShell); - /** - * Close a window. - * @param aWindow a window. - */ - void closeTopLevelWindow(in nsIXULWindow aWindow); - [noscript] void createHiddenWindow(in nsIAppShell aAppShell); diff --git a/xpfe/appshell/public/nsIWebShellWindow.h b/xpfe/appshell/public/nsIWebShellWindow.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/xpfe/appshell/src/nsAppShellService.cpp b/xpfe/appshell/src/nsAppShellService.cpp index 5c40dadb8f0..64a63c19982 100644 --- a/xpfe/appshell/src/nsAppShellService.cpp +++ b/xpfe/appshell/src/nsAppShellService.cpp @@ -57,7 +57,6 @@ #include "nsIWindowWatcher.h" #include "nsPIWindowWatcher.h" #include "nsIDOMWindowInternal.h" -#include "nsIWebShellWindow.h" #include "nsWebShellWindow.h" #include "nsIEnumerator.h" @@ -170,50 +169,43 @@ nsAppShellService::CreateHiddenWindow(nsIAppShell* aAppShell) nsCOMPtr url; rv = NS_NewURI(getter_AddRefs(url), hiddenWindowURL); - if (NS_SUCCEEDED(rv)) - { - nsCOMPtr newWindow; - rv = JustCreateTopWindow(nsnull, url, PR_FALSE, PR_FALSE, - chromeMask, initialWidth, initialHeight, - PR_TRUE, aAppShell, getter_AddRefs(newWindow)); - if (NS_SUCCEEDED(rv)) { - mHiddenWindow = newWindow; + NS_ENSURE_SUCCESS(rv, rv); + + nsRefPtr newWindow; + rv = JustCreateTopWindow(nsnull, url, + chromeMask, initialWidth, initialHeight, + PR_TRUE, aAppShell, getter_AddRefs(newWindow)); + NS_ENSURE_SUCCESS(rv, rv); + + mHiddenWindow.swap(newWindow); #if defined(XP_MAC) || defined(XP_MACOSX) - // hide the hidden window by launching it into outer space. This - // way, we can keep it visible and let the OS send it activates - // to keep menus happy. This will cause it to show up in window - // lists under osx, but I think that's ok. - nsCOMPtr base ( do_QueryInterface(newWindow) ); - if ( base ) { - base->SetPosition ( -32000, -32000 ); - base->SetVisibility ( PR_TRUE ); - } + // hide the hidden window by launching it into outer space. This + // way, we can keep it visible and let the OS send it activates + // to keep menus happy. This will cause it to show up in window + // lists under osx, but I think that's ok. + mHiddenWindow->SetPosition ( -32000, -32000 ); + mHiddenWindow->SetVisibility ( PR_TRUE ); #endif - - // Set XPConnect's fallback JSContext (used for JS Components) - // to the DOM JSContext for this thread, so that DOM-to-XPConnect - // conversions get the JSContext private magic they need to - // succeed. - SetXPConnectSafeContext(); - // RegisterTopLevelWindow(newWindow); -- Mac only - } - } - NS_ASSERTION(NS_SUCCEEDED(rv), "HiddenWindow not created"); - return(rv); + // Set XPConnect's fallback JSContext (used for JS Components) + // to the DOM JSContext for this thread, so that DOM-to-XPConnect + // conversions get the JSContext private magic they need to + // succeed. + SetXPConnectSafeContext(); + + // RegisterTopLevelWindow(newWindow); -- Mac only + + return NS_OK; } NS_IMETHODIMP nsAppShellService::DestroyHiddenWindow() { if (mHiddenWindow) { - nsCOMPtr hiddenWin(do_QueryInterface(mHiddenWindow)); - NS_ASSERTION(hiddenWin, "Hidden window is not nsIWebShellWindow!"); - if (hiddenWin) { - ClearXPConnectSafeContext(); - hiddenWin->Close(); - } + ClearXPConnectSafeContext(); + mHiddenWindow->Destroy(); + mHiddenWindow = nsnull; } @@ -225,19 +217,22 @@ nsAppShellService::DestroyHiddenWindow() */ NS_IMETHODIMP nsAppShellService::CreateTopLevelWindow(nsIXULWindow *aParent, - nsIURI *aUrl, - PRBool aShowWindow, PRBool aLoadDefaultPage, - PRUint32 aChromeMask, - PRInt32 aInitialWidth, PRInt32 aInitialHeight, - nsIAppShell* aAppShell, - nsIXULWindow **aResult) + nsIURI *aUrl, + PRUint32 aChromeMask, + PRInt32 aInitialWidth, + PRInt32 aInitialHeight, + nsIAppShell* aAppShell, + nsIXULWindow **aResult) { nsresult rv; - rv = JustCreateTopWindow(aParent, aUrl, aShowWindow, aLoadDefaultPage, - aChromeMask, aInitialWidth, aInitialHeight, - PR_FALSE, aAppShell, aResult); + nsWebShellWindow *newWindow = nsnull; + rv = JustCreateTopWindow(aParent, aUrl, + aChromeMask, aInitialWidth, aInitialHeight, + PR_FALSE, aAppShell, &newWindow); // addrefs + + *aResult = newWindow; // transfer ref if (NS_SUCCEEDED(rv)) { // the addref resulting from this is the owning addref for this window @@ -287,114 +282,94 @@ nsAppShellService::CalculateWindowZLevel(nsIXULWindow *aParent, /* * Just do the window-making part of CreateTopLevelWindow */ -NS_IMETHODIMP +nsresult nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent, - nsIURI *aUrl, - PRBool aShowWindow, PRBool aLoadDefaultPage, - PRUint32 aChromeMask, - PRInt32 aInitialWidth, PRInt32 aInitialHeight, - PRBool aIsHiddenWindow, nsIAppShell* aAppShell, - nsIXULWindow **aResult) + nsIURI *aUrl, + PRUint32 aChromeMask, + PRInt32 aInitialWidth, + PRInt32 aInitialHeight, + PRBool aIsHiddenWindow, + nsIAppShell* aAppShell, + nsWebShellWindow **aResult) { - nsresult rv; - nsWebShellWindow* window; - PRBool intrinsicallySized; - *aResult = nsnull; - intrinsicallySized = PR_FALSE; - window = new nsWebShellWindow(); - // Bump count to one so it doesn't die on us while doing init. - nsCOMPtr tempRef(window); - if (!window) - rv = NS_ERROR_OUT_OF_MEMORY; - else { - nsWidgetInitData widgetInitData; - if (aIsHiddenWindow) - widgetInitData.mWindowType = eWindowType_invisible; - else - widgetInitData.mWindowType = aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG ? - eWindowType_dialog : eWindowType_toplevel; + nsRefPtr window = new nsWebShellWindow(); + NS_ENSURE_TRUE(window, NS_ERROR_OUT_OF_MEMORY); - if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_POPUP) - widgetInitData.mWindowType = eWindowType_popup; + 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; - } + // 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 + 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_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 ); - } + widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_maximize); } - - if (aInitialWidth == nsIAppShellService::SIZE_TO_CONTENT || - aInitialHeight == nsIAppShellService::SIZE_TO_CONTENT) { - aInitialWidth = 1; - aInitialHeight = 1; - intrinsicallySized = PR_TRUE; - window->SetIntrinsicallySized(PR_TRUE); - } - - rv = window->Initialize(aParent, aAppShell, aUrl, - aShowWindow, aLoadDefaultPage, - aInitialWidth, aInitialHeight, aIsHiddenWindow, widgetInitData); - - if (NS_SUCCEEDED(rv)) { - - // this does the AddRef of the return value - rv = CallQueryInterface(NS_STATIC_CAST(nsIWebShellWindow*, window), aResult); - if (aParent) - aParent->AddChildWindow(*aResult); - } - - if (aChromeMask & nsIWebBrowserChrome::CHROME_CENTER_SCREEN) - window->Center(aParent, aParent ? PR_FALSE : PR_TRUE, PR_FALSE); + // 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; } - -NS_IMETHODIMP -nsAppShellService::CloseTopLevelWindow(nsIXULWindow* aWindow) -{ - nsCOMPtr webShellWin(do_QueryInterface(aWindow)); - NS_ENSURE_TRUE(webShellWin, NS_ERROR_FAILURE); - return webShellWin->Close(); -} - NS_IMETHODIMP nsAppShellService::GetHiddenWindow(nsIXULWindow **aWindow) { @@ -522,7 +497,7 @@ nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow) - notify the caller not to release the AppShellService after unregistering the window (we don't want to be deleted twice consecutively to - mHiddenWindow->Close() in our destructor) + mHiddenWindow->Destroy() in our destructor) */ return NS_ERROR_FAILURE; } @@ -567,10 +542,9 @@ nsAppShellService::Observe(nsISupports* aSubject, const char *aTopic, NS_ASSERTION(!strcmp(aTopic, "xpcom-shutdown"), "Unexpected observer topic!"); mXPCOMShuttingDown = PR_TRUE; - nsCOMPtr hiddenWin (do_QueryInterface(mHiddenWindow)); - if (hiddenWin) { + if (mHiddenWindow) { ClearXPConnectSafeContext(); - hiddenWin->Close(); + mHiddenWindow->Destroy(); } return NS_OK; diff --git a/xpfe/appshell/src/nsAppShellService.h b/xpfe/appshell/src/nsAppShellService.h index a5c3e524667..ee31907232b 100644 --- a/xpfe/appshell/src/nsAppShellService.h +++ b/xpfe/appshell/src/nsAppShellService.h @@ -42,8 +42,9 @@ #include "nsIObserver.h" //Interfaces Needed -#include "nsIXULWindow.h" +#include "nsWebShellWindow.h" #include "nsStringFwd.h" +#include "nsAutoPtr.h" // {0099907D-123C-4853-A46A-43098B5FB68C} #define NS_APPSHELLSERVICE_CID \ @@ -62,18 +63,17 @@ public: protected: ~nsAppShellService(); - NS_IMETHOD JustCreateTopWindow(nsIXULWindow *aParent, - nsIURI *aUrl, - PRBool aShowWindow, PRBool aLoadDefaultPage, - PRUint32 aChromeMask, - PRInt32 aInitialWidth, PRInt32 aInitialHeight, - PRBool aIsHiddenWindow, nsIAppShell* aAppShell, - nsIXULWindow **aResult); + 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(); - nsCOMPtr mHiddenWindow; + nsRefPtr mHiddenWindow; PRPackedBool mXPCOMShuttingDown; PRUint16 mModalWindowCount; }; diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 42201b37b44..77afb596aa7 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -144,28 +144,11 @@ static NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID); #include "nsWidgetsCID.h" static NS_DEFINE_CID(kMenuBarCID, NS_MENUBAR_CID); -static NS_DEFINE_CID(kMenuCID, NS_MENU_CID); -static NS_DEFINE_CID(kMenuItemCID, NS_MENUITEM_CID); - - -#ifdef DEBUG_rods -#define DEBUG_MENUSDEL 1 -#endif #define SIZE_PERSISTENCE_TIMEOUT 500 // msec -struct ThreadedWindowEvent { - PLEvent event; - nsWebShellWindow *window; -}; - nsWebShellWindow::nsWebShellWindow() : nsXULWindow() { - mWindow = nsnull; - mLockedUntilChromeLoad = PR_FALSE; - mIntrinsicallySized = PR_FALSE; - mDebuting = PR_FALSE; - mLoadDefaultPage = PR_TRUE; mSPTimerLock = PR_NewLock(); } @@ -189,26 +172,21 @@ NS_IMPL_ADDREF_INHERITED(nsWebShellWindow, nsXULWindow) NS_IMPL_RELEASE_INHERITED(nsWebShellWindow, nsXULWindow) NS_INTERFACE_MAP_BEGIN(nsWebShellWindow) - NS_INTERFACE_MAP_ENTRY(nsIWebShellWindow) - NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) - NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver) + NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_END_INHERITING(nsXULWindow) nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, nsIAppShell* aShell, nsIURI* aUrl, - PRBool aCreatedVisible, - PRBool aLoadDefaultPage, - PRInt32 aInitialWidth, PRInt32 aInitialHeight, - PRBool aIsHiddenWindow, nsWidgetInitData& widgetInitData) + PRInt32 aInitialWidth, + PRInt32 aInitialHeight, + PRBool aIsHiddenWindow, + nsWidgetInitData& widgetInitData) { nsresult rv; nsCOMPtr parentWidget; mIsHiddenWindow = aIsHiddenWindow; - mShowAfterLoad = aCreatedVisible; - mLoadDefaultPage = aLoadDefaultPage; - // XXX: need to get the default window size from prefs... // Doesn't come from prefs... will come from CSS/XUL/RDF nsRect r(0, 0, aInitialWidth, aInitialHeight); @@ -294,12 +272,13 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, /* * Toolbar */ -NS_METHOD +nsresult nsWebShellWindow::Toolbar() { - nsCOMPtr kungFuDeathGrip(this); + nsCOMPtr kungFuDeathGrip(this); nsCOMPtr wbc(do_GetInterface(kungFuDeathGrip)); - if (!wbc) return(PR_FALSE); + if (!wbc) + return NS_ERROR_UNEXPECTED; // rjc: don't use "nsIWebBrowserChrome::CHROME_EXTRA" // due to components with multiple sidebar components @@ -320,16 +299,6 @@ nsWebShellWindow::Toolbar() } -/* - * Close the window - */ -NS_METHOD -nsWebShellWindow::Close() -{ - return Destroy(); -} - - /* * Event handler function... * @@ -367,14 +336,13 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) break; } case NS_SIZE: { - PRBool chromeLock = PR_FALSE; nsSizeEvent* sizeEvent = (nsSizeEvent*)aEvent; nsCOMPtr shellAsWin(do_QueryInterface(docShell)); shellAsWin->SetPositionAndSize(0, 0, sizeEvent->windowSize->width, sizeEvent->windowSize->height, PR_FALSE); // persist size, but not immediately, in case this OS is firing // repeated size events as the user drags the sizing handle - if (NS_FAILED(eventWindow->GetLockedState(chromeLock)) || !chromeLock) + if (!eventWindow->IsLocked()) eventWindow->SetPersistenceTimer(PAD_SIZE | PAD_MISC); result = nsEventStatus_eConsumeNoDefault; break; @@ -412,23 +380,19 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) // minimizing the window vs. just clicking in a different window to cause // the deactivation. Bug #82534 if(modeEvent->mSizeMode == nsSizeMode_Minimized) { - nsCOMPtr domWindow; - eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow)); - if (domWindow) { - nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); - if(privateDOMWindow) { - nsIFocusController *focusController = - privateDOMWindow->GetRootFocusController(); - if (focusController) - focusController->RewindFocusState(); - } + nsCOMPtr privateDOMWindow = do_GetInterface(docShell); + if(privateDOMWindow) { + nsIFocusController *focusController = + privateDOMWindow->GetRootFocusController(); + if (focusController) + focusController->RewindFocusState(); } } #endif break; } case NS_OS_TOOLBAR: { - nsCOMPtr kungFuDeathGrip(eventWindow); + nsCOMPtr kungFuDeathGrip(eventWindow); eventWindow->Toolbar(); break; } @@ -437,16 +401,16 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) // (it probably shouldn't, but you never know what the users JS // code will do). Therefore we add a death-grip to the window // for the duration of the close handler. - nsCOMPtr kungFuDeathGrip(eventWindow); + nsCOMPtr kungFuDeathGrip(eventWindow); if (!eventWindow->ExecuteCloseHandler()) - eventWindow->Close(); + eventWindow->Destroy(); break; } /* * Notify the ApplicationShellService that the window is being closed... */ case NS_DESTROY: { - eventWindow->Close(); + eventWindow->Destroy(); break; } @@ -467,30 +431,11 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) #ifdef DEBUG_saari printf("nsWebShellWindow::NS_ACTIVATE\n"); #endif - nsCOMPtr domWindow; - eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow)); - /* - nsCOMPtr contentShell; - eventWindow->GetContentDocShell(getter_AddRefs(contentShell)); - if (contentShell) { - - if (NS_SUCCEEDED(eventWindow-> - ConvertDocShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) { - if(domWindow){ - nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); - if(privateDOMWindow) - privateDOMWindow->Activate(); - } - } - } - else */ - if (domWindow) { - nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); - if(privateDOMWindow) - privateDOMWindow->Activate(); - } - break; + nsCOMPtr privateDOMWindow = do_GetInterface(docShell); + if (privateDOMWindow) + privateDOMWindow->Activate(); + break; } case NS_DEACTIVATE: { @@ -498,32 +443,14 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) printf("nsWebShellWindow::NS_DEACTIVATE\n"); #endif - nsCOMPtr domWindow; - eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow)); - /* - nsCOMPtr contentShell; - eventWindow->GetContentDocShell(getter_AddRefs(contentShell)); - if (contentShell) { - - if (NS_SUCCEEDED(eventWindow-> - ConvertDocShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) { - if(domWindow){ - nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); - if(privateDOMWindow) - privateDOMWindow->Deactivate(); - } - } - } - else */ - if (domWindow) { - nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); - if(privateDOMWindow) { - nsIFocusController *focusController = - privateDOMWindow->GetRootFocusController(); - if (focusController) - focusController->SetActive(PR_FALSE); - privateDOMWindow->Deactivate(); - } + nsCOMPtr privateDOMWindow = do_GetInterface(docShell); + if (privateDOMWindow) { + nsIFocusController *focusController = + privateDOMWindow->GetRootFocusController(); + if (focusController) + focusController->SetActive(PR_FALSE); + + privateDOMWindow->Deactivate(); } break; } @@ -533,10 +460,8 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) printf("nsWebShellWindow::GOTFOCUS\n"); #endif nsCOMPtr domDocument; - nsCOMPtr domWindow; - eventWindow->ConvertDocShellToDOMWindow(docShell, getter_AddRefs(domWindow)); - nsCOMPtr piWin(do_QueryInterface(domWindow)); - if (!domWindow) { + nsCOMPtr piWin = do_GetInterface(docShell); + if (!piWin) { break; } nsIFocusController *focusController = piWin->GetRootFocusController(); @@ -557,9 +482,16 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) // It's possible for focusing the window to cause it to close. // To avoid holding a pointer to deleted memory, keep a reference // on eventWindow. -bryner - nsCOMPtr kungFuDeathGrip(eventWindow); + nsCOMPtr kungFuDeathGrip(eventWindow); focusController->SetSuppressFocus(PR_TRUE, "Activation Suppression"); + + nsCOMPtr domWindow = + do_QueryInterface(piWin); + + NS_ASSERTION(domWindow, + "windows must support nsIDOMWindowInternal"); + domWindow->Focus(); // This sets focus, but we'll ignore it. // A subsequent activate will cause us to stop suppressing. @@ -584,541 +516,35 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) return result; } -#if 0 //---------------------------------------- -NS_IMETHODIMP nsWebShellWindow::CreateMenu(nsIMenuBar * aMenuBar, - nsIDOMNode * aMenuNode, - nsString & aMenuName) +void nsWebShellWindow::LoadNativeMenus(nsIDOMDocument *aDOMDoc, + nsIWidget *aParentWindow) { - // Create nsMenu - nsIMenu * pnsMenu = nsnull; - nsresult rv = CallCreateInstance(kMenuCID, &pnsMenu); - if (NS_OK == rv) { - // Call Create - nsISupports * supports = nsnull; - aMenuBar->QueryInterface(NS_GET_IID(nsISupports), (void**) &supports); - pnsMenu->Create(supports, aMenuName); - NS_RELEASE(supports); + // Find the menubar tag (if there is more than one, we ignore all but + // the first). + nsCOMPtr menubarElements; + aDOMDoc->GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"), + NS_LITERAL_STRING("menubar"), + getter_AddRefs(menubarElements)); - // Set nsMenu Name - pnsMenu->SetLabel(aMenuName); - // Make nsMenu a child of nsMenuBar - aMenuBar->AddMenu(pnsMenu); - - // Open the node so that the contents are visible. - nsCOMPtr menuElement = do_QueryInterface(aMenuNode); - if (menuElement) - menuElement->SetAttribute(NS_LITERAL_STRING("open"), NS_LITERAL_STRING("true")); - - // Begin menuitem inner loop - - // Now get the kids. Retrieve our menupopup child. - nsCOMPtr menuPopupNode; - aMenuNode->GetFirstChild(getter_AddRefs(menuPopupNode)); - while (menuPopupNode) { - nsCOMPtr menuPopupElement(do_QueryInterface(menuPopupNode)); - if (menuPopupElement) { - nsString menuPopupNodeType; - menuPopupElement->GetNodeName(menuPopupNodeType); - if (menuPopupNodeType.EqualsLiteral("menupopup")) - break; - } - nsCOMPtr oldMenuPopupNode(menuPopupNode); - oldMenuPopupNode->GetNextSibling(getter_AddRefs(menuPopupNode)); - } - - if (!menuPopupNode) - return NS_OK; - - nsCOMPtr menuitemNode; - menuPopupNode->GetFirstChild(getter_AddRefs(menuitemNode)); - - while (menuitemNode) { - nsCOMPtr menuitemElement(do_QueryInterface(menuitemNode)); - if (menuitemElement) { - nsString menuitemNodeType; - nsString menuitemName; - menuitemElement->GetNodeName(menuitemNodeType); - if (menuitemNodeType.EqualsLiteral("menuitem")) { - // LoadMenuItem - LoadMenuItem(pnsMenu, menuitemElement, menuitemNode); - } else if (menuitemNodeType.EqualsLiteral("menuseparator")) { - pnsMenu->AddSeparator(); - } else if (menuitemNodeType.EqualsLiteral("menu")) { - // Load a submenu - LoadSubMenu(pnsMenu, menuitemElement, menuitemNode); - } - } - nsCOMPtr oldmenuitemNode(menuitemNode); - oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode)); - } // end menu item innner loop - // The parent owns us, so we can release - NS_RELEASE(pnsMenu); - } - - return NS_OK; -} - -//---------------------------------------- -NS_IMETHODIMP nsWebShellWindow::LoadMenuItem( - nsIMenu * pParentMenu, - nsIDOMElement * menuitemElement, - nsIDOMNode * menuitemNode) -{ - nsString menuitemName; - nsString menuitemCmd; - - menuitemElement->GetAttribute(NS_LITERAL_STRING("label"), menuitemName); - menuitemElement->GetAttribute(NS_LITERAL_STRING("cmd"), menuitemCmd); - // Create nsMenuItem - nsIMenuItem * pnsMenuItem = nsnull; - nsresult rv = CallCreateInstance(kMenuItemCID, &pnsMenuItem); - if (NS_OK == rv) { - // Create MenuDelegate - this is the intermediator inbetween - // the DOM node and the nsIMenuItem - // The nsWebShellWindow wacthes for Document changes and then notifies the - // the appropriate nsMenuDelegate object - nsCOMPtr domElement(do_QueryInterface(menuitemNode)); - if (!domElement) { - return NS_ERROR_FAILURE; - } - - pnsMenuItem->Create(pParentMenu, menuitemName, 0); - // Set nsMenuItem Name - //pnsMenuItem->SetLabel(menuitemName); - - // Set key shortcut and modifiers - nsAutoString keyAtom(NS_LITERAL_STRING("key")); - nsString keyValue; - domElement->GetAttribute(keyAtom, keyValue); - - // Try to find the key node. - nsCOMPtr document; - nsCOMPtr content = do_QueryInterface(domElement); - if (NS_FAILED(rv = content->GetDocument(getter_AddRefs(document)))) { - NS_ERROR("Unable to retrieve the document."); - return rv; - } - - // Turn the document into a XUL document so we can use getElementById - nsCOMPtr xulDocument = do_QueryInterface(document); - if (xulDocument == nsnull) { - NS_ERROR("not XUL!"); - return NS_ERROR_FAILURE; - } - nsCOMPtr keyElement; - xulDocument->GetElementById(keyValue, getter_AddRefs(keyElement)); - - if(keyElement){ - PRUint8 modifiers = knsMenuItemNoModifier; - nsAutoString shiftAtom(NS_LITERAL_STRING("shift")); - nsAutoString altAtom(NS_LITERAL_STRING("alt")); - nsAutoString commandAtom(NS_LITERAL_STRING("command")); - nsString shiftValue; - nsString altValue; - nsString commandValue; - nsString keyChar(NS_LITERAL_STRING(" ")); - - keyElement->GetAttribute(keyAtom, keyChar); - keyElement->GetAttribute(shiftAtom, shiftValue); - keyElement->GetAttribute(altAtom, altValue); - keyElement->GetAttribute(commandAtom, commandValue); - - if(!keyChar.EqualsLiteral(" ")) - pnsMenuItem->SetShortcutChar(keyChar); - - if(shiftValue.EqualsLiteral("true")) - modifiers |= knsMenuItemShiftModifier; - - if(altValue.EqualsLiteral("true")) - modifiers |= knsMenuItemAltModifier; - - if(commandValue.EqualsLiteral("false")) - modifiers |= knsMenuItemCommandModifier; - - pnsMenuItem->SetModifiers(modifiers); - } - - // Make nsMenuItem a child of nsMenu - nsISupports * supports = nsnull; - pnsMenuItem->QueryInterface(NS_GET_IID(nsISupports), (void**) &supports); - pParentMenu->AddItem(supports); - NS_RELEASE(supports); - + nsCOMPtr menubarNode; + if (menubarElements) + menubarElements->Item(0, getter_AddRefs(menubarNode)); - - nsAutoString cmdAtom(NS_LITERAL_STRING("onaction")); - nsString cmdName; - - domElement->GetAttribute(cmdAtom, cmdName); - - nsXULCommand * menuDelegate = new nsXULCommand(); - if ( menuDelegate ) { - menuDelegate->SetCommand(cmdName); - menuDelegate->SetDocShell(mDocShell); - menuDelegate->SetDOMElement(domElement); - menuDelegate->SetMenuItem(pnsMenuItem); - } else { - NS_RELEASE( pnsMenuItem ); - return NS_ERROR_OUT_OF_MEMORY; - } - - nsIXULCommand * icmd; - if (NS_OK == menuDelegate->QueryInterface(NS_GET_IID(nsIXULCommand), (void**) &icmd)) { - nsCOMPtr listener(do_QueryInterface(menuDelegate)); - - if (listener) - { - pnsMenuItem->AddMenuListener(listener); - -#ifdef DEBUG_MENUSDEL - printf("Adding menu listener to [%s]\n", NS_LossyConvertUCS2toASCII(menuitemName).get()); -#endif - } -#ifdef DEBUG_MENUSDEL - else - { - printf("*** NOT Adding menu listener to [%s]\n", NS_LossyConvertUCS2toASCII(menuitemName).get()); - } -#endif - NS_RELEASE(icmd); - } - - // The parent owns us, so we can release - NS_RELEASE(pnsMenuItem); - } - return NS_OK; -} - -//---------------------------------------- -void nsWebShellWindow::LoadSubMenu( - nsIMenu * pParentMenu, - nsIDOMElement * menuElement, - nsIDOMNode * menuNode) -{ - nsString menuName; - menuElement->GetAttribute(NS_LITERAL_STRING("label"), menuName); - //printf("Creating Menu [%s] \n", NS_LossyConvertUCS2toASCII(menuName).get()); - - // Create nsMenu - nsIMenu * pnsMenu = nsnull; - nsresult rv = CallCreateInstance(kMenuCID, &pnsMenu); - if (NS_OK == rv) { - // Call Create - nsISupports * supports = nsnull; - pParentMenu->QueryInterface(NS_GET_IID(nsISupports), (void**) &supports); - pnsMenu->Create(supports, menuName); - NS_RELEASE(supports); // Balance QI - - // Open the node so that the contents are visible. - menuElement->SetAttribute(NS_LITERAL_STRING("open"), NS_LITERAL_STRING("true")); - - // Set nsMenu Name - pnsMenu->SetLabel(menuName); - // Make nsMenu a child of parent nsMenu - //pParentMenu->AddMenu(pnsMenu); - supports = nsnull; - pnsMenu->QueryInterface(NS_GET_IID(nsISupports), (void**) &supports); - pParentMenu->AddItem(supports); - NS_RELEASE(supports); - - // Begin menuitem inner loop - - // Now get the kids. Retrieve our menupopup child. - nsCOMPtr menuPopupNode; - menuNode->GetFirstChild(getter_AddRefs(menuPopupNode)); - while (menuPopupNode) { - nsCOMPtr menuPopupElement(do_QueryInterface(menuPopupNode)); - if (menuPopupElement) { - nsString menuPopupNodeType; - menuPopupElement->GetNodeName(menuPopupNodeType); - if (menuPopupNodeType.EqualsLiteral("menupopup")) - break; - } - nsCOMPtr oldMenuPopupNode(menuPopupNode); - oldMenuPopupNode->GetNextSibling(getter_AddRefs(menuPopupNode)); - } - - if (!menuPopupNode) - return; - - nsCOMPtr menuitemNode; - menuPopupNode->GetFirstChild(getter_AddRefs(menuitemNode)); - - while (menuitemNode) { - nsCOMPtr menuitemElement(do_QueryInterface(menuitemNode)); - if (menuitemElement) { - nsString menuitemNodeType; - menuitemElement->GetNodeName(menuitemNodeType); - -#ifdef DEBUG_saari - printf("Type [%s] %d\n", NS_LossyConvertUCS2toASCII(menuitemNodeType).get(), menuitemNodeType.Equals("menuseparator")); -#endif - - if (menuitemNodeType.EqualsLiteral("menuitem")) { - // Load a menuitem - LoadMenuItem(pnsMenu, menuitemElement, menuitemNode); - } else if (menuitemNodeType.EqualsLiteral("menuseparator")) { - pnsMenu->AddSeparator(); - } else if (menuitemNodeType.EqualsLiteral("menu")) { - // Add a submenu - LoadSubMenu(pnsMenu, menuitemElement, menuitemNode); - } - } - nsCOMPtr oldmenuitemNode(menuitemNode); - oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode)); - } // end menu item innner loop - - // The parent owns us, so we can release - NS_RELEASE(pnsMenu); - } -} -#endif - -//---------------------------------------- -void nsWebShellWindow::DynamicLoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow) -{ - nsRect oldRect; - mWindow->GetClientBounds(oldRect); - - // locate the window element which holds toolbars and menus and commands - nsCOMPtr element; - aDOMDoc->GetDocumentElement(getter_AddRefs(element)); - if (!element) { + if (!menubarNode) return; - } - nsCOMPtr window(do_QueryInterface(element)); - nsresult rv; - int endCount = 0; - nsCOMPtr menubarNode(FindNamedDOMNode(NS_LITERAL_STRING("menubar"), window, endCount, 1)); - if (menubarNode) { - nsIMenuBar * pnsMenuBar = nsnull; - rv = CallCreateInstance(kMenuBarCID, &pnsMenuBar); - if (NS_OK == rv) { - if (nsnull != pnsMenuBar) { - // set pnsMenuBar as a nsMenuListener on aParentWindow - nsCOMPtr menuListener; - pnsMenuBar->QueryInterface(NS_GET_IID(nsIMenuListener), getter_AddRefs(menuListener)); - - //fake event - nsMenuEvent fake; - menuListener->MenuConstruct(fake, aParentWindow, menubarNode, mDocShell); - - // Parent should own menubar now - NS_RELEASE(pnsMenuBar); - - #ifdef USE_NATIVE_MENUS - #else - // Resize around the menu. - rv = NS_ERROR_FAILURE; - - // do a resize - nsCOMPtr contentViewer; - if( NS_FAILED(mDocShell->GetContentViewer(getter_AddRefs(contentViewer)))) - { - NS_WARN_IF_FALSE(PR_FALSE, "Error Getting contentViewer"); - return; - } - - nsCOMPtr docViewer; - docViewer = do_QueryInterface(contentViewer); - if (!docViewer) { - NS_ERROR("Document viewer interface not supported by the content viewer."); - return; - } - - nsCOMPtr presContext; - if (NS_FAILED(rv = docViewer->GetPresContext(getter_AddRefs(presContext)))) { - NS_ERROR("Unable to retrieve the doc viewer's presentation context."); - return; - } - - nsRect rect; - - if (NS_FAILED(rv = mWindow->GetClientBounds(rect))) { - NS_ERROR("Failed to get web shells bounds"); - return; - } - - // Resize the browser window by the difference. - PRInt32 heightDelta = oldRect.height - rect.height; - PRInt32 cx, cy; - GetSize(&cx, &cy); - SetSize(cx, cy + heightDelta, PR_FALSE); - // END REFLOW CODE - #endif - - } // end if ( nsnull != pnsMenuBar ) - } - } // end if (menuBar) -} // nsWebShellWindow::DynamicLoadMenus - -#if 0 -//---------------------------------------- -void nsWebShellWindow::LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow) -{ - // locate the window element which holds toolbars and menus and commands - nsCOMPtr element; - aDOMDoc->GetDocumentElement(getter_AddRefs(element)); - if (!element) { + nsCOMPtr pnsMenuBar = do_CreateInstance(kMenuBarCID); + if (!pnsMenuBar) return; - } - nsCOMPtr window(do_QueryInterface(element)); - nsresult rv; - int endCount = 0; - nsCOMPtr menubarNode(FindNamedDOMNode(NS_LITERAL_STRING("menubar"), window, endCount, 1)); - if (menubarNode) { - nsIMenuBar * pnsMenuBar = nsnull; - rv = CallCreateInstance(kMenuBarCID, &pnsMenuBar); - if (NS_OK == rv) { - if (nsnull != pnsMenuBar) { - pnsMenuBar->Create(aParentWindow); - - // set pnsMenuBar as a nsMenuListener on aParentWindow - nsCOMPtr menuListener; - pnsMenuBar->QueryInterface(NS_GET_IID(nsIMenuListener), getter_AddRefs(menuListener)); - aParentWindow->AddMenuListener(menuListener); + // set pnsMenuBar as a nsMenuListener on aParentWindow + nsCOMPtr menuListener = do_QueryInterface(pnsMenuBar); - nsCOMPtr menuNode; - menubarNode->GetFirstChild(getter_AddRefs(menuNode)); - while (menuNode) { - nsCOMPtr menuElement(do_QueryInterface(menuNode)); - if (menuElement) { - nsString menuNodeType; - nsString menuName; - menuElement->GetNodeName(menuNodeType); - if (menuNodeType.EqualsLiteral("menu")) { - menuElement->GetAttribute(NS_LITERAL_STRING("label"), menuName); - -#ifdef DEBUG_rods - printf("Creating Menu [%s] \n", NS_LossyConvertUCS2toASCII(menuName).get()); -#endif - CreateMenu(pnsMenuBar, menuNode, menuName); - } - - } - nsCOMPtr oldmenuNode(menuNode); - oldmenuNode->GetNextSibling(getter_AddRefs(menuNode)); - } // end while (nsnull != menuNode) - - // Give the aParentWindow this nsMenuBar to own. - aParentWindow->SetMenuBar(pnsMenuBar); - - // HACK: force a paint for now - pnsMenuBar->Paint(); - - // HACK for M4, should be removed by M5 - // ... it is now M15 -#ifdef USE_NATIVE_MENUS - Handle tempMenuBar = ::GetMenuBar(); // Get a copy of the menu list - pnsMenuBar->SetNativeData((void*)tempMenuBar); -#endif - - // The parent owns the menubar, so we can release it - NS_RELEASE(pnsMenuBar); - } // end if ( nsnull != pnsMenuBar ) - } - } // end if (menuBar) - -} // nsWebShellWindow::LoadMenus -#endif - - -//------------------------------------------------------------------------------ -NS_IMETHODIMP -nsWebShellWindow::ConvertDocShellToDOMWindow(nsIDocShell* aShell, nsIDOMWindowInternal** aDOMWindow) -{ - nsCOMPtr globalObjectOwner(do_QueryInterface(aShell)); - NS_ENSURE_TRUE(globalObjectOwner, NS_ERROR_FAILURE); - - nsIScriptGlobalObject* globalObject = globalObjectOwner->GetScriptGlobalObject(); - NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); - - nsCOMPtr newDOMWindow(do_QueryInterface(globalObject)); - NS_ENSURE_TRUE(newDOMWindow, NS_ERROR_FAILURE); - - *aDOMWindow = newDOMWindow.get(); - NS_ADDREF(*aDOMWindow); - return NS_OK; -} - -//---------------------------------------- -// nsIWebShellWindow methods... -//---------------------------------------- -NS_IMETHODIMP -nsWebShellWindow::Show(PRBool aShow) -{ - return nsXULWindow::SetVisibility(aShow); -} - -NS_IMETHODIMP -nsWebShellWindow::ShowModal() -{ - return nsXULWindow::ShowModal(); -} - -/* return the main, outermost webshell in this window */ -NS_IMETHODIMP -nsWebShellWindow::GetDocShell(nsIDocShell *& aDocShell) -{ - NS_ADDREF(aDocShell = mDocShell); - return NS_OK; -} - -/* return the webshell intended to hold (html) content. In a simple - browser window, that would be the main content area. If no such - webshell was found for any reason, the outermost webshell will be - returned. (Note that is the main chrome webshell, and probably - not what you wanted, but at least it's a webshell.) - Also note that if no content webshell was marked "primary," - we return the chrome webshell, even if (non-primary) content webshells - do exist. Thas was done intentionally. The selection would be - nondeterministic, and it seems dangerous to set a precedent like that. -*/ -NS_IMETHODIMP -nsWebShellWindow::GetContentDocShell(nsIDocShell **aResult) -{ - *aResult = nsnull; - nsCOMPtr content; - - GetPrimaryContentShell(getter_AddRefs(content)); - if(!content) - return NS_OK; - CallQueryInterface(content, aResult); - - return NS_OK; -} - -NS_IMETHODIMP -nsWebShellWindow::GetWidget(nsIWidget *& aWidget) -{ - aWidget = mWindow; - NS_IF_ADDREF(aWidget); - return NS_OK; -} - -NS_IMETHODIMP -nsWebShellWindow::GetDOMWindow(nsIDOMWindowInternal** aDOMWindow) -{ - return ConvertDocShellToDOMWindow(mDocShell, aDOMWindow); -} - -void * -nsWebShellWindow::HandleModalDialogEvent(PLEvent *aEvent) -{ - ThreadedWindowEvent *event = (ThreadedWindowEvent *) aEvent; - - event->window->ShowModal(); - return 0; -} - -void -nsWebShellWindow::DestroyModalDialogEvent(PLEvent *aEvent) -{ - PR_Free(aEvent); + // fake event + nsMenuEvent fake; + menuListener->MenuConstruct(fake, aParentWindow, menubarNode, mDocShell); } void @@ -1184,11 +610,6 @@ nsWebShellWindow::OnStateChange(nsIWebProgress *aProgress, return NS_OK; } - -#ifdef DEBUG_MENUSDEL - printf("OnEndDocumentLoad\n"); -#endif - if (mChromeLoaded) return NS_OK; @@ -1205,26 +626,6 @@ nsWebShellWindow::OnStateChange(nsIWebProgress *aProgress, mChromeLoaded = PR_TRUE; mLockedUntilChromeLoad = PR_FALSE; -#ifdef USE_NATIVE_MENUS - // register as document listener - // this is needed for menus - nsCOMPtr cv; - mDocShell->GetContentViewer(getter_AddRefs(cv)); - if (cv) { - - nsCOMPtr docv(do_QueryInterface(cv)); - if (!docv) - return NS_OK; - - nsCOMPtr doc; - docv->GetDocument(getter_AddRefs(doc)); - if (!doc) - return NS_OK; - - doc->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); - } -#endif - #ifdef USE_NATIVE_MENUS /////////////////////////////// // Find the Menubar DOM and Load the menus, hooking them up to the loaded commands @@ -1232,19 +633,7 @@ nsWebShellWindow::OnStateChange(nsIWebProgress *aProgress, nsCOMPtr menubarDOMDoc(GetNamedDOMDoc(NS_LITERAL_STRING("this"))); // XXX "this" is a small kludge for code reused if (menubarDOMDoc) { -#ifdef SOME_PLATFORM // Anyone using native non-dynamic menus should add themselves here. - LoadMenus(menubarDOMDoc, mWindow); - // Context Menu test - nsCOMPtr element; - menubarDOMDoc->GetDocumentElement(getter_AddRefs(element)); - nsCOMPtr window(do_QueryInterface(element)); - - int endCount = 0; - contextMenuTest = FindNamedDOMNode(NS_LITERAL_STRING("contextmenu"), window, endCount, 1); - // End Context Menu test -#else - DynamicLoadMenus(menubarDOMDoc, mWindow); -#endif + LoadNativeMenus(menubarDOMDoc, mWindow); } #endif // USE_NATIVE_MENUS @@ -1283,38 +672,6 @@ nsWebShellWindow::OnSecurityChange(nsIWebProgress *aWebProgress, } -//---------------------------------------- -nsCOMPtr nsWebShellWindow::FindNamedDOMNode(const nsAString &aName, nsIDOMNode * aParent, PRInt32 & aCount, PRInt32 aEndCount) -{ - if(!aParent) - return nsnull; - - nsCOMPtr node; - aParent->GetFirstChild(getter_AddRefs(node)); - while (node) { - nsString name; - node->GetNodeName(name); - //printf("FindNamedDOMNode[%s]==[%s] %d == %d\n", NS_LossyConvertUCS2toASCII(aName).get(), NS_LossyConvertUCS2toASCII(name).get(), aCount+1, aEndCount); - if (name.Equals(aName)) { - aCount++; - if (aCount == aEndCount) - return node; - } - PRBool hasChildren; - node->HasChildNodes(&hasChildren); - if (hasChildren) { - nsCOMPtr found(FindNamedDOMNode(aName, node, aCount, aEndCount)); - if (found) - return found; - } - nsCOMPtr oldNode = node; - oldNode->GetNextSibling(getter_AddRefs(node)); - } - node = do_QueryInterface(nsnull); - return node; - -} // nsWebShellWindow::FindNamedDOMNode - //---------------------------------------- nsCOMPtr nsWebShellWindow::GetNamedDOMDoc(const nsAString & aDocShellName) { @@ -1439,7 +796,7 @@ PRBool nsWebShellWindow::ExecuteCloseHandler() (The problem may be the death grip in nsWindow::windowProc, which forces this window's widget to remain alive longer than it otherwise would.) */ - nsCOMPtr kungFuDeathGrip(this); + nsCOMPtr kungFuDeathGrip(this); nsCOMPtr globalObject(do_GetInterface(mDocShell)); @@ -1466,80 +823,6 @@ PRBool nsWebShellWindow::ExecuteCloseHandler() return PR_FALSE; } // ExecuteCloseHandler -//---------------------------------------------------------------- -//-- nsIDocumentObserver -//---------------------------------------------------------------- -NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(nsWebShellWindow) -NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(nsWebShellWindow) -NS_IMPL_NSIDOCUMENTOBSERVER_REFLOW_STUB(nsWebShellWindow) -NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(nsWebShellWindow) -NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(nsWebShellWindow) - -/////////////////////////////////////////////////////////////// -// nsIDocumentObserver -// this is needed for menu changes -/////////////////////////////////////////////////////////////// -void -nsWebShellWindow::CharacterDataChanged(nsIDocument *aDocument, - nsIContent* aContent, - PRBool aAppend) -{ -} - -void -nsWebShellWindow::AttributeChanged(nsIDocument *aDocument, - nsIContent* aContent, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aModType) -{ - // XXX: Uh, none of this nsIDocumentObserver stuff is needed if the - // below code isn't needed. -#if 0 - //printf("AttributeChanged\n"); - PRInt32 i; - for (i=0;iGetDOMElement(&node); - //nsCOMPtr content(do_QueryInterface(node)); - // Doing this for the must speed - nsIContent * content; - if (NS_OK == node->QueryInterface(NS_GET_IID(nsIContent), (void**) &content)) { - if (content == aContent) { - nsAutoString attr; - aAttribute->ToString(attr); - cmd->AttributeHasBeenSet(attr); - } - NS_RELEASE(content); - } - } -#endif -} - -void -nsWebShellWindow::ContentAppended(nsIDocument *aDocument, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer) -{ -} - -void -nsWebShellWindow::ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ -} - -void -nsWebShellWindow::ContentRemoved(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ -} - // nsIBaseWindow NS_IMETHODIMP nsWebShellWindow::Destroy() { @@ -1549,25 +832,7 @@ NS_IMETHODIMP nsWebShellWindow::Destroy() webProgress->RemoveProgressListener(this); } -#ifdef USE_NATIVE_MENUS - { - // unregister as document listener - // this is needed for menus - nsCOMPtr cv; - if(mDocShell) - mDocShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr docv(do_QueryInterface(cv)); - if(docv) - { - nsCOMPtr doc; - docv->GetDocument(getter_AddRefs(doc)); - if(doc) - doc->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); - } - } -#endif - - nsCOMPtr kungFuDeathGrip(this); + nsCOMPtr kungFuDeathGrip(this); if (mSPTimerLock) { PR_Lock(mSPTimerLock); if (mSPTimer) { diff --git a/xpfe/appshell/src/nsWebShellWindow.h b/xpfe/appshell/src/nsWebShellWindow.h index 4970449b2d6..d07427672c0 100644 --- a/xpfe/appshell/src/nsWebShellWindow.h +++ b/xpfe/appshell/src/nsWebShellWindow.h @@ -38,44 +38,22 @@ #ifndef nsWebShellWindow_h__ #define nsWebShellWindow_h__ -#include "nsISupports.h" -#include "nsIWebShellWindow.h" #include "nsGUIEvent.h" #include "nsIWebProgressListener.h" -#include "nsIDocumentObserver.h" -#include "nsVoidArray.h" -#include "nsIMenu.h" #include "nsITimer.h" -#include "nsIPrompt.h" // can't use forward class decl's because of template bugs on Solaris #include "nsIDOMDocument.h" -#include "nsIDOMNode.h" #include "nsCOMPtr.h" #include "nsXULWindow.h" /* Forward declarations.... */ -struct PLEvent; - class nsIURI; class nsIAppShell; -class nsIContent; -class nsIDocument; -class nsIDOMCharacterData; -class nsIDOMElement; -class nsIDOMWindowInternal; -class nsIDOMHTMLImageElement; -class nsIDOMHTMLInputElement; -class nsIStreamObserver; -class nsIWidget; -class nsVoidArray; class nsWebShellWindow : public nsXULWindow, - public nsIWebShellWindow, - public nsIWebProgressListener, - public nsIDocumentObserver - + public nsIWebProgressListener { public: nsWebShellWindow(); @@ -83,78 +61,38 @@ public: // nsISupports interface... NS_DECL_ISUPPORTS_INHERITED - NS_IMETHOD LockUntilChromeLoad() { mLockedUntilChromeLoad = PR_TRUE; return NS_OK; } - NS_IMETHOD GetLockedState(PRBool& aResult) { aResult = mLockedUntilChromeLoad; return NS_OK; } - - NS_IMETHOD ShouldLoadDefaultPage(PRBool *aYes) - { *aYes = mLoadDefaultPage; return NS_OK; } - - // nsIWebShellWindow methods... - NS_IMETHOD Show(PRBool aShow); - NS_IMETHOD ShowModal(); - NS_IMETHOD Toolbar(); - NS_IMETHOD Close(); - NS_IMETHOD GetDocShell(nsIDocShell *& aWebShell); - NS_IMETHOD GetContentDocShell(nsIDocShell **aResult); - NS_IMETHOD GetWidget(nsIWidget *& aWidget); - NS_IMETHOD GetDOMWindow(nsIDOMWindowInternal** aDOMWindow); - NS_IMETHOD ConvertDocShellToDOMWindow(nsIDocShell* aShell, nsIDOMWindowInternal** aDOMWindow); // nsWebShellWindow methods... - nsresult Initialize(nsIXULWindow * aParent, nsIAppShell* aShell, nsIURI* aUrl, - PRBool aCreatedVisible, PRBool aLoadDefaultPage, + nsresult Initialize(nsIXULWindow * aParent, nsIAppShell* aShell, + nsIURI* aUrl, PRInt32 aInitialWidth, PRInt32 aInitialHeight, - PRBool aIsHiddenWindow, nsWidgetInitData& widgetInitData); - nsIWidget* GetWidget(void) { return mWindow; } + PRBool aIsHiddenWindow, + nsWidgetInitData& widgetInitData); + + nsresult Toolbar(); // nsIWebProgressListener NS_DECL_NSIWEBPROGRESSLISTENER - - // nsIDocumentObserver - NS_DECL_NSIDOCUMENTOBSERVER - // nsINetSupport // nsIBaseWindow NS_IMETHOD Destroy(); protected: - nsCOMPtr FindNamedDOMNode(const nsAString &aName, nsIDOMNode * aParent, PRInt32 & aCount, PRInt32 aEndCount); - nsCOMPtr GetNamedDOMDoc(const nsAString & aWebShellName); - void DynamicLoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow); -#if 0 - void LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow); - NS_IMETHOD CreateMenu(nsIMenuBar * aMenuBar, nsIDOMNode * aMenuNode, nsString & aMenuName); - void LoadSubMenu(nsIMenu * pParentMenu, nsIDOMElement * menuElement,nsIDOMNode * menuNode); - NS_IMETHOD LoadMenuItem(nsIMenu * pParentMenu, nsIDOMElement * menuitemElement, nsIDOMNode * menuitemNode); -#endif + virtual ~nsWebShellWindow(); + + nsCOMPtr GetNamedDOMDoc(const nsAString & aWebShellName); + void LoadNativeMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow); - nsCOMPtr GetDOMNodeFromDocShell(nsIDocShell *aShell); - void ExecuteStartupCode(); void LoadContentAreas(); PRBool ExecuteCloseHandler(); - virtual ~nsWebShellWindow(); - static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent); - PRBool mLockedUntilChromeLoad; - PRBool mLoadDefaultPage; - - nsVoidArray mMenuDelegates; - - nsIDOMNode * contextMenuTest; - nsCOMPtr mSPTimer; PRLock * mSPTimerLock; - nsCOMPtr mPrompter; void SetPersistenceTimer(PRUint32 aDirtyFlags); static void FirePersistenceTimer(nsITimer *aTimer, void *aClosure); - -private: - - static void * HandleModalDialogEvent(PLEvent *aEvent); - static void DestroyModalDialogEvent(PLEvent *aEvent); }; diff --git a/xpfe/appshell/src/nsXULWindow.cpp b/xpfe/appshell/src/nsXULWindow.cpp index e0f3042fd59..ea86782326b 100644 --- a/xpfe/appshell/src/nsXULWindow.cpp +++ b/xpfe/appshell/src/nsXULWindow.cpp @@ -89,9 +89,6 @@ #include "nsReadableUtils.h" #include "nsStyleConsts.h" -// XXX Get rid of this -#pragma message("WARNING: XXX bad include, remove it.") -#include "nsIWebShellWindow.h" #include "nsWebShellWindow.h" // get rid of this one, too... #define SIZEMODE_NORMAL NS_LITERAL_STRING("normal") @@ -124,6 +121,7 @@ nsXULWindow::nsXULWindow() : mChromeTreeOwner(nsnull), mDebuting(PR_FALSE), mChromeLoaded(PR_FALSE), mShowAfterLoad(PR_FALSE), mIntrinsicallySized(PR_FALSE), mCenterAfterLoad(PR_FALSE), mIsHiddenWindow(PR_FALSE), + mLockedUntilChromeLoad(PR_FALSE), mContextFlags(0), mBlurSuppressionLevel(0), mPersistentAttributesDirty(0), mPersistentAttributesMask(0), mChromeFlags(nsIWebBrowserChrome::CHROME_ALL) @@ -137,7 +135,7 @@ nsXULWindow::~nsXULWindow() //***************************************************************************** // nsXULWindow::nsISupports -//***************************************************************************** +//***************************************************************************** NS_IMPL_THREADSAFE_ADDREF(nsXULWindow) NS_IMPL_THREADSAFE_RELEASE(nsXULWindow) @@ -1703,9 +1701,10 @@ NS_IMETHODIMP nsXULWindow::CreateNewChromeWindow(PRInt32 aChromeFlags, parent = this; nsCOMPtr newWindow; - appShell->CreateTopLevelWindow(parent, nsnull, PR_FALSE, PR_FALSE, - aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, aAppShell, getter_AddRefs(newWindow)); + appShell->CreateTopLevelWindow(parent, nsnull, aChromeFlags, + nsIAppShellService::SIZE_TO_CONTENT, + nsIAppShellService::SIZE_TO_CONTENT, + aAppShell, getter_AddRefs(newWindow)); NS_ENSURE_TRUE(newWindow, NS_ERROR_FAILURE); @@ -1765,14 +1764,12 @@ NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(PRInt32 aChromeFlags, NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); nsCOMPtr newWindow; - appShell->CreateTopLevelWindow(parent, uri, PR_FALSE, PR_FALSE, + appShell->CreateTopLevelWindow(parent, uri, aChromeFlags, 615, 480, aAppShell, - getter_AddRefs(newWindow)); + getter_AddRefs(newWindow)); NS_ENSURE_TRUE(newWindow, NS_ERROR_FAILURE); - nsCOMPtr webShellWindow(do_QueryInterface(newWindow)); - newWindow->SetChromeFlags(aChromeFlags); nsCOMPtr subShell(do_CreateInstance(kAppShellCID)); @@ -1782,25 +1779,24 @@ NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(PRInt32 aChromeFlags, subShell->Spinup(); // Specify that we want the window to remain locked until the chrome has loaded. - webShellWindow->LockUntilChromeLoad(); + nsXULWindow *xulWin = NS_STATIC_CAST(nsXULWindow*, + NS_STATIC_CAST(nsIXULWindow*, + newWindow)); - PRBool locked = PR_FALSE; - webShellWindow->GetLockedState(locked); + xulWin->LockUntilChromeLoad(); // Push nsnull onto the JSContext stack before we dispatch a native event. nsCOMPtr stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1")); if(stack && NS_SUCCEEDED(stack->Push(nsnull))) { nsresult looprv = NS_OK; - while(NS_SUCCEEDED(looprv) && locked) + while(NS_SUCCEEDED(looprv) && xulWin->IsLocked()) { void *data; PRBool isRealEvent; looprv = subShell->GetNativeEvent(isRealEvent, data); subShell->DispatchNativeEvent(isRealEvent, data); - - webShellWindow->GetLockedState(locked); } JSContext *cx; @@ -1912,9 +1908,7 @@ PRBool nsXULWindow::ConstrainToZLevel( void *data; (*aActualBelow)->GetClientData(data); if (data) { - nsWebShellWindow *win; - win = NS_REINTERPRET_CAST(nsWebShellWindow *, data); - windowAbove = do_QueryInterface(NS_STATIC_CAST(nsIWebShellWindow *,win)); + windowAbove = NS_REINTERPRET_CAST(nsWebShellWindow*, data); } } diff --git a/xpfe/appshell/src/nsXULWindow.h b/xpfe/appshell/src/nsXULWindow.h index d49b9785a20..6d3e9a9a42f 100644 --- a/xpfe/appshell/src/nsXULWindow.h +++ b/xpfe/appshell/src/nsXULWindow.h @@ -69,7 +69,7 @@ class nsXULWindow : public nsIBaseWindow, public nsIInterfaceRequestor, - public nsIXULWindow, + public nsIXULWindow, public nsSupportsWeakReference { friend class nsChromeTreeOwner; @@ -82,6 +82,9 @@ public: NS_DECL_NSIXULWINDOW NS_DECL_NSIBASEWINDOW + void LockUntilChromeLoad() { mLockedUntilChromeLoad = PR_TRUE; } + PRBool IsLocked() const { return mLockedUntilChromeLoad; } + protected: enum persistentAttributes { PAD_MISC = 0x1, @@ -151,6 +154,7 @@ protected: PRPackedBool mIntrinsicallySized; PRPackedBool mCenterAfterLoad; PRPackedBool mIsHiddenWindow; + PRPackedBool mLockedUntilChromeLoad; PRUint32 mContextFlags; PRUint32 mBlurSuppressionLevel; PRUint32 mPersistentAttributesDirty; // persistentAttributes diff --git a/xpfe/bootstrap/appleevents/nsWindowUtils.cpp b/xpfe/bootstrap/appleevents/nsWindowUtils.cpp index 4c436c3c40e..bee7a109454 100644 --- a/xpfe/bootstrap/appleevents/nsWindowUtils.cpp +++ b/xpfe/bootstrap/appleevents/nsWindowUtils.cpp @@ -54,7 +54,6 @@ #include "nsIDOMNode.h" #include "nsIServiceManager.h" #include "nsIWebNavigation.h" -#include "nsIWebShellWindow.h" #include "nsIWidget.h" #include "nsIWindowMediator.h" #include "nsIURI.h" diff --git a/xpfe/browser/src/nsBrowserInstance.cpp b/xpfe/browser/src/nsBrowserInstance.cpp index fc4d11353fa..d9b57bb8232 100644 --- a/xpfe/browser/src/nsBrowserInstance.cpp +++ b/xpfe/browser/src/nsBrowserInstance.cpp @@ -67,7 +67,6 @@ #include "nsIContentViewer.h" #include "nsIContentViewerEdit.h" -#include "nsIWebShellWindow.h" #include "nsIWebBrowserChrome.h" #include "nsIWindowWatcher.h" #include "nsCOMPtr.h" diff --git a/xpfe/components/startup/src/nsAppStartup.cpp b/xpfe/components/startup/src/nsAppStartup.cpp index 771e32d028c..ff0b5dbab8d 100644 --- a/xpfe/components/startup/src/nsAppStartup.cpp +++ b/xpfe/components/startup/src/nsAppStartup.cpp @@ -59,7 +59,6 @@ #include "nsISupportsPrimitives.h" #include "nsITimelineService.h" #include "nsIWebBrowserChrome.h" -#include "nsIWebShellWindow.h" #include "nsIWindowMediator.h" #include "nsIWindowWatcher.h" #include "nsIXULWindow.h" @@ -892,9 +891,10 @@ nsAppStartup::CreateChromeWindow2(nsIWebBrowserChrome *aParent, if (!appShell) return NS_ERROR_FAILURE; - appShell->CreateTopLevelWindow(0, 0, PR_FALSE, PR_FALSE, - aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, mAppShell, getter_AddRefs(newWindow)); + appShell->CreateTopLevelWindow(0, 0, aChromeFlags, + nsIAppShellService::SIZE_TO_CONTENT, + nsIAppShellService::SIZE_TO_CONTENT, + mAppShell, getter_AddRefs(newWindow)); } // if anybody gave us anything to work with, use it diff --git a/xpfe/components/startup/src/nsCommandLineServiceMac.cpp b/xpfe/components/startup/src/nsCommandLineServiceMac.cpp index e41e990f2d2..8f19533b210 100644 --- a/xpfe/components/startup/src/nsCommandLineServiceMac.cpp +++ b/xpfe/components/startup/src/nsCommandLineServiceMac.cpp @@ -53,7 +53,6 @@ #include "nsIURL.h" #include "nsIServiceManager.h" #include "nsNetCID.h" -#include "nsIWebShellWindow.h" #include "nsIDOMWindow.h" #include "nsXPCOM.h" #include "nsISupportsPrimitives.h"