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..63981638ed64ad5691b2938a12e22db39c7ebc1f 100644 |
--- a/ui/gfx/compositor/layer_animator.h |
+++ b/ui/gfx/compositor/layer_animator.h |
@@ -6,119 +6,126 @@ |
#define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ |
#pragma once |
-#include <map> |
+#include <deque> |
+#include <vector> |
-#include "base/basictypes.h" |
-#include "base/compiler_specific.h" |
+#include "base/memory/ref_counted.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/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 LayerAnimationPreemptionStrategy; |
+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. |
+ struct RunningAnimation { |
+ RunningAnimation(LayerAnimationSequence* sequence, |
+ base::TimeTicks start_time) |
+ : sequence(sequence), |
+ start_time(start_time) { |
+ } |
+ LayerAnimationSequence* sequence; |
+ base::TimeTicks start_time; |
}; |
+ typedef std::vector<RunningAnimation> RunningAnimations; |
+ typedef std::deque<scoped_refptr<LayerAnimationSequence> > AnimationQueue; |
- explicit LayerAnimator(Layer* layer); |
- virtual ~LayerAnimator(); |
+ // No implicit animations when properties are set. |
+ static LayerAnimator* CreateDefaultAnimator(); |
- // Sets the animation to use. LayerAnimator takes ownership of the animation. |
- void SetAnimation(Animation* animation); |
+ // Implicitly animates when properties are set. |
+ static LayerAnimator* CreateImplicitAnimator(); |
- ui::Layer* layer() { return layer_; } |
+ explicit LayerAnimator(base::TimeDelta transition_duration); |
+ virtual ~LayerAnimator(); |
- // Animates the layer to the specified point. The point is relative to the |
- // parent layer. |
- void AnimateToPoint(const gfx::Point& target); |
+ // Sets the transform on the Layer. |
+ virtual void SetTransform(const Transform& transform); |
- // Animates the transform from the current transform to |transform|. |
- void AnimateTransform(const Transform& transform); |
+ // Sets the bounds of the layer. |
+ virtual void SetBounds(const gfx::Rect& bounds); |
- // Animates the opacity from the current opacity to |target_opacity|. |
- void AnimateOpacity(float target_opacity); |
+ // Sets the opacity of the layer. |
+ virtual void SetOpacity(float opacity); |
- // 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(); |
+ // Sets the layer the property setter is associated with. The property setter |
+ // does not own the layer and can only be associated with a single layer. |
+ void SetLayer(Layer* layer); |
- // Returns true if animating |property|. |
- bool IsAnimating(AnimationProperty property) const; |
+ // Sets the animation preemption strategy. This determines the behaviour if |
+ // a property is set during an animation. This class does not own the |
+ // strategy. |
+ void set_preemption_strategy(LayerAnimationPreemptionStrategy* strategy) { |
+ preemption_strategy_ = strategy; |
+ } |
- // Returns true if the animation is running. |
- bool IsRunning() const; |
+ // Set an animation sequence. If an animation for the same property is in |
+ // progress, it needs to be interrupted with the new animation. |
+ void SetAnimation(LayerAnimationSequence* animation); |
sky
2011/10/14 16:39:52
The name 'Set' implies you can only have one. How
|
- // Returns true if the animation has progressed at least once since |
- // SetAnimation() was invoked. |
- bool got_initial_tick() const { return got_initial_tick_; } |
+ // Enqueue an animation |
+ void EnqueueAnimation(LayerAnimationSequence* animation); |
sky
2011/10/14 16:39:52
How about Add.
|
- // AnimationDelegate: |
- virtual void AnimationProgressed(const Animation* animation) OVERRIDE; |
- virtual void AnimationEnded(const Animation* animation) OVERRIDE; |
+ // Returns true if there is an animation in the queue (animations remain in |
+ // the queue until they complete). |
+ bool IsAnimating() const; |
- private: |
- // Parameters used when animating the location. |
- struct LocationParams { |
- int start_x; |
- int start_y; |
- int target_x; |
- int target_y; |
- }; |
+ // Stops animating the given property. No effect if there is no running |
+ // animation for the given property. |
+ void StopAnimatingProperty( |
+ LayerAnimationElement::AnimatableProperty property); |
- // Parameters used when animating the transform. |
- struct TransformParams { |
- SkMScalar start[16]; |
- SkMScalar target[16]; |
- }; |
+ // Stops all animation and clears any queued animations. |
+ void StopAnimating(); |
- // Parameters used when animating the opacity. |
- struct OpacityParams { |
- float start; |
- float target; |
- }; |
+ void Step(base::TimeTicks now); |
- union Params { |
- LocationParams location; |
- OpacityParams opacity; |
- TransformParams transform; |
- }; |
- |
- typedef std::map<AnimationProperty, Params> Elements; |
- |
- // Stops animating the specified property. This does not set the property |
- // being animated to its final value. |
- void StopAnimating(AnimationProperty property); |
+ protected: |
+ Layer* layer() { return layer_; } |
- LayerAnimatorDelegate* delegate(); |
- |
- // The layer. |
+ private: |
+ void UpdateAnimationState(); |
+ void RemoveAnimation(LayerAnimationSequence* sequence); |
+ void FinishAnimation(LayerAnimationSequence* sequence); |
+ void FinishAnyAnimationWithZeroDuration(); |
+ void ClearAnimations(); |
+ RunningAnimation* GetRunningAnimation( |
+ LayerAnimationElement::AnimatableProperty property); |
+ void AddToQueueIfNotPresent(LayerAnimationSequence* sequence); |
+ void ProcessQueue(); |
+ bool StartSequence(LayerAnimationSequence* sequence); |
+ |
+ // This is the queue of animations to run |
+ AnimationQueue animation_queue_; |
+ |
+ // The target of all layer animations |
Layer* layer_; |
- // Properties being animated. |
- Elements elements_; |
+ // The currently running animations |
+ RunningAnimations running_animations_; |
+ |
+ // Determines how animations are replaced. |
+ LayerAnimationPreemptionStrategy* preemption_strategy_; |
- scoped_ptr<ui::Animation> animation_; |
+ // The default length of animations. |
+ base::TimeDelta transition_duration_; |
- bool got_initial_tick_; |
+ // Drives the animations |
+ scoped_ptr<Animation> animation_; |
DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
}; |