Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / layout / generic / ScrollAnimationPhysics.h
blob0a1bae05326d263802231726991d2737eef58a6d
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/. */
7 #ifndef mozilla_layout_ScrollAnimationPhysics_h_
8 #define mozilla_layout_ScrollAnimationPhysics_h_
10 #include "mozilla/TimeStamp.h"
11 #include "nsPoint.h"
12 #include "Units.h"
14 namespace mozilla {
16 class ScrollAnimationPhysics {
17 public:
18 // Update the animation to have |aDestination| as its new destination.
19 // The animation's current position remains unchanged, and the shape
20 // of the animation curve is recomputed between the current position
21 // and the new destination.
22 // This is used in cases where an input event that would cause another
23 // animation of this kind is received while this animation is running.
24 virtual void Update(const TimeStamp& aTime, const nsPoint& aDestination,
25 const nsSize& aCurrentVelocity) = 0;
27 // Shift both the current position and the destination of the animation
28 // by |aShiftDelta|. The progress of the animation along its animation
29 // curve is unchanged.
30 // This is used in cases where the main thread changes the scroll offset
31 // (e.g. via scrollBy()) but we want the "momentum" represented by the
32 // animation to be preserved.
33 virtual void ApplyContentShift(const CSSPoint& aShiftDelta) = 0;
35 // Get the velocity at a point in time in nscoords/sec.
36 virtual nsSize VelocityAt(const TimeStamp& aTime) = 0;
38 // Returns the expected scroll position at a given point in time, in app
39 // units, relative to the scroll frame.
40 virtual nsPoint PositionAt(const TimeStamp& aTime) = 0;
42 virtual bool IsFinished(const TimeStamp& aTime) = 0;
44 virtual ~ScrollAnimationPhysics() = default;
47 // Helper for accelerated wheel deltas. This can be called from the main thread
48 // or the APZ Controller thread.
49 static inline double ComputeAcceleratedWheelDelta(double aDelta,
50 int32_t aCounter,
51 int32_t aFactor) {
52 if (!aDelta) {
53 return aDelta;
55 return (aDelta * aCounter * double(aFactor) / 10);
58 } // namespace mozilla
60 #endif // mozilla_layout_ScrollAnimationPhysics_h_