From 691d3a678ffcaa7e0c6a5b272cc1045aca85cbf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Wed, 2 Aug 2017 16:50:02 -0400 Subject: [PATCH] Bug 1356705 - Use CSS smooth scroll when smooth scrolling a XUL scrollbox. r=mconley MozReview-Commit-ID: 4Cjr1MuSVkk --HG-- extra : rebase_source : ed2a4e1be80d504f6e77f61427cd895b9e688fa5 --- browser/base/content/tabbrowser.xml | 6 +- toolkit/content/widgets/scrollbox.xml | 248 ++------------------------ toolkit/content/xul.css | 4 + 3 files changed, 18 insertions(+), 240 deletions(-) diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index 03d2ccb1f6ea..368125ebd40c 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -6591,9 +6591,9 @@ return; } - this.mTabstrip._smoothScrollByPixels(this.mTabstrip._isRTLScrollbox ? - selected.right - scrollRect.right : - selected.left - scrollRect.left); + this.mTabstrip.scrollByPixels(this.mTabstrip._isRTLScrollbox ? + selected.right - scrollRect.right : + selected.left - scrollRect.left); } if (!this._animateElement.hasAttribute("highlight")) { diff --git a/toolkit/content/widgets/scrollbox.xml b/toolkit/content/widgets/scrollbox.xml index aa787f862db1..50c3ade864a8 100644 --- a/toolkit/content/widgets/scrollbox.xml +++ b/toolkit/content/widgets/scrollbox.xml @@ -43,7 +43,7 @@ + xbl:inherits="orient,align,pack,dir,smoothscroll"> - - document.getAnonymousElementByAttribute(this, "anonid", "scrollbox"); @@ -96,21 +97,12 @@ ]]> - null @@ -254,177 +246,10 @@ if (!this._canScrollToElement(element)) return; - var vertical = this.orient == "vertical"; - var rect = this.scrollClientRect; - var containerStart = vertical ? rect.top : rect.left; - var containerEnd = vertical ? rect.bottom : rect.right; - rect = element.getBoundingClientRect(); - var elementStart = vertical ? rect.top : rect.left; - var elementEnd = vertical ? rect.bottom : rect.right; - - var scrollPaddingRect = this.scrollPaddingRect; - let style = window.getComputedStyle(this._scrollbox); - var scrollContentRect = { - left: scrollPaddingRect.left + parseFloat(style.paddingLeft), - top: scrollPaddingRect.top + parseFloat(style.paddingTop), - right: scrollPaddingRect.right - parseFloat(style.paddingRight), - bottom: scrollPaddingRect.bottom - parseFloat(style.paddingBottom) - }; - - if (elementStart <= (vertical ? scrollContentRect.top : scrollContentRect.left)) { - elementStart = vertical ? scrollPaddingRect.top : scrollPaddingRect.left; - } - if (elementEnd >= (vertical ? scrollContentRect.bottom : scrollContentRect.right)) { - elementEnd = vertical ? scrollPaddingRect.bottom : scrollPaddingRect.right; - } - - var amountToScroll; - - if (elementStart < containerStart) { - amountToScroll = elementStart - containerStart; - } else if (containerEnd < elementEnd) { - amountToScroll = elementEnd - containerEnd; - } else if (this._isScrolling) { - // decelerate if a currently-visible element is selected during the scroll - const STOP_DISTANCE = 15; - if (this._isScrolling == -1 && elementStart - STOP_DISTANCE < containerStart) - amountToScroll = elementStart - containerStart; - else if (this._isScrolling == 1 && containerEnd - STOP_DISTANCE < elementEnd) - amountToScroll = elementEnd - containerEnd; - else - amountToScroll = this._isScrolling * STOP_DISTANCE; - } else { - return; - } - - this._stopSmoothScroll(); - - if (aSmoothScroll != false && this.smoothScroll) { - this._smoothScrollByPixels(amountToScroll, element); - } else { - this.scrollByPixels(amountToScroll); - } + element.scrollIntoView({ behavior: aSmoothScroll == false ? "instant" : "auto" }); ]]> - - - - - - - = this.duration ? 1 : - 1 - Math.pow(1 - timePassed / this.duration, 4); - - this.scrollbox.scrollPosition = this.startPos + (this.distance * pos); - - if (pos == 1) - this.scrollbox._stopSmoothScroll(); - else - this.requestHandle = window.requestAnimationFrame(this.sample.bind(this)); - }, - - _clampPosition: function scrollAnim_clampPosition(aScrollPosition) { - if (aScrollPosition < 0) { - return 0; - } - var maxPos = this.scrollbox.scrollSize - this.scrollbox.scrollClientSize; - if (aScrollPosition > maxPos) { - return maxPos; - } - return aScrollPosition; - } - })]]> - @@ -605,24 +430,10 @@ ]]> - - 0 [null, null] -1 - - - - false + xbl:inherits="orient,align,pack,dir,smoothscroll"> - - diff --git a/toolkit/content/xul.css b/toolkit/content/xul.css index 095e7da69afc..8e513c9afd63 100644 --- a/toolkit/content/xul.css +++ b/toolkit/content/xul.css @@ -1073,6 +1073,10 @@ scrollbox { overflow: hidden; } +scrollbox[smoothscroll=true] { + scroll-behavior: smooth; +} + arrowscrollbox { -moz-binding: url("chrome://global/content/bindings/scrollbox.xml#arrowscrollbox"); }