Bug 1544198 - Factor out the function to get the frame for scroll-snap-type and scroll-padding. r=botond
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 23 Apr 2019 01:12:24 +0000
changeset 470429 530a3f39ecbd096436a8cf38d1d73068ff1fbcb8
parent 470428 f413cb36905d980cccb30577f827938f80cbe913
child 470430 5b413410d2c5f93ca4240a3c4608a1182d53a2d2
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 - Factor out the function to get the frame for scroll-snap-type and scroll-padding. r=botond Differential Revision: https://phabricator.services.mozilla.com/D27985
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsGfxScrollFrame.h
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -5321,16 +5321,30 @@ nsIFrame* ScrollFrameHelper::GetFrameFor
         frame = rootsFrame;
       }
     }
   }
 
   return frame;
 }
 
+nsIFrame* ScrollFrameHelper::GetFrameForScrollSnap() const {
+  nsIFrame* styleFrame = nullptr;
+  if (mIsRoot) {
+    if (const Element* rootElement =
+            mOuter->PresContext()->Document()->GetRootElement()) {
+      styleFrame = rootElement->GetPrimaryFrame();
+    }
+  } else {
+    styleFrame = mOuter;
+  }
+
+  return styleFrame;
+}
+
 bool ScrollFrameHelper::IsScrollbarOnRight() const {
   nsPresContext* presContext = mOuter->PresContext();
 
   // The position of the scrollbar in top-level windows depends on the pref
   // layout.scrollbar.side. For non-top-level elements, it depends only on the
   // directionaliy of the element (equivalent to a value of "1" for the pref).
   if (!mIsRoot) {
     return IsPhysicalLTR();
@@ -6767,26 +6781,17 @@ static nsMargin ResolveScrollPaddingStyl
                                                  eSideRight, aScrollPortSize),
                   ResolveScrollPaddingStyleValue(aScrollPaddingStyle,
                                                  eSideBottom, aScrollPortSize),
                   ResolveScrollPaddingStyleValue(aScrollPaddingStyle, eSideLeft,
                                                  aScrollPortSize));
 }
 
 nsMargin ScrollFrameHelper::GetScrollPadding() const {
-  nsIFrame* styleFrame = nullptr;
-  if (mIsRoot) {
-    if (const Element* rootElement =
-            mOuter->PresContext()->Document()->GetRootElement()) {
-      styleFrame = rootElement->GetPrimaryFrame();
-    }
-  } else {
-    styleFrame = mOuter;
-  }
-
+  nsIFrame* styleFrame = GetFrameForScrollSnap();
   if (!styleFrame) {
     return nsMargin();
   }
 
   // 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());
--- a/layout/generic/nsGfxScrollFrame.h
+++ b/layout/generic/nsGfxScrollFrame.h
@@ -405,16 +405,19 @@ class ScrollFrameHelper : public nsIRefl
   bool IsBidiLTR() const {
     nsIFrame* frame = GetFrameForDir();
     return frame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_LTR;
   }
 
  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
 
   ScrollSnapInfo ComputeScrollSnapInfo(
       const Maybe<nsPoint>& aDestination) const;
 
  public:
   bool IsScrollbarOnRight() const;
   bool IsScrollingActive(nsDisplayListBuilder* aBuilder) const;
   bool IsMaybeAsynchronouslyScrolled() const {