Index: ui/gfx/compositor/layer_animator.h |
diff --git a/ui/gfx/compositor/layer_animator.h b/ui/gfx/compositor/layer_animator.h |
index 52b8870b66c4ddb43faa696f24652619ac704617..4f2d1e60c027a099ffecdc27c6585a12f85de743 100644 |
--- a/ui/gfx/compositor/layer_animator.h |
+++ b/ui/gfx/compositor/layer_animator.h |
@@ -6,119 +6,159 @@ |
#define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ |
#pragma once |
-#include <map> |
+#include <vector> |
-#include "base/basictypes.h" |
-#include "base/compiler_specific.h" |
#include "base/memory/scoped_ptr.h" |
-#include "third_party/skia/include/core/SkScalar.h" |
-#include "third_party/skia/include/utils/SkMatrix44.h" |
-#include "ui/base/animation/animation_delegate.h" |
+#include "base/memory/scoped_vector.h" |
+#include "base/time.h" |
#include "ui/gfx/compositor/compositor_export.h" |
+#include "ui/gfx/compositor/layer_animation_element.h" |
namespace gfx { |
-class Point; |
+class Rect; |
} |
namespace ui { |
- |
class Animation; |
class Layer; |
-class LayerAnimatorDelegate; |
+class LayerAnimationSequence; |
class Transform; |
-// LayerAnimator manages animating various properties of a Layer. |
-class COMPOSITOR_EXPORT LayerAnimator : public ui::AnimationDelegate { |
+// When a property of layer needs to be changed it is set by way of |
+// LayerAnimator. This enables LayerAnimator to animate property |
+// changes. |
+class COMPOSITOR_EXPORT LayerAnimator { |
public: |
- // Types of properties that can be animated. |
- enum AnimationProperty { |
- LOCATION, |
- OPACITY, |
- TRANSFORM, |
+ // We need to keep track of the start time of every running animation. |
sky
2011/10/19 00:06:33
Make these (and typedefs private).
|
+ struct RunningAnimation { |
+ RunningAnimation(LayerAnimationSequence* sequence, |
+ base::TimeTicks start_time) |
+ : sequence(sequence), |
+ start_time(start_time) { |
+ } |
+ LayerAnimationSequence* sequence; |
+ base::TimeTicks start_time; |
}; |
- explicit LayerAnimator(Layer* layer); |
- virtual ~LayerAnimator(); |
- |
- // Sets the animation to use. LayerAnimator takes ownership of the animation. |
- void SetAnimation(Animation* animation); |
+ typedef std::vector<RunningAnimation> RunningAnimations; |
+ typedef ScopedVector<LayerAnimationSequence> AnimationQueue; |
- ui::Layer* layer() { return layer_; } |
- |
- // Animates the layer to the specified point. The point is relative to the |
- // parent layer. |
- void AnimateToPoint(const gfx::Point& target); |
+ enum PreemptionStrategy { |
+ IMMEDIATELY_SET_NEW_TARGET, |
+ IMMEDIATELY_ANIMATE_TO_NEW_TARGET, |
+ ENQUEUE_NEW_ANIMATION, |
+ REPLACE_QUEUED_ANIMATIONS, |
+ BLEND_WITH_CURRENT_ANIMATION |
+ }; |
- // Animates the transform from the current transform to |transform|. |
- void AnimateTransform(const Transform& transform); |
+ // No implicit animations when properties are set. |
+ static LayerAnimator* CreateDefaultAnimator(); |
- // Animates the opacity from the current opacity to |target_opacity|. |
- void AnimateOpacity(float target_opacity); |
+ // Implicitly animates when properties are set. |
+ static LayerAnimator* CreateImplicitAnimator(); |
- // Returns the target value for the specified type. If the specified property |
- // is not animating, the current value is returned. |
- gfx::Point GetTargetPoint(); |
- float GetTargetOpacity(); |
- ui::Transform GetTargetTransform(); |
+ explicit LayerAnimator(base::TimeDelta transition_duration); |
+ virtual ~LayerAnimator(); |
sky
2011/10/19 00:06:33
constructors before other methods
|
- // Returns true if animating |property|. |
- bool IsAnimating(AnimationProperty property) const; |
+ // Sets the transform on the Layer. |
sky
2011/10/19 15:43:25
Document what these does (the 3 setters). Also, do
|
+ virtual void SetTransform(const Transform& transform); |
- // Returns true if the animation is running. |
- bool IsRunning() const; |
+ // Sets the bounds of the layer. |
+ virtual void SetBounds(const gfx::Rect& bounds); |
- // Returns true if the animation has progressed at least once since |
- // SetAnimation() was invoked. |
- bool got_initial_tick() const { return got_initial_tick_; } |
+ // Sets the opacity of the layer. |
+ virtual void SetOpacity(float opacity); |
- // AnimationDelegate: |
- virtual void AnimationProgressed(const Animation* animation) OVERRIDE; |
- virtual void AnimationEnded(const Animation* animation) OVERRIDE; |
+ // Sets the layer animation delegate the animator is associated with. The |
+ // animator does not own the delegate. |
+ void SetDelegate(LayerAnimationDelegate* delegate); |
- private: |
- // Parameters used when animating the location. |
- struct LocationParams { |
- int start_x; |
- int start_y; |
- int target_x; |
- int target_y; |
- }; |
+ // Sets the animation preemption strategy. This determines the behaviour if |
+ // a property is set during an animation. This class does not own the |
sky
2011/10/19 15:43:25
Remove last sentence and document what the default
|
+ // strategy. |
+ void set_preemption_strategy(PreemptionStrategy strategy) { |
+ preemption_strategy_ = strategy; |
+ } |
- // Parameters used when animating the transform. |
- struct TransformParams { |
- SkMScalar start[16]; |
- SkMScalar target[16]; |
- }; |
+ // Start an animation sequence. If an animation for the same property is in |
+ // progress, it needs to be interrupted with the new animation. The animator |
+ // takes ownership of this animation sequence. |
+ void StartAnimation(LayerAnimationSequence* animation); |
- // Parameters used when animating the opacity. |
- struct OpacityParams { |
- float start; |
- float target; |
- }; |
+ // Schedule an animation to be run when possible. The animator takes ownership |
+ // of this animation sequence. |
+ void ScheduleAnimation(LayerAnimationSequence* animation); |
- union Params { |
- LocationParams location; |
- OpacityParams opacity; |
- TransformParams transform; |
- }; |
+ // Schedules the animations to be run together. Obviously will no work if |
+ // they animate any common properties. The animator takes ownership of the |
+ // animation sequences. |
+ void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); |
- typedef std::map<AnimationProperty, Params> Elements; |
+ // Returns true if there is an animation in the queue (animations remain in |
+ // the queue until they complete). |
+ bool IsAnimating() const; |
- // Stops animating the specified property. This does not set the property |
- // being animated to its final value. |
- void StopAnimating(AnimationProperty property); |
+ // Stops animating the given property. No effect if there is no running |
+ // animation for the given property. Skips to the final state of the |
+ // animation. |
+ void StopAnimatingProperty( |
+ LayerAnimationElement::AnimatableProperty property); |
- LayerAnimatorDelegate* delegate(); |
+ // Stops all animation and clears any queued animations. |
+ void StopAnimating(); |
- // The layer. |
- Layer* layer_; |
+ void Step(base::TimeTicks now); |
sky
2011/10/19 15:43:25
This shouldn't be public.
|
- // Properties being animated. |
- Elements elements_; |
+ // For testing purposes only. |
+ void SetAnimationForTest(Animation* animation); |
+ base::TimeTicks get_last_step_time_for_test() { return last_step_time_; } |
- scoped_ptr<ui::Animation> animation_; |
+ protected: |
+ LayerAnimationDelegate* delegate() { return delegate_; } |
- bool got_initial_tick_; |
+ private: |
+ void UpdateAnimationState(); |
sky
2011/10/19 15:43:25
Add descriptions for these methods.
|
+ void RemoveAnimation(LayerAnimationSequence* sequence); |
+ void FinishAnimation(LayerAnimationSequence* sequence); |
+ void FinishAnyAnimationWithZeroDuration(); |
+ void ClearAnimations(); |
+ RunningAnimation* GetRunningAnimation( |
+ LayerAnimationElement::AnimatableProperty property); |
+ void AddToQueueIfNotPresent(LayerAnimationSequence* sequence); |
+ void RemoveAllAnimationsWithACommonProperty(LayerAnimationSequence* sequence, |
+ bool abort); |
+ void ImmediatelySetNewTarget(LayerAnimationSequence* sequence); |
+ void ImmediatelyAnimateToNewTarget(LayerAnimationSequence* sequence); |
+ void EnqueueNewAnimation(LayerAnimationSequence* sequence); |
+ void ReplaceQueuedAnimations(LayerAnimationSequence* sequence); |
+ |
+ // If there's an animation in the queue that doesn't animate the same property |
+ // as a running animation, or an animation schedule to run before it, start it |
+ // up. Repeat until there are no such animations. |
+ void ProcessQueue(); |
+ |
+ bool StartSequenceImmediately(LayerAnimationSequence* sequence); |
+ |
+ // This is the queue of animations to run |
sky
2011/10/19 15:43:25
end sentences with periods.
|
+ AnimationQueue animation_queue_; |
+ |
+ // The target of all layer animations |
+ LayerAnimationDelegate* delegate_; |
+ |
+ // The currently running animations |
+ RunningAnimations running_animations_; |
+ |
+ // Determines how animations are replaced. |
+ PreemptionStrategy preemption_strategy_; |
+ |
+ // The default length of animations. |
+ base::TimeDelta transition_duration_; |
+ |
+ // Used for coordinating the starting of animations. |
+ base::TimeTicks last_step_time_; |
+ |
+ // Drives the animations |
+ scoped_ptr<Animation> animation_; |
DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
}; |