/src/mozilla-central/layout/generic/ScrollAnimationMSDPhysics.h
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef mozilla_layout_ScrollAnimationMSDPhysics_h_ |
8 | | #define mozilla_layout_ScrollAnimationMSDPhysics_h_ |
9 | | |
10 | | #include "ScrollAnimationPhysics.h" |
11 | | #include "mozilla/layers/AxisPhysicsMSDModel.h" |
12 | | |
13 | | namespace mozilla { |
14 | | |
15 | | // This class implements a cubic MSD timing function and automatically |
16 | | // adapts the animation duration based on the scrolling rate. |
17 | | class ScrollAnimationMSDPhysics final : public ScrollAnimationPhysics |
18 | | { |
19 | | public: |
20 | | typedef mozilla::layers::AxisPhysicsMSDModel AxisPhysicsMSDModel; |
21 | | |
22 | | explicit ScrollAnimationMSDPhysics(const nsPoint& aStartPos); |
23 | | |
24 | | void Update(const TimeStamp& aTime, |
25 | | const nsPoint& aDestination, |
26 | | const nsSize& aCurrentVelocity) override; |
27 | | |
28 | | // Get the velocity at a point in time in nscoords/sec. |
29 | | nsSize VelocityAt(const TimeStamp& aTime) override; |
30 | | |
31 | | // Returns the expected scroll position at a given point in time, in app |
32 | | // units, relative to the scroll frame. |
33 | | nsPoint PositionAt(const TimeStamp& aTime) override; |
34 | | |
35 | 0 | bool IsFinished(const TimeStamp& aTime) override { |
36 | 0 | SimulateUntil(aTime); |
37 | 0 | return mModelX.IsFinished(1) && mModelY.IsFinished(1); |
38 | 0 | } |
39 | | |
40 | | protected: |
41 | | double ComputeSpringConstant(const TimeStamp& aTime); |
42 | | void SimulateUntil(const TimeStamp& aTime); |
43 | | |
44 | | TimeStamp mPreviousEventTime; |
45 | | TimeDuration mPreviousDelta; |
46 | | |
47 | | TimeStamp mStartTime; |
48 | | |
49 | | nsPoint mStartPos; |
50 | | nsPoint mDestination; |
51 | | TimeStamp mLastSimulatedTime; |
52 | | AxisPhysicsMSDModel mModelX; |
53 | | AxisPhysicsMSDModel mModelY; |
54 | | bool mIsFirstIteration; |
55 | | }; |
56 | | |
57 | | } // namespace mozilla |
58 | | |
59 | | #endif // mozilla_layout_ScrollAnimationMSDPhysics_h_ |