Bug 458898. Fix intrinsic sizing of windows by ensuring CanvasFrame converts an NS_UNCONSTRAINEDSIZE desired height to its actual desired height. r+sr=dbaron
☠☠ backed out by 833b6fe6a82f ☠ ☠
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 03 Dec 2008 09:50:16 +1300
changeset 22178 357d1c01bde3a91b3391e0d5143fa9dd49ed9963
parent 22177 992000e45526c4ef3c398585f54d1c8e6896f7b4
child 22179 7baaa800925d3e2fb14afd71dadc314706d5d383
child 22230 833b6fe6a82f2ba2d97a2fc6dc54e6125afb2ddd
push id3843
push userrocallahan@mozilla.com
push dateTue, 02 Dec 2008 21:22:28 +0000
treeherdermozilla-central@31e5958cb97a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs458898
milestone1.9.2a1pre
Bug 458898. Fix intrinsic sizing of windows by ensuring CanvasFrame converts an NS_UNCONSTRAINEDSIZE desired height to its actual desired height. r+sr=dbaron
layout/base/nsPresContext.h
layout/base/tests/Makefile.in
layout/base/tests/test_bug458898.html
layout/generic/nsHTMLFrame.cpp
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -412,17 +412,17 @@ public:
 #endif
 
   // XXX this are going to be replaced with set/get container
   void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
   nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
 
   /**
    * Get the visible area associated with this presentation context.
-   * This is the size of the visiable area that is used for
+   * This is the size of the visible area that is used for
    * presenting the document. The returned value is in the standard
    * nscoord units (as scaled by the device context).
    */
   nsRect GetVisibleArea() { return mVisibleArea; }
 
   /**
    * Set the currently visible area. The units for r are standard
    * nscoord units (as scaled by the device context).
--- a/layout/base/tests/Makefile.in
+++ b/layout/base/tests/Makefile.in
@@ -89,15 +89,16 @@ DEFINES += -D_IMPL_NS_LAYOUT
 		test_bug399951.html \
 		test_bug404209.xhtml \
 		test_bug416896.html \
 		test_bug420499.xul \
 		test_bug423523.html \
 		test_bug445810.html \
 		test_bug449781.html \
 		test_bug450930.xhtml \
+		test_bug458898.html \
 		$(NULL)
 # test_bug396024.html is currently disabled because it interacts badly with
 # the "You can't print-preview while the page is loading" dialog.
 # (See bug 407080)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/test_bug458898.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=458898
+-->
+<head>
+  <title>Test for Bug 458898</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=458898">Mozilla Bug 458898</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+var win = window.openDialog("data:text/html,<div style='height:200px; width:100px;'>");
+
+function loaded() {
+  win.sizeToContent();
+  ok(win.innerWidth >= 100, "innerWidth");
+  ok(win.innerHeight >= 200, "innerHeight");
+  win.close();
+  SimpleTest.finish();
+}
+
+win.addEventListener("load", loaded, false);
+
+</script>
+</pre>
+</body>
+</html>
--- a/layout/generic/nsHTMLFrame.cpp
+++ b/layout/generic/nsHTMLFrame.cpp
@@ -704,19 +704,26 @@ CanvasFrame::Reflow(nsPresContext*      
       // Also note: GetPosition() on a CanvasFrame is always going to return
       // (0, 0). We only want to invalidate GetRect() since GetOverflowRect()
       // could also include overflow to our top and left (out of the viewport)
       // which doesn't need to be painted.
       nsIFrame* viewport = PresContext()->GetPresShell()->GetRootFrame();
       viewport->Invalidate(nsRect(nsPoint(0, 0), viewport->GetSize()));
     }
     
-    // Return our desired size (which doesn't matter)
+    // Return our desired size. Normally it's what we're told, but
+    // sometimes we can be given an unconstrained height (when a window
+    // is sizing-to-content), and we should compute our desired height.
     aDesiredSize.width = aReflowState.ComputedWidth();
-    aDesiredSize.height = aReflowState.ComputedHeight();
+    if (aReflowState.ComputedHeight() == NS_UNCONSTRAINEDSIZE) {
+      aDesiredSize.height = kidFrame->GetRect().height +
+        kidReflowState.mComputedMargin.TopBottom();
+    } else {
+      aDesiredSize.height = aReflowState.ComputedHeight();
+    }
 
     aDesiredSize.mOverflowArea.UnionRect(
       nsRect(0, 0, aDesiredSize.width, aDesiredSize.height),
       kidDesiredSize.mOverflowArea + kidPt);
 
     if (mAbsoluteContainer.HasAbsoluteFrames()) {
       PRBool widthChanged = aDesiredSize.width != mRect.width;
       PRBool heightChanged = aDesiredSize.height != mRect.height;