From 767c8e2c5f9101735cfbf7e2c45776bb3eb77e45 Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Thu, 10 Feb 2000 07:47:24 +0000 Subject: [PATCH] Moved the loading of the Title, Position and size from XUL into nsXULWindow from WebShellWindow. r=hyatt git-svn-id: svn://10.0.0.236/trunk@60304 18797224-902f-48f8-a5cc-f745e15eee43 --- .../xpfe/appshell/src/nsWebShellWindow.cpp | 248 +----------------- mozilla/xpfe/appshell/src/nsWebShellWindow.h | 3 - mozilla/xpfe/appshell/src/nsXULWindow.cpp | 149 +++++++++-- mozilla/xpfe/appshell/src/nsXULWindow.h | 5 +- 4 files changed, 137 insertions(+), 268 deletions(-) diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 5860643dfbf..e4f3d49e87c 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -1509,22 +1509,8 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader, } #endif // XP_MAC - SetTitleFromXUL(); - ShowAppropriateChrome(); - LoadContentAreas(); - - SetBoundsFromXUL(PR_TRUE, PR_TRUE /* !mIntrinsicallySized */); - if (mIntrinsicallySized) - { - nsCOMPtr cv; - mDocShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr markupViewer(do_QueryInterface(cv)); - if(markupViewer) - markupViewer->SizeToContent(); - } - - // Here's where we service the "show" request initially given in Initialize() OnChromeLoaded(); + LoadContentAreas(); return NS_OK; } @@ -1704,130 +1690,10 @@ void nsWebShellWindow::ExecuteStartupCode() mCallbacks->ConstructAfterJavaScript(mWebShell); } -/* This simply reads attributes from the window tag and blindly sets the size - to whatever it finds within. -*/ -void nsWebShellWindow::SetBoundsFromXUL(PRBool aPosition, PRBool aSize) -{ - nsCOMPtr webshellNode = GetDOMNodeFromWebShell(mWebShell); - nsIWidget *windowWidget = GetWidget(); - nsCOMPtr webshellElement; - nsAutoString sizeString; - PRInt32 errorCode, - specX, specY, specWidth, specHeight, - specSize; - nsRect currentBounds; - - if (webshellNode) - webshellElement = do_QueryInterface(webshellNode); - if (!webshellElement || !windowWidget) // it's hopeless - return; - - mWindow->GetBounds(currentBounds); - - if (aPosition) { - // first guess: use current position - specX = currentBounds.x; - specY = currentBounds.y; - - // read position attributes - if (NS_SUCCEEDED(webshellElement->GetAttribute("screenX", sizeString))) { - specSize = sizeString.ToInteger(&errorCode); - if (NS_SUCCEEDED(errorCode) && specSize > 0) - specX = specSize; - } - if (NS_SUCCEEDED(webshellElement->GetAttribute("screenY", sizeString))) { - specSize = sizeString.ToInteger(&errorCode); - if (NS_SUCCEEDED(errorCode) && specSize > 0) - specY = specSize; - } - - // position the window - if (specX != currentBounds.x || specY != currentBounds.y) - MoveTo(specX, specY); - } - - if (aSize) { - // first guess: use current size - specWidth = currentBounds.width; - specHeight = currentBounds.height; - - // read "height" attribute - if (NS_SUCCEEDED(webshellElement->GetAttribute("height", sizeString))) { - specSize = sizeString.ToInteger(&errorCode); - if (NS_SUCCEEDED(errorCode) && specSize > 0) { - specHeight = specSize; - mIntrinsicallySized = PR_FALSE; - } - } - - // read "width" attribute - if (NS_SUCCEEDED(webshellElement->GetAttribute("width", sizeString))) { - specSize = sizeString.ToInteger(&errorCode); - if (NS_SUCCEEDED(errorCode) || specSize > 0) { - specWidth = specSize; - mIntrinsicallySized = PR_FALSE; - } - } - - if (specWidth != currentBounds.width || specHeight != currentBounds.height) - windowWidget->Resize(specWidth, specHeight, PR_TRUE); - } -} // SetBoundsFromXUL - - /* copy the window's size and position to the window tag */ void nsWebShellWindow::StoreBoundsToXUL(PRBool aPosition, PRBool aSize) { - nsCOMPtr webshellNode = GetDOMNodeFromWebShell(mWebShell); - nsCOMPtr webshellElement; - nsAutoString sizeString, - persistString; - char sizeBuf[10]; - nsRect currentSize; - - if (webshellNode) - webshellElement = do_QueryInterface(webshellNode); - if (!webshellElement) // it's hopeless - return; - - GetWindowBounds(currentSize); - // (But only for size elements which are persisted.) - /* Note we use the same cheesy way to determine that as in - nsXULDocument.cpp. Some day that'll be fixed and there will - be an obscure bug here. */ - /* Note that storing sizes which are not persisted makes it - difficult to distinguish between windows intrinsically sized - and not. */ - webshellElement->GetAttribute("persist", persistString); - - if (aPosition) { - if (persistString.Find("screenX") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%ld", (long) currentSize.x); - sizeString = sizeBuf; - webshellElement->SetAttribute("screenX", sizeString); - } - - if (persistString.Find("screenY") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%ld", (long) currentSize.y); - sizeString = sizeBuf; - webshellElement->SetAttribute("screenY", sizeString); - } - } - - if (aSize) { - if (persistString.Find("width") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%ld", (long) currentSize.width); - sizeString = sizeBuf; - webshellElement->SetAttribute("width", sizeString); - } - - if (persistString.Find("height") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%ld", (long) currentSize.height); - sizeString = sizeBuf; - webshellElement->SetAttribute("height", sizeString); - } - } + PersistPositionAndSize(aPosition, aSize); } // StoreBoundsToXUL @@ -1840,109 +1706,6 @@ void nsWebShellWindow::KillPersistentSize() } -void nsWebShellWindow::SetTitleFromXUL() -{ - nsCOMPtr webshellNode = GetDOMNodeFromWebShell(mWebShell); - nsIWidget *windowWidget = GetWidget(); - nsCOMPtr webshellElement; - nsString windowTitle; - - if (webshellNode) - webshellElement = do_QueryInterface(webshellNode); - if (webshellElement && windowWidget && - NS_SUCCEEDED(webshellElement->GetAttribute("title", windowTitle)) && - windowTitle != "") - - if(NS_SUCCEEDED(EnsureChromeTreeOwner())) - mChromeTreeOwner->SetTitle(windowTitle.GetUnicode()); -} // SetTitleFromXUL - - -// show/hide contents according to the current chrome mask -void nsWebShellWindow::ShowAppropriateChrome() -{ - nsCOMPtr rootElement; - nsCOMPtr xulRoot; - nsCOMPtr chromeDoc; - nsCOMPtr domWindow; - PRUint32 chromeMask; - - // get this window's document - if (NS_FAILED(ConvertWebShellToDOMWindow(mWebShell, getter_AddRefs(domWindow)))) - return; - if (NS_FAILED(domWindow->GetDocument(getter_AddRefs(chromeDoc))) || !chromeDoc) - return; - if (NS_FAILED(chromeDoc->GetDocumentElement(getter_AddRefs(rootElement))) || !rootElement) - return; - - // calculate a special version of the chrome mask. we store the actual - // value sent, but we make local changes depending on whether defaults - // were asked for. Note that only internal (not OS-) chrome matters - // at this point, so the OS chrome is not calculated. - chromeMask = mChromeMask; - if (chromeMask & NS_CHROME_DEFAULT_CHROME) - if (chromeMask & NS_CHROME_OPEN_AS_DIALOG) - chromeMask &= ~(NS_CHROME_MENU_BAR_ON | NS_CHROME_TOOL_BAR_ON | - NS_CHROME_LOCATION_BAR_ON | NS_CHROME_STATUS_BAR_ON | - NS_CHROME_PERSONAL_TOOLBAR_ON | NS_CHROME_SCROLLBARS_ON |NS_CHROME_EXTRACHROME_ON); - else - // theoretically, this won't happen (only dialogs can have defaults) - // but, we cover this case anyway - chromeMask |= NS_CHROME_ALL_CHROME; - - // special treatment for the menubar - ShowMenuBar(mChromeMask & NS_CHROME_MENU_BAR_ON ? PR_TRUE : PR_FALSE); - - // get a list of this document's elements with the chromeclass attribute specified - xulRoot = do_QueryInterface(rootElement); - if (xulRoot) { // todo (maybe) the longer, straight DOM (not RDF) version? - nsCOMPtr chromeNodes; - if (NS_SUCCEEDED(xulRoot->GetElementsByAttribute("chromeclass", "*", - getter_AddRefs(chromeNodes)))) { - PRUint32 nodeCtr, nodeCount; - chromeNodes->GetLength(&nodeCount); - for (nodeCtr = 0; nodeCtr < nodeCount; nodeCtr++) { - nsCOMPtr domNode; - nsCOMPtr domElement; - chromeNodes->Item(nodeCtr, getter_AddRefs(domNode)); - domElement = do_QueryInterface(domNode); - if (domElement) { - nsAutoString chromeClass; - PRBool makeChange; - PRUint32 flag; - // show or hide the element according to its chromeclass and the chromemask - domElement->GetAttribute("chromeclass", chromeClass); - makeChange = PR_FALSE; - if (chromeClass == "menubar") { - makeChange = PR_TRUE; - flag = mChromeMask & NS_CHROME_MENU_BAR_ON; - } else if (chromeClass == "toolbar") { - makeChange = PR_TRUE; - flag = mChromeMask & NS_CHROME_TOOL_BAR_ON; - } else if (chromeClass == "location") { - makeChange = PR_TRUE; - flag = mChromeMask & NS_CHROME_LOCATION_BAR_ON; - } else if (chromeClass == "directories") { - makeChange = PR_TRUE; - flag = mChromeMask & NS_CHROME_PERSONAL_TOOLBAR_ON; - } else if (chromeClass == "status") { - makeChange = PR_TRUE; - flag = mChromeMask & NS_CHROME_STATUS_BAR_ON; - }else if (chromeClass == "extrachrome") { - makeChange = PR_TRUE; - flag = mChromeMask & NS_CHROME_EXTRACHROME_ON; - } - if (makeChange) - if (flag) - domElement->RemoveAttribute("chromehidden"); - else - domElement->SetAttribute("chromehidden", "T"); - } - } - } - } -} - // if the main document URL specified URLs for any content areas, start them loading void nsWebShellWindow::LoadContentAreas() { @@ -2345,14 +2108,15 @@ NS_IMETHODIMP nsWebShellWindow::GetWindowBounds(nsRect& aResult) NS_IMETHODIMP nsWebShellWindow::SetChrome(PRUint32 aNewChromeMask) { - mChromeMask = aNewChromeMask; - ShowAppropriateChrome(); + if(mContentTreeOwner) + return mContentTreeOwner->SetChromeMask(aNewChromeMask); return NS_OK; } NS_IMETHODIMP nsWebShellWindow::GetChrome(PRUint32& aChromeMaskResult) { - aChromeMaskResult = mChromeMask; + if(mContentTreeOwner) + return mContentTreeOwner->GetChromeMask(&aChromeMaskResult); return NS_OK; } diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.h b/mozilla/xpfe/appshell/src/nsWebShellWindow.h index 505b1cacf20..369ac40c271 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.h +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.h @@ -254,11 +254,8 @@ protected: nsCOMPtr GetDOMNodeFromWebShell(nsIWebShell *aShell); void ExecuteStartupCode(); - void SetBoundsFromXUL(PRBool aPosition, PRBool aSize); - void SetTitleFromXUL(); void StoreBoundsToXUL(PRBool aPosition, PRBool aSize); void KillPersistentSize(); - void ShowAppropriateChrome(); void LoadContentAreas(); PRBool ExecuteCloseHandler(); diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.cpp b/mozilla/xpfe/appshell/src/nsXULWindow.cpp index bcf9ad5acb7..ab84abc991f 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsXULWindow.cpp @@ -41,6 +41,7 @@ #include "nsIInterfaceRequestor.h" #include "nsIIOService.h" #include "nsIJSContextStack.h" +#include "nsIMarkupDocumentViewer.h" #include "nsIWindowMediator.h" // XXX Get rid of this @@ -607,40 +608,113 @@ NS_IMETHODIMP nsXULWindow::EnsurePrimaryContentTreeOwner() void nsXULWindow::OnChromeLoaded() { mChromeLoaded = PR_TRUE; - + if(mContentTreeOwner) mContentTreeOwner->ApplyChromeMask(); + + LoadTitleFromXUL(); + LoadPositionAndSizeFromXUL(PR_TRUE, PR_TRUE); + + if(mIntrinsicallySized) + { + nsCOMPtr cv; + mDocShell->GetContentViewer(getter_AddRefs(cv)); + nsCOMPtr markupViewer(do_QueryInterface(cv)); + if(markupViewer) + markupViewer->SizeToContent(); + } + + //LoadContentAreas(); + if(mShowAfterLoad) SetVisibility(PR_TRUE); } -NS_IMETHODIMP nsXULWindow::GetDOMElementFromDocShell(nsIDocShell* aDocShell, - nsIDOMElement** aDOMElement) +NS_IMETHODIMP nsXULWindow::LoadPositionAndSizeFromXUL(PRBool aPosition, + PRBool aSize) { - NS_ENSURE_ARG(aDocShell); - NS_ENSURE_ARG_POINTER(aDOMElement); + nsCOMPtr docShellElement; + GetDOMElementFromDocShell(mDocShell, getter_AddRefs(docShellElement)); + NS_ENSURE_TRUE(docShellElement, NS_ERROR_FAILURE); - *aDOMElement = nsnull; + PRInt32 curX = 0; + PRInt32 curY = 0; + PRInt32 curCX = 0; + PRInt32 curCY = 0; - nsCOMPtr cv; - - aDocShell->GetContentViewer(getter_AddRefs(cv)); - if(!cv) - return NS_ERROR_FAILURE; + GetPositionAndSize(&curX, &curY, &curCX, &curCY); - nsCOMPtr docv(do_QueryInterface(cv)); - if(!docv) - return NS_ERROR_FAILURE; + PRInt32 errorCode; + PRInt32 temp; - nsCOMPtr doc; - docv->GetDocument(*getter_AddRefs(doc)); - nsCOMPtr domdoc(do_QueryInterface(doc)); - if(!domdoc) - return NS_ERROR_FAILURE; + if(aPosition) + { + PRInt32 specX = curX; + PRInt32 specY = curY; + nsAutoString sizeString; - domdoc->GetDocumentElement(aDOMElement); - if(!*aDOMElement) - return NS_ERROR_FAILURE; + if(NS_SUCCEEDED(docShellElement->GetAttribute("screenX", sizeString))) + { + temp = sizeString.ToInteger(&errorCode); + if(NS_SUCCEEDED(errorCode) && temp > 0) + specX = temp; + } + if(NS_SUCCEEDED(docShellElement->GetAttribute("screenY", sizeString))) + { + temp = sizeString.ToInteger(&errorCode); + if(NS_SUCCEEDED(errorCode) && temp > 0) + specY = temp; + } + + if((specX != curX) || (specY != curY)) + SetPosition(specX, specY); + } + + if(aSize) + { + PRInt32 specCX = curCX; + PRInt32 specCY = curCY; + nsAutoString sizeString; + + if(NS_SUCCEEDED(docShellElement->GetAttribute("width", sizeString))) + { + temp = sizeString.ToInteger(&errorCode); + if(NS_SUCCEEDED(errorCode) && temp > 0) + { + specCX = temp; + mIntrinsicallySized = PR_FALSE; + } + } + if(NS_SUCCEEDED(docShellElement->GetAttribute("height", sizeString))) + { + temp = sizeString.ToInteger(&errorCode); + if(NS_SUCCEEDED(errorCode) && temp > 0) + { + specCY = temp; + mIntrinsicallySized = PR_FALSE; + } + } + + if((specCX != curCX) || (specCY != curCY)) + SetSize(specCX, specCY, PR_FALSE); + } + + return NS_OK; +} + +NS_IMETHODIMP nsXULWindow::LoadTitleFromXUL() +{ + nsCOMPtr docShellElement; + GetDOMElementFromDocShell(mDocShell, getter_AddRefs(docShellElement)); + NS_ENSURE_TRUE(docShellElement, NS_ERROR_FAILURE); + + nsAutoString windowTitle; + docShellElement->GetAttribute("title", windowTitle); + if(windowTitle == "") + return NS_OK; + + NS_ENSURE_SUCCESS(EnsureChromeTreeOwner(), NS_ERROR_FAILURE); + mChromeTreeOwner->SetTitle(windowTitle.GetUnicode()); return NS_OK; } @@ -702,6 +776,37 @@ NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize return NS_OK; } +NS_IMETHODIMP nsXULWindow::GetDOMElementFromDocShell(nsIDocShell* aDocShell, + nsIDOMElement** aDOMElement) +{ + NS_ENSURE_ARG(aDocShell); + NS_ENSURE_ARG_POINTER(aDOMElement); + + *aDOMElement = nsnull; + + nsCOMPtr cv; + + aDocShell->GetContentViewer(getter_AddRefs(cv)); + if(!cv) + return NS_ERROR_FAILURE; + + nsCOMPtr docv(do_QueryInterface(cv)); + if(!docv) + return NS_ERROR_FAILURE; + + nsCOMPtr doc; + docv->GetDocument(*getter_AddRefs(doc)); + nsCOMPtr domdoc(do_QueryInterface(doc)); + if(!domdoc) + return NS_ERROR_FAILURE; + + domdoc->GetDocumentElement(aDOMElement); + if(!*aDOMElement) + return NS_ERROR_FAILURE; + + return NS_OK; +} + NS_IMETHODIMP nsXULWindow::ContentShellAdded(nsIDocShellTreeItem* aContentShell, PRBool aPrimary, const PRUnichar* aID) { diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.h b/mozilla/xpfe/appshell/src/nsXULWindow.h index 78c4f5d5509..88b852106fd 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.h +++ b/mozilla/xpfe/appshell/src/nsXULWindow.h @@ -63,12 +63,15 @@ protected: NS_IMETHOD EnsureChromeTreeOwner(); NS_IMETHOD EnsureContentTreeOwner(); NS_IMETHOD EnsurePrimaryContentTreeOwner(); + void OnChromeLoaded(); + NS_IMETHOD LoadPositionAndSizeFromXUL(PRBool aPosition, PRBool aSize); + NS_IMETHOD LoadTitleFromXUL(); + NS_IMETHOD PersistPositionAndSize(PRBool aPosition, PRBool aSize); NS_IMETHOD GetDOMElementFromDocShell(nsIDocShell* aDocShell, nsIDOMElement** aDOMElement); - NS_IMETHOD PersistPositionAndSize(PRBool aPosition, PRBool aSize); NS_IMETHOD ContentShellAdded(nsIDocShellTreeItem* aContentShell, PRBool aPrimary, const PRUnichar* aID); NS_IMETHOD SizeShellTo(nsIDocShellTreeItem* aShellItem, PRInt32 aCX,