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 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "ui/compositor/compositor_export.h" | 16 #include "ui/compositor/compositor_export.h" |
17 #include "ui/compositor/layer_animation_element.h" | 17 #include "ui/compositor/layer_animation_element.h" |
18 #include "ui/gfx/animation/animation_container_element.h" | |
19 #include "ui/gfx/animation/tween.h" | 18 #include "ui/gfx/animation/tween.h" |
20 | 19 |
21 namespace gfx { | 20 namespace gfx { |
22 class Animation; | 21 class Animation; |
23 class Rect; | 22 class Rect; |
24 class Transform; | 23 class Transform; |
25 } | 24 } |
26 | 25 |
27 namespace ui { | 26 namespace ui { |
28 class Layer; | 27 class Layer; |
29 class LayerAnimationSequence; | 28 class LayerAnimationSequence; |
30 class LayerAnimationDelegate; | 29 class LayerAnimationDelegate; |
31 class LayerAnimationObserver; | 30 class LayerAnimationObserver; |
32 class ScopedLayerAnimationSettings; | 31 class ScopedLayerAnimationSettings; |
33 | 32 |
34 // When a property of layer needs to be changed it is set by way of | 33 // When a property of layer needs to be changed it is set by way of |
35 // LayerAnimator. This enables LayerAnimator to animate property changes. | 34 // LayerAnimator. This enables LayerAnimator to animate property changes. |
36 // NB: during many tests, set_disable_animations_for_test is used and causes | 35 // NB: during many tests, set_disable_animations_for_test is used and causes |
37 // all animations to complete immediately. The layer animation is ref counted | 36 // all animations to complete immediately. The layer animation is ref counted |
38 // so that if its owning layer is deleted (and the owning layer is only other | 37 // so that if its owning layer is deleted (and the owning layer is only other |
39 // class that should ever hold a ref ptr to a LayerAnimator), the animator can | 38 // class that should ever hold a ref ptr to a LayerAnimator), the animator can |
40 // ensure that it is not disposed of until it finishes executing. It does this | 39 // ensure that it is not disposed of until it finishes executing. It does this |
41 // by holding a reference to itself for the duration of methods for which it | 40 // by holding a reference to itself for the duration of methods for which it |
42 // must guarantee that |this| is valid. | 41 // must guarantee that |this| is valid. |
43 class COMPOSITOR_EXPORT LayerAnimator | 42 class COMPOSITOR_EXPORT LayerAnimator : public base::RefCounted<LayerAnimator> { |
44 : public gfx::AnimationContainerElement, | |
45 public base::RefCounted<LayerAnimator> { | |
46 public: | 43 public: |
47 enum PreemptionStrategy { | 44 enum PreemptionStrategy { |
48 IMMEDIATELY_SET_NEW_TARGET, | 45 IMMEDIATELY_SET_NEW_TARGET, |
49 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 46 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
50 ENQUEUE_NEW_ANIMATION, | 47 ENQUEUE_NEW_ANIMATION, |
51 REPLACE_QUEUED_ANIMATIONS, | 48 REPLACE_QUEUED_ANIMATIONS, |
52 BLEND_WITH_CURRENT_ANIMATION | 49 BLEND_WITH_CURRENT_ANIMATION |
53 }; | 50 }; |
54 | 51 |
55 explicit LayerAnimator(base::TimeDelta transition_duration); | 52 explicit LayerAnimator(base::TimeDelta transition_duration); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 // For testing purposes only. | 178 // For testing purposes only. |
182 void set_disable_timer_for_test(bool disable_timer) { | 179 void set_disable_timer_for_test(bool disable_timer) { |
183 disable_timer_for_test_ = disable_timer; | 180 disable_timer_for_test_ = disable_timer; |
184 } | 181 } |
185 | 182 |
186 void set_last_step_time(base::TimeTicks time) { | 183 void set_last_step_time(base::TimeTicks time) { |
187 last_step_time_ = time; | 184 last_step_time_ = time; |
188 } | 185 } |
189 base::TimeTicks last_step_time() const { return last_step_time_; } | 186 base::TimeTicks last_step_time() const { return last_step_time_; } |
190 | 187 |
| 188 void Step(base::TimeTicks time_now); |
| 189 |
191 protected: | 190 protected: |
192 virtual ~LayerAnimator(); | 191 virtual ~LayerAnimator(); |
193 | 192 |
194 LayerAnimationDelegate* delegate() { return delegate_; } | 193 LayerAnimationDelegate* delegate() { return delegate_; } |
195 const LayerAnimationDelegate* delegate() const { return delegate_; } | 194 const LayerAnimationDelegate* delegate() const { return delegate_; } |
196 | 195 |
197 // Virtual for testing. | 196 // Virtual for testing. |
198 virtual void ProgressAnimation(LayerAnimationSequence* sequence, | 197 virtual void ProgressAnimation(LayerAnimationSequence* sequence, |
199 base::TimeTicks now); | 198 base::TimeTicks now); |
200 | 199 |
(...skipping 17 matching lines...) Expand all Loading... |
218 | 217 |
219 private: | 218 private: |
220 base::WeakPtr<LayerAnimationSequence> sequence_; | 219 base::WeakPtr<LayerAnimationSequence> sequence_; |
221 | 220 |
222 // Copy and assign are allowed. | 221 // Copy and assign are allowed. |
223 }; | 222 }; |
224 | 223 |
225 typedef std::vector<RunningAnimation> RunningAnimations; | 224 typedef std::vector<RunningAnimation> RunningAnimations; |
226 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; | 225 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; |
227 | 226 |
228 // Implementation of AnimationContainerElement | |
229 virtual void SetStartTime(base::TimeTicks start_time) OVERRIDE; | |
230 virtual void Step(base::TimeTicks time_now) OVERRIDE; | |
231 virtual base::TimeDelta GetTimerInterval() const OVERRIDE; | |
232 | |
233 // Finishes all animations by either advancing them to their final state or by | 227 // Finishes all animations by either advancing them to their final state or by |
234 // aborting them. | 228 // aborting them. |
235 void StopAnimatingInternal(bool abort); | 229 void StopAnimatingInternal(bool abort); |
236 | 230 |
237 // Starts or stops stepping depending on whether thare are running animations. | 231 // Starts or stops stepping depending on whether thare are running animations. |
238 void UpdateAnimationState(); | 232 void UpdateAnimationState(); |
239 | 233 |
240 // Removes the sequences from both the running animations and the queue. | 234 // Removes the sequences from both the running animations and the queue. |
241 // Returns a pointer to the removed animation, if any. NOTE: the caller is | 235 // Returns a pointer to the removed animation, if any. NOTE: the caller is |
242 // responsible for deleting the returned pointer. | 236 // responsible for deleting the returned pointer. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 // Observers are notified when layer animations end, are scheduled or are | 340 // Observers are notified when layer animations end, are scheduled or are |
347 // aborted. | 341 // aborted. |
348 ObserverList<LayerAnimationObserver> observers_; | 342 ObserverList<LayerAnimationObserver> observers_; |
349 | 343 |
350 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); | 344 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
351 }; | 345 }; |
352 | 346 |
353 } // namespace ui | 347 } // namespace ui |
354 | 348 |
355 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ | 349 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ |
OLD | NEW |