Bug 1153156 part.3 Don't allow to override system scroll speed if the wheel event causes too fast scroll r=smaug+jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 27 Jan 2016 15:09:13 +0900
changeset 281871 d3f1f3501ce23f10b472720b88d77e77128bd234
parent 281870 0e3407fff0c1d255b216f3fe6dea5957c3c975a4
child 281872 8773a723f7a2361313704075a1b1aba20ff9457a
push id29950
push usercbook@mozilla.com
push dateThu, 28 Jan 2016 11:14:03 +0000
treeherdermozilla-central@2b73b0a4d52b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1153156
milestone47.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 1153156 part.3 Don't allow to override system scroll speed if the wheel event causes too fast scroll r=smaug+jimm
widget/MouseEvents.h
widget/windows/WinMouseScrollHandler.cpp
widget/windows/WinMouseScrollHandler.h
widget/windows/nsWindow.cpp
--- a/widget/MouseEvents.h
+++ b/widget/MouseEvents.h
@@ -633,24 +633,27 @@ public:
   // case, we should override the scroll speed computed with system settings.
   // Following methods return preferred delta values which are multiplied by
   // factors specified by prefs.  If system scroll speed shouldn't be
   // overridden (e.g., this feature is disabled by pref), they return raw
   // delta values.
   double OverriddenDeltaX() const;
   double OverriddenDeltaY() const;
 
+  // Compute the overridden delta value.  This may be useful for suppressing
+  // too fast scroll by system scroll speed overriding when widget sets
+  // mAllowToOverrideSystemScrollSpeed.
+  static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
+
 private:
   static bool sInitialized;
   static bool sIsSystemScrollSpeedOverrideEnabled;
   static int32_t sOverrideFactorX;
   static int32_t sOverrideFactorY;
   static void Initialize();
-
-  static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
 };
 
 /******************************************************************************
  * mozilla::WidgetPointerEvent
  ******************************************************************************/
 
 class WidgetPointerEvent : public WidgetMouseEvent
 {
--- a/widget/windows/WinMouseScrollHandler.cpp
+++ b/widget/windows/WinMouseScrollHandler.cpp
@@ -858,19 +858,46 @@ MouseScrollHandler::LastEventInfo::InitW
 
   delta = static_cast<double>(mDelta) * orienter / nativeDeltaPerUnit;
   mAccumulatedDelta += mDelta;
   lineOrPageDelta =
     mAccumulatedDelta * orienter / RoundDelta(nativeDeltaPerUnit);
   mAccumulatedDelta -=
     lineOrPageDelta * orienter * RoundDelta(nativeDeltaPerUnit);
 
-  aWheelEvent.mAllowToOverrideSystemScrollSpeed =
-    MouseScrollHandler::sInstance->
-      mSystemSettings.IsOverridingSystemScrollSpeedAllowed();
+  if (aWheelEvent.deltaMode != nsIDOMWheelEvent::DOM_DELTA_LINE) {
+    // If the scroll delta mode isn't per line scroll, we shouldn't allow to
+    // override the system scroll speed setting.
+    aWheelEvent.mAllowToOverrideSystemScrollSpeed = false;
+  } else if (!MouseScrollHandler::sInstance->
+                mSystemSettings.IsOverridingSystemScrollSpeedAllowed()) {
+    // If the system settings are customized by either the user or
+    // the mouse utility, we shouldn't allow to override the system scroll
+    // speed setting.
+    aWheelEvent.mAllowToOverrideSystemScrollSpeed = false;
+  } else {
+    // For suppressing too fast scroll, we should ensure that the maximum
+    // overridden delta value should be less than overridden scroll speed
+    // with default scroll amount.
+    double defaultScrollAmount =
+      mIsVertical ? SystemSettings::DefaultScrollLines() :
+                    SystemSettings::DefaultScrollChars();
+    double maxDelta =
+      WidgetWheelEvent::ComputeOverriddenDelta(defaultScrollAmount,
+                                               mIsVertical);
+    if (maxDelta != defaultScrollAmount) {
+      double overriddenDelta =
+        WidgetWheelEvent::ComputeOverriddenDelta(Abs(delta), mIsVertical);
+      if (overriddenDelta > maxDelta) {
+        // Suppress to fast scroll since overriding system scroll speed with
+        // current delta value causes too big delta value.
+        aWheelEvent.mAllowToOverrideSystemScrollSpeed = false;
+      }
+    }
+  }
 
   MOZ_LOG(gMouseScrollLog, LogLevel::Info,
     ("MouseScroll::LastEventInfo::InitWheelEvent: aWidget=%p, "
      "aWheelEvent { refPoint: { x: %d, y: %d }, deltaX: %f, deltaY: %f, "
      "lineOrPageDeltaX: %d, lineOrPageDeltaY: %d, "
      "isShift: %s, isControl: %s, isAlt: %s, isMeta: %s, "
      "mAllowToOverrideSystemScrollSpeed: %s }, "
      "mAccumulatedDelta: %d",
@@ -925,17 +952,17 @@ MouseScrollHandler::SystemSettings::Init
       ("MouseScroll::SystemSettings::InitScrollLines(): mScrollLines is "
        "overridden by the pref: %d",
        mScrollLines));
   } else if (!::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
                                      &mScrollLines, 0)) {
     MOZ_LOG(gMouseScrollLog, LogLevel::Info,
       ("MouseScroll::SystemSettings::InitScrollLines(): ::SystemParametersInfo("
        "SPI_GETWHEELSCROLLLINES) failed"));
-    mScrollLines = 3;
+    mScrollLines = DefaultScrollLines();
   }
 
   if (mScrollLines > WHEEL_DELTA) {
     MOZ_LOG(gMouseScrollLog, LogLevel::Info,
       ("MouseScroll::SystemSettings::InitScrollLines(): the result of "
        "::SystemParametersInfo(SPI_GETWHEELSCROLLLINES) is too large: %d",
        mScrollLines));
     // sScrollLines usually equals 3 or 0 (for no scrolling)
@@ -967,16 +994,17 @@ MouseScrollHandler::SystemSettings::Init
   } else if (!::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0,
                                      &mScrollChars, 0)) {
     MOZ_LOG(gMouseScrollLog, LogLevel::Info,
       ("MouseScroll::SystemSettings::InitScrollChars(): ::SystemParametersInfo("
        "SPI_GETWHEELSCROLLCHARS) failed, %s",
        IsVistaOrLater() ?
          "this is unexpected on Vista or later" :
          "but on XP or earlier, this is not a problem"));
+    // XXX Should we use DefaultScrollChars()?
     mScrollChars = 1;
   }
 
   if (mScrollChars > WHEEL_DELTA) {
     MOZ_LOG(gMouseScrollLog, LogLevel::Info,
       ("MouseScroll::SystemSettings::InitScrollChars(): the result of "
        "::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS) is too large: %d",
        mScrollChars));
@@ -1050,21 +1078,18 @@ MouseScrollHandler::SystemSettings::Trus
   }
 
   // XXX We're not sure about other touchpad drivers...
 }
 
 bool
 MouseScrollHandler::SystemSettings::IsOverridingSystemScrollSpeedAllowed()
 {
-  // The default vertical and horizontal scrolling speed is 3, this is defined
-  // on the document of SystemParametersInfo in MSDN.
-  const uint32_t kSystemDefaultScrollingSpeed = 3;
-  return mScrollLines == kSystemDefaultScrollingSpeed &&
-         (!IsVistaOrLater() || mScrollChars == kSystemDefaultScrollingSpeed);
+  return mScrollLines == DefaultScrollLines() &&
+         (!IsVistaOrLater() || mScrollChars == DefaultScrollChars());
 }
 
 /******************************************************************************
  *
  * UserPrefs
  *
  ******************************************************************************/
 
