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 #ifndef CC_ANIMATION_ANIMATION_H_ | 5 #ifndef CC_ANIMATION_ANIMATION_H_ |
6 #define CC_ANIMATION_ANIMATION_H_ | 6 #define CC_ANIMATION_ANIMATION_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "cc/animation/animation_target_property.h" |
11 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
12 | 13 |
13 namespace cc { | 14 namespace cc { |
14 | 15 |
15 class AnimationCurve; | 16 class AnimationCurve; |
16 | 17 |
17 // An Animation contains all the state required to play an AnimationCurve. | 18 // An Animation contains all the state required to play an AnimationCurve. |
18 // Specifically, the affected property, the run state (paused, finished, etc.), | 19 // Specifically, the affected property, the run state (paused, finished, etc.), |
19 // loop count, last pause time, and the total time spent paused. | 20 // loop count, last pause time, and the total time spent paused. |
20 class CC_EXPORT Animation { | 21 class CC_EXPORT Animation { |
(...skipping 11 matching lines...) Expand all Loading... |
32 WAITING_FOR_DELETION, | 33 WAITING_FOR_DELETION, |
33 STARTING, | 34 STARTING, |
34 RUNNING, | 35 RUNNING, |
35 PAUSED, | 36 PAUSED, |
36 FINISHED, | 37 FINISHED, |
37 ABORTED, | 38 ABORTED, |
38 // This sentinel must be last. | 39 // This sentinel must be last. |
39 LAST_RUN_STATE = ABORTED | 40 LAST_RUN_STATE = ABORTED |
40 }; | 41 }; |
41 | 42 |
42 enum TargetProperty { | |
43 TRANSFORM = 0, | |
44 OPACITY, | |
45 FILTER, | |
46 SCROLL_OFFSET, | |
47 BACKGROUND_COLOR, | |
48 // This sentinel must be last. | |
49 LAST_TARGET_PROPERTY = BACKGROUND_COLOR | |
50 }; | |
51 | |
52 enum Direction { | 43 enum Direction { |
53 DIRECTION_NORMAL, | 44 DIRECTION_NORMAL, |
54 DIRECTION_REVERSE, | 45 DIRECTION_REVERSE, |
55 DIRECTION_ALTERNATE, | 46 DIRECTION_ALTERNATE, |
56 DIRECTION_ALTERNATE_REVERSE | 47 DIRECTION_ALTERNATE_REVERSE |
57 }; | 48 }; |
58 | 49 |
59 enum FillMode { | 50 enum FillMode { |
60 FILL_MODE_NONE, | 51 FILL_MODE_NONE, |
61 FILL_MODE_FORWARDS, | 52 FILL_MODE_FORWARDS, |
62 FILL_MODE_BACKWARDS, | 53 FILL_MODE_BACKWARDS, |
63 FILL_MODE_BOTH | 54 FILL_MODE_BOTH |
64 }; | 55 }; |
65 | 56 |
66 static scoped_ptr<Animation> Create(scoped_ptr<AnimationCurve> curve, | 57 static scoped_ptr<Animation> Create( |
67 int animation_id, | 58 scoped_ptr<AnimationCurve> curve, |
68 int group_id, | 59 int animation_id, |
69 TargetProperty target_property); | 60 int group_id, |
| 61 AnimationTargetProperty::Enum target_property); |
70 | 62 |
71 virtual ~Animation(); | 63 virtual ~Animation(); |
72 | 64 |
73 int id() const { return id_; } | 65 int id() const { return id_; } |
74 int group() const { return group_; } | 66 int group() const { return group_; } |
75 TargetProperty target_property() const { return target_property_; } | 67 AnimationTargetProperty::Enum target_property() const { |
| 68 return target_property_; |
| 69 } |
76 | 70 |
77 RunState run_state() const { return run_state_; } | 71 RunState run_state() const { return run_state_; } |
78 void SetRunState(RunState run_state, base::TimeTicks monotonic_time); | 72 void SetRunState(RunState run_state, base::TimeTicks monotonic_time); |
79 | 73 |
80 // This is the number of times that the animation will play. If this | 74 // This is the number of times that the animation will play. If this |
81 // value is zero the animation will not play. If it is negative, then | 75 // value is zero the animation will not play. If it is negative, then |
82 // the animation will loop indefinitely. | 76 // the animation will loop indefinitely. |
83 double iterations() const { return iterations_; } | 77 double iterations() const { return iterations_; } |
84 void set_iterations(double n) { iterations_ = n; } | 78 void set_iterations(double n) { iterations_ = n; } |
85 | 79 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 162 |
169 void set_affects_pending_observers(bool affects_pending_observers) { | 163 void set_affects_pending_observers(bool affects_pending_observers) { |
170 affects_pending_observers_ = affects_pending_observers; | 164 affects_pending_observers_ = affects_pending_observers; |
171 } | 165 } |
172 bool affects_pending_observers() const { return affects_pending_observers_; } | 166 bool affects_pending_observers() const { return affects_pending_observers_; } |
173 | 167 |
174 private: | 168 private: |
175 Animation(scoped_ptr<AnimationCurve> curve, | 169 Animation(scoped_ptr<AnimationCurve> curve, |
176 int animation_id, | 170 int animation_id, |
177 int group_id, | 171 int group_id, |
178 TargetProperty target_property); | 172 AnimationTargetProperty::Enum target_property); |
179 | 173 |
180 base::TimeDelta ConvertToActiveTime(base::TimeTicks monotonic_time) const; | 174 base::TimeDelta ConvertToActiveTime(base::TimeTicks monotonic_time) const; |
181 | 175 |
182 scoped_ptr<AnimationCurve> curve_; | 176 scoped_ptr<AnimationCurve> curve_; |
183 | 177 |
184 // IDs must be unique. | 178 // IDs must be unique. |
185 int id_; | 179 int id_; |
186 | 180 |
187 // Animations that must be run together are called 'grouped' and have the same | 181 // Animations that must be run together are called 'grouped' and have the same |
188 // group id. Grouped animations are guaranteed to start at the same time and | 182 // group id. Grouped animations are guaranteed to start at the same time and |
189 // no other animations may animate any of the group's target properties until | 183 // no other animations may animate any of the group's target properties until |
190 // all animations in the group have finished animating. | 184 // all animations in the group have finished animating. |
191 int group_; | 185 int group_; |
192 | 186 |
193 TargetProperty target_property_; | 187 AnimationTargetProperty::Enum target_property_; |
194 RunState run_state_; | 188 RunState run_state_; |
195 double iterations_; | 189 double iterations_; |
196 double iteration_start_; | 190 double iteration_start_; |
197 base::TimeTicks start_time_; | 191 base::TimeTicks start_time_; |
198 Direction direction_; | 192 Direction direction_; |
199 double playback_rate_; | 193 double playback_rate_; |
200 FillMode fill_mode_; | 194 FillMode fill_mode_; |
201 | 195 |
202 // The time offset effectively pushes the start of the animation back in time. | 196 // The time offset effectively pushes the start of the animation back in time. |
203 // This is used for resuming paused animations -- an animation is added with a | 197 // This is used for resuming paused animations -- an animation is added with a |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // longer affect any observers, and are deleted. | 238 // longer affect any observers, and are deleted. |
245 bool affects_active_observers_; | 239 bool affects_active_observers_; |
246 bool affects_pending_observers_; | 240 bool affects_pending_observers_; |
247 | 241 |
248 DISALLOW_COPY_AND_ASSIGN(Animation); | 242 DISALLOW_COPY_AND_ASSIGN(Animation); |
249 }; | 243 }; |
250 | 244 |
251 } // namespace cc | 245 } // namespace cc |
252 | 246 |
253 #endif // CC_ANIMATION_ANIMATION_H_ | 247 #endif // CC_ANIMATION_ANIMATION_H_ |
OLD | NEW |