OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/gfx/compositor/layer_animation_element.h" | |
6 | |
7 #include "base/compiler_specific.h" | |
8 #include "ui/base/animation/tween.h" | |
9 #include "ui/gfx/compositor/layer_animation_delegate.h" | |
10 #include "ui/gfx/rect.h" | |
11 #include "ui/gfx/transform.h" | |
12 | |
13 namespace ui { | |
14 | |
15 namespace { | |
16 | |
17 // Pause ----------------------------------------------------------------------- | |
18 class Pause : public LayerAnimationElement { | |
19 public: | |
20 Pause(const AnimatableProperties& properties, base::TimeDelta duration) | |
21 : LayerAnimationElement(properties, duration) { | |
22 } | |
23 virtual ~Pause() {} | |
24 | |
25 private: | |
26 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} | |
27 virtual void OnProgress(double t, | |
28 LayerAnimationDelegate* delegate) OVERRIDE {} | |
29 virtual void OnAbort() OVERRIDE {} | |
30 | |
31 AnimatableProperties properties_; | |
sky
2011/10/20 16:33:03
Remove these.
| |
32 base::TimeDelta duration_; | |
33 | |
34 DISALLOW_COPY_AND_ASSIGN(Pause); | |
35 }; | |
36 | |
37 // TransformTransition --------------------------------------------------------- | |
38 | |
39 class TransformTransition : public LayerAnimationElement { | |
40 public: | |
41 TransformTransition(const Transform& target, base::TimeDelta duration) | |
42 : LayerAnimationElement(GetProperties(), duration), | |
43 target_(target) { | |
44 } | |
45 virtual ~TransformTransition() {} | |
46 | |
47 protected: | |
48 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | |
49 start_ = delegate->GetTransformForAnimation(); | |
50 } | |
51 | |
52 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | |
53 delegate->SetTransformFromAnimation( | |
54 Tween::ValueBetween(t, start_, target_)); | |
55 } | |
56 | |
57 virtual void OnAbort() OVERRIDE {} | |
58 | |
59 private: | |
60 static const AnimatableProperties& GetProperties() { | |
61 static AnimatableProperties properties; | |
62 if (properties.size() == 0) | |
63 properties.insert(LayerAnimationElement::TRANSFORM); | |
64 return properties; | |
65 } | |
66 | |
67 Transform start_; | |
68 Transform target_; | |
sky
2011/10/20 16:33:03
const
| |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(TransformTransition); | |
71 }; | |
72 | |
73 // BoundsTransition ------------------------------------------------------------ | |
74 | |
75 class BoundsTransition : public LayerAnimationElement { | |
76 public: | |
77 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration) | |
78 : LayerAnimationElement(GetProperties(), duration), | |
79 target_(target) { | |
80 } | |
81 virtual ~BoundsTransition() {} | |
82 | |
83 protected: | |
84 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | |
85 start_ = delegate->GetBoundsForAnimation(); | |
86 } | |
87 | |
88 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | |
89 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); | |
90 } | |
91 | |
92 virtual void OnAbort() OVERRIDE {} | |
93 | |
94 private: | |
95 static const AnimatableProperties& GetProperties() { | |
96 static AnimatableProperties properties; | |
97 if (properties.size() == 0) | |
98 properties.insert(LayerAnimationElement::BOUNDS); | |
99 return properties; | |
100 } | |
101 | |
102 gfx::Rect start_; | |
103 gfx::Rect target_; | |
sky
2011/10/20 16:33:03
const
| |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(BoundsTransition); | |
106 }; | |
107 | |
108 class OpacityTransition : public LayerAnimationElement { | |
109 public: | |
110 OpacityTransition(float target, base::TimeDelta duration) | |
111 : LayerAnimationElement(GetProperties(), duration), | |
112 target_(target) { | |
113 } | |
114 virtual ~OpacityTransition() {} | |
115 | |
116 protected: | |
117 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | |
118 start_ = delegate->GetOpacityForAnimation(); | |
119 } | |
120 | |
121 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | |
122 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); | |
123 } | |
124 | |
125 virtual void OnAbort() OVERRIDE {} | |
126 | |
127 private: | |
128 static const AnimatableProperties& GetProperties() { | |
129 static AnimatableProperties properties; | |
130 if (properties.size() == 0) | |
131 properties.insert(LayerAnimationElement::OPACITY); | |
132 return properties; | |
133 } | |
134 | |
135 float start_; | |
136 float target_; | |
sky
2011/10/20 16:33:03
const
| |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(OpacityTransition); | |
139 }; | |
140 | |
141 } // namespace | |
142 | |
143 // LayerAnimationElement ------------------------------------------------------- | |
144 | |
145 LayerAnimationElement::LayerAnimationElement( | |
146 const AnimatableProperties& properties, | |
147 base::TimeDelta duration) | |
148 : first_frame_(true), | |
149 properties_(properties), | |
150 duration_(duration) { | |
151 } | |
152 | |
153 LayerAnimationElement::~LayerAnimationElement() { | |
154 } | |
155 | |
156 void LayerAnimationElement::Progress(double t, | |
157 LayerAnimationDelegate* delegate) { | |
158 if (first_frame_) | |
159 OnStart(delegate); | |
160 OnProgress(t, delegate); | |
161 first_frame_ = t == 1.0; | |
162 } | |
163 | |
164 void LayerAnimationElement::Abort() { | |
165 first_frame_ = true; | |
166 OnAbort(); | |
167 } | |
168 | |
169 // static | |
170 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( | |
171 const Transform& transform, base::TimeDelta duration) { | |
172 return new TransformTransition(transform, duration); | |
173 } | |
174 | |
175 // static | |
176 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( | |
177 const gfx::Rect& bounds, base::TimeDelta duration) { | |
178 return new BoundsTransition(bounds, duration); | |
179 } | |
180 | |
181 // static | |
182 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( | |
183 float opacity, base::TimeDelta duration) { | |
184 return new OpacityTransition(opacity, duration); | |
185 } | |
186 | |
187 // static | |
188 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( | |
189 const AnimatableProperties& properties, base::TimeDelta duration) { | |
190 return new Pause(properties, duration); | |
191 } | |
192 | |
193 } // namespace ui | |
OLD | NEW |