OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | |
6 #define UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | |
7 #pragma once | |
8 | |
9 #include <set> | |
10 | |
11 #include "base/time.h" | |
12 #include "ui/base/animation/tween.h" | |
13 #include "ui/gfx/compositor/compositor_export.h" | |
14 #include "ui/gfx/rect.h" | |
15 #include "ui/gfx/transform.h" | |
16 | |
17 namespace ui { | |
18 | |
19 class InterpolatedTransform; | |
20 class LayerAnimationDelegate; | |
21 class Transform; | |
22 | |
23 // LayerAnimationElements represent one segment of an animation between two | |
24 // keyframes. They know how to update a LayerAnimationDelegate given a value | |
25 // between 0 and 1 (0 for initial, and 1 for final). | |
26 class COMPOSITOR_EXPORT LayerAnimationElement { | |
27 public: | |
28 enum AnimatableProperty { | |
29 TRANSFORM = 0, | |
30 BOUNDS, | |
31 OPACITY, | |
32 VISIBILITY | |
33 }; | |
34 | |
35 struct COMPOSITOR_EXPORT TargetValue { | |
36 TargetValue(); | |
37 // Initializes the target value to match the delegate. NULL may be supplied. | |
38 explicit TargetValue(const LayerAnimationDelegate* delegate); | |
39 | |
40 gfx::Rect bounds; | |
41 Transform transform; | |
42 float opacity; | |
43 bool visibility; | |
44 }; | |
45 | |
46 typedef std::set<AnimatableProperty> AnimatableProperties; | |
47 | |
48 LayerAnimationElement(const AnimatableProperties& properties, | |
49 base::TimeDelta duration); | |
50 virtual ~LayerAnimationElement(); | |
51 | |
52 // Creates an element that transitions to the given transform. The caller owns | |
53 // the return value. | |
54 static LayerAnimationElement* CreateTransformElement( | |
55 const Transform& transform, | |
56 base::TimeDelta duration); | |
57 | |
58 // Creates an element that transitions to another in a way determined by an | |
59 // interpolated transform. The element accepts ownership of the interpolated | |
60 // transform. NB: at every step, the interpolated transform clobbers the | |
61 // existing transform. That is, it does not interpolate between the existing | |
62 // transform and the last value the interpolated transform will assume. It is | |
63 // therefore important that the value of the interpolated at time 0 matches | |
64 // the current transform. | |
65 static LayerAnimationElement* CreateInterpolatedTransformElement( | |
66 InterpolatedTransform* interpolated_transform, | |
67 base::TimeDelta duration); | |
68 | |
69 // Creates an element that transitions to the given bounds. The caller owns | |
70 // the return value. | |
71 static LayerAnimationElement* CreateBoundsElement( | |
72 const gfx::Rect& bounds, | |
73 base::TimeDelta duration); | |
74 | |
75 // Creates an element that transitions to the given opacity. The caller owns | |
76 // the return value. | |
77 static LayerAnimationElement* CreateOpacityElement( | |
78 float opacity, | |
79 base::TimeDelta duration); | |
80 | |
81 // Creates an element that sets visibily following a delay. The caller owns | |
82 // the return value. | |
83 static LayerAnimationElement* CreateVisibilityElement( | |
84 bool visibility, | |
85 base::TimeDelta duration); | |
86 | |
87 // Creates an element that pauses the given properties. The caller owns the | |
88 // return value. | |
89 static LayerAnimationElement* CreatePauseElement( | |
90 const AnimatableProperties& properties, | |
91 base::TimeDelta duration); | |
92 | |
93 // Updates the delegate to the appropriate value for |t|, which is in the | |
94 // range [0, 1] (0 for initial, and 1 for final). If the animation is not | |
95 // aborted, it is guaranteed that Progress will eventually be called with | |
96 // t = 1.0. Returns true if a redraw is required. | |
97 bool Progress(double t, LayerAnimationDelegate* delegate); | |
98 | |
99 // Called if the animation is not allowed to complete. This may be called | |
100 // before OnStarted or Progress. | |
101 void Abort(); | |
102 | |
103 // Assigns the target value to |target|. | |
104 void GetTargetValue(TargetValue* target) const; | |
105 | |
106 // The properties that the element modifies. | |
107 const AnimatableProperties& properties() const { return properties_; } | |
108 | |
109 // The duration of the animation | |
110 base::TimeDelta duration() const { return duration_; } | |
111 | |
112 Tween::Type tween_type() const { return tween_type_; } | |
113 void set_tween_type(Tween::Type tween_type) { tween_type_ = tween_type;} | |
114 | |
115 protected: | |
116 // Called once each time the animation element is run before any call to | |
117 // OnProgress. | |
118 virtual void OnStart(LayerAnimationDelegate* delegate) = 0; | |
119 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0; | |
120 virtual void OnGetTarget(TargetValue* target) const = 0; | |
121 virtual void OnAbort() = 0; | |
122 | |
123 private: | |
124 bool first_frame_; | |
125 const AnimatableProperties properties_; | |
126 const base::TimeDelta duration_; | |
127 Tween::Type tween_type_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(LayerAnimationElement); | |
130 }; | |
131 | |
132 } // namespace ui | |
133 | |
134 #endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_ | |
OLD | NEW |