| 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 <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "third_party/skia/include/core/SkScalar.h" | 14 #include "third_party/skia/include/core/SkScalar.h" |
| 14 #include "third_party/skia/include/utils/SkMatrix44.h" | 15 #include "third_party/skia/include/utils/SkMatrix44.h" |
| 15 #include "ui/base/animation/animation_delegate.h" | 16 #include "ui/base/animation/animation_delegate.h" |
| 16 #include "ui/base/animation/tween.h" | |
| 17 #include "ui/gfx/compositor/compositor_export.h" | 17 #include "ui/gfx/compositor/compositor_export.h" |
| 18 #include "ui/gfx/point.h" | 18 |
| 19 namespace gfx { |
| 20 class Point; |
| 21 } |
| 19 | 22 |
| 20 namespace ui { | 23 namespace ui { |
| 21 | 24 |
| 25 class Animation; |
| 22 class Layer; | 26 class Layer; |
| 23 class MultiAnimation; | 27 class LayerAnimatorDelegate; |
| 24 class Transform; | 28 class Transform; |
| 25 | 29 |
| 26 // LayerAnimator manages animating various properties of a Layer. | 30 // LayerAnimator manages animating various properties of a Layer. |
| 27 class COMPOSITOR_EXPORT LayerAnimator : public ui::AnimationDelegate { | 31 class COMPOSITOR_EXPORT LayerAnimator : public ui::AnimationDelegate { |
| 28 public: | 32 public: |
| 33 // Types of properties that can be animated. |
| 34 enum AnimationProperty { |
| 35 LOCATION, |
| 36 OPACITY, |
| 37 TRANSFORM, |
| 38 }; |
| 39 |
| 29 explicit LayerAnimator(Layer* layer); | 40 explicit LayerAnimator(Layer* layer); |
| 30 virtual ~LayerAnimator(); | 41 virtual ~LayerAnimator(); |
| 31 | 42 |
| 43 // Sets the animation to use. LayerAnimator takes ownership of the animation. |
| 44 void SetAnimation(Animation* animation); |
| 45 |
| 32 ui::Layer* layer() { return layer_; } | 46 ui::Layer* layer() { return layer_; } |
| 33 | 47 |
| 34 // Sets the duration (in ms) and type of animation. This does not effect | |
| 35 // existing animations, only newly created animations. | |
| 36 void SetAnimationDurationAndType(int duration, ui::Tween::Type tween_type); | |
| 37 | |
| 38 // Animates the layer to the specified point. The point is relative to the | 48 // Animates the layer to the specified point. The point is relative to the |
| 39 // parent layer. | 49 // parent layer. |
| 40 void AnimateToPoint(const gfx::Point& target); | 50 void AnimateToPoint(const gfx::Point& target); |
| 41 void StopAnimatingToPoint() { | |
| 42 StopAnimating(LOCATION); | |
| 43 } | |
| 44 | 51 |
| 45 // Animates the transform from from the current transform to |transform|. | 52 // Animates the transform from the current transform to |transform|. |
| 46 void AnimateTransform(const Transform& transform); | 53 void AnimateTransform(const Transform& transform); |
| 47 void StopAnimatingTransform() { | 54 |
| 48 StopAnimating(TRANSFORM); | 55 // Animates the opacity from the current opacity to |target_opacity|. |
| 49 } | 56 void AnimateOpacity(float target_opacity); |
| 57 |
| 58 // Returns the target value for the specified type. If the specified property |
| 59 // is not animating, the current value is returned. |
| 60 gfx::Point GetTargetPoint(); |
| 61 float GetTargetOpacity(); |
| 62 ui::Transform GetTargetTransform(); |
| 63 |
| 64 // Returns true if animating |property|. |
| 65 bool IsAnimating(AnimationProperty property) const; |
| 66 |
| 67 // Returns true if the animation is running. |
| 68 bool IsRunning() const; |
| 69 |
| 70 // Returns true if the animation has progressed at least once since |
| 71 // SetAnimation() was invoked. |
| 72 bool got_initial_tick() const { return got_initial_tick_; } |
| 50 | 73 |
| 51 // AnimationDelegate: | 74 // AnimationDelegate: |
| 52 virtual void AnimationProgressed(const Animation* animation) OVERRIDE; | 75 virtual void AnimationProgressed(const Animation* animation) OVERRIDE; |
| 53 virtual void AnimationEnded(const Animation* animation) OVERRIDE; | 76 virtual void AnimationEnded(const Animation* animation) OVERRIDE; |
| 54 | 77 |
| 55 private: | 78 private: |
| 56 // Types of properties that can be animated. | |
| 57 enum AnimationProperty { | |
| 58 LOCATION, | |
| 59 TRANSFORM | |
| 60 }; | |
| 61 | |
| 62 // Parameters used when animating the location. | 79 // Parameters used when animating the location. |
| 63 struct LocationParams { | 80 struct LocationParams { |
| 64 int start_x; | 81 int start_x; |
| 65 int start_y; | 82 int start_y; |
| 66 int target_x; | 83 int target_x; |
| 67 int target_y; | 84 int target_y; |
| 68 }; | 85 }; |
| 69 | 86 |
| 70 // Parameters used whe animating the transform. | 87 // Parameters used when animating the transform. |
| 71 struct TransformParams { | 88 struct TransformParams { |
| 72 // TODO: make 4x4 whe Transform is updated. | |
| 73 SkMScalar start[16]; | 89 SkMScalar start[16]; |
| 74 SkMScalar target[16]; | 90 SkMScalar target[16]; |
| 75 }; | 91 }; |
| 76 | 92 |
| 93 // Parameters used when animating the opacity. |
| 94 struct OpacityParams { |
| 95 float start; |
| 96 float target; |
| 97 }; |
| 98 |
| 77 union Params { | 99 union Params { |
| 78 LocationParams location; | 100 LocationParams location; |
| 101 OpacityParams opacity; |
| 79 TransformParams transform; | 102 TransformParams transform; |
| 80 }; | 103 }; |
| 81 | 104 |
| 82 // Used for tracking the animation of a particular property. | 105 typedef std::map<AnimationProperty, Params> Elements; |
| 83 struct Element { | |
| 84 Params params; | |
| 85 ui::MultiAnimation* animation; | |
| 86 }; | |
| 87 | |
| 88 typedef std::map<AnimationProperty, Element> Elements; | |
| 89 | 106 |
| 90 // Stops animating the specified property. This does not set the property | 107 // Stops animating the specified property. This does not set the property |
| 91 // being animated to its final value. | 108 // being animated to its final value. |
| 92 void StopAnimating(AnimationProperty property); | 109 void StopAnimating(AnimationProperty property); |
| 93 | 110 |
| 94 // Creates an animation. | 111 LayerAnimatorDelegate* delegate(); |
| 95 ui::MultiAnimation* CreateAndStartAnimation(); | |
| 96 | |
| 97 // Returns an iterator into |elements_| that matches the specified animation. | |
| 98 Elements::iterator GetElementByAnimation(const ui::MultiAnimation* animation); | |
| 99 | 112 |
| 100 // The layer. | 113 // The layer. |
| 101 Layer* layer_; | 114 Layer* layer_; |
| 102 | 115 |
| 103 // Properties being animated. | 116 // Properties being animated. |
| 104 Elements elements_; | 117 Elements elements_; |
| 105 | 118 |
| 106 // Duration in ms for newly created animations. | 119 scoped_ptr<ui::Animation> animation_; |
| 107 int duration_in_ms_; | |
| 108 | 120 |
| 109 // Type of animation for newly created animations. | 121 bool got_initial_tick_; |
| 110 ui::Tween::Type animation_type_; | |
| 111 | 122 |
| 112 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); | 123 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); |
| 113 }; | 124 }; |
| 114 | 125 |
| 115 } // namespace ui | 126 } // namespace ui |
| 116 | 127 |
| 117 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ | 128 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ |
| OLD | NEW |