Bug 945584: Part 2 - Add CSS scroll snapping attributes to ScrollbarStyles (v10 Patch),r=mstange
authorKearwood (Kip) Gilbert <kgilbert@mozilla.com>
Tue, 04 Feb 2014 14:54:22 +1300
changeset 260986 c86b570fbb7815b075f72216a98e2b20871ebe2d
parent 260985 6fb93b485e4c1d025b550508d644dfac8b1cae75
child 260987 4f18d0348d0c57ea2109db1ca79a2b43cf00f7ac
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs945584
milestone39.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 945584: Part 2 - Add CSS scroll snapping attributes to ScrollbarStyles (v10 Patch),r=mstange - ScrollbarStyles now carries additional variables to support new CSS scroll snapping attributes: - scroll-snap-type / scroll-snap-type-x / scroll-snap-type-y - scroll-snap-points-x / scroll-snap-points-y - scroll-snap-destination - (scroll-snap-coordinate does not apply to the scroll container) - Simplified the constructor and operator== for ScrollbarStyles.
layout/base/ScrollbarStyles.cpp
layout/base/ScrollbarStyles.h
layout/base/moz.build
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsPresContext.cpp
layout/forms/nsListControlFrame.cpp
layout/generic/nsGfxScrollFrame.cpp
new file mode 100644
--- /dev/null
+++ b/layout/base/ScrollbarStyles.cpp
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ScrollbarStyles.h"
+#include "nsStyleStruct.h" // for nsStyleDisplay and nsStyleBackground::Position
+
+namespace mozilla {
+
+  ScrollbarStyles::ScrollbarStyles(uint8_t aH, uint8_t aV,
+                                   const nsStyleDisplay* aDisplay)
+    : mHorizontal(aH), mVertical(aV),
+      mScrollBehavior(aDisplay->mScrollBehavior),
+      mScrollSnapTypeX(aDisplay->mScrollSnapTypeX),
+      mScrollSnapTypeY(aDisplay->mScrollSnapTypeY),
+      mScrollSnapPointsX(aDisplay->mScrollSnapPointsX),
+      mScrollSnapPointsY(aDisplay->mScrollSnapPointsY),
+      mScrollSnapDestinationX(aDisplay->mScrollSnapDestination.mXPosition),
+      mScrollSnapDestinationY(aDisplay->mScrollSnapDestination.mYPosition) {}
+
+  ScrollbarStyles::ScrollbarStyles(const nsStyleDisplay* aDisplay)
+    : mHorizontal(aDisplay->mOverflowX), mVertical(aDisplay->mOverflowY),
+      mScrollBehavior(aDisplay->mScrollBehavior),
+      mScrollSnapTypeX(aDisplay->mScrollSnapTypeX),
+      mScrollSnapTypeY(aDisplay->mScrollSnapTypeY),
+      mScrollSnapPointsX(aDisplay->mScrollSnapPointsX),
+      mScrollSnapPointsY(aDisplay->mScrollSnapPointsY),
+      mScrollSnapDestinationX(aDisplay->mScrollSnapDestination.mXPosition),
+      mScrollSnapDestinationY(aDisplay->mScrollSnapDestination.mYPosition) {}
+
+}
--- a/layout/base/ScrollbarStyles.h
+++ b/layout/base/ScrollbarStyles.h
@@ -2,41 +2,74 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef ScrollbarStyles_h
 #define ScrollbarStyles_h
 
 #include <stdint.h>
-#include "nsStyleConsts.h"
+#include "nsStyleConsts.h" // for NS_STYLE_SCROLL_SNAP_*
+#include "nsStyleCoord.h" // for nsStyleCoord
 #include "mozilla/dom/WindowBinding.h"
 
