diff --git a/gfx/layers/apz/public/APZPublicUtils.h b/gfx/layers/apz/public/APZPublicUtils.h index e3de5d0279d4..272422bb71e0 100644 --- a/gfx/layers/apz/public/APZPublicUtils.h +++ b/gfx/layers/apz/public/APZPublicUtils.h @@ -12,6 +12,7 @@ #include // for uint32_t #include +#include #include "gfxTypes.h" #include "FrameMetrics.h" #include "LayersTypes.h" @@ -73,6 +74,15 @@ void InitializeGlobalState(); const ScreenMargin CalculatePendingDisplayPort( const FrameMetrics& aFrameMetrics, const ParentLayerPoint& aVelocity); +/** + * This computes the min/max values to use for the mousewheel animation + * duration. Normally this just comes from prefs but we are doing a gradual + * migration of users from old values to new values so this encapsulates some + * of that behaviour. Values are in milliseconds, same as the + * general.smoothScroll.mouseWheel.duration* prefs. + */ +std::pair GetMouseWheelAnimationDurations(); + } // namespace apz } // namespace layers diff --git a/gfx/layers/apz/src/APZPublicUtils.cpp b/gfx/layers/apz/src/APZPublicUtils.cpp index 645435b947aa..0ed9b377b600 100644 --- a/gfx/layers/apz/src/APZPublicUtils.cpp +++ b/gfx/layers/apz/src/APZPublicUtils.cpp @@ -7,6 +7,7 @@ #include "mozilla/layers/APZPublicUtils.h" #include "AsyncPanZoomController.h" +#include "mozilla/StaticPrefs_general.h" namespace mozilla { namespace layers { @@ -24,6 +25,33 @@ namespace apz { aVelocity); } +/*static*/ std::pair GetMouseWheelAnimationDurations() { + // Special code for migrating users from old values to new values over + // a period of time. The old values are defaults prior to bug 1660933, which + // we hard-code here. The user's migration percentage is stored in the + // migration pref. If the migration percentage is zero, the user gets the old + // values, and at a 100 percentage the user gets the new values. Linear + // interpolation in between. We can control the speed of migration by + // increasing the percentage value over time (e.g. by increasing the min + // bound on the clamped migration value). Once it reaches 100 the migration + // code can be removed. + + int32_t minMS = StaticPrefs::general_smoothScroll_mouseWheel_durationMinMS(); + int32_t maxMS = StaticPrefs::general_smoothScroll_mouseWheel_durationMaxMS(); + + const int32_t oldMin = 200; + const int32_t oldMax = 400; + + int32_t migration = + StaticPrefs::general_smoothScroll_mouseWheel_migrationPercent(); + migration = clamped(migration, 0, 100); + + minMS = ((oldMin * (100 - migration)) + (minMS * migration)) / 100; + maxMS = ((oldMax * (100 - migration)) + (maxMS * migration)) / 100; + + return std::make_pair(minMS, maxMS); +} + } // namespace apz } // namespace layers } // namespace mozilla diff --git a/gfx/layers/apz/src/WheelScrollAnimation.cpp b/gfx/layers/apz/src/WheelScrollAnimation.cpp index 9eefcee5eebe..d00004d12700 100644 --- a/gfx/layers/apz/src/WheelScrollAnimation.cpp +++ b/gfx/layers/apz/src/WheelScrollAnimation.cpp @@ -5,11 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "WheelScrollAnimation.h" -#include "ScrollAnimationBezierPhysics.h" +#include #include "AsyncPanZoomController.h" #include "mozilla/StaticPrefs_general.h" +#include "mozilla/layers/APZPublicUtils.h" #include "nsPoint.h" +#include "ScrollAnimationBezierPhysics.h" namespace mozilla { namespace layers { @@ -33,12 +35,9 @@ static ScrollAnimationBezierPhysicsSettings SettingsForDeltaType( 0, maxMS); break; case ScrollWheelInput::SCROLLDELTA_LINE: - maxMS = - clamped(StaticPrefs::general_smoothScroll_mouseWheel_durationMaxMS(), - 0, 10000); - minMS = - clamped(StaticPrefs::general_smoothScroll_mouseWheel_durationMinMS(), - 0, maxMS); + std::tie(minMS, maxMS) = apz::GetMouseWheelAnimationDurations(); + maxMS = clamped(maxMS, 0, 10000); + minMS = clamped(minMS, 0, maxMS); break; } diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 0bc62e99ed3f..3a4fbae38c8a 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -78,6 +78,7 @@ #include "ViewportFrame.h" #include "mozilla/gfx/gfxVars.h" #include "mozilla/layers/APZCCallbackHelper.h" +#include "mozilla/layers/APZPublicUtils.h" #include "mozilla/layers/AxisPhysicsModel.h" #include "mozilla/layers/AxisPhysicsMSDModel.h" #include "mozilla/layers/LayerTransactionChild.h" @@ -89,6 +90,7 @@ #include #include // for std::abs(int/long) #include // for std::abs(float/double) +#include // for std::tie static mozilla::LazyLogModule sApzPaintSkipLog("apz.paintskip"); #define PAINT_SKIP_LOG(...) \ @@ -2119,6 +2121,10 @@ ComputeBezierAnimationSettingsForOrigin(ScrollOrigin aOrigin) { minMS = Preferences::GetInt(prefMin.get(), kDefaultMinMS); maxMS = Preferences::GetInt(prefMax.get(), kDefaultMaxMS); + if (aOrigin == ScrollOrigin::MouseWheel) { + std::tie(minMS, maxMS) = layers::apz::GetMouseWheelAnimationDurations(); + } + static const int32_t kSmoothScrollMaxAllowedAnimationDurationMS = 10000; maxMS = clamped(maxMS, 0, kSmoothScrollMaxAllowedAnimationDurationMS); minMS = clamped(minMS, 0, maxMS);