From 73b08a974dd7c7326709bd67180467bf5ec7b991 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Sun, 4 Jul 1999 04:09:54 +0000 Subject: [PATCH] Checking in support for intrinsic sizing of chrome. --- content/xul/document/src/nsXULDocument.cpp | 67 +-- dom/src/base/nsGlobalWindow.cpp | 44 +- layout/base/nsPresShell.cpp | 42 +- layout/generic/nsViewportFrame.cpp | 25 +- layout/html/base/src/nsPresShell.cpp | 42 +- layout/html/base/src/nsViewportFrame.cpp | 25 +- mailnews/base/src/nsMessenger.cpp | 4 +- rdf/content/src/nsXULDocument.cpp | 67 +-- webshell/public/nsIBrowserWindow.h | 6 +- webshell/tests/viewer/nsBrowserWindow.cpp | 12 +- webshell/tests/viewer/nsBrowserWindow.h | 5 +- webshell/tests/viewer/nsWebCrawler.cpp | 6 +- xpfe/AppCores/src/nsBrowserAppCore.cpp | 4 +- xpfe/AppCores/src/nsDOMPropsCore.cpp | 509 ++++++++++++++++++ xpfe/AppCores/src/nsToolkitCore.cpp | 4 +- xpfe/appshell/public/nsIAppShellService.idl | 2 + xpfe/appshell/src/nsAppShellService.cpp | 17 + xpfe/appshell/src/nsCommandLineServiceMac.cpp | 2 +- xpfe/appshell/src/nsWebShellWindow.cpp | 104 ++-- xpfe/appshell/src/nsWebShellWindow.h | 10 +- xpfe/bootstrap/nsAppRunner.cpp | 4 +- xpfe/browser/src/navigator.xul | 2 +- .../startup/src/nsCommandLineServiceMac.cpp | 2 +- 23 files changed, 833 insertions(+), 172 deletions(-) create mode 100644 xpfe/AppCores/src/nsDOMPropsCore.cpp diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 731169318d82..2b939d4c9165 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -107,6 +107,7 @@ #include "rdfutil.h" #include "rdf.h" +#include "nsIFrameReflow.h" #include "nsIDOMXULFocusTracker.h" #include "nsIXULFocusTracker.h" #include "nsIDOMEventCapturer.h" @@ -3951,43 +3952,49 @@ XULDocumentImpl::StartLayout(void) PRInt32 count = GetNumberOfShells(); for (PRInt32 i = 0; i < count; i++) { - nsIPresShell* shell = GetShellAt(i); - if (nsnull == shell) - continue; + nsIPresShell* shell = GetShellAt(i); + if (nsnull == shell) + continue; - // Resize-reflow this time - nsCOMPtr cx; - shell->GetPresContext(getter_AddRefs(cx)); + // Resize-reflow this time + nsCOMPtr cx; + shell->GetPresContext(getter_AddRefs(cx)); - if (cx) { - nsCOMPtr container; - cx->GetContainer(getter_AddRefs(container)); - if (container) { - nsCOMPtr webShell; - webShell = do_QueryInterface(container); - if (webShell) { - webShell->SetScrolling(NS_STYLE_OVERFLOW_HIDDEN); + if (cx) { + nsCOMPtr container; + cx->GetContainer(getter_AddRefs(container)); + if (container) { + nsCOMPtr webShell; + webShell = do_QueryInterface(container); + if (webShell) { + webShell->SetScrolling(NS_STYLE_OVERFLOW_HIDDEN); + } } - } - } + } - nsRect r; - cx->GetVisibleArea(r); - shell->InitialReflow(r.width, r.height); + nsRect r; + cx->GetVisibleArea(r); + if (r.width == 0 || r.height == 0) { + // Flow at an unconstrained width and height + r.width = NS_UNCONSTRAINEDSIZE; + r.height = NS_UNCONSTRAINEDSIZE; + } - // Now trigger a refresh - nsCOMPtr vm; - shell->GetViewManager(getter_AddRefs(vm)); - if (vm) { - vm->EnableRefresh(); - } + shell->InitialReflow(r.width, r.height); - // Start observing the document _after_ we do the initial - // reflow. Otherwise, we'll get into an trouble trying to - // create kids before the root frame is established. - shell->BeginObservingDocument(); + // Now trigger a refresh + nsCOMPtr vm; + shell->GetViewManager(getter_AddRefs(vm)); + if (vm) { + vm->EnableRefresh(); + } - NS_RELEASE(shell); + // Start observing the document _after_ we do the initial + // reflow. Otherwise, we'll get into an trouble trying to + // create kids before the root frame is established. + shell->BeginObservingDocument(); + + NS_RELEASE(shell); } return NS_OK; } diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 0868f1b8a958..4cd58d49f2ee 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -752,7 +752,7 @@ GlobalWindowImpl::GetInnerWidth(PRInt32* aInnerWidth) if (NS_OK == GetBrowserWindowInterface(mBrowser)) { nsRect r; - mBrowser->GetBounds(r); + mBrowser->GetContentBounds(r); *aInnerWidth = r.width; NS_RELEASE(mBrowser); } @@ -770,9 +770,9 @@ GlobalWindowImpl::SetInnerWidth(PRInt32 aInnerWidth) if (NS_OK == GetBrowserWindowInterface(mBrowser)) { nsRect r; - mBrowser->GetBounds(r); + mBrowser->GetContentBounds(r); - mBrowser->SizeTo(aInnerWidth, r.height); + mBrowser->SizeContentTo(aInnerWidth, r.height); NS_RELEASE(mBrowser); } return NS_OK; @@ -785,7 +785,7 @@ GlobalWindowImpl::GetInnerHeight(PRInt32* aInnerHeight) if (NS_OK == GetBrowserWindowInterface(mBrowser)) { nsRect r; - mBrowser->GetBounds(r); + mBrowser->GetContentBounds(r); *aInnerHeight = r.height; NS_RELEASE(mBrowser); } @@ -803,9 +803,9 @@ GlobalWindowImpl::SetInnerHeight(PRInt32 aInnerHeight) if (NS_OK == GetBrowserWindowInterface(mBrowser)) { nsRect r; - mBrowser->GetBounds(r); + mBrowser->GetContentBounds(r); - mBrowser->SizeTo(r.width, aInnerHeight); + mBrowser->SizeContentTo(r.width, aInnerHeight); NS_RELEASE(mBrowser); } return NS_OK; @@ -838,7 +838,7 @@ GlobalWindowImpl::SetOuterWidth(PRInt32 aOuterWidth) nsRect r; mBrowser->GetWindowBounds(r); - mBrowser->SizeTo(aOuterWidth, r.height); + mBrowser->SizeWindowTo(aOuterWidth, r.height); NS_RELEASE(mBrowser); } return NS_OK; @@ -871,7 +871,7 @@ GlobalWindowImpl::SetOuterHeight(PRInt32 aOuterHeight) nsRect r; mBrowser->GetWindowBounds(r); - mBrowser->SizeTo(r.width, aOuterHeight); + mBrowser->SizeWindowTo(r.width, aOuterHeight); NS_RELEASE(mBrowser); } return NS_OK; @@ -1323,7 +1323,7 @@ GlobalWindowImpl::ResizeTo(PRInt32 aWidth, PRInt32 aHeight) nsIBrowserWindow *mBrowser; if (NS_OK == GetBrowserWindowInterface(mBrowser)) { - mBrowser->SizeTo(aWidth, aHeight); + mBrowser->SizeWindowTo(aWidth, aHeight); NS_RELEASE(mBrowser); } return NS_OK; @@ -1338,7 +1338,7 @@ GlobalWindowImpl::ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif) nsRect r; mBrowser->GetWindowBounds(r); - mBrowser->SizeTo(r.width + aWidthDif, r.height + aHeightDif); + mBrowser->SizeWindowTo(r.width + aWidthDif, r.height + aHeightDif); NS_RELEASE(mBrowser); } return NS_OK; @@ -2066,12 +2066,20 @@ GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFea // set size if (nsnull != openedWindow) { - if (nsnull != aFeatures) { - width = WinHasOption(aFeatures, "innerWidth") | WinHasOption(aFeatures, "width"); - height = WinHasOption(aFeatures, "innerHeight") | WinHasOption(aFeatures, "height"); + PRUint32 chromeFlags = CalculateChromeFlags(aFeatures); + PRBool openAsContent = ((chromeFlags & NS_CHROME_OPEN_AS_CHROME) == 0); - // width = WinHasOption(aFeatures, "outerWidth"); - // height = WinHasOption(aFeatures, "outerHeight"); + if (nsnull != aFeatures) { + + if (openAsContent) { + width = WinHasOption(aFeatures, "innerWidth") | WinHasOption(aFeatures, "width"); + height = WinHasOption(aFeatures, "innerHeight") | WinHasOption(aFeatures, "height"); + } + else { + // Chrome. Look for outerWidth, outerHeight, or width/height + width = WinHasOption(aFeatures, "outerWidth") | WinHasOption(aFeatures, "width"); + height = WinHasOption(aFeatures, "outerHeight") | WinHasOption(aFeatures, "height"); + } left = WinHasOption(aFeatures, "left") | WinHasOption(aFeatures, "screenX"); top = WinHasOption(aFeatures, "top") | WinHasOption(aFeatures, "screenY"); @@ -2079,7 +2087,11 @@ GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFea // beard: don't resize/reposition the window if it is the same web shell. if (aOuterShell != mWebShell) { - openedWindow->SizeTo(width ? width : defaultBounds.width, height ? height : defaultBounds.height); + if (openAsContent) + openedWindow->SizeContentTo(width ? width : defaultBounds.width, height ? height : defaultBounds.height); + else if (width > 0 || height > 0) + openedWindow->SizeWindowTo(width ? width : defaultBounds.width, height ? height : defaultBounds.height); + openedWindow->MoveTo(left ? left : defaultBounds.x, top ? top : defaultBounds.y); openedWindow->Show(); } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 49d2660bc401..901867ba77f3 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -72,7 +72,7 @@ #include "nsITransferable.h" #include "nsIFormatConverter.h" #include "nsIWebShell.h" - +#include "nsIBrowserWindow.h" // Drag & Drop, Clipboard Support static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); @@ -896,6 +896,46 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + + if (maxSize.width == NS_UNCONSTRAINEDSIZE && maxSize.height == NS_UNCONSTRAINEDSIZE) { + // We were flowed intrinsically. Set our new visible area to our intrinsic + // size. + mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width, desiredSize.height)); + + // Provide our window with the hint that it needs to resize. + nsCOMPtr webShell; + nsCOMPtr container; + mPresContext->GetContainer(getter_AddRefs(container)); + if (container) { + webShell = do_QueryInterface(container); + if (webShell) { + // Retrieve our container and see if it's a browser window. + nsCOMPtr rootContainer; + webShell->GetContainer(*getter_AddRefs(rootContainer)); + if (rootContainer) { + nsCOMPtr browserWindow = do_QueryInterface(rootContainer); + if (browserWindow) { + PRInt32 chromeX,chromeY,chromeWidth,chromeHeight; + webShell->GetBounds(chromeX,chromeY,chromeWidth,chromeHeight); + + float t2p; + mPresContext->GetTwipsToPixels(&t2p); + PRInt32 width = PRInt32((float)desiredSize.width*t2p); + PRInt32 height = PRInt32((float)desiredSize.height*t2p); + + PRInt32 widthDelta = width - chromeWidth; + PRInt32 heightDelta = height - chromeHeight; + + nsRect windowBounds; + browserWindow->GetWindowBounds(windowBounds); + browserWindow->SizeWindowTo(windowBounds.width + widthDelta, + windowBounds.height + heightDelta); + } + } + } + } + } + #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { mRootFrame->VerifyTree(); diff --git a/layout/generic/nsViewportFrame.cpp b/layout/generic/nsViewportFrame.cpp index f042ed23970d..5a8b9cb0e651 100644 --- a/layout/generic/nsViewportFrame.cpp +++ b/layout/generic/nsViewportFrame.cpp @@ -397,6 +397,8 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext, } } + nsRect kidRect(0,0,aReflowState.availableWidth,aReflowState.availableHeight); + if (!isHandled) { if ((eReflowReason_Incremental == aReflowState.reason) && (mFixedFrames.ContainsFrame(nextFrame))) { @@ -437,6 +439,7 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext, nsRect rect(0, 0, kidDesiredSize.width, kidDesiredSize.height); kidFrame->SetRect(rect); + kidRect = rect; // XXX We should resolve the details of who/when DidReflow() // notifications are sent... @@ -452,11 +455,23 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext, } } - // Return the max size as our desired size - aDesiredSize.width = aReflowState.availableWidth; - aDesiredSize.height = aReflowState.availableHeight; - aDesiredSize.ascent = aReflowState.availableHeight; - aDesiredSize.descent = 0; + // If we were flowed initially at both an unconstrained width and height, + // this is a hint that we should return our child's intrinsic size. + if (eReflowReason_Initial == aReflowState.reason && + aReflowState.availableWidth == NS_UNCONSTRAINEDSIZE && + aReflowState.availableHeight == NS_UNCONSTRAINEDSIZE) { + aDesiredSize.width = kidRect.width; + aDesiredSize.height = kidRect.height; + aDesiredSize.ascent = kidRect.height; + aDesiredSize.descent = 0; + } + else { + // Return the max size as our desired size + aDesiredSize.width = aReflowState.availableWidth; + aDesiredSize.height = aReflowState.availableHeight; + aDesiredSize.ascent = aReflowState.availableHeight; + aDesiredSize.descent = 0; + } NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus); return NS_OK; diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index 49d2660bc401..901867ba77f3 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -72,7 +72,7 @@ #include "nsITransferable.h" #include "nsIFormatConverter.h" #include "nsIWebShell.h" - +#include "nsIBrowserWindow.h" // Drag & Drop, Clipboard Support static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); @@ -896,6 +896,46 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) if (NS_OK == mRootFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) { htmlReflow->Reflow(*mPresContext, desiredSize, reflowState, status); mRootFrame->SizeTo(desiredSize.width, desiredSize.height); + + if (maxSize.width == NS_UNCONSTRAINEDSIZE && maxSize.height == NS_UNCONSTRAINEDSIZE) { + // We were flowed intrinsically. Set our new visible area to our intrinsic + // size. + mPresContext->SetVisibleArea(nsRect(0,0,desiredSize.width, desiredSize.height)); + + // Provide our window with the hint that it needs to resize. + nsCOMPtr webShell; + nsCOMPtr container; + mPresContext->GetContainer(getter_AddRefs(container)); + if (container) { + webShell = do_QueryInterface(container); + if (webShell) { + // Retrieve our container and see if it's a browser window. + nsCOMPtr rootContainer; + webShell->GetContainer(*getter_AddRefs(rootContainer)); + if (rootContainer) { + nsCOMPtr browserWindow = do_QueryInterface(rootContainer); + if (browserWindow) { + PRInt32 chromeX,chromeY,chromeWidth,chromeHeight; + webShell->GetBounds(chromeX,chromeY,chromeWidth,chromeHeight); + + float t2p; + mPresContext->GetTwipsToPixels(&t2p); + PRInt32 width = PRInt32((float)desiredSize.width*t2p); + PRInt32 height = PRInt32((float)desiredSize.height*t2p); + + PRInt32 widthDelta = width - chromeWidth; + PRInt32 heightDelta = height - chromeHeight; + + nsRect windowBounds; + browserWindow->GetWindowBounds(windowBounds); + browserWindow->SizeWindowTo(windowBounds.width + widthDelta, + windowBounds.height + heightDelta); + } + } + } + } + } + #ifdef NS_DEBUG if (nsIFrame::GetVerifyTreeEnable()) { mRootFrame->VerifyTree(); diff --git a/layout/html/base/src/nsViewportFrame.cpp b/layout/html/base/src/nsViewportFrame.cpp index f042ed23970d..5a8b9cb0e651 100644 --- a/layout/html/base/src/nsViewportFrame.cpp +++ b/layout/html/base/src/nsViewportFrame.cpp @@ -397,6 +397,8 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext, } } + nsRect kidRect(0,0,aReflowState.availableWidth,aReflowState.availableHeight); + if (!isHandled) { if ((eReflowReason_Incremental == aReflowState.reason) && (mFixedFrames.ContainsFrame(nextFrame))) { @@ -437,6 +439,7 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext, nsRect rect(0, 0, kidDesiredSize.width, kidDesiredSize.height); kidFrame->SetRect(rect); + kidRect = rect; // XXX We should resolve the details of who/when DidReflow() // notifications are sent... @@ -452,11 +455,23 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext, } } - // Return the max size as our desired size - aDesiredSize.width = aReflowState.availableWidth; - aDesiredSize.height = aReflowState.availableHeight; - aDesiredSize.ascent = aReflowState.availableHeight; - aDesiredSize.descent = 0; + // If we were flowed initially at both an unconstrained width and height, + // this is a hint that we should return our child's intrinsic size. + if (eReflowReason_Initial == aReflowState.reason && + aReflowState.availableWidth == NS_UNCONSTRAINEDSIZE && + aReflowState.availableHeight == NS_UNCONSTRAINEDSIZE) { + aDesiredSize.width = kidRect.width; + aDesiredSize.height = kidRect.height; + aDesiredSize.ascent = kidRect.height; + aDesiredSize.descent = 0; + } + else { + // Return the max size as our desired size + aDesiredSize.width = aReflowState.availableWidth; + aDesiredSize.height = aReflowState.availableHeight; + aDesiredSize.ascent = aReflowState.availableHeight; + aDesiredSize.descent = 0; + } NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus); return NS_OK; diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index a6d6e9ad3068..f9255e2ae080 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -276,8 +276,8 @@ nsMessenger::Open3PaneWindow() getter_AddRefs(newWindow), // result widget nsnull, // observer nsnull, // callbacks - 200, // width - 200); // height + NS_SIZETOCONTENT, // width + NS_SIZETOCONTENT); // height done: NS_IF_RELEASE(url); return NS_OK; diff --git a/rdf/content/src/nsXULDocument.cpp b/rdf/content/src/nsXULDocument.cpp index 731169318d82..2b939d4c9165 100644 --- a/rdf/content/src/nsXULDocument.cpp +++ b/rdf/content/src/nsXULDocument.cpp @@ -107,6 +107,7 @@ #include "rdfutil.h" #include "rdf.h" +#include "nsIFrameReflow.h" #include "nsIDOMXULFocusTracker.h" #include "nsIXULFocusTracker.h" #include "nsIDOMEventCapturer.h" @@ -3951,43 +3952,49 @@ XULDocumentImpl::StartLayout(void) PRInt32 count = GetNumberOfShells(); for (PRInt32 i = 0; i < count; i++) { - nsIPresShell* shell = GetShellAt(i); - if (nsnull == shell) - continue; + nsIPresShell* shell = GetShellAt(i); + if (nsnull == shell) + continue; - // Resize-reflow this time - nsCOMPtr cx; - shell->GetPresContext(getter_AddRefs(cx)); + // Resize-reflow this time + nsCOMPtr cx; + shell->GetPresContext(getter_AddRefs(cx)); - if (cx) { - nsCOMPtr container; - cx->GetContainer(getter_AddRefs(container)); - if (container) { - nsCOMPtr webShell; - webShell = do_QueryInterface(container); - if (webShell) { - webShell->SetScrolling(NS_STYLE_OVERFLOW_HIDDEN); + if (cx) { + nsCOMPtr container; + cx->GetContainer(getter_AddRefs(container)); + if (container) { + nsCOMPtr webShell; + webShell = do_QueryInterface(container); + if (webShell) { + webShell->SetScrolling(NS_STYLE_OVERFLOW_HIDDEN); + } } - } - } + } - nsRect r; - cx->GetVisibleArea(r); - shell->InitialReflow(r.width, r.height); + nsRect r; + cx->GetVisibleArea(r); + if (r.width == 0 || r.height == 0) { + // Flow at an unconstrained width and height + r.width = NS_UNCONSTRAINEDSIZE; + r.height = NS_UNCONSTRAINEDSIZE; + } - // Now trigger a refresh - nsCOMPtr vm; - shell->GetViewManager(getter_AddRefs(vm)); - if (vm) { - vm->EnableRefresh(); - } + shell->InitialReflow(r.width, r.height); - // Start observing the document _after_ we do the initial - // reflow. Otherwise, we'll get into an trouble trying to - // create kids before the root frame is established. - shell->BeginObservingDocument(); + // Now trigger a refresh + nsCOMPtr vm; + shell->GetViewManager(getter_AddRefs(vm)); + if (vm) { + vm->EnableRefresh(); + } - NS_RELEASE(shell); + // Start observing the document _after_ we do the initial + // reflow. Otherwise, we'll get into an trouble trying to + // create kids before the root frame is established. + shell->BeginObservingDocument(); + + NS_RELEASE(shell); } return NS_OK; } diff --git a/webshell/public/nsIBrowserWindow.h b/webshell/public/nsIBrowserWindow.h index 89d2df9e20f6..17c455a1ba8e 100644 --- a/webshell/public/nsIBrowserWindow.h +++ b/webshell/public/nsIBrowserWindow.h @@ -65,10 +65,10 @@ public: NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY) = 0; - NS_IMETHOD SizeTo(PRInt32 aWidth, PRInt32 aHeight) = 0; - - NS_IMETHOD GetBounds(nsRect& aResult) = 0; + NS_IMETHOD SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight) = 0; + NS_IMETHOD SizeContentTo(PRInt32 aWidth, PRInt32 aHeight) = 0; + NS_IMETHOD GetContentBounds(nsRect& aResult) = 0; NS_IMETHOD GetWindowBounds(nsRect& aResult) = 0; NS_IMETHOD Show() = 0; diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index 5a5cea922921..26fdac45f18d 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -1526,7 +1526,7 @@ nsBrowserWindow::MoveTo(PRInt32 aX, PRInt32 aY) } NS_IMETHODIMP -nsBrowserWindow::SizeTo(PRInt32 aWidth, PRInt32 aHeight) +nsBrowserWindow::SizeContentTo(PRInt32 aWidth, PRInt32 aHeight) { NS_PRECONDITION(nsnull != mWindow, "null window"); @@ -1538,7 +1538,13 @@ nsBrowserWindow::SizeTo(PRInt32 aWidth, PRInt32 aHeight) } NS_IMETHODIMP -nsBrowserWindow::GetBounds(nsRect& aBounds) +nsBrowserWindow::SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight) +{ + return SizeContentTo(aWidth, aHeight); +} + +NS_IMETHODIMP +nsBrowserWindow::GetContentBounds(nsRect& aBounds) { mWindow->GetClientBounds(aBounds); return NS_OK; @@ -1769,7 +1775,7 @@ nsBrowserWindow::NewWebShell(PRUint32 aChromeMask, if (nsnull != browser) { nsRect bounds; - GetBounds(bounds); + GetContentBounds(bounds); browser->SetApp(mApp); diff --git a/webshell/tests/viewer/nsBrowserWindow.h b/webshell/tests/viewer/nsBrowserWindow.h index 6216ee7fb320..4cd5dfaacfa7 100644 --- a/webshell/tests/viewer/nsBrowserWindow.h +++ b/webshell/tests/viewer/nsBrowserWindow.h @@ -87,8 +87,9 @@ public: // nsIBrowserWindow NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY); - NS_IMETHOD SizeTo(PRInt32 aWidth, PRInt32 aHeight); - NS_IMETHOD GetBounds(nsRect& aBounds); + NS_IMETHOD SizeContentTo(PRInt32 aWidth, PRInt32 aHeight); + NS_IMETHOD SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight); + NS_IMETHOD GetContentBounds(nsRect& aBounds); NS_IMETHOD GetWindowBounds(nsRect& aBounds); NS_IMETHOD Show(); NS_IMETHOD Hide(); diff --git a/webshell/tests/viewer/nsWebCrawler.cpp b/webshell/tests/viewer/nsWebCrawler.cpp index 8b811148fd29..2f1df1a16146 100644 --- a/webshell/tests/viewer/nsWebCrawler.cpp +++ b/webshell/tests/viewer/nsWebCrawler.cpp @@ -300,15 +300,15 @@ nsWebCrawler::OnEndDocumentLoad(nsIDocumentLoader* loader, if (mJiggleLayout) { nsRect r; - mBrowser->GetBounds(r); + mBrowser->GetContentBounds(r); nscoord oldWidth = r.width; while (r.width > 100) { r.width -= 10; - mBrowser->SizeTo(r.width, r.height); + mBrowser->SizeWindowTo(r.width, r.height); } while (r.width < oldWidth) { r.width += 10; - mBrowser->SizeTo(r.width, r.height); + mBrowser->SizeWindowTo(r.width, r.height); } } diff --git a/xpfe/AppCores/src/nsBrowserAppCore.cpp b/xpfe/AppCores/src/nsBrowserAppCore.cpp index 57777971cdc9..7ded86958477 100644 --- a/xpfe/AppCores/src/nsBrowserAppCore.cpp +++ b/xpfe/AppCores/src/nsBrowserAppCore.cpp @@ -434,7 +434,7 @@ newWind(char* urlName) nsCOMPtr newWindow; appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow), - nsnull, nsnull, 615, 480); + nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT); NS_RELEASE(url); @@ -1537,7 +1537,7 @@ nsBrowserAppCore::NewWindow() nsCOMPtr newWindow; appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow), - nsnull, nsnull, 615, 480); + nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT); NS_RELEASE(url); return NS_OK; diff --git a/xpfe/AppCores/src/nsDOMPropsCore.cpp b/xpfe/AppCores/src/nsDOMPropsCore.cpp new file mode 100644 index 000000000000..7ade4324a5ba --- /dev/null +++ b/xpfe/AppCores/src/nsDOMPropsCore.cpp @@ -0,0 +1,509 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + + +#include "nsAppCoresManager.h" +#include "nsAppShellCIDs.h" +#include "nsIAppShellService.h" +#include "nsIDOMBaseAppCore.h" +#include "nsIDOMWindow.h" +#include "nsIScriptGlobalObject.h" +#include "nsIServiceManager.h" +#include "nsISupports.h" +#include "nsIURL.h" +#ifdef NECKO +#include "nsIIOService.h" +#include "nsIURL.h" +static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); +#endif // NECKO +#include "nsIWebShell.h" +#include "nsIWebShellWindow.h" +#include "nsIWidget.h" +#include "nsDOMPropsCore.h" + +#include "nsIDOMNode.h" +#include "nsIDOMNamedNodeMap.h" +//#include "nsIDOMNode.h" +//#include + +// Stuff to implement properties dialog. +#include "nsIDOMXULDocument.h" +#include "nsIDocumentViewer.h" +#include "nsIDOMHTMLImageElement.h" +#include "nsIContent.h" +#include "nsIDocument.h" +#include "nsIDOMWindow.h" +#include "nsIXULWindowCallbacks.h" +#include "nsIDocumentObserver.h" +#include "nsINameSpaceManager.h" + +class nsIScriptContext; + +static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); +static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID); +static NS_DEFINE_IID(kIDOMBaseAppCoreIID, NS_IDOMBASEAPPCORE_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIDOMPropsCoreIID, NS_IDOMDOMPROPSCORE_IID); + +///////////////////////////////////////////////////////////////////////// +// nsPropertiesDialog +///////////////////////////////////////////////////////////////////////// +// Note: This is only a temporary home for nsPropertiesDialog +// It will be moving to it's own component .h/.cpp file soon. +struct nsPropertiesDialog : public nsIXULWindowCallbacks, + nsIDocumentObserver { + // Declare implementation of ISupports stuff. + NS_DECL_ISUPPORTS + + // Declare implementations of nsIXULWindowCallbacks interface functions. + NS_IMETHOD ConstructBeforeJavaScript(nsIWebShell *aWebShell); + NS_IMETHOD ConstructAfterJavaScript(nsIWebShell *aWebShell) { return NS_OK; } + + // Declare implementations of nsIDocumentObserver functions. + NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell) + { return NS_OK; } + NS_IMETHOD EndReflow(nsIDocument *aDocument, nsIPresShell* aShell) + { return NS_OK; } + NS_IMETHOD ContentChanged(nsIDocument *aDocument, + nsIContent* aContent, + nsISupports* aSubContent) { return NS_OK; } + NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, + nsIContent* aContent1, + nsIContent* aContent2) { return NS_OK; } + // This one we care about; see implementation below. + NS_IMETHOD AttributeChanged(nsIDocument *aDocument, + nsIContent* aContent, + nsIAtom* aAttribute, + PRInt32 aHint); + NS_IMETHOD ContentAppended(nsIDocument *aDocument, + nsIContent* aContainer, + PRInt32 aNewIndexInContainer) + { return NS_OK; } + NS_IMETHOD ContentInserted(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) { return NS_OK; } + NS_IMETHOD ContentReplaced(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aOldChild, + nsIContent* aNewChild, + PRInt32 aIndexInContainer) { return NS_OK; } + NS_IMETHOD ContentRemoved(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) { return NS_OK; } + NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet) { return NS_OK; } + NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet) { return NS_OK; } + NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + PRBool aDisabled) { return NS_OK; } + NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule, + PRInt32 aHint) { return NS_OK; } + NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule) { return NS_OK; } + NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule) { return NS_OK; } + NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument) + { return NS_OK; } + + // nsPropertiesDialog stuff + nsPropertiesDialog( nsIDOMNode *aNode ); + virtual ~nsPropertiesDialog() {} + //void SetWindow( nsIWebShellWindow *aWindow ); + +private: + nsCOMPtr mNode; + //nsCOMPtr mWebShell; + //nsCOMPtr mWindow; + static nsIAtom *kIdAtom; +}; // nsPropertiesDialog + +nsIAtom *nsPropertiesDialog::kIdAtom = 0; + +// Standard implementations of addref/release. +NS_IMPL_ADDREF( nsPropertiesDialog ); +NS_IMPL_RELEASE( nsPropertiesDialog ); + +NS_IMETHODIMP +nsPropertiesDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr) +{ + if (aInstancePtr == NULL) { + return NS_ERROR_NULL_POINTER; + } + + // Always NULL result, in case of failure + *aInstancePtr = NULL; + + if (aIID.Equals(nsIDocumentObserver::GetIID())) { + *aInstancePtr = (void*) ((nsIDocumentObserver*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(nsIXULWindowCallbacks::GetIID())) { + *aInstancePtr = (void*) ((nsIXULWindowCallbacks*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return NS_ERROR_NO_INTERFACE; +} + +// ctor +nsPropertiesDialog::nsPropertiesDialog( nsIDOMNode *aNode ) + : mNode( nsDontQueryInterface(aNode) ) { + + // Initialize ref count. + NS_INIT_REFCNT(); + + // Initialize static atoms. + static PRBool initialized = 0; + if ( !initialized ) { + kIdAtom = NS_NewAtom("id"); + initialized = 1; + } +} + +static nsresult setAttribute( nsIWebShell *shell, + const char *id, + const nsString &name, + const nsString &value ) { + nsresult rv = NS_OK; + + nsCOMPtr cv; + rv = shell->GetContentViewer(getter_AddRefs(cv)); + if ( cv ) { + // Up-cast. + nsCOMPtr docv(do_QueryInterface(cv)); + if ( docv ) { + // Get the document from the doc viewer. + nsCOMPtr doc; + rv = docv->GetDocument(*getter_AddRefs(doc)); + if ( doc ) { + // Up-cast. + nsCOMPtr xulDoc( do_QueryInterface(doc) ); + if ( xulDoc ) { + // Find specified element. + nsCOMPtr elem; + rv = xulDoc->GetElementById( id, getter_AddRefs(elem) ); + if ( elem ) { + // Set the text attribute. + rv = elem->SetAttribute( name, value ); + if ( rv != NS_OK ) { + } + } + } + } + } + } + return rv; +} + +// Do startup stuff from C++ side. +NS_IMETHODIMP +nsPropertiesDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell) { + nsresult rv = NS_OK; + + // Save web shell pointer. + //mWebShell = nsDontQueryInterface( aWebShell ); + + // Store attributes of propeties node into dialog's DOM. + + + nsIDOMNamedNodeMap* map; + nsresult result = mNode->GetAttributes(&map); + + if (NS_OK == result) { + nsIDOMNode *node; + PRUint32 attr_count; + + result = map->GetLength(&attr_count); + if (NS_OK == result) { + for (PRUint32 ii=0; iiItem(ii,&node); + if (NS_OK == result) { + nsString name; + result = node->GetNodeName(name); + if (NS_OK == result) { + nsString value; + result = node->GetNodeValue(value); + if (NS_OK == result) { + if (name == "id") { + name = "url"; + } + setAttribute( aWebShell, "properties_node", name, value ); + //cout << "BM Props: " << "name=" << name << " value=" << value << endl; + } + } + NS_RELEASE(node); + } + } + } + NS_RELEASE(map); + } + + + + // Add as observer of the xul document. + nsCOMPtr cv; + rv = aWebShell->GetContentViewer(getter_AddRefs(cv)); + if ( cv ) { + // Up-cast. + nsCOMPtr docv(do_QueryInterface(cv)); + if ( docv ) { + // Get the document from the doc viewer. + nsCOMPtr doc; + rv = docv->GetDocument(*getter_AddRefs(doc)); + if ( doc ) { + doc->AddObserver( this ); + } + } + } + + // Trigger dialog startup code. + setAttribute( aWebShell, "dialog.start", "ready", "true" ); + + return rv; +} + +// Handle attribute changing; we only care about the element "data.execute" +// which is used to signal command execution from the UI. +NS_IMETHODIMP +nsPropertiesDialog::AttributeChanged( nsIDocument *aDocument, + nsIContent* aContent, + nsIAtom* aAttribute, + PRInt32 aHint ) { + nsresult rv = NS_OK; + + nsString id; + aContent->GetAttribute( kNameSpaceID_None, kIdAtom, id ); + if ( id == "properties_node" ) { + //cout << "BM properties node changed" << endl; + + nsIDOMNamedNodeMap* map; + nsresult result = mNode->GetAttributes(&map); + + if (NS_OK == result) { + nsIDOMNode *attr_node; + PRUint32 attr_count; + + result = map->GetLength(&attr_count); + if (NS_OK == result) { + for (PRUint32 ii=0; iiItem(ii,&attr_node); + if (NS_OK == result) { + nsString name; + result = attr_node->GetNodeName(name); + if (NS_OK == result && name != "id") { + nsString attr; + nsIAtom *atom = NS_NewAtom(name); + aContent->GetAttribute( kNameSpaceID_None, atom, attr ); + //cerr << "BM Props: name=" << name << " value=" << attr << " (setting)" << endl; + attr_node->SetNodeValue(attr); + //attr_node->SetNodeValue("something"); + NS_RELEASE(atom); + } + NS_RELEASE(attr_node); + } + } + } + NS_RELEASE(map); + } + } + + return rv; +} + +///////////////////////////////////////////////////////////////////////// +// nsDOMPropsCore +///////////////////////////////////////////////////////////////////////// + +nsDOMPropsCore::nsDOMPropsCore() { + + printf("Created nsDOMPropsCore\n"); + + IncInstanceCount(); + NS_INIT_REFCNT(); +} + +nsDOMPropsCore::~nsDOMPropsCore() { + DecInstanceCount(); +} + + +NS_IMPL_ADDREF_INHERITED(nsDOMPropsCore, nsBaseAppCore) +NS_IMPL_RELEASE_INHERITED(nsDOMPropsCore, nsBaseAppCore) + + +NS_IMETHODIMP +nsDOMPropsCore::QueryInterface(REFNSIID aIID, void** aInstancePtr) { + + if (aInstancePtr == NULL) + return NS_ERROR_NULL_POINTER; + + *aInstancePtr = NULL; + + if (aIID.Equals(kIDOMPropsCoreIID)) { + *aInstancePtr = (void*) ((nsIDOMDOMPropsCore*) this); + AddRef(); + return NS_OK; + } + + return nsBaseAppCore::QueryInterface(aIID, aInstancePtr); +} + + +NS_IMETHODIMP +nsDOMPropsCore::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { + nsresult rv = NS_OK; + + NS_PRECONDITION(aScriptObject != nsnull, "null arg"); + if (mScriptObject == nsnull) { + nsISupports *core; + rv = QueryInterface(kISupportsIID, (void **)&core); + if (NS_SUCCEEDED(rv)) { + rv = NS_NewScriptDOMPropsCore(aContext, + (nsISupports *) core, + nsnull, + &mScriptObject); + NS_RELEASE(core); + } + } + + *aScriptObject = mScriptObject; + return rv; +} + + +NS_IMETHODIMP +nsDOMPropsCore::Init(const nsString& aId) { + + nsresult rv; + + nsBaseAppCore::Init(aId); + + nsIDOMBaseAppCore *core; + rv = QueryInterface(kIDOMBaseAppCoreIID, (void **)&core); + if (NS_SUCCEEDED(rv)) { + nsAppCoresManager* sdm = new nsAppCoresManager(); + if (sdm) { + sdm->Add(core); + delete sdm; + return NS_OK; + } else + rv = NS_ERROR_OUT_OF_MEMORY; + NS_RELEASE(core); + } + return rv; +} + +NS_IMETHODIMP +nsDOMPropsCore::GetNode(nsIDOMNode** aNode) { + nsresult err = NS_OK; + return err; +} + +NS_IMETHODIMP +nsDOMPropsCore::SetNode(nsIDOMNode* aNode) { + nsresult err = NS_OK; + return err; +} + +NS_IMETHODIMP +nsDOMPropsCore::ShowProperties(const nsString& aUrl, nsIDOMWindow* aParent, nsIDOMNode* aNode) { + + nsresult rv; + nsIAppShellService *appShell; + + nsCOMPtr urlObj; +#ifndef NECKO + rv = NS_NewURL(getter_AddRefs(urlObj), aUrl); +#else + NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv); + if (NS_FAILED(rv)) return rv; + + nsIURI *uri = nsnull; + const char *uriStr = aUrl.GetBuffer(); + rv = service->NewURI(uriStr, nsnull, &uri); + if (NS_FAILED(rv)) return rv; + + rv = uri->QueryInterface(nsIURI::GetIID(), (void**)&urlObj); + NS_RELEASE(uri); +#endif // NECKO + if (NS_FAILED(rv)) + return rv; + + rv = nsServiceManager::GetService(kAppShellServiceCID, kIAppShellServiceIID, + (nsISupports**) &appShell); + if (NS_FAILED(rv)) + return rv; + + + nsPropertiesDialog *dialog = new nsPropertiesDialog(aNode); + + nsCOMPtr parent = DOMWindowToWebShellWindow(aParent); + + nsCOMPtr newWindow; + rv = appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, getter_AddRefs(newWindow), + nsnull, dialog, NS_SIZETOCONTENT, NS_SIZETOCONTENT); + + nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); + + return rv; +} + +NS_IMETHODIMP +nsDOMPropsCore::Commit() { + nsresult rv = NS_OK; + return rv; +} + + +NS_IMETHODIMP +nsDOMPropsCore::Cancel() { + nsresult rv = NS_OK; + return rv; +} + +// horribly complicated routine to simply convert from one to the other +nsCOMPtr +nsDOMPropsCore::DOMWindowToWebShellWindow(nsIDOMWindow *DOMWindow) const { + + nsCOMPtr webWindow; + + nsCOMPtr globalScript(do_QueryInterface(DOMWindow)); + nsCOMPtr webshell; + if (globalScript) + globalScript->GetWebShell(getter_AddRefs(webshell)); + if (webshell) { + nsCOMPtr webshellContainer; + webshell->GetContainer(*getter_AddRefs(webshellContainer)); + webWindow = do_QueryInterface(webshellContainer); + } + return webWindow; +} diff --git a/xpfe/AppCores/src/nsToolkitCore.cpp b/xpfe/AppCores/src/nsToolkitCore.cpp index bb4416e4cd66..8827b2e74e64 100644 --- a/xpfe/AppCores/src/nsToolkitCore.cpp +++ b/xpfe/AppCores/src/nsToolkitCore.cpp @@ -214,7 +214,7 @@ nsToolkitCore::ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent) { DOMWindowToWebShellWindow(aParent, &parent); nsCOMPtr window; appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, getter_AddRefs(window), - nsnull, nsnull, 615, 480); + nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT); if (window) window->Show(PR_TRUE); @@ -339,7 +339,7 @@ nsToolkitCore::ShowWindowWithArgs(const nsString& aUrl, nsCOMPtr window; appShell->CreateTopLevelWindow(parent, urlObj, PR_TRUE, getter_AddRefs(window), - nsnull, cb, 615, 650); + nsnull, cb, NS_SIZETOCONTENT, NS_SIZETOCONTENT); if (window) window->Show(PR_TRUE); diff --git a/xpfe/appshell/public/nsIAppShellService.idl b/xpfe/appshell/public/nsIAppShellService.idl index 722bc3908184..adf41fe388f0 100644 --- a/xpfe/appshell/public/nsIAppShellService.idl +++ b/xpfe/appshell/public/nsIAppShellService.idl @@ -35,6 +35,8 @@ interface nsICmdLineService; struct PRThread; class nsIFactory; +#define NS_SIZETOCONTENT -1 + // e5e5af70-8a38-11d2-9938-0080c7cb1080 #define NS_IAPPSHELL_SERVICE_IID \ { 0xe5e5af70, 0x8a38, 0x11d2, \ diff --git a/xpfe/appshell/src/nsAppShellService.cpp b/xpfe/appshell/src/nsAppShellService.cpp index 742541ab9ead..7e8a3bad0941 100644 --- a/xpfe/appshell/src/nsAppShellService.cpp +++ b/xpfe/appshell/src/nsAppShellService.cpp @@ -496,9 +496,18 @@ nsAppShellService::CreateTopLevelWindow(nsIWebShellWindow *aParent, nsWidgetInitData widgetInitData; widgetInitData.mBorderStyle = eBorderStyle_window; + if (aInitialWidth == NS_SIZETOCONTENT || + aInitialHeight == NS_SIZETOCONTENT) { + aInitialWidth = 0; + aInitialHeight = 0; + showWindow = PR_FALSE; // Don't show until we have the intrinsic size figured out. + window->SetIntrinsicallySized(PR_TRUE); + } + rv = window->Initialize((nsIWebShellWindow *) nsnull, mAppShell, aUrl, anObserver, aCallbacks, aInitialWidth, aInitialHeight, widgetInitData); + if (NS_SUCCEEDED(rv)) { // this does the AddRef of the return value @@ -547,6 +556,14 @@ nsAppShellService::CreateDialogWindow(nsIWebShellWindow * aParent, nsWidgetInitData widgetInitData; widgetInitData.mBorderStyle = eBorderStyle_window; + if (aInitialWidth == NS_SIZETOCONTENT || + aInitialHeight == NS_SIZETOCONTENT) { + aInitialWidth = 0; + aInitialHeight = 0; + showWindow = PR_FALSE; // Don't show until we have the intrinsic size figured out. + window->SetIntrinsicallySized(PR_TRUE); + } + rv = window->Initialize((nsIWebShellWindow *) nsnull, mAppShell, aUrl, anObserver, aCallbacks, aInitialWidth, aInitialHeight, widgetInitData); diff --git a/xpfe/appshell/src/nsCommandLineServiceMac.cpp b/xpfe/appshell/src/nsCommandLineServiceMac.cpp index 844de46f69ab..40a96c4f1647 100644 --- a/xpfe/appshell/src/nsCommandLineServiceMac.cpp +++ b/xpfe/appshell/src/nsCommandLineServiceMac.cpp @@ -1009,7 +1009,7 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) &aWindow, nsnull, inCallbacks, // callbacks - windowWidth, windowHeight); + NS_SIZETOCONTENT, NS_SIZETOCONTENT); if (NS_FAILED(rv)) return nsnull; return aWindow; diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index c0553fe26939..363e3ccb2e3a 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -205,6 +205,7 @@ nsWebShellWindow::nsWebShellWindow() mLockedUntilChromeLoad = PR_FALSE; mContentShells = nsnull; mChromeMask = NS_CHROME_ALL_CHROME; + mIntrinsicallySized = PR_FALSE; } @@ -1375,7 +1376,7 @@ nsWebShellWindow::NewWebShell(PRUint32 aChromeMask, PRBool aVisible, // Just do a nice normal create of a web shell and // return it immediately. rv = appShell->CreateTopLevelWindow(nsnull, nsnull, PR_FALSE, getter_AddRefs(newWindow), - nsnull, nsnull, 615, 480); + nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT); if (NS_SUCCEEDED(rv)) { nsCOMPtr browser(do_QueryInterface(newWindow)); if (browser) @@ -1777,44 +1778,9 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader, SetTitleFromXUL(); ShowAppropriateChrome(); LoadContentAreas(); - -#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 + + // Always show the window at this point. + mWindow->Show(PR_TRUE); return NS_OK; } @@ -2213,26 +2179,11 @@ void nsWebShellWindow::SetSizeFromXUL() specWidth = specSize; } - if (specWidth != currentSize.width || specHeight != currentSize.height) + 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); + mIntrinsicallySized = PR_FALSE; } -#endif + } // SetSizeFromXUL @@ -2610,17 +2561,50 @@ NS_IMETHODIMP nsWebShellWindow::MoveTo(PRInt32 aX, PRInt32 aY) return NS_OK; } -NS_IMETHODIMP nsWebShellWindow::SizeTo(PRInt32 aWidth, PRInt32 aHeight) +NS_IMETHODIMP nsWebShellWindow::SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight) { + // XXX We have to look at the delta between our content shell's + // size and the size passed in and then resize ourselves based on that + // delta. + mIntrinsicallySized = PR_FALSE; // We got changed. No more intrinsic sizing here. mWindow->Resize(aWidth, aHeight, PR_TRUE); return NS_OK; } -NS_IMETHODIMP nsWebShellWindow::GetBounds(nsRect& aResult) +NS_IMETHODIMP nsWebShellWindow::SizeContentTo(PRInt32 aWidth, PRInt32 aHeight) { - mWindow->GetClientBounds(aResult); + PRInt32 x,y,width,height; + mWebShell->GetBounds(x,y,width,height); + PRInt32 aWidthDelta = aWidth - width; + PRInt32 aHeightDelta = aHeight - height; + + nsRect windowBounds; + mWindow->GetBounds(windowBounds); + mWindow->Resize(windowBounds.width + aWidthDelta, + windowBounds.height + aHeightDelta, + PR_TRUE); return NS_OK; } + +NS_IMETHODIMP nsWebShellWindow::GetContentBounds(nsRect& aResult) +{ + // Should return the size of the content webshell. + nsCOMPtr contentShell; + GetContentWebShell(getter_AddRefs(contentShell)); + if (!contentShell) { + NS_ERROR("Attempt to retrieve the content bounds for a window with no content."); + return NS_ERROR_FAILURE; + } + + PRInt32 x,y,width,height; + contentShell->GetBounds(x,y,width,height); + aResult.x = x; + aResult.y = y; + aResult.width = width; + aResult.height = height; + + return NS_OK; +} NS_IMETHODIMP nsWebShellWindow::GetWindowBounds(nsRect& aResult) { diff --git a/xpfe/appshell/src/nsWebShellWindow.h b/xpfe/appshell/src/nsWebShellWindow.h index 40e16c80e5d6..6b094f21704e 100644 --- a/xpfe/appshell/src/nsWebShellWindow.h +++ b/xpfe/appshell/src/nsWebShellWindow.h @@ -125,6 +125,8 @@ public: nsWidgetInitData& widgetInitData); nsIWidget* GetWidget(void) { return mWindow; } + void SetIntrinsicallySized(PRBool isIntrinsicallySized) { mIntrinsicallySized = isIntrinsicallySized; }; + void DoContextMenu( nsMenuEvent * aMenuEvent, nsIDOMNode * aMenuNode, @@ -224,8 +226,9 @@ public: PRUint32 aChromeMask, PRBool aAllowPlugins = PR_TRUE); NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY); - NS_IMETHOD SizeTo(PRInt32 aWidth, PRInt32 aHeight); - NS_IMETHOD GetBounds(nsRect& aResult); + NS_IMETHOD SizeContentTo(PRInt32 aWidth, PRInt32 aHeight); + NS_IMETHOD SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight); + NS_IMETHOD GetContentBounds(nsRect& aResult); NS_IMETHOD GetWindowBounds(nsRect& aResult); NS_IMETHOD Show() { Show(PR_TRUE); return NS_OK; } NS_IMETHOD Hide() { Show(PR_FALSE); return NS_OK; } @@ -285,6 +288,9 @@ protected: nsIDOMNode * contextMenuTest; nsString mStatus; + + PRBool mIntrinsicallySized; // Whether or not this window gets sized to its content. + private: static void * HandleModalDialogEvent(PLEvent *aEvent); diff --git a/xpfe/bootstrap/nsAppRunner.cpp b/xpfe/bootstrap/nsAppRunner.cpp index f68c61426d0d..7728546f9722 100644 --- a/xpfe/bootstrap/nsAppRunner.cpp +++ b/xpfe/bootstrap/nsAppRunner.cpp @@ -614,7 +614,7 @@ int main(int argc, char* argv[]) nsCOMPtr profWindow; rv = profAppShell->CreateTopLevelWindow(nsnull, profURL, PR_TRUE, getter_AddRefs(profWindow), - nsnull, nsnull, profWinWidth, profWinHeight); + nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT); NS_RELEASE(profURL); @@ -643,7 +643,7 @@ int main(int argc, char* argv[]) if ( !useArgs ) { nsCOMPtr newWindow; rv = appShell->CreateTopLevelWindow(nsnull, url, PR_TRUE, getter_AddRefs(newWindow), - nsnull, nsnull, widthVal, heightVal); + nsnull, nsnull, NS_SIZETOCONTENT, NS_SIZETOCONTENT); } else { nsIDOMToolkitCore* toolkit = nsnull; rv = nsServiceManager::GetService(kToolkitCoreCID, diff --git a/xpfe/browser/src/navigator.xul b/xpfe/browser/src/navigator.xul index af3cbabd42ed..d91036acd4b7 100644 --- a/xpfe/browser/src/navigator.xul +++ b/xpfe/browser/src/navigator.xul @@ -262,7 +262,7 @@ Contributor(s): ______________________________________. --> - + diff --git a/xpfe/components/startup/src/nsCommandLineServiceMac.cpp b/xpfe/components/startup/src/nsCommandLineServiceMac.cpp index 844de46f69ab..40a96c4f1647 100644 --- a/xpfe/components/startup/src/nsCommandLineServiceMac.cpp +++ b/xpfe/components/startup/src/nsCommandLineServiceMac.cpp @@ -1009,7 +1009,7 @@ nsIWebShellWindow* FindWebShellWindow(nsIXULWindowCallbacks* inCallbacks) &aWindow, nsnull, inCallbacks, // callbacks - windowWidth, windowHeight); + NS_SIZETOCONTENT, NS_SIZETOCONTENT); if (NS_FAILED(rv)) return nsnull; return aWindow;