+// Forward declarations
+struct nsStyleDisplay;
+
 namespace mozilla {
 
 struct ScrollbarStyles
 {
   // Always one of NS_STYLE_OVERFLOW_SCROLL, NS_STYLE_OVERFLOW_HIDDEN,
   // or NS_STYLE_OVERFLOW_AUTO.
   uint8_t mHorizontal;
   uint8_t mVertical;
   // Always one of NS_STYLE_SCROLL_BEHAVIOR_AUTO or
   // NS_STYLE_SCROLL_BEHAVIOR_SMOOTH
   uint8_t mScrollBehavior;
-  ScrollbarStyles(uint8_t aH, uint8_t aV, uint8_t aB) : mHorizontal(aH),
-                                                        mVertical(aV),
-                                                        mScrollBehavior(aB) {}
+  // Always one of NS_STYLE_SCROLL_SNAP_NONE, NS_STYLE_SCROLL_SNAP_MANDATORY,
+  // or NS_STYLE_SCROLL_SNAP_PROXIMITY.
+  uint8_t mScrollSnapTypeX;
+  uint8_t mScrollSnapTypeY;
+  nsStyleCoord mScrollSnapPointsX;
+  nsStyleCoord mScrollSnapPointsY;
+  nsStyleCoord::CalcValue mScrollSnapDestinationX;
+  nsStyleCoord::CalcValue mScrollSnapDestinationY;
+
+  ScrollbarStyles(uint8_t aH, uint8_t aV)
+    : mHorizontal(aH), mVertical(aV),
+      mScrollBehavior(NS_STYLE_SCROLL_BEHAVIOR_AUTO),
+      mScrollSnapTypeX(NS_STYLE_SCROLL_SNAP_TYPE_NONE),
+      mScrollSnapTypeY(NS_STYLE_SCROLL_SNAP_TYPE_NONE),
+      mScrollSnapPointsX(nsStyleCoord(eStyleUnit_None)),
+      mScrollSnapPointsY(nsStyleCoord(eStyleUnit_None)) {
+
+    mScrollSnapDestinationX.mPercent = 0;
+    mScrollSnapDestinationX.mLength = nscoord(0.0f);
+    mScrollSnapDestinationX.mHasPercent = false;
+    mScrollSnapDestinationY.mPercent = 0;
+    mScrollSnapDestinationY.mLength = nscoord(0.0f);
+    mScrollSnapDestinationY.mHasPercent = false;
+  }
+
+  explicit ScrollbarStyles(const nsStyleDisplay* aDisplay);
+  ScrollbarStyles(uint8_t aH, uint8_t aV, const nsStyleDisplay* aDisplay);
   ScrollbarStyles() {}
   bool operator==(const ScrollbarStyles& aStyles) const {
     return aStyles.mHorizontal == mHorizontal && aStyles.mVertical == mVertical &&
-           aStyles.mScrollBehavior == mScrollBehavior;
+           aStyles.mScrollBehavior == mScrollBehavior &&
+           aStyles.mScrollSnapTypeX == mScrollSnapTypeX &&
+           aStyles.mScrollSnapTypeY == mScrollSnapTypeY &&
+           aStyles.mScrollSnapPointsX == mScrollSnapPointsX &&
+           aStyles.mScrollSnapPointsY == mScrollSnapPointsY &&
+           aStyles.mScrollSnapDestinationX == mScrollSnapDestinationX &&
+           aStyles.mScrollSnapDestinationY == mScrollSnapDestinationY;
   }
   bool operator!=(const ScrollbarStyles& aStyles) const {
-    return aStyles.mHorizontal != mHorizontal || aStyles.mVertical != mVertical ||
-           aStyles.mScrollBehavior != mScrollBehavior;
+    return !(*this == aStyles);
   }
   bool IsHiddenInBothDirections() const {
     return mHorizontal == NS_STYLE_OVERFLOW_HIDDEN &&
            mVertical == NS_STYLE_OVERFLOW_HIDDEN;
   }
   bool IsSmoothScroll(dom::ScrollBehavior aBehavior) const {
     return aBehavior == dom::ScrollBehavior::Smooth ||
              (aBehavior == dom::ScrollBehavior::Auto &&
--- a/layout/base/moz.build
+++ b/layout/base/moz.build
@@ -127,16 +127,17 @@ UNIFIED_SOURCES += [
     'nsPresShell.cpp',
     'nsQuoteList.cpp',
     'nsStyleChangeList.cpp',
     'nsStyleSheetService.cpp',
     'PaintTracker.cpp',
     'PositionedEventTargeting.cpp',
     'RestyleManager.cpp',
     'RestyleTracker.cpp',
+    'ScrollbarStyles.cpp',
     'SelectionCarets.cpp',
     'StackArena.cpp',
     'TouchCaret.cpp',
     'TouchManager.cpp',
 ]
 
 # nsPresArena.cpp needs to be built separately because it uses plarena.h.
 # nsRefreshDriver.cpp needs to be built separately because of name clashes in the OS X headers
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2296,30 +2296,36 @@ NeedFrameFor(const nsFrameConstructorSta
 /***********************************************
  * END TABLE SECTION
  ***********************************************/
 
 static bool CheckOverflow(nsPresContext* aPresContext,
                             const nsStyleDisplay* aDisplay)
 {
   if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE &&
-      aDisplay->mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_AUTO) {
+      aDisplay->mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_AUTO &&
+      aDisplay->mScrollSnapTypeX == NS_STYLE_SCROLL_SNAP_TYPE_NONE &&
+      aDisplay->mScrollSnapTypeY == NS_STYLE_SCROLL_SNAP_TYPE_NONE &&
+      aDisplay->mScrollSnapPointsX == nsStyleCoord(eStyleUnit_None) &&
+      aDisplay->mScrollSnapPointsY == nsStyleCoord(eStyleUnit_None) &&
+      !aDisplay->mScrollSnapDestination.mXPosition.mHasPercent &&
+      !aDisplay->mScrollSnapDestination.mYPosition.mHasPercent &&
+      aDisplay->mScrollSnapDestination.mXPosition.mLength == 0 &&
+      aDisplay->mScrollSnapDestination.mYPosition.mLength == 0) {
     return false;
   }
 
   if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_CLIP) {
     aPresContext->SetViewportScrollbarStylesOverride(
                                     ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
                                                     NS_STYLE_OVERFLOW_HIDDEN,
-                                                    aDisplay->mScrollBehavior));
+                                                    aDisplay));
   } else {
     aPresContext->SetViewportScrollbarStylesOverride(
-                                    ScrollbarStyles(aDisplay->mOverflowX,
-                                                    aDisplay->mOverflowY,
-                                                    aDisplay->mScrollBehavior));
+                                    ScrollbarStyles(aDisplay));
   }
   return true;
 }
 
 /**
  * This checks the root element and the HTML BODY, if any, for an "overflow" property
  * that should be applied to the viewport. If one is found then we return the
  * element that we took the overflow from (which should then be treated as
@@ -2329,18 +2335,17 @@ static bool CheckOverflow(nsPresContext*
  */
 nsIContent*
 nsCSSFrameConstructor::PropagateScrollToViewport()
 {
   // Set default
   nsPresContext* presContext = mPresShell->GetPresContext();
   presContext->SetViewportScrollbarStylesOverride(
                              ScrollbarStyles(NS_STYLE_OVERFLOW_AUTO,
-                                             NS_STYLE_OVERFLOW_AUTO,
-                                             NS_STYLE_SCROLL_BEHAVIOR_AUTO));
+                                             NS_STYLE_OVERFLOW_AUTO));
 
   // We never mess with the viewport scroll state
   // when printing or in print preview
   if (presContext->IsPaginated()) {
     return nullptr;
   }
 
   Element* docElement = mDocument->GetRootElement();
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -101,17 +101,17 @@
 #ifdef MOZ_XUL
 #include "nsXULPopupManager.h"
 #endif
 
 #include "GeckoProfiler.h"
 #include "nsAnimationManager.h"
 #include "nsTransitionManager.h"
 #include "RestyleManager.h"
