Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1390)

Side by Side Diff: ui/gfx/compositor/layer_animator.h

Issue 7972023: Implicit animations through Layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: SetAnimator Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:
29 explicit LayerAnimator(Layer* layer); 33 explicit LayerAnimator(Layer* layer);
30 virtual ~LayerAnimator(); 34 virtual ~LayerAnimator();
31 35
36 void SetAnimation(Animation* animation);
37
32 ui::Layer* layer() { return layer_; } 38 ui::Layer* layer() { return layer_; }
33 39
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 40 // Animates the layer to the specified point. The point is relative to the
39 // parent layer. 41 // parent layer.
40 void AnimateToPoint(const gfx::Point& target); 42 void AnimateToPoint(const gfx::Point& target);
41 void StopAnimatingToPoint() { 43 void StopAnimatingToPoint() {
42 StopAnimating(LOCATION); 44 StopAnimating(LOCATION);
43 } 45 }
44 46
45 // Animates the transform from from the current transform to |transform|. 47 // Animates the transform from from the current transform to |transform|.
46 void AnimateTransform(const Transform& transform); 48 void AnimateTransform(const Transform& transform);
47 void StopAnimatingTransform() { 49 void StopAnimatingTransform() {
48 StopAnimating(TRANSFORM); 50 StopAnimating(TRANSFORM);
49 } 51 }
50 52
53 void AnimateOpacity(float target_opacity);
54 void StopAnimatingOpacity() {
55 StopAnimating(OPACITY);
56 }
57
58 bool IsRunning() const;
59
51 // AnimationDelegate: 60 // AnimationDelegate:
52 virtual void AnimationProgressed(const Animation* animation) OVERRIDE; 61 virtual void AnimationProgressed(const Animation* animation) OVERRIDE;
53 virtual void AnimationEnded(const Animation* animation) OVERRIDE; 62 virtual void AnimationEnded(const Animation* animation) OVERRIDE;
54 63
55 private: 64 private:
56 // Types of properties that can be animated. 65 // Types of properties that can be animated.
57 enum AnimationProperty { 66 enum AnimationProperty {
58 LOCATION, 67 LOCATION,
59 TRANSFORM 68 OPACITY,
69 TRANSFORM,
60 }; 70 };
61 71
62 // Parameters used when animating the location. 72 // Parameters used when animating the location.
63 struct LocationParams { 73 struct LocationParams {
64 int start_x; 74 int start_x;
65 int start_y; 75 int start_y;
66 int target_x; 76 int target_x;
67 int target_y; 77 int target_y;
68 }; 78 };
69 79
70 // Parameters used whe animating the transform. 80 // Parameters used when animating the transform.
71 struct TransformParams { 81 struct TransformParams {
72 // TODO: make 4x4 whe Transform is updated.
73 SkMScalar start[16]; 82 SkMScalar start[16];
74 SkMScalar target[16]; 83 SkMScalar target[16];
75 }; 84 };
76 85
86 // Parameters used when animating the opacity.
87 struct OpacityParams {
88 float start;
89 float target;
90 };
91
77 union Params { 92 union Params {
78 LocationParams location; 93 LocationParams location;
94 OpacityParams opacity;
79 TransformParams transform; 95 TransformParams transform;
80 }; 96 };
81 97
82 // Used for tracking the animation of a particular property. 98 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 99
90 // Stops animating the specified property. This does not set the property 100 // Stops animating the specified property. This does not set the property
91 // being animated to its final value. 101 // being animated to its final value.
92 void StopAnimating(AnimationProperty property); 102 void StopAnimating(AnimationProperty property);
93 103
94 // Creates an animation. 104 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 105
100 // The layer. 106 // The layer.
101 Layer* layer_; 107 Layer* layer_;
102 108
103 // Properties being animated. 109 // Properties being animated.
104 Elements elements_; 110 Elements elements_;
105 111
106 // Duration in ms for newly created animations. 112 scoped_ptr<ui::Animation> animation_;
107 int duration_in_ms_;
108
109 // Type of animation for newly created animations.
110 ui::Tween::Type animation_type_;
111 113
112 DISALLOW_COPY_AND_ASSIGN(LayerAnimator); 114 DISALLOW_COPY_AND_ASSIGN(LayerAnimator);
113 }; 115 };
114 116
115 } // namespace ui 117 } // namespace ui
116 118
117 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_ 119 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698