FlingAccelerator.h (1929B)
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_layers_FlingAccelerator_h 8 #define mozilla_layers_FlingAccelerator_h 9 10 #include "mozilla/layers/SampleTime.h" 11 #include "Units.h" 12 13 namespace mozilla { 14 namespace layers { 15 16 struct FlingHandoffState; 17 18 /** 19 * This class is used to track state that is used when determining whether a 20 * fling should be accelerated. 21 */ 22 class FlingAccelerator final { 23 public: 24 FlingAccelerator() {} 25 26 // Resets state so that the next fling will not be accelerated. 27 void Reset(); 28 29 // Returns false after a reset or before the first fling. 30 bool IsTracking() const { return mIsTracking; } 31 32 // Starts a new fling, and returns the (potentially accelerated) velocity that 33 // should be used for that fling. 34 ParentLayerPoint GetFlingStartingVelocity( 35 const SampleTime& aNow, const ParentLayerPoint& aVelocity, 36 const FlingHandoffState& aHandoffState); 37 38 void ObserveFlingCanceled(const ParentLayerPoint& aVelocity) { 39 mPreviousFlingCancelVelocity = aVelocity; 40 } 41 42 protected: 43 bool ShouldAccelerate(const SampleTime& aNow, 44 const ParentLayerPoint& aVelocity, 45 const FlingHandoffState& aHandoffState) const; 46 47 // The initial velocity of the most recent fling. 48 ParentLayerPoint mPreviousFlingStartingVelocity; 49 // The velocity that the previous fling animation had at the point it was 50 // interrupted. 51 ParentLayerPoint mPreviousFlingCancelVelocity; 52 // Whether the upcoming fling is eligible for acceleration. 53 bool mIsTracking = false; 54 }; 55 56 } // namespace layers 57 } // namespace mozilla 58 59 #endif // mozilla_layers_FlingAccelerator_h