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 "WheelScrollAnimation.h"
8
#include "ScrollAnimationBezierPhysics.h"
9
10
#include "AsyncPanZoomController.h"
11
#include "mozilla/StaticPrefs_general.h"
12
#include "nsPoint.h"
13
14
namespace mozilla {
15
namespace layers {
16
17
static ScrollAnimationBezierPhysicsSettings SettingsForDeltaType(
18
ScrollWheelInput::ScrollDeltaType aDeltaType) {
19
int32_t minMS = 0;
20
int32_t maxMS = 0;
21
22
switch (aDeltaType) {
23
case ScrollWheelInput::SCROLLDELTA_PAGE:
24
maxMS = clamped(StaticPrefs::general_smoothScroll_pages_durationMaxMS(),
25
0, 10000);
26
minMS = clamped(StaticPrefs::general_smoothScroll_pages_durationMinMS(),
27
0, maxMS);
28
break;
29
case ScrollWheelInput::SCROLLDELTA_PIXEL:
30
maxMS = clamped(StaticPrefs::general_smoothScroll_pixels_durationMaxMS(),
31
0, 10000);
32
minMS = clamped(StaticPrefs::general_smoothScroll_pixels_durationMinMS(),
33
0, maxMS);
34
break;
35
case ScrollWheelInput::SCROLLDELTA_LINE:
36
maxMS =
37
clamped(StaticPrefs::general_smoothScroll_mouseWheel_durationMaxMS(),
38
0, 10000);
39
minMS =
40
clamped(StaticPrefs::general_smoothScroll_mouseWheel_durationMinMS(),
41
0, maxMS);
42
break;
43
}
44
45
// The pref is 100-based int percentage, while mIntervalRatio is 1-based ratio
46
double intervalRatio =
47
((double)StaticPrefs::general_smoothScroll_durationToIntervalRatio()) /
48
100.0;
49
intervalRatio = std::max(1.0, intervalRatio);
50
return ScrollAnimationBezierPhysicsSettings{minMS, maxMS, intervalRatio};
51
}
52
53
WheelScrollAnimation::WheelScrollAnimation(
54
AsyncPanZoomController& aApzc, const nsPoint& aInitialPosition,
55
ScrollWheelInput::ScrollDeltaType aDeltaType)
56
: GenericScrollAnimation(aApzc, aInitialPosition,
57
SettingsForDeltaType(aDeltaType)) {
58
mDirectionForcedToOverscroll =
59
mApzc.mScrollMetadata.GetDisregardedDirection();
60
}
61
62
} // namespace layers
63
} // namespace mozilla