Bug 1247677 - Add support for the general.smoothScroll.{pages,pixels} prefs in APZ. r?dvander draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 11 Feb 2016 15:14:49 -0500
changeset 330460 ce7e3b8055ea30911be8128006d4135973450a26
parent 330345 904f3554c08488c53d24deb20a486600ddddd56b
child 514179 3a3920001a82d631b76fbe5a6d43a542c3959f9c
push id10762
push userkgupta@mozilla.com
push dateThu, 11 Feb 2016 20:17:56 +0000
reviewersdvander
bugs1247677
milestone47.0a1
Bug 1247677 - Add support for the general.smoothScroll.{pages,pixels} prefs in APZ. r?dvander MozReview-Commit-ID: 8bHu0gnRSie
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/WheelScrollAnimation.cpp
gfx/layers/apz/src/WheelScrollAnimation.h
gfx/thebes/gfxPrefs.h
widget/InputData.h
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -1045,19 +1045,23 @@ APZCTreeManager::ProcessMouseEvent(Widge
 }
 
 nsEventStatus
 APZCTreeManager::ProcessWheelEvent(WidgetWheelEvent& aEvent,
                                    ScrollableLayerGuid* aOutTargetGuid,
                                    uint64_t* aOutInputBlockId)
 {
   ScrollWheelInput::ScrollMode scrollMode = ScrollWheelInput::SCROLLMODE_INSTANT;
-  if ((aEvent.deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE ||
-       aEvent.deltaMode == nsIDOMWheelEvent::DOM_DELTA_PAGE) &&
-      gfxPrefs::SmoothScrollEnabled() && gfxPrefs::WheelSmoothScrollEnabled())
+  if (gfxPrefs::SmoothScrollEnabled() &&
+      (aEvent.deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE &&
+       gfxPrefs::WheelSmoothScrollEnabled()) ||
+      (aEvent.deltaMode == nsIDOMWheelEvent::DOM_DELTA_PAGE &&
+       gfxPrefs::PageSmoothScrollEnabled()) ||
+      (aEvent.deltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL &&
+       gfxPrefs::PixelSmoothScrollEnabled()))
   {
     scrollMode = ScrollWheelInput::SCROLLMODE_SMOOTH;
   }
 
   ScreenPoint origin(aEvent.refPoint.x, aEvent.refPoint.y);
   ScrollWheelInput input(aEvent.time, aEvent.timeStamp, 0,
                          scrollMode,
                          ScrollWheelInput::DeltaTypeForDeltaMode(aEvent.deltaMode),
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -1787,18 +1787,17 @@ nsEventStatus AsyncPanZoomController::On
       ReentrantMonitorAutoEnter lock(mMonitor);
 
       if (mState != WHEEL_SCROLL) {
         CancelAnimation();
         SetState(WHEEL_SCROLL);
 
         nsPoint initialPosition = CSSPoint::ToAppUnits(mFrameMetrics.GetScrollOffset());
         StartAnimation(new WheelScrollAnimation(
-          *this,
-          initialPosition));
+          *this, initialPosition, aEvent.mDeltaType));
       }
 
       nsPoint deltaInAppUnits =
         CSSPoint::ToAppUnits(delta / mFrameMetrics.GetZoom());
       // Cast velocity from ParentLayerPoints/ms to CSSPoints/ms then convert to
       // appunits/second
       nsPoint velocity =
         CSSPoint::ToAppUnits(CSSPoint(mX.GetVelocity(), mY.GetVelocity())) * 1000.0f;
