1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "KeyboardScrollAnimation.h"
8 #include "ScrollAnimationBezierPhysics.h"
9 
10 #include "gfxPrefs.h"
11 
12 namespace mozilla {
13 namespace layers {
14 
SettingsForType(KeyboardScrollAction::KeyboardScrollActionType aType)15 static ScrollAnimationBezierPhysicsSettings SettingsForType(
16     KeyboardScrollAction::KeyboardScrollActionType aType) {
17   int32_t minMS = 0;
18   int32_t maxMS = 0;
19 
20   switch (aType) {
21     case KeyboardScrollAction::eScrollCharacter:
22     case KeyboardScrollAction::eScrollLine: {
23       maxMS = clamped(gfxPrefs::LineSmoothScrollMaxDurationMs(), 0, 10000);
24       minMS = clamped(gfxPrefs::LineSmoothScrollMinDurationMs(), 0, maxMS);
25       break;
26     }
27     case KeyboardScrollAction::eScrollPage: {
28       maxMS = clamped(gfxPrefs::PageSmoothScrollMaxDurationMs(), 0, 10000);
29       minMS = clamped(gfxPrefs::PageSmoothScrollMinDurationMs(), 0, maxMS);
30       break;
31     }
32     case KeyboardScrollAction::eScrollComplete: {
33       maxMS = clamped(gfxPrefs::OtherSmoothScrollMaxDurationMs(), 0, 10000);
34       minMS = clamped(gfxPrefs::OtherSmoothScrollMinDurationMs(), 0, maxMS);
35       break;
36     }
37   }
38 
39   // The pref is 100-based int percentage, while mIntervalRatio is 1-based ratio
40   double intervalRatio =
41       ((double)gfxPrefs::SmoothScrollDurationToIntervalRatio()) / 100.0;
42   intervalRatio = std::max(1.0, intervalRatio);
43   return ScrollAnimationBezierPhysicsSettings{minMS, maxMS, intervalRatio};
44 }
45 
KeyboardScrollAnimation(AsyncPanZoomController & aApzc,const nsPoint & aInitialPosition,KeyboardScrollAction::KeyboardScrollActionType aType)46 KeyboardScrollAnimation::KeyboardScrollAnimation(
47     AsyncPanZoomController& aApzc, const nsPoint& aInitialPosition,
48     KeyboardScrollAction::KeyboardScrollActionType aType)
49     : GenericScrollAnimation(aApzc, aInitialPosition, SettingsForType(aType)) {}
50 
51 }  // namespace layers
52 }  // namespace mozilla
53