Bug 845010 - turn nsIDOMWindowUtils.getScrollbarWidth() into .getScrollbarSize(); r=roc
authorTim Taubert <ttaubert@mozilla.com>
Mon, 25 Feb 2013 23:13:36 +0100
changeset 122999 449530bfce47bcd53bf31e7bfb4810251e32b3b2
parent 122998 652d420b1800a29d8410c2b28d72c868a66533c0
child 123000 0282296facc580d7b9dd98e2b2572433557c6ad0
push id24369
push userttaubert@mozilla.com
push dateWed, 27 Feb 2013 00:00:58 +0000
treeherdermozilla-central@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs845010
milestone22.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 845010 - turn nsIDOMWindowUtils.getScrollbarWidth() into .getScrollbarSize(); r=roc
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
dom/tests/mochitest/general/Makefile.in
dom/tests/mochitest/general/file_domWindowUtils_scrollbarSize.html
dom/tests/mochitest/general/file_domWindowUtils_scrollbarWidth.html
dom/tests/mochitest/general/test_domWindowUtils_scrollbarSize.html
dom/tests/mochitest/general/test_domWindowUtils_scrollbarWidth.html
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1435,23 +1435,25 @@ nsDOMWindowUtils::GetScrollXY(bool aFlus
 
   *aScrollX = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.x);
   *aScrollY = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMWindowUtils::GetScrollbarWidth(bool aFlushLayout, int32_t* aResult)
