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_ScrollAnimationPhysics_h_
8 #define mozilla_layout_ScrollAnimationPhysics_h_
9 
10 #include "mozilla/TimeStamp.h"
11 #include "nsPoint.h"
12 #include "Units.h"
13 
14 namespace mozilla {
15 
16 class ScrollAnimationPhysics {
17  public:
18   virtual void Update(const TimeStamp& aTime, const nsPoint& aDestination,
19                       const nsSize& aCurrentVelocity) = 0;
20 
21   virtual void ApplyContentShift(const CSSPoint& aShiftDelta) = 0;
22 
23   // Get the velocity at a point in time in nscoords/sec.
24   virtual nsSize VelocityAt(const TimeStamp& aTime) = 0;
25 
26   // Returns the expected scroll position at a given point in time, in app
27   // units, relative to the scroll frame.
28   virtual nsPoint PositionAt(const TimeStamp& aTime) = 0;
29 
30   virtual bool IsFinished(const TimeStamp& aTime) = 0;
31 
32   virtual ~ScrollAnimationPhysics() = default;
33 };
34 
35 // Helper for accelerated wheel deltas. This can be called from the main thread
36 // or the APZ Controller thread.
ComputeAcceleratedWheelDelta(double aDelta,int32_t aCounter,int32_t aFactor)37 static inline double ComputeAcceleratedWheelDelta(double aDelta,
38                                                   int32_t aCounter,
39                                                   int32_t aFactor) {
40   if (!aDelta) {
41     return aDelta;
42   }
43   return (aDelta * aCounter * double(aFactor) / 10);
44 }
45 
46 static const uint32_t kScrollSeriesTimeoutMs = 80;  // in milliseconds
47 
48 }  // namespace mozilla
49 
50 #endif  // mozilla_layout_ScrollAnimationPhysics_h_
51