Source code

Revision control

Other Tools

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
#include "mozilla/StaticPrefs_general.h"
10
11
namespace mozilla {
12
namespace layers {
13
14
static ScrollAnimationBezierPhysicsSettings SettingsForType(
15
KeyboardScrollAction::KeyboardScrollActionType aType) {
16
int32_t minMS = 0;
17
int32_t maxMS = 0;
18
19
switch (aType) {
20
case KeyboardScrollAction::eScrollCharacter:
21
case KeyboardScrollAction::eScrollLine: {
22
maxMS = clamped(StaticPrefs::general_smoothScroll_lines_durationMaxMS(),
23
0, 10000);
24
minMS = clamped(StaticPrefs::general_smoothScroll_lines_durationMinMS(),
25
0, maxMS);
26
break;
27
}
28
case KeyboardScrollAction::eScrollPage: {
29
maxMS = clamped(StaticPrefs::general_smoothScroll_pages_durationMaxMS(),
30
0, 10000);
31
minMS = clamped(StaticPrefs::general_smoothScroll_pages_durationMinMS(),
32
0, maxMS);
33
break;
34
}
35
case KeyboardScrollAction::eScrollComplete: {
36
maxMS = clamped(StaticPrefs::general_smoothScroll_other_durationMaxMS(),
37
0, 10000);
38
minMS = clamped(StaticPrefs::general_smoothScroll_other_durationMinMS(),
39
0, maxMS);
40
break;
41
}
42
}
43
44
// The pref is 100-based int percentage, while mIntervalRatio is 1-based ratio
45
double intervalRatio =
46
((double)StaticPrefs::general_smoothScroll_durationToIntervalRatio()) /
47
100.0;
48
intervalRatio = std::max(1.0, intervalRatio);
49
return ScrollAnimationBezierPhysicsSettings{minMS, maxMS, intervalRatio};
50
}
51
52
KeyboardScrollAnimation::KeyboardScrollAnimation(
53
AsyncPanZoomController& aApzc, const nsPoint& aInitialPosition,
54
KeyboardScrollAction::KeyboardScrollActionType aType)
55
: GenericScrollAnimation(aApzc, aInitialPosition, SettingsForType(aType)) {}
56
57
} // namespace layers
58
} // namespace mozilla