+nsDOMWindowUtils::GetScrollbarSize(bool aFlushLayout, int32_t* aWidth,
+                                                      int32_t* aHeight)
 {
   if (!nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
-  *aResult = 0;
+  *aWidth = 0;
+  *aHeight = 0;
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
   NS_ENSURE_STATE(window);
 
   nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
   NS_ENSURE_STATE(doc);
 
   if (aFlushLayout) {
@@ -1460,17 +1462,18 @@ nsDOMWindowUtils::GetScrollbarWidth(bool
 
   nsIPresShell* presShell = doc->GetShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_NOT_AVAILABLE);
 
   nsIScrollableFrame* scrollFrame = presShell->GetRootScrollFrameAsScrollable();
   NS_ENSURE_TRUE(scrollFrame, NS_OK);
 
   nsMargin sizes = scrollFrame->GetActualScrollbarSizes();
-  *aResult = nsPresContext::AppUnitsToIntCSSPixels(sizes.LeftRight());
+  *aWidth = nsPresContext::AppUnitsToIntCSSPixels(sizes.LeftRight());
+  *aHeight = nsPresContext::AppUnitsToIntCSSPixels(sizes.TopBottom());
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetRootBounds(nsIDOMClientRect** aResult)
 {
   if (!nsContentUtils::IsCallerChrome()) {
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -36,17 +36,17 @@ interface nsIDOMWindow;
 interface nsIDOMBlob;
 interface nsIDOMFile;
 interface nsIFile;
 interface nsIDOMTouch;
 interface nsIDOMClientRect;
 interface nsIURI;
 interface nsIDOMEventTarget;
 
-[scriptable, uuid(16b3bdcc-75d4-11e2-8a20-aaff78957a39)]
+[scriptable, uuid(9ab64e24-7f8d-11e2-9a5f-a24379957a39)]
 interface nsIDOMWindowUtils : nsISupports {
 
   /**
    * Image animation mode of the window. When this attribute's value
    * is changed, the implementation should set all images in the window
    * to the given value. That is, when set to kDontAnimMode, all images
    * will stop animating. The attribute's value must be one of the
    * animationMode values from imgIContainer.
@@ -647,17 +647,17 @@ interface nsIDOMWindowUtils : nsISupport
    */
   void getScrollXY(in boolean aFlushLayout, out long aScrollX, out long aScrollY);
 
   /**
    * Returns the scrollbar width of the window's scroll frame.
    *
    * @param aFlushLayout flushes layout if true. Otherwise, no flush occurs.
    */
-  long getScrollbarWidth(in boolean aFlushLayout);
+  void getScrollbarSize(in boolean aFlushLayout, out long aWidth, out long aHeight);
 
   /**
    * Returns the bounds of the window's currently loaded document. This will
    * generally be (0, 0, pageWidth, pageHeight) but in some cases (e.g. RTL
    * documents) may have a negative left value.
    */
   nsIDOMClientRect getRootBounds();
 
--- a/dom/tests/mochitest/general/Makefile.in
+++ b/dom/tests/mochitest/general/Makefile.in
@@ -24,18 +24,18 @@ MOCHITEST_FILES = \
 		file_bug628069.html \
 		test_bug631440.html \
 		test_bug653364.html \
 		test_bug629535.html \
 		test_clientRects.html \
 		test_consoleAPI.html \
 		test_domWindowUtils.html \
 		test_domWindowUtils_scrollXY.html \
-		test_domWindowUtils_scrollbarWidth.html \
-		file_domWindowUtils_scrollbarWidth.html \
+		test_domWindowUtils_scrollbarSize.html \
+		file_domWindowUtils_scrollbarSize.html \
 		test_offsets.html \
 		test_offsets.js \
 		test_windowProperties.html \
 		test_clipboard_events.html \
 		test_frameElementWrapping.html \
 		file_frameElementWrapping.html \
 		test_framedhistoryframes.html \
 		test_windowedhistoryframes.html \
rename from dom/tests/mochitest/general/file_domWindowUtils_scrollbarWidth.html
rename to dom/tests/mochitest/general/file_domWindowUtils_scrollbarSize.html
rename from dom/tests/mochitest/general/test_domWindowUtils_scrollbarWidth.html
rename to dom/tests/mochitest/general/test_domWindowUtils_scrollbarSize.html
--- a/dom/tests/mochitest/general/test_domWindowUtils_scrollbarWidth.html
+++ b/dom/tests/mochitest/general/test_domWindowUtils_scrollbarSize.html
@@ -1,48 +1,65 @@
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>nsIDOMWindowUtils::getScrollbarWidth test</title>
+  <title>nsIDOMWindowUtils::getScrollbarSize test</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
 </head>
 
 <body id="body">
   <script type="application/javascript;version=1.8">
     function doTests() {
       let iframe = document.getElementById("iframe");
       let cwindow = iframe.contentWindow;
       let utils = SpecialPowers.getDOMWindowUtils(cwindow);
       let doc = cwindow.document;
 
       function haveNonFloatingScrollbars() {
         return doc.getElementById("float").offsetWidth > 200;
       }
 
-      is(utils.getScrollbarWidth(true), 0,
-         "getScrollbarWidth returns zero without a scrollbar");
+      checkScrollbarSizeFlush(utils, function (w, h) w == 0 && h == 0,
+        "[overflow=hidden] corrrect scrollbar size after flushing");
 
       // Some platforms (esp. mobile) may have floating scrollbars that don't
-      // affect layout. Thus getScrollbarWidth() would always return 0.
+      // affect layout. Thus getScrollbarSize() would always return zeros.
       if (haveNonFloatingScrollbars()) {
         let body = doc.querySelector("body");
         body.style.overflowY = "scroll";
 
-        is(utils.getScrollbarWidth(false), 0,
-           "getScrollbarWidth returns zero with a vertical scrollbar w/o flushing");
+        checkScrollbarSize(utils, function (w, h) w == 0 && h == 0,
+          "[overflowY=scroll] correct scrollbar size w/o flushing");
+
+        checkScrollbarSizeFlush(utils, function (w, h) w > 0 && h == 0,
+          "[overflowY=scroll] correct scrollbar size after flushing");
 
-        ok(utils.getScrollbarWidth(true) > 0,
-           "getScrollbarWidth returns non-zero with a vertical scrollbar with flushing");
+        body.style.overflowX = "scroll";
+        checkScrollbarSize(utils, function (w, h) w > 0 && h == 0,
+          "[overflowXY=scroll] correct scrollbar size w/o flushing");
+
+        checkScrollbarSizeFlush(utils, function (w, h) w > 0 && h > 0,
+          "[overflowXY=scroll] correct scrollbar size after flushing");
       }
 
       SimpleTest.finish();
     }
 
+    function checkScrollbarSize(utils, check, msg, flush = false) {
+      let width = {}, height = {};
+      utils.getScrollbarSize(flush, width, height);
+      ok(check(width.value, height.value), msg);
+    }
+
+    function checkScrollbarSizeFlush(utils, check, msg) {
+      checkScrollbarSize(utils, check, msg, true);
+    }
+
     SimpleTest.waitForExplicitFinish();
   </script>
 
-  <iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_domWindowUtils_scrollbarWidth.html"
+  <iframe src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_domWindowUtils_scrollbarSize.html"
           id="iframe" onload="doTests();">
   </iframe>
 
 </body>
 </html>