OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 UI_COMPOSITOR_LAYER_ANIMATOR_H_ | 5 #ifndef UI_COMPOSITOR_LAYER_ANIMATOR_H_ |
6 #define UI_COMPOSITOR_LAYER_ANIMATOR_H_ | 6 #define UI_COMPOSITOR_LAYER_ANIMATOR_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 | 106 |
107 // Start an animation sequence. If an animation for the same property is in | 107 // Start an animation sequence. If an animation for the same property is in |
108 // progress, it needs to be interrupted with the new animation. The animator | 108 // progress, it needs to be interrupted with the new animation. The animator |
109 // takes ownership of this animation sequence. | 109 // takes ownership of this animation sequence. |
110 void StartAnimation(LayerAnimationSequence* animation); | 110 void StartAnimation(LayerAnimationSequence* animation); |
111 | 111 |
112 // Schedule an animation to be run when possible. The animator takes ownership | 112 // Schedule an animation to be run when possible. The animator takes ownership |
113 // of this animation sequence. | 113 // of this animation sequence. |
114 void ScheduleAnimation(LayerAnimationSequence* animation); | 114 void ScheduleAnimation(LayerAnimationSequence* animation); |
115 | 115 |
116 // Starts the animations to be run together. Obviously will not work if | 116 // Starts the animations to be run together, ensuring that the first elements |
117 // they animate any common properties. The animator takes ownership of the | 117 // in these sequences have the same effective start time even when some of |
118 // them start on the compositor thread (but there is no such guarantee for | |
119 // the effective start time of subsequent elements). Obviously will not work | |
120 // if they animate any common properties. The animator takes ownership of the | |
118 // animation sequences. Takes PreemptionStrategy into account. | 121 // animation sequences. Takes PreemptionStrategy into account. |
119 void StartTogether(const std::vector<LayerAnimationSequence*>& animations); | 122 void StartTogether(const std::vector<LayerAnimationSequence*>& animations); |
120 | 123 |
121 // Schedules the animations to be run together. Obviously will not work if | 124 // Schedules the animations to be run together, ensuring that the first |
122 // they animate any common properties. The animator takes ownership of the | 125 // elements in these sequences have the same effective start time even when |
123 // animation sequences. | 126 // some of them start on the compositor thread (but there is no such guarantee |
127 // for the effective start time of subsequent elements). Obviously will not | |
128 // work if they animate any common properties. The animator takes ownership | |
129 // of the animation sequences. | |
124 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); | 130 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); |
125 | 131 |
126 // Schedules a pause for length |duration| of all the specified properties. | 132 // Schedules a pause for length |duration| of all the specified properties. |
127 // End the list with -1. | 133 // End the list with -1. |
128 void SchedulePauseForProperties( | 134 void SchedulePauseForProperties( |
129 base::TimeDelta duration, | 135 base::TimeDelta duration, |
130 LayerAnimationElement::AnimatableProperty property, | 136 LayerAnimationElement::AnimatableProperty property, |
131 ...); | 137 ...); |
132 | 138 |
133 // Returns true if there is an animation in the queue (animations remain in | 139 // Returns true if there is an animation in the queue (animations remain in |
(...skipping 18 matching lines...) Expand all Loading... | |
152 | 158 |
153 // This is similar to StopAnimating, but aborts rather than finishes the | 159 // This is similar to StopAnimating, but aborts rather than finishes the |
154 // animations and notifies all observers. | 160 // animations and notifies all observers. |
155 void AbortAllAnimations() { StopAnimatingInternal(true); } | 161 void AbortAllAnimations() { StopAnimatingInternal(true); } |
156 | 162 |
157 // These functions are used for adding or removing observers from the observer | 163 // These functions are used for adding or removing observers from the observer |
158 // list. The observers are notified when animations end. | 164 // list. The observers are notified when animations end. |
159 void AddObserver(LayerAnimationObserver* observer); | 165 void AddObserver(LayerAnimationObserver* observer); |
160 void RemoveObserver(LayerAnimationObserver* observer); | 166 void RemoveObserver(LayerAnimationObserver* observer); |
161 | 167 |
168 // Called when a threaded animation is actually started. | |
169 void OnThreadedAnimationStarted(const cc::AnimationEvent& event); | |
170 | |
162 // This determines how implicit animations will be tweened. This has no | 171 // This determines how implicit animations will be tweened. This has no |
163 // effect on animations that are explicitly started or scheduled. The default | 172 // effect on animations that are explicitly started or scheduled. The default |
164 // is Tween::LINEAR. | 173 // is Tween::LINEAR. |
165 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } | 174 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } |
166 Tween::Type tween_type() const { return tween_type_; } | 175 Tween::Type tween_type() const { return tween_type_; } |
167 | 176 |
168 // For testing purposes only. | 177 // For testing purposes only. |
169 void set_disable_timer_for_test(bool disable_timer) { | 178 void set_disable_timer_for_test(bool disable_timer) { |
170 disable_timer_for_test_ = disable_timer; | 179 disable_timer_for_test_ = disable_timer; |
171 } | 180 } |
(...skipping 19 matching lines...) Expand all Loading... | |
191 | 200 |
192 // When set to true, all animations complete immediately. | 201 // When set to true, all animations complete immediately. |
193 static void set_disable_animations_for_test(bool disable_animations) { | 202 static void set_disable_animations_for_test(bool disable_animations) { |
194 disable_animations_for_test_ = disable_animations; | 203 disable_animations_for_test_ = disable_animations; |
195 } | 204 } |
196 | 205 |
197 static bool disable_animations_for_test() { | 206 static bool disable_animations_for_test() { |
198 return disable_animations_for_test_; | 207 return disable_animations_for_test_; |
199 } | 208 } |
200 | 209 |
210 // Allows tests to access sequences owned by the animator. | |
211 class TestController { | |
sky
2013/02/19 17:06:56
If this is only for tests move it into its own fil
ajuma
2013/02/20 16:09:10
Moved to ui/compositor/test/layer_animator_test_co
| |
212 public: | |
213 TestController(scoped_refptr<LayerAnimator> animator); | |
214 | |
215 ~TestController(); | |
216 | |
217 LayerAnimator* animator() { return animator_.get(); } | |
218 | |
219 // Returns the running sequence animating the given property, if any. | |
220 LayerAnimationSequence* GetRunningSequence( | |
221 LayerAnimationElement::AnimatableProperty property); | |
222 | |
223 private: | |
224 scoped_refptr<LayerAnimator> animator_; | |
225 }; | |
226 | |
201 protected: | 227 protected: |
202 virtual ~LayerAnimator(); | 228 virtual ~LayerAnimator(); |
203 | 229 |
204 LayerAnimationDelegate* delegate() { return delegate_; } | 230 LayerAnimationDelegate* delegate() { return delegate_; } |
205 const LayerAnimationDelegate* delegate() const { return delegate_; } | 231 const LayerAnimationDelegate* delegate() const { return delegate_; } |
206 | 232 |
207 // Virtual for testing. | 233 // Virtual for testing. |
208 virtual void ProgressAnimation(LayerAnimationSequence* sequence, | 234 virtual void ProgressAnimation(LayerAnimationSequence* sequence, |
209 base::TimeTicks now); | 235 base::TimeTicks now); |
210 | 236 |
211 void ProgressAnimationToEnd(LayerAnimationSequence* sequence); | 237 void ProgressAnimationToEnd(LayerAnimationSequence* sequence); |
212 | 238 |
213 // Returns true if the sequence is owned by this animator. | 239 // Returns true if the sequence is owned by this animator. |
214 bool HasAnimation(LayerAnimationSequence* sequence) const; | 240 bool HasAnimation(LayerAnimationSequence* sequence) const; |
215 | 241 |
216 private: | 242 private: |
217 friend class base::RefCounted<LayerAnimator>; | 243 friend class base::RefCounted<LayerAnimator>; |
218 friend class ScopedLayerAnimationSettings; | 244 friend class ScopedLayerAnimationSettings; |
245 friend class LayerAnimator::TestController; | |
219 | 246 |
220 class RunningAnimation { | 247 class RunningAnimation { |
221 public: | 248 public: |
222 RunningAnimation(const base::WeakPtr<LayerAnimationSequence>& sequence); | 249 RunningAnimation(const base::WeakPtr<LayerAnimationSequence>& sequence); |
223 ~RunningAnimation(); | 250 ~RunningAnimation(); |
224 | 251 |
225 bool is_sequence_alive() const { return !!sequence_; } | 252 bool is_sequence_alive() const { return !!sequence_; } |
226 LayerAnimationSequence* sequence() const { return sequence_.get(); } | 253 LayerAnimationSequence* sequence() const { return sequence_.get(); } |
227 | 254 |
228 private: | 255 private: |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 // Observers are notified when layer animations end, are scheduled or are | 388 // Observers are notified when layer animations end, are scheduled or are |
362 // aborted. | 389 // aborted. |
363 ObserverList<LayerAnimationObserver> observers_; | 390 ObserverList<LayerAnimationObserver> observers_; |
364 | 391 |
365 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); | 392 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
366 }; | 393 }; |
367 | 394 |
368 } // namespace ui | 395 } // namespace ui |
369 | 396 |
370 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ | 397 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ |
OLD | NEW |