--- a/widget/windows/WinMouseScrollHandler.h
+++ b/widget/windows/WinMouseScrollHandler.h
@@ -295,16 +295,21 @@ private:
 
     bool IsPageScroll(bool aForVertical) const
     {
       MOZ_ASSERT(mInitialized, "SystemSettings must be initialized");
       return aForVertical ? (uint32_t(mScrollLines) == WHEEL_PAGESCROLL) :
                             (uint32_t(mScrollChars) == WHEEL_PAGESCROLL);
     }
 
+    // The default vertical and horizontal scrolling speed is 3, this is defined
+    // on the document of SystemParametersInfo in MSDN.
+    static int32_t DefaultScrollLines() { return 3; }
+    static int32_t DefaultScrollChars() { return 3; }
+
   private:
     bool mInitialized;
     // The result of SystemParametersInfo() may not be reliable since it may
     // be hooked.  So, if the values are initialized with prefs, we can trust
     // the value.  Following mIsReliableScroll* are set true when mScroll* are
     // initialized with prefs.
     bool mIsReliableScrollLines;
     bool mIsReliableScrollChars;
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3710,58 +3710,16 @@ nsWindow::OnDefaultButtonLoaded(const La
 
   if (!::SetCursorPos(centerOfButton.x, centerOfButton.y)) {
     NS_ERROR("SetCursorPos failed");
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
-#if 0
-NS_IMETHODIMP
-nsWindow::OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
-                                         double aOriginalDeltaY,
-                                         double& aOverriddenDeltaX,
-                                         double& aOverriddenDeltaY)
-{
-  // The default vertical and horizontal scrolling speed is 3, this is defined
-  // on the document of SystemParametersInfo in MSDN.
-  const uint32_t kSystemDefaultScrollingSpeed = 3;
-
-  // Limit the overridden delta value from the system settings.  The mouse
-  // driver might accelerate the scrolling speed already.  If so, we shouldn't
-  // override the scrolling speed for preventing the unexpected high speed
-  // scrolling.
-  double absDeltaLimitX, absDeltaLimitY;
-  rv =
-    nsBaseWidget::OverrideSystemMouseScrollSpeed(kSystemDefaultScrollingSpeed,
-                                                 kSystemDefaultScrollingSpeed,
-                                                 absDeltaLimitX,
-                                                 absDeltaLimitY);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // If the given delta is larger than our computed limitation value, the delta
-  // was accelerated by the mouse driver.  So, we should do nothing here.
-  if (absDeltaLimitX <= absOriginDeltaX || absDeltaLimitY <= absOriginDeltaY) {
-    return NS_OK;
-  }
-
-  aOverriddenDeltaX = std::min(absComputedOverriddenDeltaX, absDeltaLimitX);
-  aOverriddenDeltaY = std::min(absComputedOverriddenDeltaY, absDeltaLimitY);
-
-  if (aOriginalDeltaX < 0) {
-    aOverriddenDeltaX *= -1;
-  }
-  if (aOriginalDeltaY < 0) {
-    aOverriddenDeltaY *= -1;
-  }
-  return NS_OK;
-}
-#endif
-
 already_AddRefed<mozilla::gfx::DrawTarget>
 nsWindow::StartRemoteDrawing()
 {
   MOZ_ASSERT(!mCompositeDC);
   NS_ASSERTION(IsRenderMode(gfxWindowsPlatform::RENDER_DIRECT2D) ||
                IsRenderMode(gfxWindowsPlatform::RENDER_GDI),
                "Unexpected render mode for remote drawing");