| 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/base/animation/animation_container_element.h" | |
| 17 #include "ui/base/animation/tween.h" | |
| 18 #include "ui/compositor/compositor_export.h" | 16 #include "ui/compositor/compositor_export.h" |
| 19 #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" |
| 20 | 20 |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 class Animation; |
| 22 class Rect; | 23 class Rect; |
| 23 class Transform; | 24 class Transform; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace ui { | 27 namespace ui { |
| 27 class Animation; | |
| 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 ScopedLayerAnimationSettings; | 32 class ScopedLayerAnimationSettings; |
| 33 | 33 |
| 34 // When a property of layer needs to be changed it is set by way of | 34 // When a property of layer needs to be changed it is set by way of |
| 35 // LayerAnimator. This enables LayerAnimator to animate property changes. | 35 // LayerAnimator. This enables LayerAnimator to animate property changes. |
| 36 // NB: during many tests, set_disable_animations_for_test is used and causes | 36 // 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 | 37 // 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 | 38 // 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 | 39 // 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 | 40 // 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 | 41 // by holding a reference to itself for the duration of methods for which it |
| 42 // must guarantee that |this| is valid. | 42 // must guarantee that |this| is valid. |
| 43 class COMPOSITOR_EXPORT LayerAnimator | 43 class COMPOSITOR_EXPORT LayerAnimator |
| 44 : public AnimationContainerElement, public base::RefCounted<LayerAnimator> { | 44 : public gfx::AnimationContainerElement, |
| 45 public base::RefCounted<LayerAnimator> { |
| 45 public: | 46 public: |
| 46 enum PreemptionStrategy { | 47 enum PreemptionStrategy { |
| 47 IMMEDIATELY_SET_NEW_TARGET, | 48 IMMEDIATELY_SET_NEW_TARGET, |
| 48 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 49 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 49 ENQUEUE_NEW_ANIMATION, | 50 ENQUEUE_NEW_ANIMATION, |
| 50 REPLACE_QUEUED_ANIMATIONS, | 51 REPLACE_QUEUED_ANIMATIONS, |
| 51 BLEND_WITH_CURRENT_ANIMATION | 52 BLEND_WITH_CURRENT_ANIMATION |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 explicit LayerAnimator(base::TimeDelta transition_duration); | 55 explicit LayerAnimator(base::TimeDelta transition_duration); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // list. The observers are notified when animations end. | 165 // list. The observers are notified when animations end. |
| 165 void AddObserver(LayerAnimationObserver* observer); | 166 void AddObserver(LayerAnimationObserver* observer); |
| 166 void RemoveObserver(LayerAnimationObserver* observer); | 167 void RemoveObserver(LayerAnimationObserver* observer); |
| 167 | 168 |
| 168 // Called when a threaded animation is actually started. | 169 // Called when a threaded animation is actually started. |
| 169 void OnThreadedAnimationStarted(const cc::AnimationEvent& event); | 170 void OnThreadedAnimationStarted(const cc::AnimationEvent& event); |
| 170 | 171 |
| 171 // This determines how implicit animations will be tweened. This has no | 172 // This determines how implicit animations will be tweened. This has no |
| 172 // effect on animations that are explicitly started or scheduled. The default | 173 // effect on animations that are explicitly started or scheduled. The default |
| 173 // is Tween::LINEAR. | 174 // is Tween::LINEAR. |
| 174 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type; } | 175 void set_tween_type(gfx::Tween::Type tween_type) { tween_type_ = tween_type; } |
| 175 Tween::Type tween_type() const { return tween_type_; } | 176 gfx::Tween::Type tween_type() const { return tween_type_; } |
| 176 | 177 |
| 177 // For testing purposes only. | 178 // For testing purposes only. |
| 178 void set_disable_timer_for_test(bool disable_timer) { | 179 void set_disable_timer_for_test(bool disable_timer) { |
| 179 disable_timer_for_test_ = disable_timer; | 180 disable_timer_for_test_ = disable_timer; |
| 180 } | 181 } |
| 181 | 182 |
| 182 void set_last_step_time(base::TimeTicks time) { | 183 void set_last_step_time(base::TimeTicks time) { |
| 183 last_step_time_ = time; | 184 last_step_time_ = time; |
| 184 } | 185 } |
| 185 base::TimeTicks last_step_time() const { return last_step_time_; } | 186 base::TimeTicks last_step_time() const { return last_step_time_; } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 // The currently running animations. | 314 // The currently running animations. |
| 314 RunningAnimations running_animations_; | 315 RunningAnimations running_animations_; |
| 315 | 316 |
| 316 // Determines how animations are replaced. | 317 // Determines how animations are replaced. |
| 317 PreemptionStrategy preemption_strategy_; | 318 PreemptionStrategy preemption_strategy_; |
| 318 | 319 |
| 319 // The default length of animations. | 320 // The default length of animations. |
| 320 base::TimeDelta transition_duration_; | 321 base::TimeDelta transition_duration_; |
| 321 | 322 |
| 322 // The default tween type for implicit transitions | 323 // The default tween type for implicit transitions |
| 323 Tween::Type tween_type_; | 324 gfx::Tween::Type tween_type_; |
| 324 | 325 |
| 325 // Used for coordinating the starting of animations. | 326 // Used for coordinating the starting of animations. |
| 326 base::TimeTicks last_step_time_; | 327 base::TimeTicks last_step_time_; |
| 327 | 328 |
| 328 // True if we are being stepped by our container. | 329 // True if we are being stepped by our container. |
| 329 bool is_started_; | 330 bool is_started_; |
| 330 | 331 |
| 331 // This prevents the animator from automatically stepping through animations | 332 // This prevents the animator from automatically stepping through animations |
| 332 // and allows for manual stepping. | 333 // and allows for manual stepping. |
| 333 bool disable_timer_for_test_; | 334 bool disable_timer_for_test_; |
| 334 | 335 |
| 335 // Prevents timer adjustments in case when we start multiple animations | 336 // Prevents timer adjustments in case when we start multiple animations |
| 336 // with preemption strategies that discard previous animations. | 337 // with preemption strategies that discard previous animations. |
| 337 bool adding_animations_; | 338 bool adding_animations_; |
| 338 | 339 |
| 339 // Observers are notified when layer animations end, are scheduled or are | 340 // Observers are notified when layer animations end, are scheduled or are |
| 340 // aborted. | 341 // aborted. |
| 341 ObserverList<LayerAnimationObserver> observers_; | 342 ObserverList<LayerAnimationObserver> observers_; |
| 342 | 343 |
| 343 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); | 344 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
| 344 }; | 345 }; |
| 345 | 346 |
| 346 } // namespace ui | 347 } // namespace ui |
| 347 | 348 |
| 348 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ | 349 #endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ |
| OLD | NEW |