Bug 1513007 - avoid permanently breaking scrolling to background tabs when promiseDocumentFlushed returns synchronously, r=dao a=RyanVM
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 13 Dec 2018 11:31:31 +0000
changeset 508997 d6a0b8b5bccaeb41eade51dcf2d84152f2f65fb2
parent 508996 2c85064c240cc9e3046fee8b781182a6291d3ee4
child 508998 7e036d607afaca9bda58e90127bb0064dc966345
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, RyanVM
bugs1513007
milestone65.0
Bug 1513007 - avoid permanently breaking scrolling to background tabs when promiseDocumentFlushed returns synchronously, r=dao a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D14086
browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -940,40 +940,49 @@
               let lastTabRect = this._lastTabToScrollIntoView.getBoundingClientRect();
               let selectedTab = this.selectedItem;
               if (selectedTab.pinned) {
                 selectedTab = null;
               } else {
                 selectedTab = selectedTab.getBoundingClientRect();
                 selectedTab = {left: selectedTab.left, right: selectedTab.right};
               }
-              delete this._lastTabToScrollIntoView;
-              delete this._backgroundTabScrollPromise;
               return [
+                this._lastTabToScrollIntoView,
                 this.arrowScrollbox.scrollClientRect,
                 {left: lastTabRect.left, right: lastTabRect.right},
                 selectedTab,
               ];
-            }).then(([scrollRect, tab, selected]) => {
+            }).then(([tabUsed, scrollRect, tabRect, selectedRect]) => {
+              // First off, remove the promise so we can re-enter if necessary.
+              delete this._backgroundTabScrollPromise;
+              // Then, if the layout info isn't for the last-scrolled-to-tab, re-run
+              // the code above to get layout info for *that* tab, and don't do
+              // anything here, as we really just want to run this for the last-opened tab.
+              if (this._lastTabToScrollIntoView != tabUsed) {
+                this._notifyBackgroundTab(this._lastTabToScrollIntoView);
+                return;
+              }
+              delete this._lastTabToScrollIntoView;
               // Is the new tab already completely visible?
-              if (scrollRect.left <= tab.left && tab.right <= scrollRect.right)
+              if (scrollRect.left <= tabRect.left && tabRect.right <= scrollRect.right)
                 return;
 
               if (this.arrowScrollbox.smoothScroll) {
                 // 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) <=
+                if (!selectedRect ||
+                    Math.max(tabRect.right - selectedRect.left, selectedRect.right - tabRect.left) <=
                       scrollRect.width) {
                   this.arrowScrollbox.ensureElementIsVisible(aTab);
                   return;
                 }
 
                 this.arrowScrollbox.scrollByPixels(RTL_UI ?
-                                                     selected.right - scrollRect.right :
-                                                     selected.left - scrollRect.left);
+                                                     selectedRect.right - scrollRect.right :
+                                                     selectedRect.left - scrollRect.left);
               }
 
               if (!this._animateElement.hasAttribute("highlight")) {
                 this._animateElement.setAttribute("highlight", "true");
                 setTimeout(function(ele) {
                   ele.removeAttribute("highlight");
                 }, 150, this._animateElement);
               }