diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 4a3ed075af5c..29ac4d030d82 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -132,6 +132,7 @@ nsWebShellWindow::nsWebShellWindow() mController = nsnull; mCallbacks = nsnull; mContinueModalLoop = PR_FALSE; + mChromeInitialized = PR_FALSE; } @@ -252,12 +253,7 @@ nsresult nsWebShellWindow::Initialize(nsIWebShellWindow* aParent, PR_TRUE); mWebShell->SetContainer(this); mWebShell->SetObserver((nsIStreamObserver*)anObserver); - - nsIDocumentLoader * docLoader; - mWebShell->GetDocumentLoader(docLoader); - if (nsnull != docLoader) { - docLoader->AddObserver((nsIDocumentLoaderObserver *)this); - } + mWebShell->SetDocLoaderObserver(this); /* * XXX: How should preferences be supplied to the nsWebShellWindow? @@ -401,6 +397,8 @@ nsWebShellWindow::EndLoadURL(nsIWebShell* aWebShell, const PRUnichar* aURL, return NS_OK; } + + //---------------------------------------- nsCOMPtr nsWebShellWindow::FindNamedParentFromDoc(nsIDOMDocument * aDomDoc, const nsString &aName) { @@ -805,9 +803,7 @@ nsWebShellWindow::DestroyModalDialogEvent(PLEvent *aEvent) } -//---------------------------------------- -//---------------------------------------- -//---------------------------------------- + //---------------------------------------- // nsIDocumentLoaderObserver implementation //---------------------------------------- @@ -820,6 +816,88 @@ nsWebShellWindow::OnStartDocumentLoad(nsIURL* aURL, const char* aCommand) NS_IMETHODIMP nsWebShellWindow::OnEndDocumentLoad(nsIURL* aURL, PRInt32 aStatus) { +#ifdef DEBUG_MENUSDEL + printf("OnEndDocumentLoad\n"); +#endif + + /* We get notified every time a page/Frame is loaded. But we need to + * Load the menus, run the startup script etc.. only once. So, Use + * the mChrome Initialized member to check whether chrome should be + * initialized or not - Radha + */ + if (mChromeInitialized) + return NS_OK; + + mChromeInitialized = PR_TRUE; + + // register as document listener + // this is needed for menus + nsCOMPtr cv; + mWebShell->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)); + } + + ExecuteStartupCode(); + + /////////////////////////////// + // Find the Menubar DOM and Load the menus, hooking them up to the loaded commands + /////////////////////////////// + nsCOMPtr menubarDOMDoc(GetNamedDOMDoc(nsAutoString("this"))); // XXX "this" is a small kludge for code reused + if (menubarDOMDoc) + LoadMenus(menubarDOMDoc, mWindow); + + SetSizeFromXUL(); + SetTitleFromXUL(); + +#if 0 + nsCOMPtr toolbarDOMDoc(GetNamedDOMDoc(nsAutoString("browser.toolbar"))); + nsCOMPtr contentDOMDoc(GetNamedDOMDoc(nsAutoString("browser.webwindow"))); + nsCOMPtr contentDoc(do_QueryInterface(contentDOMDoc)); + nsCOMPtr statusDoc(do_QueryInterface(statusDOMDoc)); + nsCOMPtr toolbarDoc(do_QueryInterface(toolbarDOMDoc)); + + nsIWebShell* statusWebShell = nsnull; + mWebShell->FindChildWithName(nsAutoString("browser.status"), statusWebShell); + + PRInt32 actualStatusHeight = GetDocHeight(statusDoc); + PRInt32 actualToolbarHeight = GetDocHeight(toolbarDoc); + + + PRInt32 height = 0; + PRInt32 x,y,w,h; + PRInt32 contentHeight; + PRInt32 toolbarHeight; + PRInt32 statusHeight; + + mWebShell->GetBounds(x, y, w, h); + toolbarWebShell->GetBounds(x, y, w, toolbarHeight); + contentWebShell->GetBounds(x, y, w, contentHeight); + statusWebShell->GetBounds(x, y, w, statusHeight); + + //h = toolbarHeight + contentHeight + statusHeight; + contentHeight = h - actualStatusHeight - actualToolbarHeight; + + toolbarWebShell->GetBounds(x, y, w, h); + toolbarWebShell->SetBounds(x, y, w, actualToolbarHeight); + + contentWebShell->GetBounds(x, y, w, h); + contentWebShell->SetBounds(x, y, w, contentHeight); + + statusWebShell->GetBounds(x, y, w, h); + statusWebShell->SetBounds(x, y, w, actualStatusHeight); +#endif + return NS_OK; } @@ -957,6 +1035,7 @@ PRInt32 nsWebShellWindow::GetDocHeight(nsIDocument * aDoc) } //---------------------------------------- +#if 0 NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete() { #ifdef DEBUG_MENUSDEL @@ -1033,6 +1112,8 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete() return NS_OK; } // nsWebShellWindow::OnConnectionsComplete +#endif /* 0 */ + /** diff --git a/xpfe/appshell/src/nsWebShellWindow.h b/xpfe/appshell/src/nsWebShellWindow.h index 1969b42e014e..2a2004c73666 100644 --- a/xpfe/appshell/src/nsWebShellWindow.h +++ b/xpfe/appshell/src/nsWebShellWindow.h @@ -62,6 +62,7 @@ public: // nsISupports interface... NS_DECL_ISUPPORTS + // nsIWebShellContainer interface... NS_IMETHOD WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, @@ -79,6 +80,7 @@ public: const PRUnichar* aURL, PRInt32 aStatus); + NS_IMETHOD NewWebShell(PRUint32 aChromeMask, PRBool aVisible, nsIWebShell *&aNewWebShell); @@ -106,14 +108,14 @@ public: // nsIDocumentLoaderObserver NS_IMETHOD OnStartDocumentLoad(nsIURL* aURL, const char* aCommand); NS_IMETHOD OnEndDocumentLoad(nsIURL *aUrl, PRInt32 aStatus); - NS_IMETHOD OnStartURLLoad(nsIURL* aURL, const char* aContentType, nsIContentViewer* aViewer); + NS_IMETHOD OnStartURLLoad(nsIURL* aURL, const char* aContentType, + nsIContentViewer* aViewer); NS_IMETHOD OnProgressURLLoad(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax); NS_IMETHOD OnStatusURLLoad(nsIURL* aURL, nsString& aMsg); NS_IMETHOD OnEndURLLoad(nsIURL* aURL, PRInt32 aStatus); - NS_IMETHOD OnConnectionsComplete(); - + // nsIDocumentObserver NS_IMETHOD BeginUpdate(nsIDocument *aDocument); NS_IMETHOD EndUpdate(nsIDocument *aDocument); @@ -196,6 +198,7 @@ protected: nsIWidgetController* mController; nsIXULWindowCallbacks* mCallbacks; PRBool mContinueModalLoop; + PRBool mChromeInitialized; nsVoidArray mMenuDelegates;