From 4f3260d4a91516952df5167ad745d777f1d85538 Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Wed, 31 Mar 1999 04:21:05 +0000 Subject: [PATCH] simple ability to at least specify a size for the window in XUL --- xpfe/appshell/src/nsWebShellWindow.cpp | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 2398089874b0..4a3ed075af5c 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -1120,8 +1120,65 @@ void nsWebShellWindow::ExecuteStartupCode() } +/* A somewhat early version of window sizing code. This simply reads attributes + from the window tag and blindly sets the size to whatever it finds within. +*/ void nsWebShellWindow::SetSizeFromXUL() { + nsCOMPtr webshellNode = GetDOMNodeFromWebShell(mWebShell); + nsIWidget *windowWidget = GetWidget(); + nsCOMPtr webshellElement; + nsString sizeString; + PRInt32 errorCode, + specWidth, specHeight, + specSize; + nsRect currentSize; + + if (webshellNode) + webshellElement = do_QueryInterface(webshellNode); + if (!webshellElement || !windowWidget) // it's hopeless + return; + + // first guess: use current size + mWindow->GetBounds(currentSize); + specWidth = currentSize.width; + specHeight = currentSize.height; + + // read "height" attribute + if (NS_SUCCEEDED(webshellElement->GetAttribute("height", sizeString))) { + specSize = sizeString.ToInteger(&errorCode); + if (NS_SUCCEEDED(errorCode) && specSize > 0) + specHeight = specSize; + } + + // read "width" attribute + if (NS_SUCCEEDED(webshellElement->GetAttribute("width", sizeString))) { + specSize = sizeString.ToInteger(&errorCode); + if (NS_SUCCEEDED(errorCode) || specSize > 0) + specWidth = specSize; + } + + if (specWidth != currentSize.width || specHeight != currentSize.height) + windowWidget->Resize(specWidth, specHeight, PR_TRUE); + +#if 0 + // adjust height to fit contents? + if (fitHeight == PR_TRUE) { + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + nsCOMPtr docv(do_QueryInterface(cv)); + if (docv) { + nsCOMPtr doc; + docv->GetDocument(*getter_AddRefs(doc)); + if (doc) + specHeight = GetDocHeight(doc); + } + } + mWindow->GetBounds(currentSize); + windowWidget->Resize(currentSize.width, specHeight, PR_TRUE); + } +#endif } // SetSizeFromXUL