--- a/gfx/layers/apz/src/WheelScrollAnimation.cpp
+++ b/gfx/layers/apz/src/WheelScrollAnimation.cpp
@@ -8,20 +8,23 @@
 
 #include "AsyncPanZoomController.h"
 #include "gfxPrefs.h"
 #include "nsPoint.h"
 
 namespace mozilla {
 namespace layers {
 
-WheelScrollAnimation::WheelScrollAnimation(AsyncPanZoomController& aApzc, const nsPoint& aInitialPosition)
+WheelScrollAnimation::WheelScrollAnimation(AsyncPanZoomController& aApzc,
+                                           const nsPoint& aInitialPosition,
+                                           ScrollWheelInput::ScrollDeltaType aDeltaType)
   : AsyncScrollBase(aInitialPosition)
   , mApzc(aApzc)
   , mFinalDestination(aInitialPosition)
+  , mDeltaType(aDeltaType)
 {
 }
 
 void
 WheelScrollAnimation::Update(TimeStamp aTime, nsPoint aDelta, const nsSize& aCurrentVelocity)
 {
   InitPreferences(aTime);
 
@@ -81,18 +84,31 @@ WheelScrollAnimation::DoSample(FrameMetr
 
 void
 WheelScrollAnimation::InitPreferences(TimeStamp aTime)
 {
   if (!mIsFirstIteration) {
     return;
   }
 
-  mOriginMaxMS = clamped(gfxPrefs::WheelSmoothScrollMaxDurationMs(), 0, 10000);
-  mOriginMinMS = clamped(gfxPrefs::WheelSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
+  switch (mDeltaType) {
+  case ScrollWheelInput::SCROLLDELTA_PAGE:
+    mOriginMaxMS = clamped(gfxPrefs::PageSmoothScrollMaxDurationMs(), 0, 10000);
+    mOriginMinMS = clamped(gfxPrefs::PageSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
+    break;
+  case ScrollWheelInput::SCROLLDELTA_PIXEL:
+    mOriginMaxMS = clamped(gfxPrefs::PixelSmoothScrollMaxDurationMs(), 0, 10000);
+    mOriginMinMS = clamped(gfxPrefs::PixelSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
+    break;
+  case ScrollWheelInput::SCROLLDELTA_LINE:
+  default:
+    mOriginMaxMS = clamped(gfxPrefs::WheelSmoothScrollMaxDurationMs(), 0, 10000);
+    mOriginMinMS = clamped(gfxPrefs::WheelSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
+    break;
+  }
 
   // The pref is 100-based int percentage, while mIntervalRatio is 1-based ratio
   mIntervalRatio = ((double)gfxPrefs::SmoothScrollDurationToIntervalRatio()) / 100.0;
   mIntervalRatio = std::max(1.0, mIntervalRatio);
 
   InitializeHistory(aTime);
 }
 
--- a/gfx/layers/apz/src/WheelScrollAnimation.h
+++ b/gfx/layers/apz/src/WheelScrollAnimation.h
@@ -4,40 +4,44 @@
  * 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 mozilla_layers_WheelScrollAnimation_h_
 #define mozilla_layers_WheelScrollAnimation_h_
 
 #include "AsyncPanZoomAnimation.h"
 #include "AsyncScrollBase.h"
+#include "InputData.h"
 
 namespace mozilla {
 namespace layers {
 
 class AsyncPanZoomController;
 
 class WheelScrollAnimation
   : public AsyncPanZoomAnimation,
     public AsyncScrollBase
 {
 public:
-  WheelScrollAnimation(AsyncPanZoomController& aApzc, const nsPoint& aInitialPosition);
+  WheelScrollAnimation(AsyncPanZoomController& aApzc,
+                       const nsPoint& aInitialPosition,
+                       ScrollWheelInput::ScrollDeltaType aDeltaType);
 
   bool DoSample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta) override;
   void Update(TimeStamp aTime, nsPoint aDelta, const nsSize& aCurrentVelocity);
 
   WheelScrollAnimation* AsWheelScrollAnimation() override {
     return this;
   }
 
 private:
   void InitPreferences(TimeStamp aTime);
 
 private:
   AsyncPanZoomController& mApzc;
   nsPoint mFinalDestination;
+  ScrollWheelInput::ScrollDeltaType mDeltaType;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // mozilla_layers_WheelScrollAnimation_h_
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -207,16 +207,26 @@ private:
                 SmoothScrollCurrentVelocityWeighting, float, 0.25);
   DECL_GFX_PREF(Live, "general.smoothScroll.durationToIntervalRatio",
                 SmoothScrollDurationToIntervalRatio, int32_t, 200);
   DECL_GFX_PREF(Live, "general.smoothScroll.mouseWheel",       WheelSmoothScrollEnabled, bool, true);
   DECL_GFX_PREF(Live, "general.smoothScroll.mouseWheel.durationMaxMS",
                 WheelSmoothScrollMaxDurationMs, int32_t, 400);
   DECL_GFX_PREF(Live, "general.smoothScroll.mouseWheel.durationMinMS",
                 WheelSmoothScrollMinDurationMs, int32_t, 200);
+  DECL_GFX_PREF(Live, "general.smoothScroll.pages",            PageSmoothScrollEnabled, bool, true);
+  DECL_GFX_PREF(Live, "general.smoothScroll.pages.durationMaxMS",
+                PageSmoothScrollMaxDurationMs, int32_t, 150);
+  DECL_GFX_PREF(Live, "general.smoothScroll.pages.durationMinMS",
+                PageSmoothScrollMinDurationMs, int32_t, 150);
+  DECL_GFX_PREF(Live, "general.smoothScroll.pixels",           PixelSmoothScrollEnabled, bool, true);
+  DECL_GFX_PREF(Live, "general.smoothScroll.pixels.durationMaxMS",
+                PixelSmoothScrollMaxDurationMs, int32_t, 150);
+  DECL_GFX_PREF(Live, "general.smoothScroll.pixels.durationMinMS",
+                PixelSmoothScrollMinDurationMs, int32_t, 150);
   DECL_GFX_PREF(Live, "general.smoothScroll.stopDecelerationWeighting",
                 SmoothScrollStopDecelerationWeighting, float, 0.4f);
 
   DECL_GFX_PREF(Once, "gfx.android.rgb16.force",               AndroidRGB16Force, bool, false);
 #if defined(ANDROID)
   DECL_GFX_PREF(Once, "gfx.apitrace.enabled",                  UseApitrace, bool, false);
 #endif
 #if defined(RELEASE_BUILD)
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -532,17 +532,17 @@ public:
 // with physical scroll wheels, and on Windows by most touchpads when using
 // scroll gestures.
 class ScrollWheelInput : public InputData
 {
 public:
   enum ScrollDeltaType
   {
     // There are three kinds of scroll delta modes in Gecko: "page", "line" and
-    // "pixel". For apz, we currently only support the "line" and "pixel" modes.
+    // "pixel".
     SCROLLDELTA_LINE,
     SCROLLDELTA_PAGE,
     SCROLLDELTA_PIXEL
   };
 
   static ScrollDeltaType
   DeltaTypeForDeltaMode(uint32_t aDeltaMode)
   {