Bug 807571 - popup now resizes when sizeTo is called with the same height while open. r=enndeakin
authorMark Hammond <mhammond@skippinet.com.au>
Wed, 07 Nov 2012 11:58:01 +1100
changeset 112488 59e5f407eb75ab1b50b8215f7ca9023401123289
parent 112487 70f7e6ce95b8f6de7a42da57f13c1cb1040e935a
child 112496 4e8873d14ed3c7a7498cad6e109cbdd12b1e0444
push id17609
push usermhammond@skippinet.com.au
push dateWed, 07 Nov 2012 00:58:28 +0000
treeherdermozilla-inbound@59e5f407eb75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin
bugs807571
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 807571 - popup now resizes when sizeTo is called with the same height while open. r=enndeakin
layout/xul/base/src/nsPopupBoxObject.cpp
layout/xul/base/test/Makefile.in
layout/xul/base/test/test_popupSizeTo.xul
--- a/layout/xul/base/src/nsPopupBoxObject.cpp
+++ b/layout/xul/base/src/nsPopupBoxObject.cpp
@@ -139,17 +139,24 @@ nsPopupBoxObject::SizeTo(int32_t aWidth,
   if (!mContent)
     return NS_OK;
 
   nsAutoString width, height;
   width.AppendInt(aWidth);
   height.AppendInt(aHeight);
 
   nsCOMPtr<nsIContent> content = mContent;
-  content->SetAttr(kNameSpaceID_None, nsGkAtoms::width, width, false);
+
+  // We only want to pass aNotify=true to SetAttr once, but must make sure
+  // we pass it when a value is being changed.  Thus, we check if the height
+  // is the same and if so, pass true when setting the width and skip setting
+  // the height.
+  bool heightSame = content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::height, height, eCaseMatters);
+
+  content->SetAttr(kNameSpaceID_None, nsGkAtoms::width, width, heightSame);
   content->SetAttr(kNameSpaceID_None, nsGkAtoms::height, height, true);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPopupBoxObject::GetAutoPosition(bool* aShouldAutoPosition)
 {
--- a/layout/xul/base/test/Makefile.in
+++ b/layout/xul/base/test/Makefile.in
@@ -14,16 +14,17 @@ include $(DEPTH)/config/autoconf.mk
 MOCHITEST_FILES = 	test_bug511075.html \
 		test_splitter.xul \
 		test_resizer_incontent.xul \
 		$(NULL)
 
 MOCHITEST_CHROME_FILES =	test_bug381167.xhtml \
 		test_bug393970.xul \
 		test_bug477754.xul \
+		test_popupSizeTo.xul \
 		test_stack.xul \
 		test_resizer.xul \
 		window_resizer.xul \
 		window_resizer_element.xul \
 		test_windowminmaxsize.xul \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/layout/xul/base/test/test_popupSizeTo.xul
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
+<!--
+XUL Panel sizeTo tests
+-->
+<window title="XUL Panel sizeTo tests"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript"><![CDATA[
+    SimpleTest.waitForExplicitFinish();
+
+    function openPopup()
+    {
+      document.getElementById("panel").
+        openPopupAtScreen(Math.round(window.mozInnerScreenX) + window.innerWidth - 130,
+                          Math.round(window.mozInnerScreenY) + window.innerHeight - 130);
+    }
+
+    function sizeAndCheck(width, height) {
+      var panel = document.getElementById("panel");
+      panel.sizeTo(width, height);
+      is(panel.getBoundingClientRect().width, width, "width is correct");
+      is(panel.getBoundingClientRect().height, height, "height is correct");
+
+    }
+    function popupShown(event)
+    {
+      var panel = document.getElementById("panel");
+      var bcr = panel.getBoundingClientRect();
+      // resize to 10px bigger in both dimensions.
+      sizeAndCheck(bcr.width+10, bcr.height+10);
+      // Same width, different height (based on *new* size from last sizeAndCheck)
+      sizeAndCheck(bcr.width+10, bcr.height);
+      // Same height, different width (also based on *new* size from last sizeAndCheck)
+      sizeAndCheck(bcr.width, bcr.height);
+      event.target.hidePopup();
+    }
+
+    SimpleTest.waitForFocus(openPopup);
+   ]]></script>
+
+<panel id="panel" onpopupshown="popupShown(event)" onpopuphidden="SimpleTest.finish()">
+  <resizer id="resizer" dir="bottomend" width="16" height="16"/>
+  <hbox width="50" height="50" flex="1"/>
+</panel>
+
+</window>