Bug 1010538 - Part 2 - Add scroll-behavior to ScrollbarStyles. r=mstange
authorKearwood (Kip) Gilbert <kgilbert@mozilla.com>
Mon, 15 Sep 2014 12:30:00 -0700
changeset 211414 968aa79b1200034d34b0d8d9f9b89cc0d1fbc06a
parent 211413 6e287db609ed1b93a49115ccbaf38d1d5e008526
child 211415 5e6ced1dbccec591bc474a08431b24c2d554bab1
push id9492
push usercbook@mozilla.com
push dateTue, 21 Oct 2014 13:59:16 +0000
treeherderfx-team@b642421cdb49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1010538
milestone36.0a1
Bug 1010538 - Part 2 - Add scroll-behavior to ScrollbarStyles. r=mstange - ScrollbarStyles extended to support the scroll-behavior CSS property - Corrected naming of parameters to ScrollbarStyles CTOR
layout/base/ScrollbarStyles.h
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSFrameConstructor.h
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
layout/forms/nsListControlFrame.cpp
layout/generic/nsFrame.cpp
layout/generic/nsGfxScrollFrame.cpp
--- a/layout/base/ScrollbarStyles.h
+++ b/layout/base/ScrollbarStyles.h
@@ -2,30 +2,43 @@
 /* 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"
 
 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;
-  ScrollbarStyles(uint8_t h, uint8_t v) : mHorizontal(h), mVertical(v) {}
+  // Always one of NS_STYLE_SCROLL_BEHAVIOR_AUTO,
+  // NS_STYLE_SCROLL_BEHAVIOR_INSTANT, 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) {}
   ScrollbarStyles() {}
   bool operator==(const ScrollbarStyles& aStyles) const {
-    return aStyles.mHorizontal == mHorizontal && aStyles.mVertical == mVertical;
+    return aStyles.mHorizontal == mHorizontal && aStyles.mVertical == mVertical &&
+           aStyles.mScrollBehavior == mScrollBehavior;
   }
   bool operator!=(const ScrollbarStyles& aStyles) const {
-    return aStyles.mHorizontal != mHorizontal || aStyles.mVertical != mVertical;
+    return aStyles.mHorizontal != mHorizontal || aStyles.mVertical != mVertical ||
+           aStyles.mScrollBehavior != mScrollBehavior;
+  }
+  bool IsHiddenInBothDirections() {
+    return mHorizontal == NS_STYLE_OVERFLOW_HIDDEN &&
+           mVertical == NS_STYLE_OVERFLOW_HIDDEN;
   }
 };
 
 }
 
 #endif
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2301,43 +2301,52 @@ NeedFrameFor(const nsFrameConstructorSta
 
 /***********************************************
  * END TABLE SECTION
  ***********************************************/
 
 static bool CheckOverflow(nsPresContext* aPresContext,
                             const nsStyleDisplay* aDisplay)
 {
-  if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE)
+  if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE &&
+      aDisplay->mScrollBehavior == NS_STYLE_SCROLL_BEHAVIOR_AUTO) {
     return false;
-
-  if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_CLIP)
-    aPresContext->SetViewportOverflowOverride(NS_STYLE_OVERFLOW_HIDDEN,
-                                              NS_STYLE_OVERFLOW_HIDDEN);
-  else
-    aPresContext->SetViewportOverflowOverride(aDisplay->mOverflowX,
-                                              aDisplay->mOverflowY);
+  }
+
+  if (aDisplay->mOverflowX == NS_STYLE_OVERFLOW_CLIP) {
+    aPresContext->SetViewportScrollbarStylesOverride(
+                                    ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
+                                                    NS_STYLE_OVERFLOW_HIDDEN,
+                                                    aDisplay->mScrollBehavior));
+  } else {
+    aPresContext->SetViewportScrollbarStylesOverride(
+                                    ScrollbarStyles(aDisplay->mOverflowX,
+                                                    aDisplay->mOverflowY,
+                                                    aDisplay->mScrollBehavior));
+  }
   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
  * "overflow:visible"), and we store the overflow style in the prescontext.
  * @return if scroll was propagated from some content node, the content node it
  *         was propagated from.
  */
 nsIContent*
 nsCSSFrameConstructor::PropagateScrollToViewport()
 {
   // Set default
   nsPresContext* presContext = mPresShell->GetPresContext();
-  presContext->SetViewportOverflowOverride(NS_STYLE_OVERFLOW_AUTO,
-                                           NS_STYLE_OVERFLOW_AUTO);
+  presContext->SetViewportScrollbarStylesOverride(
+                             ScrollbarStyles(NS_STYLE_OVERFLOW_AUTO,
+                                             NS_STYLE_OVERFLOW_AUTO,
+                                             NS_STYLE_SCROLL_BEHAVIOR_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/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -16,16 +16,17 @@
 #include "nsCOMPtr.h"
 #include "nsILayoutHistoryState.h"
 #include "nsQuoteList.h"
 #include "nsCounterManager.h"
 #include "nsCSSPseudoElements.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsFrameManager.h"
 #include "nsIDocument.h"
+#include "ScrollbarStyles.h"
 
 struct nsFrameItems;
 struct nsAbsoluteItems;
 class nsStyleContext;
 struct nsStyleDisplay;
 class nsIDOMHTMLSelectElement;
 struct nsGenConInitializer;
 
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -184,17 +184,19 @@ 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),
-    mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
+    mViewportStyleScrollbar(NS_STYLE_OVERFLOW_AUTO,
+                            NS_STYLE_OVERFLOW_AUTO,
+                            NS_STYLE_SCROLL_BEHAVIOR_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/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -133,16 +133,17 @@ public:
 class nsRootPresContext;
 
 // An interface for presentation contexts. Presentation contexts are
 // objects that provide an outer context for a presentation shell.
 
 class nsPresContext : public nsIObserver {
 public:
   typedef mozilla::FramePropertyTable FramePropertyTable;
+  typedef mozilla::ScrollbarStyles ScrollbarStyles;
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
   NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
 
   enum nsPresContextType {
     eContext_Galley,       // unpaginated screen presentation
@@ -674,24 +675,23 @@ public:
 
   static nscoord CSSPointsToAppUnits(float aPoints)
   { return NSToCoordRound(aPoints * mozilla::AppUnitsPerCSSInch() /
                           POINTS_PER_INCH_FLOAT); }
 
   nscoord RoundAppUnitsToNearestDevPixels(nscoord aAppUnits) const
   { return DevPixelsToAppUnits(AppUnitsToDevPixels(aAppUnits)); }
 
-  void SetViewportOverflowOverride(uint8_t aX, uint8_t aY)
+  void SetViewportScrollbarStylesOverride(const ScrollbarStyles& aScrollbarStyle)
   {
-    mViewportStyleOverflow.mHorizontal = aX;
-    mViewportStyleOverflow.mVertical = aY;
+    mViewportStyleScrollbar = aScrollbarStyle;
   }
-  mozilla::ScrollbarStyles GetViewportOverflowOverride()
+  ScrollbarStyles GetViewportScrollbarStylesOverride()
   {
-    return mViewportStyleOverflow;
+    return mViewportStyleScrollbar;
   }
 
   /**
    * Set and get methods for controlling the background drawing
   */
   bool GetBackgroundImageDraw() const { return mDrawImageBackground; }
   void   SetBackgroundImageDraw(bool aCanDraw)
   {
@@ -1275,17 +1275,17 @@ protected:
   nscolor               mActiveLinkColor;
   nscolor               mVisitedLinkColor;
 
   nscolor               mFocusBackgroundColor;
   nscolor               mFocusTextColor;
 
   nscolor               mBodyTextColor;
 
-  mozilla::ScrollbarStyles mViewportStyleOverflow;
+  ScrollbarStyles       mViewportStyleScrollbar;
   uint8_t               mFocusRingWidth;
 
   bool mExistThrottledUpdates;
 
   uint16_t              mImageAnimationMode;
   uint16_t              mImageAnimationModePref;
 
   LangGroupFontPrefs    mLangGroupFontPrefs;
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -583,17 +583,18 @@ 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);
+  return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, verticalStyle,
+                         NS_STYLE_SCROLL_BEHAVIOR_AUTO);
 }
 
 bool
 nsListControlFrame::ShouldPropagateComputedHeightToScrolledContent() const
 {
   return !IsInDropDownMode();
 }
 
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -7804,21 +7804,21 @@ nsIFrame::IsFocusable(int32_t *aTabIndex
       // Otherwise you couldn't scroll them with keyboard, which is
       // an accessibility issue (e.g. Section 508 rules)
       // However, we don't make them to be focusable with the mouse,
       // because the extra focus outlines are considered unnecessarily ugly.
       // When clicked on, the selection position within the element 
       // will be enough to make them keyboard scrollable.
       nsIScrollableFrame *scrollFrame = do_QueryFrame(this);
       if (scrollFrame &&
-          scrollFrame->GetScrollbarStyles() != ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN) &&
+          !scrollFrame->GetScrollbarStyles().IsHiddenInBothDirections() &&
           !scrollFrame->GetScrollRange().IsEqualEdges(nsRect(0, 0, 0, 0))) {
-          // Scroll bars will be used for overflow
-          isFocusable = true;
-          tabIndex = 0;
+        // Scroll bars will be used for overflow
+        isFocusable = true;
+        tabIndex = 0;
       }
     }
   }
 
   if (aTabIndex) {
     *aTabIndex = tabIndex;
   }
   return isFocusable;
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -901,18 +901,17 @@ nsHTMLScrollFrame::GetFrameName(nsAStrin
 
 #ifdef ACCESSIBILITY
 a11y::AccType
 nsHTMLScrollFrame::AccessibleType()
 {
   // Create an accessible regardless of focusable state because the state can be
   // changed during frame life cycle without any notifications to accessibility.
   if (mContent->IsRootOfNativeAnonymousSubtree() ||
-      GetScrollbarStyles() ==
-        ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN) ) {
+      GetScrollbarStyles().IsHiddenInBothDirections()) {
     return a11y::eNoType;
   }
 
   return a11y::eHyperTextType;
 }
 #endif
 
 NS_QUERYFRAME_HEAD(nsHTMLScrollFrame)
@@ -3069,25 +3068,27 @@ 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);
+    return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN,
+                           NS_STYLE_SCROLL_BEHAVIOR_AUTO);
   }
 
   if (!mIsRoot) {
     const nsStyleDisplay* disp = mOuter->StyleDisplay();
-    return ScrollbarStyles(disp->mOverflowX, disp->mOverflowY);
-  }
-
-  ScrollbarStyles result = presContext->GetViewportOverflowOverride();
+    return ScrollbarStyles(disp->mOverflowX, disp->mOverflowY,
+                           disp->mScrollBehavior);
+  }
+
+  ScrollbarStyles result = presContext->GetViewportScrollbarStylesOverride();
   nsCOMPtr<nsISupports> container = presContext->GetContainerWeak();
   nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(container);
   if (scrollable) {
     HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_X,
                      result.mHorizontal);
     HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_Y,
                      result.mVertical);
   }