Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ | 5 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ |
| 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ | 6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "ui/base/animation/animation_container_element.h" | 15 #include "ui/base/animation/animation_container_element.h" |
| 16 #include "ui/gfx/compositor/compositor_export.h" | 16 #include "ui/gfx/compositor/compositor_export.h" |
| 17 #include "ui/gfx/compositor/layer_animation_element.h" | 17 #include "ui/gfx/compositor/layer_animation_element.h" |
| 18 | 18 |
| 19 namespace gfx { | 19 namespace gfx { |
| 20 class Rect; | 20 class Rect; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace ui { | 23 namespace ui { |
| 24 class Animation; | 24 class Animation; |
| 25 class Layer; | 25 class Layer; |
| 26 class LayerAnimationSequence; | 26 class LayerAnimationSequence; |
| 27 class LayerAnimatorDelegate; | |
| 27 class Transform; | 28 class Transform; |
| 28 | 29 |
| 29 // When a property of layer needs to be changed it is set by way of | 30 // When a property of layer needs to be changed it is set by way of |
| 30 // LayerAnimator. This enables LayerAnimator to animate property | 31 // LayerAnimator. This enables LayerAnimator to animate property changes. |
| 31 // changes. | |
| 32 class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement { | 32 class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement { |
| 33 public: | 33 public: |
| 34 enum PreemptionStrategy { | 34 enum PreemptionStrategy { |
| 35 IMMEDIATELY_SET_NEW_TARGET, | 35 IMMEDIATELY_SET_NEW_TARGET, |
| 36 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, | 36 IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
| 37 ENQUEUE_NEW_ANIMATION, | 37 ENQUEUE_NEW_ANIMATION, |
| 38 REPLACE_QUEUED_ANIMATIONS, | 38 REPLACE_QUEUED_ANIMATIONS, |
| 39 BLEND_WITH_CURRENT_ANIMATION | 39 BLEND_WITH_CURRENT_ANIMATION |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 explicit LayerAnimator(base::TimeDelta transition_duration); | 42 explicit LayerAnimator(base::TimeDelta transition_duration); |
| 43 virtual ~LayerAnimator(); | 43 virtual ~LayerAnimator(); |
| 44 | 44 |
| 45 // No implicit animations when properties are set. | 45 // No implicit animations when properties are set. |
| 46 static LayerAnimator* CreateDefaultAnimator(); | 46 static LayerAnimator* CreateDefaultAnimator(); |
| 47 | 47 |
| 48 // Implicitly animates when properties are set. | 48 // Implicitly animates when properties are set. |
| 49 static LayerAnimator* CreateImplicitAnimator(); | 49 static LayerAnimator* CreateImplicitAnimator(); |
| 50 | 50 |
| 51 // Sets the transform on the delegate. May cause an implicit animation. | 51 // Sets the transform on the delegate. May cause an implicit animation. |
| 52 virtual void SetTransform(const Transform& transform); | 52 virtual void SetTransform(const Transform& transform); |
| 53 Transform GetTargetTransform() const; | |
| 53 | 54 |
| 54 // Sets the bounds on the delegate. May cause an implicit animation. | 55 // Sets the bounds on the delegate. May cause an implicit animation. |
| 55 virtual void SetBounds(const gfx::Rect& bounds); | 56 virtual void SetBounds(const gfx::Rect& bounds); |
| 57 gfx::Rect GetTargetBounds() const; | |
| 56 | 58 |
| 57 // Sets the opacity on the delegate. May cause an implicit animation. | 59 // Sets the opacity on the delegate. May cause an implicit animation. |
| 58 virtual void SetOpacity(float opacity); | 60 virtual void SetOpacity(float opacity); |
| 61 float GetTargetOpacity() const; | |
| 59 | 62 |
| 60 // Sets the layer animation delegate the animator is associated with. The | 63 // Sets the layer animation delegate the animator is associated with. The |
| 61 // animator does not own the delegate. | 64 // animator does not own the delegate. |
| 62 void SetDelegate(LayerAnimationDelegate* delegate); | 65 void SetDelegate(LayerAnimatorDelegate* delegate); |
| 63 | 66 |
| 64 // Sets the animation preemption strategy. This determines the behaviour if | 67 // Sets the animation preemption strategy. This determines the behaviour if |
| 65 // a property is set during an animation. The default is | 68 // a property is set during an animation. The default is |
| 66 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). | 69 // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). |
| 67 void set_preemption_strategy(PreemptionStrategy strategy) { | 70 void set_preemption_strategy(PreemptionStrategy strategy) { |
| 68 preemption_strategy_ = strategy; | 71 preemption_strategy_ = strategy; |
| 69 } | 72 } |
| 70 | 73 |
| 71 // Start an animation sequence. If an animation for the same property is in | 74 // Start an animation sequence. If an animation for the same property is in |
| 72 // progress, it needs to be interrupted with the new animation. The animator | 75 // progress, it needs to be interrupted with the new animation. The animator |
| 73 // takes ownership of this animation sequence. | 76 // takes ownership of this animation sequence. |
| 74 void StartAnimation(LayerAnimationSequence* animation); | 77 void StartAnimation(LayerAnimationSequence* animation); |
| 78 void StartAnimation(LayerAnimationElement* animation); | |
|
sky
2011/10/25 04:00:55
Style guide doesn't like methods with the same nam
| |
| 75 | 79 |
| 76 // Schedule an animation to be run when possible. The animator takes ownership | 80 // Schedule an animation to be run when possible. The animator takes ownership |
| 77 // of this animation sequence. | 81 // of this animation sequence. |
| 78 void ScheduleAnimation(LayerAnimationSequence* animation); | 82 void ScheduleAnimation(LayerAnimationSequence* animation); |
| 83 void ScheduleAnimation(LayerAnimationElement* animation); | |
| 79 | 84 |
| 80 // Schedules the animations to be run together. Obviously will no work if | 85 // Schedules the animations to be run together. Obviously will no work if |
| 81 // they animate any common properties. The animator takes ownership of the | 86 // they animate any common properties. The animator takes ownership of the |
| 82 // animation sequences. | 87 // animation sequences. |
| 83 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); | 88 void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); |
| 89 void ScheduleTogether(const std::vector<LayerAnimationElement*>& animations); | |
| 84 | 90 |
| 85 // Returns true if there is an animation in the queue (animations remain in | 91 // Returns true if there is an animation in the queue (animations remain in |
| 86 // the queue until they complete). | 92 // the queue until they complete). |
| 87 bool is_animating() const { return !animation_queue_.empty(); } | 93 bool is_animating() const { return !animation_queue_.empty(); } |
| 88 | 94 |
| 89 // Stops animating the given property. No effect if there is no running | 95 // Stops animating the given property. No effect if there is no running |
| 90 // animation for the given property. Skips to the final state of the | 96 // animation for the given property. Skips to the final state of the |
| 91 // animation. | 97 // animation. |
| 92 void StopAnimatingProperty( | 98 void StopAnimatingProperty( |
| 93 LayerAnimationElement::AnimatableProperty property); | 99 LayerAnimationElement::AnimatableProperty property); |
| 94 | 100 |
| 95 // Stops all animation and clears any queued animations. | 101 // Stops all animation and clears any queued animations. |
| 96 void StopAnimating(); | 102 void StopAnimating(); |
| 97 | 103 |
| 98 // For testing purposes only. | 104 // For testing purposes only. |
| 99 void set_disable_timer_for_test(bool enabled) { | 105 void set_disable_timer_for_test(bool enabled) { |
| 100 disable_timer_for_test_ = enabled; | 106 disable_timer_for_test_ = enabled; |
| 101 } | 107 } |
| 102 base::TimeTicks get_last_step_time_for_test() { return last_step_time_; } | 108 base::TimeTicks get_last_step_time_for_test() { return last_step_time_; } |
| 103 | 109 |
| 110 class TransientSettings { | |
|
sky
2011/10/25 00:26:59
This name is confusing. Maybe ScopedSettings or so
| |
| 111 public: | |
| 112 TransientSettings(LayerAnimator* animator); | |
|
sky
2011/10/25 00:26:59
explicit
| |
| 113 ~TransientSettings(); | |
| 114 | |
| 115 void SetTransitionDuration(base::TimeDelta duration); | |
| 116 | |
| 117 private: | |
| 118 LayerAnimator* animator_; | |
| 119 base::TimeDelta old_transition_duration_; | |
| 120 }; | |
|
sky
2011/10/25 00:26:59
DISALLOW_COPY_AND_ASSIGN
| |
| 121 | |
| 104 protected: | 122 protected: |
| 105 LayerAnimationDelegate* delegate() { return delegate_; } | 123 LayerAnimatorDelegate* delegate() { return delegate_; } |
| 106 | 124 |
| 107 private: | 125 private: |
| 126 friend class TransientSettings; | |
| 127 | |
| 108 // We need to keep track of the start time of every running animation. | 128 // We need to keep track of the start time of every running animation. |
| 109 struct RunningAnimation { | 129 struct RunningAnimation { |
| 110 RunningAnimation(LayerAnimationSequence* sequence, | 130 RunningAnimation(LayerAnimationSequence* sequence, |
| 111 base::TimeTicks start_time) | 131 base::TimeTicks start_time) |
| 112 : sequence(sequence), | 132 : sequence(sequence), |
| 113 start_time(start_time) { | 133 start_time(start_time) { |
| 114 } | 134 } |
| 115 LayerAnimationSequence* sequence; | 135 LayerAnimationSequence* sequence; |
| 116 base::TimeTicks start_time; | 136 base::TimeTicks start_time; |
| 117 }; | 137 }; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 // If there's an animation in the queue that doesn't animate the same property | 189 // If there's an animation in the queue that doesn't animate the same property |
| 170 // as a running animation, or an animation schedule to run before it, start it | 190 // as a running animation, or an animation schedule to run before it, start it |
| 171 // up. Repeat until there are no such animations. | 191 // up. Repeat until there are no such animations. |
| 172 void ProcessQueue(); | 192 void ProcessQueue(); |
| 173 | 193 |
| 174 // Attempts to add the sequence to the list of running animations. Returns | 194 // Attempts to add the sequence to the list of running animations. Returns |
| 175 // false if there is an animation running that already animates one of the | 195 // false if there is an animation running that already animates one of the |
| 176 // properties affected by |sequence|. | 196 // properties affected by |sequence|. |
| 177 bool StartSequenceImmediately(LayerAnimationSequence* sequence); | 197 bool StartSequenceImmediately(LayerAnimationSequence* sequence); |
| 178 | 198 |
| 199 // Sets the value of target as if all the running and queued animations were | |
| 200 // allowed to finish. | |
| 201 void GetTargetValue(LayerAnimationElement::TargetValue* target) const; | |
| 202 | |
| 179 // This is the queue of animations to run. | 203 // This is the queue of animations to run. |
| 180 AnimationQueue animation_queue_; | 204 AnimationQueue animation_queue_; |
| 181 | 205 |
| 182 // The target of all layer animations. | 206 // The target of all layer animations. |
| 183 LayerAnimationDelegate* delegate_; | 207 LayerAnimatorDelegate* delegate_; |
| 184 | 208 |
| 185 // The currently running animations. | 209 // The currently running animations. |
| 186 RunningAnimations running_animations_; | 210 RunningAnimations running_animations_; |
| 187 | 211 |
| 188 // Determines how animations are replaced. | 212 // Determines how animations are replaced. |
| 189 PreemptionStrategy preemption_strategy_; | 213 PreemptionStrategy preemption_strategy_; |
| 190 | 214 |
| 191 // The default length of animations. | 215 // The default length of animations. |
| 192 base::TimeDelta transition_duration_; | 216 base::TimeDelta transition_duration_; |
| 193 | 217 |
| 194 // Used for coordinating the starting of animations. | 218 // Used for coordinating the starting of animations. |
| 195 base::TimeTicks last_step_time_; | 219 base::TimeTicks last_step_time_; |
| 196 | 220 |
| 197 // True if we are being stepped by our container. | 221 // True if we are being stepped by our container. |
| 198 bool is_started_; | 222 bool is_started_; |
| 199 | 223 |
| 200 // This prevents the animator from automatically stepping through animations | 224 // This prevents the animator from automatically stepping through animations |
| 201 // and allows for manual stepping. | 225 // and allows for manual stepping. |
| 202 bool disable_timer_for_test_; | 226 bool disable_timer_for_test_; |
| 203 | 227 |
| 204 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); | 228 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
| 205 }; | 229 }; |
| 206 | 230 |
| 207 } // namespace ui | 231 } // namespace ui |
| 208 | 232 |
| 209 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ | 233 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ |
| OLD | NEW |