Bug 1259235 - Add IsScrollFrameWithSnapping to speed up event regions. r=mstange draft
authorBenoit Girard <b56girard@gmail.com>
Wed, 23 Mar 2016 17:16:38 -0400
changeset 344060 ca15390be1d003c50e41ef89f40f5e7f543e8676
parent 344057 0a31a9db1c1a03b672276a2feba09651e58d4bce
child 344153 eff9ef75cb292dfb1db097a863b8df22c496a26e
child 355415 6041d3bbd2844f811b74e66b02fb4f7b67764d69
push id13751
push userb56girard@gmail.com
push dateWed, 23 Mar 2016 21:16:46 +0000
reviewersmstange
bugs1259235
milestone48.0a1
Bug 1259235 - Add IsScrollFrameWithSnapping to speed up event regions. r=mstange MozReview-Commit-ID: KdWCkXHjHzZ
layout/base/nsLayoutUtils.cpp
layout/base/nsPresContext.h
layout/forms/nsListControlFrame.h
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsGfxScrollFrame.h
layout/generic/nsIScrollableFrame.h
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -8957,19 +8957,17 @@ nsLayoutUtils::GetSelectionBoundingRect(
 
 /* static */ bool
 nsLayoutUtils::IsScrollFrameWithSnapping(nsIFrame* aFrame)
 {
   nsIScrollableFrame* sf = do_QueryFrame(aFrame);
   if (!sf) {
     return false;
   }
-  ScrollbarStyles styles = sf->GetScrollbarStyles();
-  return styles.mScrollSnapTypeY != NS_STYLE_SCROLL_SNAP_TYPE_NONE ||
-         styles.mScrollSnapTypeX != NS_STYLE_SCROLL_SNAP_TYPE_NONE;
+  return sf->IsScrollFrameWithSnapping();
 }
 
 /* static */ nsBlockFrame*
 nsLayoutUtils::GetFloatContainingBlock(nsIFrame* aFrame)
 {
   nsIFrame* ancestor = aFrame->GetParent();
   while (ancestor && !ancestor->IsFloatContainingBlock()) {
     ancestor = ancestor->GetParent();
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -699,17 +699,17 @@ public:
    * return the element that we took the overflow from (which should then be
    * treated as "overflow: visible"), and we store the overflow style here.
    * If the document is in fullscreen, and the fullscreen element is not the
    * root, the scrollbar of viewport will be suppressed.
    * @return if scroll was propagated from some content node, the content node
    *         it was propagated from.
    */
   nsIContent* UpdateViewportScrollbarStylesOverride();
-  ScrollbarStyles GetViewportScrollbarStylesOverride()
+  const ScrollbarStyles& GetViewportScrollbarStylesOverride()
   {
     return mViewportStyleScrollbar;
   }
 
   /**
    * Set and get methods for controlling the background drawing
   */
   bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
--- a/layout/forms/nsListControlFrame.h
+++ b/layout/forms/nsListControlFrame.h
@@ -103,16 +103,19 @@ public:
 #ifdef DEBUG_FRAME_DUMP
   virtual nsresult GetFrameName(nsAString& aResult) const override;
 #endif
 
     // nsIFormControlFrame
   virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) override;
   virtual void SetFocus(bool aOn = true, bool aRepaint = false) override;
 
+  virtual bool IsScrollFrameWithSnapping() const override {
+    return false;
+  }
   virtual mozilla::ScrollbarStyles GetScrollbarStyles() const override;
   virtual bool ShouldPropagateComputedBSizeToScrolledContent() const override;
 
     // for accessibility purposes
 #ifdef ACCESSIBILITY
   virtual mozilla::a11y::AccType AccessibleType() override;
 #endif
 
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -3625,16 +3625,36 @@ static void HandleScrollPref(nsIScrollab
       aValue = NS_STYLE_OVERFLOW_HIDDEN;
       break;
     case nsIScrollable::Scrollbar_Always:
       aValue = NS_STYLE_OVERFLOW_SCROLL;
       break;
   }
 }
 
+bool
+ScrollFrameHelper::IsScrollFrameWithSnapping() const
+{
+  nsPresContext* presContext = mOuter->PresContext();
+  if (!presContext->IsDynamic() &&
+      !(mIsRoot && presContext->HasPaginatedScrolling())) {
+    return false;
+  }
+
+  if (!mIsRoot) {
+    const nsStyleDisplay& display = *mOuter->StyleDisplay();
+    return display.mScrollSnapTypeY != NS_STYLE_SCROLL_SNAP_TYPE_NONE ||
+           display.mScrollSnapTypeX != NS_STYLE_SCROLL_SNAP_TYPE_NONE;
+  } else {
+    const ScrollbarStyles& display = presContext->GetViewportScrollbarStylesOverride();
+    return display.mScrollSnapTypeY != NS_STYLE_SCROLL_SNAP_TYPE_NONE ||
+           display.mScrollSnapTypeX != NS_STYLE_SCROLL_SNAP_TYPE_NONE;
+  }
+}
+
 ScrollbarStyles
 ScrollFrameHelper::GetScrollbarStylesFromFrame() const
 {
   nsPresContext* presContext = mOuter->PresContext();
   if (!presContext->IsDynamic() &&
       !(mIsRoot && presContext->HasPaginatedScrolling())) {
     return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN);
   }
--- a/layout/generic/nsGfxScrollFrame.h
+++ b/layout/generic/nsGfxScrollFrame.h
@@ -52,16 +52,17 @@ public:
   typedef mozilla::layers::Layer Layer;
 
   class AsyncScroll;
   class AsyncSmoothMSDScroll;
 
   ScrollFrameHelper(nsContainerFrame* aOuter, bool aIsRoot);
   ~ScrollFrameHelper();
 
+  bool IsScrollFrameWithSnapping() const;
   mozilla::ScrollbarStyles GetScrollbarStylesFromFrame() const;
 
   // If a child frame was added or removed on the scrollframe,
   // reload our child frame list.
   // We need this if a scrollbar frame is recreated.
   void ReloadChildFrames();
 
   nsresult CreateAnonymousContent(
@@ -744,16 +745,19 @@ public:
   virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
   virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
                                         uint32_t aFilter) override;
 
   // nsIScrollableFrame
   virtual nsIFrame* GetScrolledFrame() const override {
     return mHelper.GetScrolledFrame();
   }
+  virtual bool IsScrollFrameWithSnapping() const override {
+    return mHelper.IsScrollFrameWithSnapping();
+  }
   virtual mozilla::ScrollbarStyles GetScrollbarStyles() const override {
     return mHelper.GetScrollbarStylesFromFrame();
   }
   virtual uint32_t GetScrollbarVisibility() const override {
     return mHelper.GetScrollbarVisibility();
   }
   virtual nsMargin GetActualScrollbarSizes() const override {
     return mHelper.GetActualScrollbarSizes();
@@ -1156,16 +1160,19 @@ public:
 
   static void AdjustReflowStateForPrintPreview(nsBoxLayoutState& aState, bool& aSetBack);
   static void AdjustReflowStateBack(nsBoxLayoutState& aState, bool aSetBack);
 
   // nsIScrollableFrame
   virtual nsIFrame* GetScrolledFrame() const override {
     return mHelper.GetScrolledFrame();
   }
+  virtual bool IsScrollFrameWithSnapping() const override {
+    return mHelper.IsScrollFrameWithSnapping();
+  }
   virtual mozilla::ScrollbarStyles GetScrollbarStyles() const override {
     return mHelper.GetScrollbarStylesFromFrame();
   }
   virtual uint32_t GetScrollbarVisibility() const override {
     return mHelper.GetScrollbarVisibility();
   }
   virtual nsMargin GetActualScrollbarSizes() const override {
     return mHelper.GetActualScrollbarSizes();
--- a/layout/generic/nsIScrollableFrame.h
+++ b/layout/generic/nsIScrollableFrame.h
@@ -59,16 +59,18 @@ public:
 
   /**
    * Get the styles (NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN,
    * or NS_STYLE_OVERFLOW_AUTO) governing the horizontal and vertical
    * scrollbars for this frame.
    */
   virtual mozilla::ScrollbarStyles GetScrollbarStyles() const = 0;
 
+  virtual bool IsScrollFrameWithSnapping() const = 0;
+
   enum { HORIZONTAL = 0x01, VERTICAL = 0x02 };
   /**
    * Return the scrollbars which are visible. It's OK to call this during reflow
    * of the scrolled contents, in which case it will reflect the current
    * assumptions about scrollbar visibility.
    */
   virtual uint32_t GetScrollbarVisibility() const = 0;
   /**