Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: cc/animation/timing_function.h

Issue 2019613002: Blink Compositor Animation: Make Animation and Curve methods non-virtual. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix codereview issues. Add cc::TimingFunction::Type enum. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/animation/keyframed_animation_curve.h ('k') | cc/animation/timing_function.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_ANIMATION_TIMING_FUNCTION_H_ 5 #ifndef CC_ANIMATION_TIMING_FUNCTION_H_
6 #define CC_ANIMATION_TIMING_FUNCTION_H_ 6 #define CC_ANIMATION_TIMING_FUNCTION_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "cc/base/cc_export.h" 11 #include "cc/base/cc_export.h"
12 #include "ui/gfx/geometry/cubic_bezier.h" 12 #include "ui/gfx/geometry/cubic_bezier.h"
13 13
14 namespace cc { 14 namespace cc {
15 15
16 // See http://www.w3.org/TR/css3-transitions/. 16 // See http://www.w3.org/TR/css3-transitions/.
17 class CC_EXPORT TimingFunction { 17 class CC_EXPORT TimingFunction {
18 public: 18 public:
19 virtual ~TimingFunction(); 19 virtual ~TimingFunction();
20 20
21 // Note that LINEAR is a nullptr TimingFunction (for now).
22 enum class Type { LINEAR, CUBIC_BEZIER, STEPS };
23
24 virtual Type GetType() const = 0;
21 virtual float GetValue(double t) const = 0; 25 virtual float GetValue(double t) const = 0;
22 virtual float Velocity(double time) const = 0; 26 virtual float Velocity(double time) const = 0;
23 // The smallest and largest values returned by GetValue for inputs in [0, 1]. 27 // The smallest and largest values returned by GetValue for inputs in [0, 1].
24 virtual void Range(float* min, float* max) const = 0; 28 virtual void Range(float* min, float* max) const = 0;
25 virtual std::unique_ptr<TimingFunction> Clone() const = 0; 29 virtual std::unique_ptr<TimingFunction> Clone() const = 0;
26 30
27 protected: 31 protected:
28 TimingFunction(); 32 TimingFunction();
29 33
30 private: 34 private:
31 DISALLOW_ASSIGN(TimingFunction); 35 DISALLOW_ASSIGN(TimingFunction);
32 }; 36 };
33 37
34 class CC_EXPORT CubicBezierTimingFunction : public TimingFunction { 38 class CC_EXPORT CubicBezierTimingFunction : public TimingFunction {
35 public: 39 public:
36 enum class EaseType { EASE, EASE_IN, EASE_OUT, EASE_IN_OUT, CUSTOM }; 40 enum class EaseType { EASE, EASE_IN, EASE_OUT, EASE_IN_OUT, CUSTOM };
37 41
38 static std::unique_ptr<TimingFunction> CreatePreset(EaseType ease_type); 42 static std::unique_ptr<TimingFunction> CreatePreset(EaseType ease_type);
39 static std::unique_ptr<CubicBezierTimingFunction> Create(double x1, 43 static std::unique_ptr<CubicBezierTimingFunction> Create(double x1,
40 double y1, 44 double y1,
41 double x2, 45 double x2,
42 double y2); 46 double y2);
43 ~CubicBezierTimingFunction() override; 47 ~CubicBezierTimingFunction() override;
44 48
45 // TimingFunction implementation. 49 // TimingFunction implementation.
50 Type GetType() const override;
46 float GetValue(double time) const override; 51 float GetValue(double time) const override;
47 float Velocity(double time) const override; 52 float Velocity(double time) const override;
48 void Range(float* min, float* max) const override; 53 void Range(float* min, float* max) const override;
49 std::unique_ptr<TimingFunction> Clone() const override; 54 std::unique_ptr<TimingFunction> Clone() const override;
50 55
56 EaseType ease_type() const { return ease_type_; }
57
51 protected: 58 protected:
52 CubicBezierTimingFunction(double x1, double y1, double x2, double y2); 59 CubicBezierTimingFunction(EaseType ease_type,
60 double x1,
61 double y1,
62 double x2,
63 double y2);
53 64
54 gfx::CubicBezier bezier_; 65 gfx::CubicBezier bezier_;
66 EaseType ease_type_;
55 67
56 private: 68 private:
57 DISALLOW_ASSIGN(CubicBezierTimingFunction); 69 DISALLOW_ASSIGN(CubicBezierTimingFunction);
58 }; 70 };
59 71
60 class CC_EXPORT EaseTimingFunction { 72 class CC_EXPORT EaseTimingFunction {
61 public: 73 public:
62 static std::unique_ptr<TimingFunction> Create(); 74 static std::unique_ptr<TimingFunction> Create();
63 75
64 private: 76 private:
(...skipping 27 matching lines...) Expand all
92 class CC_EXPORT StepsTimingFunction : public TimingFunction { 104 class CC_EXPORT StepsTimingFunction : public TimingFunction {
93 public: 105 public:
94 // Web Animations specification, 3.12.4. Timing in discrete steps. 106 // Web Animations specification, 3.12.4. Timing in discrete steps.
95 enum class StepPosition { START, MIDDLE, END }; 107 enum class StepPosition { START, MIDDLE, END };
96 108
97 static std::unique_ptr<StepsTimingFunction> Create( 109 static std::unique_ptr<StepsTimingFunction> Create(
98 int steps, 110 int steps,
99 StepPosition step_position); 111 StepPosition step_position);
100 ~StepsTimingFunction() override; 112 ~StepsTimingFunction() override;
101 113
114 // TimingFunction implementation.
115 Type GetType() const override;
102 float GetValue(double t) const override; 116 float GetValue(double t) const override;
103 std::unique_ptr<TimingFunction> Clone() const override; 117 std::unique_ptr<TimingFunction> Clone() const override;
104
105 void Range(float* min, float* max) const override; 118 void Range(float* min, float* max) const override;
106 float Velocity(double time) const override; 119 float Velocity(double time) const override;
107 120
108 protected: 121 protected:
109 StepsTimingFunction(int steps, StepPosition step_position); 122 StepsTimingFunction(int steps, StepPosition step_position);
110 123
111 private: 124 private:
112 int steps_; 125 int steps_;
113 float steps_start_offset_; 126 float steps_start_offset_;
114 127
115 DISALLOW_ASSIGN(StepsTimingFunction); 128 DISALLOW_ASSIGN(StepsTimingFunction);
116 }; 129 };
117 130
118 } // namespace cc 131 } // namespace cc
119 132
120 #endif // CC_ANIMATION_TIMING_FUNCTION_H_ 133 #endif // CC_ANIMATION_TIMING_FUNCTION_H_
OLDNEW
« no previous file with comments | « cc/animation/keyframed_animation_curve.h ('k') | cc/animation/timing_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698