Bug 655005 - [RTL] left scrollbar is mispositioned when the control sidebar is visible [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Mon, 09 May 2011 13:28:48 +0200
changeset 69379 35979ec6850a57feaa05bf2f76d55847646e2505
parent 69378 3ab07933020e68961da5901fd2216fafbacce605
child 69380 807ea3a5844f7165d0930fd7cff6682ed84d6150
push id76
push userbzbarsky@mozilla.com
push dateTue, 05 Jul 2011 17:00:57 +0000
treeherdermozilla-beta@d3a2732c35f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs655005
milestone6.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 655005 - [RTL] left scrollbar is mispositioned when the control sidebar is visible [r=mfinkle]
mobile/chrome/content/browser.js
mobile/chrome/tests/browser_scrollbar.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1389,23 +1389,22 @@ Browser.MainDragger.prototype = {
 
     if (scaleY) {
       let y = Math.round(contentScroll.y * scaleY);
 
       // Vertical scrollbar is out of view when showing the tabs sidebar,
       // the 'solution' for now is to reposition it if needed
       let x = 0;
       if (Browser.floatedWhileDragging) {
+        let [tabsVis, controlsVis, tabsW, controlsW] = Browser.computeSidebarVisibility();
+        let [tabsSidebar, controlsSidebar] = [Elements.tabs.getBoundingClientRect(), Elements.controls.getBoundingClientRect()];
+
         // Check if the sidebars are inverted (rtl)
-        let [leftVis, rightVis, leftW, rightW] = Browser.computeSidebarVisibility();
-        let [leftSidebar, rightSidebar] = [Elements.tabs.getBoundingClientRect(), Elements.controls.getBoundingClientRect()];
-        if (leftSidebar.left > rightSidebar.left)
-          x = Math.round(Math.max(0, rightW * rightVis));
-        else
-          x = Math.round(Math.max(0, leftW * leftVis)) * -1.0;
+        let direction = (tabsSidebar.left > controlsSidebar.left) ? 1 : -1;
+        x = Math.round(tabsW * tabsVis) * direction
       }
 
       this._verticalScrollbar.style.MozTransform = "translate(" + x + "px," + y + "px)";
     }
   },
 
   _showScrollbars: function _showScrollbars() {
     this._updateScrollbars();
--- a/mobile/chrome/tests/browser_scrollbar.js
+++ b/mobile/chrome/tests/browser_scrollbar.js
@@ -51,16 +51,31 @@ function checkScrollbars(aHorizontalVisi
   let horizontalVisible = horizontalScrollbar.hasAttribute("panning"),
       verticalVisible = verticalScrollbar.hasAttribute("panning");
   is(horizontalVisible, aHorizontalVisible, "The horizontal scrollbar should be " + (aHorizontalVisible ? "visible" : "hidden"));
   is(verticalVisible, aVerticalVisible, "The vertical scrollbar should be " + (aVerticalVisible ? "visible" : "hidden"));
 
   EventUtils.synthesizeMouse(browser, width / 2, height * 3 / 4, { type: "mouseup" });
 }
 
+function checkScrollbarsPosition(aX) {
+  let browser = getBrowser();
+  let width = browser.getBoundingClientRect().width;
+  let height = browser.getBoundingClientRect().height;
+  EventUtils.synthesizeMouse(browser, width / 2, height / 4, { type: "mousedown" });
+  EventUtils.synthesizeMouse(browser, width / 2, height * 3 / 4, { type: "mousemove" });
+
+  let verticalRect = verticalScrollbar.getBoundingClientRect();
+  let margin = parseInt(verticalScrollbar.getAttribute("end"));
+  let expectedPosition = window.innerWidth - aX - margin;
+  is(verticalRect.right, expectedPosition, "The vertical scrollbar should be position to " + expectedPosition + " (got " + verticalRect.right + ")");
+
+  EventUtils.synthesizeMouse(browser, width / 2, height * 3 / 4, { type: "mouseup" });
+}
+
 gTests.push({
   desc: "Testing visibility of scrollbars",
 
   run: function() {
     waitForPageShow(testURL_01 + "blank", gCurrentTest.checkNotScrollable);
     gOpenedTabs.push(Browser.addTab(testURL_01 + "blank", true));
   },
 
@@ -96,16 +111,51 @@ gTests.push({
       setTimeout(function() {
         Browser.hideSidebars();
       }, 0);
       runNextTest();
     }, false);
   }
 });
 
+gTests.push({
+  desc: "Testing position of scrollbars",
+
+  run: function() {
+    waitForPageShow(testURL_01 + "vertical", gCurrentTest.checkScrollbarsPosition);
+    gOpenedTabs.push(Browser.addTab(testURL_01 + "vertical", true));
+  },
+
+  checkScrollbarsPosition: function() {
+    let [,, tabsWidth, controlsWidth] = Browser.computeSidebarVisibility();
+
+    checkScrollbarsPosition(0);
+
+    // Show the left sidebar and ensure scrollbar is visible
+    Browser.controlsScrollboxScroller.scrollTo(0, 0);
+    checkScrollbarsPosition(-tabsWidth);
+
+    // Show the right sidebar and ensure scrollbar is visible
+    Browser.controlsScrollboxScroller.scrollTo(tabsWidth + controlsWidth, 0);
+    checkScrollbarsPosition(controlsWidth);
+
+    gCurrentTest.finish();
+  },
+
+  finish: function() {
+    Elements.browsers.addEventListener("PanFinished", function(aEvent) {
+      Elements.browsers.removeEventListener("PanFinished", arguments.callee, false);
+      setTimeout(function() {
+        Browser.hideSidebars();
+      }, 0);
+      runNextTest();
+    }, false);
+  }
+});
+
 
 gTests.push({
   desc: "Check scrollbar visibility when the touch sequence is cancelled",
 
   run: function() {
     waitForPageShow(testURL_01 + "both", gCurrentTest.checkVisibility);
     gOpenedTabs.push(Browser.addTab(testURL_01 + "both", true));
   },