-
+#include "mozilla/EventDispatcher.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::image;
 using namespace mozilla::layers;
 using namespace mozilla::layout;
 using namespace mozilla::gfx;
 
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -187,19 +187,17 @@ IsVisualCharset(const nsCString& aCharse
 
   // NOTE! nsPresContext::operator new() zeroes out all members, so don't
   // bother initializing members to 0.
 
 nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
   : mType(aType), mDocument(aDocument), mBaseMinFontSize(0),
     mTextZoom(1.0), mFullZoom(1.0), mLastFontInflationScreenWidth(-1.0),
     mPageSize(-1, -1), mPPScale(1.0f),
-    mViewportStyleScrollbar(NS_STYLE_OVERFLOW_AUTO,
-                            NS_STYLE_OVERFLOW_AUTO,
-                            NS_STYLE_SCROLL_BEHAVIOR_AUTO),
+    mViewportStyleScrollbar(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
     mImageAnimationModePref(imgIContainer::kNormalAnimMode),
     mAllInvalidated(false),
     mPaintFlashing(false), mPaintFlashingInitialized(false)
 {
   // NOTE! nsPresContext::operator new() zeroes out all members, so don't
   // bother initializing members to 0.
 
   mDoScaledTwips = true;
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -583,18 +583,17 @@ nsListControlFrame::ReflowAsDropdown(nsP
 
 ScrollbarStyles
 nsListControlFrame::GetScrollbarStyles() const
 {
   // We can't express this in the style system yet; when we can, this can go away
   // and GetScrollbarStyles can be devirtualized
   int32_t verticalStyle = IsInDropDownMode() ? NS_STYLE_OVERFLOW_AUTO
     : NS_STYLE_OVERFLOW_SCROLL;
-  return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, verticalStyle,
-                         NS_STYLE_SCROLL_BEHAVIOR_AUTO);
+  return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, verticalStyle);
 }
 
 bool
 nsListControlFrame::ShouldPropagateComputedHeightToScrolledContent() const
 {
   return !IsInDropDownMode();
 }
 
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -3202,24 +3202,22 @@ static void HandleScrollPref(nsIScrollab
 }
 
 ScrollbarStyles
 ScrollFrameHelper::GetScrollbarStylesFromFrame() const
 {
   nsPresContext* presContext = mOuter->PresContext();
   if (!presContext->IsDynamic() &&
       !(mIsRoot && presContext->HasPaginatedScrolling())) {
-    return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN,
-                           NS_STYLE_SCROLL_BEHAVIOR_AUTO);
+    return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN);
   }
 
   if (!mIsRoot) {
     const nsStyleDisplay* disp = mOuter->StyleDisplay();
-    return ScrollbarStyles(disp->mOverflowX, disp->mOverflowY,
-                           disp->mScrollBehavior);
+    return ScrollbarStyles(disp);
   }
 
   ScrollbarStyles result = presContext->GetViewportScrollbarStylesOverride();
   nsCOMPtr<nsISupports> container = presContext->GetContainerWeak();
   nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(container);
   if (scrollable) {
     HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_X,
                      result.mHorizontal);