Bug 1475033 part 4 - Implement scrollbar-width: none. r?mstange draft
authorXidorn Quan <me@upsuper.org>
Mon, 06 Aug 2018 09:23:33 +1000
changeset 829852 dbbeb8f0719309c717281f9a496e0b90ab8d0766
parent 829851 08584543bcfaeda6fc946adda61cc04894c20617
child 829853 fca30130adf22b3b3d42d1ef7058e3c0d804297b
push id118798
push userxquan@mozilla.com
push dateFri, 17 Aug 2018 01:17:12 +0000
reviewersmstange
bugs1475033
milestone63.0a1
Bug 1475033 part 4 - Implement scrollbar-width: none. r?mstange MozReview-Commit-ID: 97AOILxYSw0
layout/generic/nsGfxScrollFrame.cpp
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -1091,16 +1091,27 @@ nsHTMLScrollFrame::Reflow(nsPresContext*
     mHelper.mCollapsedResizer = true;
 
     Element* browserRoot = GetBrowserRoot(mContent);
     if (browserRoot) {
       bool showResizer = browserRoot->HasAttr(kNameSpaceID_None, nsGkAtoms::showresizer);
       reflowScrollCorner = showResizer == mHelper.mCollapsedResizer;
       mHelper.mCollapsedResizer = !showResizer;
     }
+
+    // Hide the scrollbar when the scrollbar-width is set to none.
+    // This is only needed for root element because scrollbars of non-
+    // root elements with "scrollbar-width: none" is already suppressed
+    // in ScrollFrameHelper::CreateAnonymousContent.
+    ComputedStyle* scrollbarStyle = nsLayoutUtils::StyleForScrollbar(this);
+    auto scrollbarWidth = scrollbarStyle->StyleUIReset()->mScrollbarWidth;
+    if (scrollbarWidth == StyleScrollbarWidth::None) {
+      state.mVScrollbar = ShowScrollbar::Never;
+      state.mHScrollbar = ShowScrollbar::Never;
+    }
   }
 
   nsRect oldScrollAreaBounds = mHelper.mScrollPort;
   nsRect oldScrolledAreaBounds =
     mHelper.mScrolledFrame->GetScrollableOverflowRectRelativeToParent();
   nsPoint oldScrollPosition = mHelper.GetScrollPosition();
 
   state.mComputedBorder = aReflowInput.ComputedPhysicalBorderPadding() -
@@ -4657,19 +4668,25 @@ ScrollFrameHelper::CreateAnonymousConten
   // If we're the scrollframe for the root, then we want to construct
   // our scrollbar frames no matter what.  That way later dynamic
   // changes to propagated overflow styles will show or hide
   // scrollbars on the viewport without requiring frame reconstruction
   // of the viewport (good!).
   bool canHaveHorizontal;
   bool canHaveVertical;
   if (!mIsRoot) {
-    ScrollStyles styles = scrollable->GetScrollStyles();
-    canHaveHorizontal = styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN;
-    canHaveVertical = styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN;
+    if (mOuter->StyleUIReset()->mScrollbarWidth == StyleScrollbarWidth::None) {
+      // If scrollbar-width is none, don't generate scrollbars.
+      canHaveHorizontal = false;
+      canHaveVertical = false;
+    } else {
+      ScrollStyles styles = scrollable->GetScrollStyles();
+      canHaveHorizontal = styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN;
+      canHaveVertical = styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN;
+    }
     if (!canHaveHorizontal && !canHaveVertical && !isResizable) {
       // Nothing to do.
       return NS_OK;
     }
   } else {
     canHaveHorizontal = true;
     canHaveVertical = true;
   }