1 // Copyright 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CC_ANIMATION_TIMING_FUNCTION_H_ 6 #define CC_ANIMATION_TIMING_FUNCTION_H_ 7 8 #include "cc/base/cc_export.h" 9 #include "ui/gfx/geometry/cubic_bezier.h" 10 11 namespace cc { 12 13 // See http://www.w3.org/TR/css3-transitions/. 14 class CC_EXPORT TimingFunction { 15 public: 16 virtual ~TimingFunction(); 17 18 virtual float GetValue(double t) const = 0; 19 virtual float Velocity(double time) const = 0; 20 // The smallest and largest values returned by GetValue for inputs in [0, 1]. 21 virtual void Range(float* min, float* max) const = 0; 22 virtual scoped_ptr<TimingFunction> Clone() const = 0; 23 24 protected: 25 TimingFunction(); 26 27 private: 28 DISALLOW_ASSIGN(TimingFunction); 29 }; 30 31 class CC_EXPORT CubicBezierTimingFunction : public TimingFunction { 32 public: 33 static scoped_ptr<CubicBezierTimingFunction> Create(double x1, double y1, 34 double x2, double y2); 35 virtual ~CubicBezierTimingFunction(); 36 37 // TimingFunction implementation. 38 virtual float GetValue(double time) const OVERRIDE; 39 virtual float Velocity(double time) const OVERRIDE; 40 virtual void Range(float* min, float* max) const OVERRIDE; 41 virtual scoped_ptr<TimingFunction> Clone() const OVERRIDE; 42 43 protected: 44 CubicBezierTimingFunction(double x1, double y1, double x2, double y2); 45 46 gfx::CubicBezier bezier_; 47 48 private: 49 DISALLOW_ASSIGN(CubicBezierTimingFunction); 50 }; 51 52 class CC_EXPORT EaseTimingFunction { 53 public: 54 static scoped_ptr<TimingFunction> Create(); 55 56 private: 57 DISALLOW_IMPLICIT_CONSTRUCTORS(EaseTimingFunction); 58 }; 59 60 class CC_EXPORT EaseInTimingFunction { 61 public: 62 static scoped_ptr<TimingFunction> Create(); 63 64 private: 65 DISALLOW_IMPLICIT_CONSTRUCTORS(EaseInTimingFunction); 66 }; 67 68 class CC_EXPORT EaseOutTimingFunction { 69 public: 70 static scoped_ptr<TimingFunction> Create(); 71 72 private: 73 DISALLOW_IMPLICIT_CONSTRUCTORS(EaseOutTimingFunction); 74 }; 75 76 class CC_EXPORT EaseInOutTimingFunction { 77 public: 78 static scoped_ptr<TimingFunction> Create(); 79 80 private: 81 DISALLOW_IMPLICIT_CONSTRUCTORS(EaseInOutTimingFunction); 82 }; 83 84 } // namespace cc 85 86 #endif // CC_ANIMATION_TIMING_FUNCTION_H_ 87