Moved the loading of the Title, Position and size from XUL into nsXULWindow from WebShellWindow. r=hyatt

This commit is contained in:
tbogard%aol.net 2000-02-10 07:47:24 +00:00
Родитель dcc6e4e620
Коммит 6a1ffaeb57
4 изменённых файлов: 137 добавлений и 268 удалений

Просмотреть файл

@ -1509,22 +1509,8 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
}
#endif // XP_MAC
SetTitleFromXUL();
ShowAppropriateChrome();
LoadContentAreas();
SetBoundsFromXUL(PR_TRUE, PR_TRUE /* !mIntrinsicallySized */);
if (mIntrinsicallySized)
{
nsCOMPtr<nsIContentViewer> cv;
mDocShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> 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<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(mWebShell);
nsIWidget *windowWidget = GetWidget();
nsCOMPtr<nsIDOMElement> 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<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(mWebShell);
nsCOMPtr<nsIDOMElement> 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<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(mWebShell);
nsIWidget *windowWidget = GetWidget();
nsCOMPtr<nsIDOMElement> 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<nsIDOMElement> rootElement;
nsCOMPtr<nsIDOMXULElement> xulRoot;
nsCOMPtr<nsIDOMDocument> chromeDoc;
nsCOMPtr<nsIDOMWindow> 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<nsIDOMNodeList> chromeNodes;
if (NS_SUCCEEDED(xulRoot->GetElementsByAttribute("chromeclass", "*",
getter_AddRefs(chromeNodes)))) {
PRUint32 nodeCtr, nodeCount;
chromeNodes->GetLength(&nodeCount);
for (nodeCtr = 0; nodeCtr < nodeCount; nodeCtr++) {
nsCOMPtr<nsIDOMNode> domNode;
nsCOMPtr<nsIDOMElement> 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;
}

Просмотреть файл

@ -254,11 +254,8 @@ protected:
nsCOMPtr<nsIDOMNode> 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();

Просмотреть файл

@ -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<nsIContentViewer> cv;
mDocShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIMarkupDocumentViewer> 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<nsIDOMElement> 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<nsIContentViewer> cv;
aDocShell->GetContentViewer(getter_AddRefs(cv));
if(!cv)
return NS_ERROR_FAILURE;
GetPositionAndSize(&curX, &curY, &curCX, &curCY);
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if(!docv)
return NS_ERROR_FAILURE;
PRInt32 errorCode;
PRInt32 temp;
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocument> 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<nsIDOMElement> 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<nsIContentViewer> cv;
aDocShell->GetContentViewer(getter_AddRefs(cv));
if(!cv)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if(!docv)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocument> 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)
{

Просмотреть файл

@ -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,