| 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/gtest_prod_util.h" |
| 12 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "ui/compositor/compositor_export.h" | 17 #include "ui/compositor/compositor_export.h" |
| 17 #include "ui/compositor/layer_animation_element.h" | 18 #include "ui/compositor/layer_animation_element.h" |
| 18 #include "ui/gfx/animation/animation_container_element.h" | |
| 19 #include "ui/gfx/animation/tween.h" | 19 #include "ui/gfx/animation/tween.h" |
| 20 | 20 |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 class Animation; | 22 class Animation; |
| 23 class Rect; | 23 class Rect; |
| 24 class Transform; | 24 class Transform; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 class Layer; | 28 class Layer; |
| 29 class LayerAnimationSequence; | 29 class LayerAnimationSequence; |
| 30 class LayerAnimationDelegate; | 30 class LayerAnimationDelegate; |
| 31 class LayerAnimationObserver; | 31 class LayerAnimationObserver; |
| 32 class LayerAnimatorCollection; |
| 32 class ScopedLayerAnimationSettings; | 33 class ScopedLayerAnimationSettings; |
| 33 | 34 |
| 34 // When a property of layer needs to be changed it is set by way of | 35 // When a property of layer needs to be changed it is set by way of |
| 35 // LayerAnimator. This enables LayerAnimator to animate property changes. | 36 // LayerAnimator. This enables LayerAnimator to animate property changes. |
| 36 // NB: during many tests, set_disable_animations_for_test is used and causes | 37 // 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 | 38 // 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 | 39 // 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 | 40 // 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 | 41 // 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 | 42 // by holding a reference to itself for the duration of methods for which it |
| 42 // must guarantee that |this| is valid. | 43 // must guarantee that |this| is valid. |
| 43 class COMPOSITOR_EXPORT LayerAnimator | 44 class COMPOSITOR_EXPORT LayerAnimator : public base::RefCounted<LayerAnimator> { |
| 44 : public gfx::AnimationContainerElement, | |
| 45 public base::RefCounted<LayerAnimator> { | |
| 46 public: | 45 public: |
| 47 enum PreemptionStrategy { | 46 enum PreemptionStrategy { |
| 48 IMMEDIATELY_SET_NEW_TARGET, | 47 IMMEDIATELY_SET_NEW_TARGET, |
| 49 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 48 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 50 ENQUEUE_NEW_ANIMATION, | 49 ENQUEUE_NEW_ANIMATION, |
| 51 REPLACE_QUEUED_ANIMATIONS, | 50 REPLACE_QUEUED_ANIMATIONS, |
| 52 BLEND_WITH_CURRENT_ANIMATION | 51 BLEND_WITH_CURRENT_ANIMATION |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 explicit LayerAnimator(base::TimeDelta transition_duration); | 54 explicit LayerAnimator(base::TimeDelta transition_duration); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // For testing purposes only. | 180 // For testing purposes only. |
| 182 void set_disable_timer_for_test(bool disable_timer) { | 181 void set_disable_timer_for_test(bool disable_timer) { |
| 183 disable_timer_for_test_ = disable_timer; | 182 disable_timer_for_test_ = disable_timer; |
| 184 } | 183 } |
| 185 | 184 |
| 186 void set_last_step_time(base::TimeTicks time) { | 185 void set_last_step_time(base::TimeTicks time) { |
| 187 last_step_time_ = time; | 186 last_step_time_ = time; |
| 188 } | 187 } |
| 189 base::TimeTicks last_step_time() const { return last_step_time_; } | 188 base::TimeTicks last_step_time() const { return last_step_time_; } |
| 190 | 189 |
| 190 void Step(base::TimeTicks time_now); |
| 191 |
| 191 protected: | 192 protected: |
| 192 virtual ~LayerAnimator(); | 193 virtual ~LayerAnimator(); |
| 193 | 194 |
| 194 LayerAnimationDelegate* delegate() { return delegate_; } | 195 LayerAnimationDelegate* delegate() { return delegate_; } |
| 195 const LayerAnimationDelegate* delegate() const { return delegate_; } | 196 const LayerAnimationDelegate* delegate() const { return delegate_; } |
| 196 | 197 |
| 197 // Virtual for testing. | 198 // Virtual for testing. |
| 198 virtual void ProgressAnimation(LayerAnimationSequence* sequence, | 199 virtual void ProgressAnimation(LayerAnimationSequence* sequence, |
| 199 base::TimeTicks now); | 200 base::TimeTicks now); |
| 200 | 201 |
| 201 void ProgressAnimationToEnd(LayerAnimationSequence* sequence); | 202 void ProgressAnimationToEnd(LayerAnimationSequence* sequence); |
| 202 | 203 |
| 203 // Returns true if the sequence is owned by this animator. | 204 // Returns true if the sequence is owned by this animator. |
| 204 bool HasAnimation(LayerAnimationSequence* sequence) const; | 205 bool HasAnimation(LayerAnimationSequence* sequence) const; |
| 205 | 206 |
| 206 private: | 207 private: |
| 207 friend class base::RefCounted<LayerAnimator>; | 208 friend class base::RefCounted<LayerAnimator>; |
| 208 friend class ScopedLayerAnimationSettings; | 209 friend class ScopedLayerAnimationSettings; |
| 209 friend class LayerAnimatorTestController; | 210 friend class LayerAnimatorTestController; |
| 211 FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, AnimatorStartedCorrectly); |
| 210 | 212 |
| 211 class RunningAnimation { | 213 class RunningAnimation { |
| 212 public: | 214 public: |
| 213 RunningAnimation(const base::WeakPtr<LayerAnimationSequence>& sequence); | 215 RunningAnimation(const base::WeakPtr<LayerAnimationSequence>& sequence); |
| 214 ~RunningAnimation(); | 216 ~RunningAnimation(); |
| 215 | 217 |
| 216 bool is_sequence_alive() const { return !!sequence_.get(); } | 218 bool is_sequence_alive() const { return !!sequence_.get(); } |
| 217 LayerAnimationSequence* sequence() const { return sequence_.get(); } | 219 LayerAnimationSequence* sequence() const { return sequence_.get(); } |
| 218 | 220 |
| 219 private: | 221 private: |
| 220 base::WeakPtr<LayerAnimationSequence> sequence_; | 222 base::WeakPtr<LayerAnimationSequence> sequence_; |
| 221 | 223 |
| 222 // Copy and assign are allowed. | 224 // Copy and assign are allowed. |
| 223 }; | 225 }; |
| 224 | 226 |
| 225 typedef std::vector<RunningAnimation> RunningAnimations; | 227 typedef std::vector<RunningAnimation> RunningAnimations; |
| 226 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; | 228 typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; |
| 227 | 229 |
| 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 | 230 // Finishes all animations by either advancing them to their final state or by |
| 234 // aborting them. | 231 // aborting them. |
| 235 void StopAnimatingInternal(bool abort); | 232 void StopAnimatingInternal(bool abort); |
| 236 | 233 |
| 237 // Starts or stops stepping depending on whether thare are running animations. | 234 // Starts or stops stepping depending on whether thare are running animations. |
| 238 void UpdateAnimationState(); | 235 void UpdateAnimationState(); |
| 239 | 236 |
| 240 // Removes the sequences from both the running animations and the queue. | 237 // 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 | 238 // Returns a pointer to the removed animation, if any. NOTE: the caller is |
| 242 // responsible for deleting the returned pointer. | 239 // responsible for deleting the returned pointer. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // Sets |transition_duration_| unless |is_transition_duration_locked_| is set. | 297 // Sets |transition_duration_| unless |is_transition_duration_locked_| is set. |
| 301 void SetTransitionDuration(base::TimeDelta duration); | 298 void SetTransitionDuration(base::TimeDelta duration); |
| 302 | 299 |
| 303 // Clears the animation queues and notifies any running animations that they | 300 // Clears the animation queues and notifies any running animations that they |
| 304 // have been aborted. | 301 // have been aborted. |
| 305 void ClearAnimationsInternal(); | 302 void ClearAnimationsInternal(); |
| 306 | 303 |
| 307 // Cleans up any running animations that may have been deleted. | 304 // Cleans up any running animations that may have been deleted. |
| 308 void PurgeDeletedAnimations(); | 305 void PurgeDeletedAnimations(); |
| 309 | 306 |
| 307 LayerAnimatorCollection* GetLayerAnimatorCollection(); |
| 308 |
| 310 // This is the queue of animations to run. | 309 // This is the queue of animations to run. |
| 311 AnimationQueue animation_queue_; | 310 AnimationQueue animation_queue_; |
| 312 | 311 |
| 313 // The target of all layer animations. | 312 // The target of all layer animations. |
| 314 LayerAnimationDelegate* delegate_; | 313 LayerAnimationDelegate* delegate_; |
| 315 | 314 |
| 316 // The currently running animations. | 315 // The currently running animations. |
| 317 RunningAnimations running_animations_; | 316 RunningAnimations running_animations_; |
| 318 | 317 |
| 319 // Determines how animations are replaced. | 318 // Determines how animations are replaced. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 346 // Observers are notified when layer animations end, are scheduled or are | 345 // Observers are notified when layer animations end, are scheduled or are |
| 347 // aborted. | 346 // aborted. |
| 348 ObserverList<LayerAnimationObserver> observers_; | 347 ObserverList<LayerAnimationObserver> observers_; |
| 349 | 348 |
| 350 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); | 349 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
| 351 }; | 350 }; |
| 352 | 351 |
| 353 } // namespace ui | 352 } // namespace ui |
| 354 | 353 |
| 355 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ | 354 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ |
| OLD | NEW |