Bug 1510414 - Use RTL_UI throughout tabbrowser.xml. r=florian
authorDão Gottwald <dao@mozilla.com>
Wed, 28 Nov 2018 17:34:57 +0000
changeset 504984 f6632f5349d67c87d41aab7b07577abd8cc58a48
parent 504983 2b9aaf2f3b58ee8d39ce4d4b2c4f4c935894d030
child 504985 3b37632be987ce0ae9df8354eaa46ce91c73c18a
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1510414
milestone65.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 1510414 - Use RTL_UI throughout tabbrowser.xml. r=florian Differential Revision: https://phabricator.services.mozilla.com/D13124
browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -764,20 +764,19 @@
               addAnimationData(movingTab, insertAtPos, "right");
             } else {
               gBrowser.moveTabTo(movingTab, insertAtPos);
             }
             insertAtPos++;
           }
 
           // Slide the relevant tabs to their new position.
-          let rtl = Services.locale.isAppLocaleRTL ? -1 : 1;
           for (let t of this._getVisibleTabs()) {
             if (t.groupingTabsData && t.groupingTabsData.translateX) {
-              let translateX = rtl * t.groupingTabsData.translateX;
+              let translateX = (RTL_UI ? -1 : 1) * t.groupingTabsData.translateX;
               t.style.transform = "translateX(" + translateX + "px)";
             }
           }
 
           function newIndex(aTab, index) {
             // Don't allow mixing pinned and unpinned tabs.
             if (aTab.pinned) {
               return Math.min(index, gBrowser._numPinnedTabs - 1);
@@ -949,17 +948,17 @@
             // Can we make both the new tab and the selected tab completely visible?
             if (!selected ||
                 Math.max(tab.right - selected.left, selected.right - tab.left) <=
                   scrollRect.width) {
               this.arrowScrollbox.ensureElementIsVisible(aTab);
               return;
             }
 
-            this.arrowScrollbox.scrollByPixels(this.arrowScrollbox._isRTLScrollbox ?
+            this.arrowScrollbox.scrollByPixels(RTL_UI ?
                                                  selected.right - scrollRect.right :
                                                  selected.left - scrollRect.left);
           }
 
           if (!this._animateElement.hasAttribute("highlight")) {
             this._animateElement.setAttribute("highlight", "true");
             setTimeout(function(ele) {
               ele.removeAttribute("highlight");
@@ -984,17 +983,17 @@
       </method>
 
       <method name="_getDropIndex">
         <parameter name="event"/>
         <parameter name="isLink"/>
         <body><![CDATA[
           var tabs = this.children;
           var tab = this._getDragTargetTab(event, isLink);
-          if (window.getComputedStyle(this).direction == "ltr") {
+          if (!RTL_UI) {
             for (let i = tab ? tab._tPos : 0; i < tabs.length; i++)
               if (event.screenX < tabs[i].boxObject.screenX + tabs[i].boxObject.width / 2)
                 return i;
           } else {
             for (let i = tab ? tab._tPos : 0; i < tabs.length; i++)
               if (event.screenX > tabs[i].boxObject.screenX + tabs[i].boxObject.width / 2)
                 return i;
           }
@@ -1316,21 +1315,20 @@
           // be because they intend to open a new tab, but it could also be
           // because they just removed a tab and they now middleclicked on the
           // resulting space while that tab is closing. In that case, we don't
           // want to open a tab. So if we're removing one or more tabs, and
           // the tab click is before the end of the last visible tab, we do
           // nothing.
           if (gBrowser._removingTabs.length) {
             let visibleTabs = this._getVisibleTabs();
-            let ltr = (window.getComputedStyle(this).direction == "ltr");
             let lastTab = visibleTabs[visibleTabs.length - 1];
-            let endOfTab = lastTab.getBoundingClientRect()[ltr ? "right" : "left"];
-            if ((ltr && event.clientX > endOfTab) ||
-                (!ltr && event.clientX < endOfTab)) {
+            let endOfTab = lastTab.getBoundingClientRect()[RTL_UI ? "left" : "right"];
+            if ((!RTL_UI && event.clientX > endOfTab) ||
+                (RTL_UI && event.clientX < endOfTab)) {
               BrowserOpenTab();
             }
           } else {
             BrowserOpenTab();
           }
         } else {
           return;
         }
@@ -1372,24 +1370,21 @@
             } else {
               focusedTabIndex++;
             }
             break;
           case KeyEvent.DOM_VK_RIGHT:
           case KeyEvent.DOM_VK_LEFT:
             if (keyComboForMove) {
               gBrowser.moveTabOver(event);
+            } else if ((!RTL_UI && event.keyCode == KeyEvent.DOM_VK_RIGHT) ||
+                       (RTL_UI && event.keyCode == KeyEvent.DOM_VK_LEFT)) {
+              focusedTabIndex++;
             } else {
-              let isRTL = Services.locale.isAppLocaleRTL;
-              if ((!isRTL && event.keyCode == KeyEvent.DOM_VK_RIGHT) ||
-                  (isRTL && event.keyCode == KeyEvent.DOM_VK_LEFT)) {
-                focusedTabIndex++;
-              } else {
-                focusedTabIndex--;
-              }
+              focusedTabIndex--;
             }
             break;
           case KeyEvent.DOM_VK_HOME:
             if (keyComboForMove) {
               gBrowser.moveTabToStart();
             } else {
               focusedTabIndex = 0;
             }
@@ -1554,34 +1549,33 @@
         if (effects == "" || effects == "none") {
           ind.collapsed = true;
           return;
         }
         event.preventDefault();
         event.stopPropagation();
 
         var arrowScrollbox = this.arrowScrollbox;
-        var ltr = (window.getComputedStyle(this).direction == "ltr");
 
         // autoscroll the tab strip if we drag over the scroll
         // buttons, even if we aren't dragging a tab, but then
         // return to avoid drawing the drop indicator
         var pixelsToScroll = 0;
         if (this.getAttribute("overflow") == "true") {
           var targetAnonid = event.originalTarget.getAttribute("anonid");
           switch (targetAnonid) {
             case "scrollbutton-up":
               pixelsToScroll = arrowScrollbox.scrollIncrement * -1;
               break;
             case "scrollbutton-down":
               pixelsToScroll = arrowScrollbox.scrollIncrement;
               break;
           }
           if (pixelsToScroll)
-            arrowScrollbox.scrollByPixels((ltr ? 1 : -1) * pixelsToScroll, true);
+            arrowScrollbox.scrollByPixels((RTL_UI ? -1 : 1) * pixelsToScroll, true);
         }
 
         let draggedTab = event.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0);
         if ((effects == "move" || effects == "copy") &&
             this == draggedTab.parentNode) {
           ind.collapsed = true;
 
           if (!this._isGroupTabsAnimationOver()) {
@@ -1614,42 +1608,46 @@
         var newMargin;
         if (pixelsToScroll) {
           // if we are scrolling, put the drop indicator at the edge
           // so that it doesn't jump while scrolling
           let scrollRect = arrowScrollbox.scrollClientRect;
           let minMargin = scrollRect.left - rect.left;
           let maxMargin = Math.min(minMargin + scrollRect.width,
                                    scrollRect.right);
-          if (!ltr)
+          if (RTL_UI) {
             [minMargin, maxMargin] = [this.clientWidth - maxMargin,
                                       this.clientWidth - minMargin];
+          }
           newMargin = (pixelsToScroll > 0) ? maxMargin : minMargin;
         } else {
           let newIndex = this._getDropIndex(event, effects == "link");
           if (newIndex == this.children.length) {
             let tabRect = this.children[newIndex - 1].getBoundingClientRect();
-            if (ltr)
+            if (RTL_UI) {
+              newMargin = rect.right - tabRect.left;
+            } else {
               newMargin = tabRect.right - rect.left;
-            else
-              newMargin = rect.right - tabRect.left;
+            }
           } else {
             let tabRect = this.children[newIndex].getBoundingClientRect();
-            if (ltr)
+            if (RTL_UI) {
+              newMargin = rect.right - tabRect.right;
+            } else {
               newMargin = tabRect.left - rect.left;
-            else
-              newMargin = rect.right - tabRect.right;
+            }
           }
         }
 
         ind.collapsed = false;
 
         newMargin += ind.clientWidth / 2;
-        if (!ltr)
+        if (RTL_UI) {
           newMargin *= -1;
+        }
 
         ind.style.transform = "translate(" + Math.round(newMargin) + "px)";
         ind.style.marginInlineStart = (-ind.clientWidth) + "px";
       ]]></handler>
 
       <handler event="drop"><![CDATA[
         var dt = event.dataTransfer;
         var dropEffect = dt.dropEffect;