Bug 1356705 - Fixes to fold on to previous patch. r?dao draft
authorMike Conley <mconley@mozilla.com>
Thu, 27 Jul 2017 13:43:27 -0400
changeset 617665 74c8d893389bb584ca3dd7aff39ec35ac016d9e7
parent 617664 76880f3c4efd13bc1c2f4ff2730124eaa25cb5a1
child 639868 6ed4df526c9cf11facbe157000850398933b8bd4
push id71114
push usermconley@mozilla.com
push dateFri, 28 Jul 2017 19:50:29 +0000
reviewersdao
bugs1356705
milestone56.0a1
Bug 1356705 - Fixes to fold on to previous patch. r?dao MozReview-Commit-ID: JGn3nuobVaB
browser/base/content/tabbrowser.xml
toolkit/content/widgets/scrollbox.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -5884,16 +5884,31 @@
           if (this._tabMarginLeft === null || this._tabMarginRight === null) {
             let tabMiddle = document.getAnonymousElementByAttribute(aTab, "class", "tab-background-middle");
             let tabMiddleStyle = window.getComputedStyle(tabMiddle);
             this._tabMarginLeft = parseFloat(tabMiddleStyle.marginLeft);
             this._tabMarginRight = parseFloat(tabMiddleStyle.marginRight);
           }
         ]]></body>
       </method>
+      <method name="_adjustElementStartAndEnd">
+        <parameter name="aTab"/>
+        <parameter name="tabStart"/>
+        <parameter name="tabEnd"/>
+        <body><![CDATA[
+          this._calcTabMargins(aTab);
+          if (this._tabMarginLeft < 0) {
+            tabStart = tabStart + this._tabMarginLeft;
+          }
+          if (this._tabMarginRight < 0) {
+            tabEnd = tabEnd - this._tabMarginRight;
+          }
+          return [tabStart, tabEnd];
+        ]]></body>
+      </method>
     </implementation>
 
     <handlers>
       <handler event="underflow" phase="capturing"><![CDATA[
         if (event.originalTarget != this._scrollbox)
           return;
 
         // Ignore vertical events
--- a/toolkit/content/widgets/scrollbox.xml
+++ b/toolkit/content/widgets/scrollbox.xml
@@ -244,23 +244,53 @@
             return;
 
           let elements = this._getScrollableElements();
           let index = elements.indexOf(element);
           if (index == -1) {
             return;
           }
           if (index == 0) {
-            //XXX special case for Firefox tabs using negative margin, remove after bug 1349555
+            // XXX special case for Firefox tabs using negative margin, remove after bug 1349555
             this.scrollPosition = 0;
           } else if (index == elements.length - 1) {
-            //XXX special case for Firefox tabs using negative margin, remove after bug 1349555
+            // XXX special case for Firefox tabs using negative margin, remove after bug 1349555
             this.scrollPosition = this.scrollSize;
+          } else if (this._adjustElementStartAndEnd) {
+            // XXX special case for Firefox tabs using negative margin, remove after bug 1349555
+            let windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                                    .getInterface(Ci.nsIDOMWindowUtils);
+            let bounds = windowUtils.getBoundsWithoutFlushing(element);
+            let thisRect = windowUtils.getBoundsWithoutFlushing(this._scrollbox);
+
+            let vertical = this.orient == "vertical";
+            let containerStart = vertical ? thisRect.top : thisRect.left;
+            let containerEnd = vertical ? thisRect.bottom : thisRect.right;
+            let elementStart = vertical ? bounds.top : bounds.left;
+            let elementEnd = vertical ? bounds.bottom : bounds.right;
+
+            [elementStart, elementEnd] =
+              this._adjustElementStartAndEnd(element, elementStart, elementEnd);
+
+            let amountToScroll = 0;
+            if (elementStart < containerStart) {
+              amountToScroll = elementStart - containerStart;
+            } else if (containerEnd < elementEnd) {
+              amountToScroll = elementEnd - containerEnd;
+            } else {
+              return;
+            }
+
+            let opts = { behavior: aSmoothScroll == false ? "instant" : "auto" };
+            let prop = vertical ? "top" : "left";
+            opts[prop] = amountToScroll;
+
+            this._scrollbox.scrollBy(opts);
           } else {
-            element.scrollIntoView({ behavior: aSmoothScroll == false ? "instant" : "auto" });
+           element.scrollIntoView({ behavior: aSmoothScroll == false ? "instant" : "auto" });
           }
         ]]></body>
       </method>
 
       <method name="scrollByIndex">
         <parameter name="index"/>
         <parameter name="aSmoothScroll"/>
         <body><![CDATA[
@@ -748,20 +778,16 @@
         </body>
       </method>
 
       <method name="_stopScroll">
         <body><![CDATA[
           if (this._scrollTimer)
             this._scrollTimer.cancel();
           this._mousedown = false;
-          if (!this._scrollIndex)
-            return;
-
-          this.scrollByIndex(this._scrollIndex);
           this._scrollIndex = 0;
         ]]></body>
       </method>
 
       <method name="_pauseScroll">
         <body><![CDATA[
           if (this._mousedown) {
             this._stopScroll();