OLD | NEW |
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 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/memory/scoped_ptr.h" |
6 #include "cc/animation/timing_function.h" | 7 #include "cc/animation/timing_function.h" |
7 | 8 |
8 namespace cc { | 9 namespace cc { |
9 | 10 |
10 TimingFunction::TimingFunction() {} | 11 TimingFunction::TimingFunction() {} |
11 | 12 |
12 TimingFunction::~TimingFunction() {} | 13 TimingFunction::~TimingFunction() {} |
13 | 14 |
14 double TimingFunction::Duration() const { | |
15 return 1.0; | |
16 } | |
17 | |
18 scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::Create( | 15 scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::Create( |
19 double x1, double y1, double x2, double y2) { | 16 double x1, double y1, double x2, double y2) { |
20 return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2)); | 17 return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2)); |
21 } | 18 } |
22 | 19 |
23 CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, | 20 CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, |
24 double y1, | 21 double y1, |
25 double x2, | 22 double x2, |
26 double y2) | 23 double y2) |
27 : bezier_(x1, y1, x2, y2) {} | 24 : bezier_(x1, y1, x2, y2) {} |
28 | 25 |
29 CubicBezierTimingFunction::~CubicBezierTimingFunction() {} | 26 CubicBezierTimingFunction::~CubicBezierTimingFunction() {} |
30 | 27 |
31 float CubicBezierTimingFunction::GetValue(double x) const { | 28 float CubicBezierTimingFunction::GetValue(double x) const { |
32 return static_cast<float>(bezier_.Solve(x)); | 29 return static_cast<float>(bezier_.Solve(x)); |
33 } | 30 } |
34 | 31 |
35 scoped_ptr<AnimationCurve> CubicBezierTimingFunction::Clone() const { | 32 float CubicBezierTimingFunction::Velocity(double x) const { |
36 return make_scoped_ptr( | 33 return static_cast<float>(bezier_.Slope(x)); |
37 new CubicBezierTimingFunction(*this)).PassAs<AnimationCurve>(); | |
38 } | 34 } |
39 | 35 |
40 void CubicBezierTimingFunction::Range(float* min, float* max) const { | 36 void CubicBezierTimingFunction::Range(float* min, float* max) const { |
41 double min_d = 0; | 37 double min_d = 0; |
42 double max_d = 1; | 38 double max_d = 1; |
43 bezier_.Range(&min_d, &max_d); | 39 bezier_.Range(&min_d, &max_d); |
44 *min = static_cast<float>(min_d); | 40 *min = static_cast<float>(min_d); |
45 *max = static_cast<float>(max_d); | 41 *max = static_cast<float>(max_d); |
46 } | 42 } |
47 | 43 |
48 float CubicBezierTimingFunction::Velocity(double x) const { | 44 scoped_ptr<TimingFunction> CubicBezierTimingFunction::Clone() const { |
49 return static_cast<float>(bezier_.Slope(x)); | 45 return make_scoped_ptr(new CubicBezierTimingFunction(*this)) |
| 46 .PassAs<TimingFunction>(); |
50 } | 47 } |
51 | 48 |
52 // These numbers come from | 49 // These numbers come from |
53 // http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag. | 50 // http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag. |
54 scoped_ptr<TimingFunction> EaseTimingFunction::Create() { | 51 scoped_ptr<TimingFunction> EaseTimingFunction::Create() { |
55 return CubicBezierTimingFunction::Create( | 52 return CubicBezierTimingFunction::Create( |
56 0.25, 0.1, 0.25, 1.0).PassAs<TimingFunction>(); | 53 0.25, 0.1, 0.25, 1.0).PassAs<TimingFunction>(); |
57 } | 54 } |
58 | 55 |
59 scoped_ptr<TimingFunction> EaseInTimingFunction::Create() { | 56 scoped_ptr<TimingFunction> EaseInTimingFunction::Create() { |
60 return CubicBezierTimingFunction::Create( | 57 return CubicBezierTimingFunction::Create( |
61 0.42, 0.0, 1.0, 1.0).PassAs<TimingFunction>(); | 58 0.42, 0.0, 1.0, 1.0).PassAs<TimingFunction>(); |
62 } | 59 } |
63 | 60 |
64 scoped_ptr<TimingFunction> EaseOutTimingFunction::Create() { | 61 scoped_ptr<TimingFunction> EaseOutTimingFunction::Create() { |
65 return CubicBezierTimingFunction::Create( | 62 return CubicBezierTimingFunction::Create( |
66 0.0, 0.0, 0.58, 1.0).PassAs<TimingFunction>(); | 63 0.0, 0.0, 0.58, 1.0).PassAs<TimingFunction>(); |
67 } | 64 } |
68 | 65 |
69 scoped_ptr<TimingFunction> EaseInOutTimingFunction::Create() { | 66 scoped_ptr<TimingFunction> EaseInOutTimingFunction::Create() { |
70 return CubicBezierTimingFunction::Create( | 67 return CubicBezierTimingFunction::Create( |
71 0.42, 0.0, 0.58, 1).PassAs<TimingFunction>(); | 68 0.42, 0.0, 0.58, 1).PassAs<TimingFunction>(); |
72 } | 69 } |
73 | 70 |
74 } // namespace cc | 71 } // namespace cc |
OLD | NEW |