ScrollAnimationPhysics.h (2392B)
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 "Units.h" 11 #include "mozilla/TimeStamp.h" 12 #include "nsPoint.h" 13 14 namespace mozilla { 15 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; 26 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; 34 35 // Get the velocity at a point in time in nscoords/sec. 36 virtual nsSize VelocityAt(const TimeStamp& aTime) = 0; 37 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; 41 42 virtual bool IsFinished(const TimeStamp& aTime) = 0; 43 44 virtual ~ScrollAnimationPhysics() = default; 45 }; 46 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; 54 } 55 return (aDelta * aCounter * double(aFactor) / 10); 56 } 57 58 } // namespace mozilla 59 60 #endif // mozilla_layout_ScrollAnimationPhysics_h_