Bug 1544198 - Split ScrolLFrameHelper::ComputeScrollSnapInto into two functions. r=botond
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 23 Apr 2019 01:12:38 +0000
changeset 470430 5b413410d2c5f93ca4240a3c4608a1182d53a2d2
parent 470429 530a3f39ecbd096436a8cf38d1d73068ff1fbcb8
child 470431 52410914b543300394f6b98c8dd6e3d73fb84780
push id35905
push userdvarga@mozilla.com
push dateTue, 23 Apr 2019 09:53:27 +0000
treeherdermozilla-central@831918f009f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1544198
milestone68.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 1544198 - Split ScrolLFrameHelper::ComputeScrollSnapInto into two functions. r=botond The one is for the scroll snap module v1 implementation, the other is for the old scroll snap implementation. Now both functions have the same pieces of code to get scroll-snap-type values, but for v1 implemention in the next commit we will use GetFrameForScrollSnap() to get the value instead. Differential Revision: https://phabricator.services.mozilla.com/D27986
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsGfxScrollFrame.h
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -6792,18 +6792,18 @@ nsMargin ScrollFrameHelper::GetScrollPad
   }
 
   // The spec says percentage values are relative to the scroll port size.
   // https://drafts.csswg.org/css-scroll-snap-1/#scroll-padding
   return ResolveScrollPaddingStyle(styleFrame->StylePadding()->mScrollPadding,
                                    GetScrollPortRect().Size());
 }
 
-layers::ScrollSnapInfo ScrollFrameHelper::ComputeScrollSnapInfo(
-    const Maybe<nsPoint>& aDestination) const {
+layers::ScrollSnapInfo ScrollFrameHelper::ComputeOldScrollSnapInfo() const {
+  MOZ_ASSERT(!StaticPrefs::layout_css_scroll_snap_v1_enabled());
   ScrollSnapInfo result;
 
   ScrollStyles styles = GetScrollStylesFromFrame();
 
   if (styles.mScrollSnapTypeY == StyleScrollSnapStrictness::None &&
       styles.mScrollSnapTypeX == StyleScrollSnapStrictness::None) {
     // We won't be snapping, short-circuit the computation.
     return result;
@@ -6824,52 +6824,71 @@ layers::ScrollSnapInfo ScrollFrameHelper
             scrollPortSize.width));
   }
   if (styles.mScrollSnapPointsY.GetUnit() != eStyleUnit_None) {
     result.mScrollSnapIntervalY =
         Some(styles.mScrollSnapPointsY.ComputeCoordPercentCalc(
             scrollPortSize.height));
   }
 
-  if (StaticPrefs::layout_css_scroll_snap_v1_enabled()) {
-    nsRect snapport = GetScrollPortRect();
-    nsMargin scrollPadding = GetScrollPadding();
-
-    Maybe<nsRect> snapportOnDestination;
-    if (aDestination) {
-      if (IsPhysicalLTR()) {
-        snapport.MoveTo(aDestination.value());
-      } else {
-        snapport.MoveTo(
-            nsPoint(aDestination->x - snapport.Size().width, aDestination->y));
-      }
-      snapport.Deflate(scrollPadding);
-      snapportOnDestination.emplace(snapport);
-    } else {
-      snapport.Deflate(scrollPadding);
-    }
-
-    WritingMode writingMode = GetFrameForDir()->GetWritingMode();
-    result.mSnapportSize = snapport.Size();
-    CollectScrollPositionsForSnap(mScrolledFrame, mScrolledFrame,
-                                  GetScrolledRect(), scrollPadding,
-                                  snapportOnDestination, writingMode, result);
-    return result;
-  }
-
   CollectScrollSnapCoordinates(mScrolledFrame, mScrolledFrame,
                                result.mScrollSnapCoordinates);
 
   return result;
 }
 
+layers::ScrollSnapInfo ScrollFrameHelper::ComputeScrollSnapInfo(
+    const Maybe<nsPoint>& aDestination) const {
+  MOZ_ASSERT(StaticPrefs::layout_css_scroll_snap_v1_enabled());
+
+  ScrollSnapInfo result;
+  ScrollStyles styles = GetScrollStylesFromFrame();
+
+  if (styles.mScrollSnapTypeY == StyleScrollSnapStrictness::None &&
+      styles.mScrollSnapTypeX == StyleScrollSnapStrictness::None) {
+    // We won't be snapping, short-circuit the computation.
+    return result;
+  }
+
+  result.mScrollSnapTypeX = styles.mScrollSnapTypeX;
+  result.mScrollSnapTypeY = styles.mScrollSnapTypeY;
+
+  nsRect snapport = GetScrollPortRect();
+  nsMargin scrollPadding = GetScrollPadding();
+
+  Maybe<nsRect> snapportOnDestination;
+  if (aDestination) {
+    if (IsPhysicalLTR()) {
+      snapport.MoveTo(aDestination.value());
+    } else {
+      snapport.MoveTo(
+          nsPoint(aDestination->x - snapport.Size().width, aDestination->y));
+    }
+    snapport.Deflate(scrollPadding);
+    snapportOnDestination.emplace(snapport);
+  } else {
+    snapport.Deflate(scrollPadding);
+  }
+
+  WritingMode writingMode = GetFrameForDir()->GetWritingMode();
+  result.mSnapportSize = snapport.Size();
+  CollectScrollPositionsForSnap(mScrolledFrame, mScrolledFrame,
+                                GetScrolledRect(), scrollPadding,
+                                snapportOnDestination, writingMode, result);
+  return result;
+}
+
 layers::ScrollSnapInfo ScrollFrameHelper::GetScrollSnapInfo(
     const Maybe<nsPoint>& aDestination) const {
   // TODO(botond): Should we cache it?
-  return ComputeScrollSnapInfo(aDestination);
+  if (StaticPrefs::layout_css_scroll_snap_v1_enabled()) {
+    return ComputeScrollSnapInfo(aDestination);
+  }
+
+  return ComputeOldScrollSnapInfo();
 }
 
 bool ScrollFrameHelper::GetSnapPointForDestination(
     nsIScrollableFrame::ScrollUnit aUnit, nsPoint aStartPos,
     nsPoint& aDestination) {
   Maybe<nsPoint> snapPoint = ScrollSnapUtils::GetSnapPointForDestination(
       GetScrollSnapInfo(Some(aDestination)), aUnit, GetLayoutScrollRange(),
       aStartPos, aDestination);
--- a/layout/generic/nsGfxScrollFrame.h
+++ b/layout/generic/nsGfxScrollFrame.h
@@ -409,16 +409,19 @@ class ScrollFrameHelper : public nsIRefl
 
  private:
   nsIFrame* GetFrameForDir() const;  // helper for Is{Physical,Bidi}LTR to find
                                      // the frame whose directionality we use
   nsIFrame* GetFrameForScrollSnap() const;  // helper to find the frame whose
                                             // scroll-snap-type and
                                             // scroll-padding we use
 
+  // This is the for the old unspecced scroll snap implementation.
+  ScrollSnapInfo ComputeOldScrollSnapInfo() const;
+  // This is the for the scroll snap v1 implementation.
   ScrollSnapInfo ComputeScrollSnapInfo(
       const Maybe<nsPoint>& aDestination) const;
 
  public:
   bool IsScrollbarOnRight() const;
   bool IsScrollingActive(nsDisplayListBuilder* aBuilder) const;
   bool IsMaybeAsynchronouslyScrolled() const {
     // If this is true, then we'll build an ASR, and that's what we want