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

Side by Side Diff: ui/gfx/compositor/layer_animation_element.cc

Issue 10365007: ui: Move compositor/ directory out of gfx/, up to ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix DEPS Created 8 years, 7 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
(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 #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/compositor/layer_animator.h"
11 #include "ui/gfx/interpolated_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 bool OnProgress(double t,
28 LayerAnimationDelegate* delegate) OVERRIDE {
29 return false;
30 }
31 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {}
32 virtual void OnAbort() OVERRIDE {}
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 bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
53 delegate->SetTransformFromAnimation(
54 Tween::ValueBetween(t, start_, target_));
55 return true;
56 }
57
58 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
59 target->transform = target_;
60 }
61
62 virtual void OnAbort() OVERRIDE {}
63
64 private:
65 static AnimatableProperties GetProperties() {
66 AnimatableProperties properties;
67 properties.insert(LayerAnimationElement::TRANSFORM);
68 return properties;
69 }
70
71 Transform start_;
72 const Transform target_;
73
74 DISALLOW_COPY_AND_ASSIGN(TransformTransition);
75 };
76
77 // InterpolatedTransformTransition ---------------------------------------------
78
79 class InterpolatedTransformTransition : public LayerAnimationElement {
80 public:
81 InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform,
82 base::TimeDelta duration)
83 : LayerAnimationElement(GetProperties(), duration),
84 interpolated_transform_(interpolated_transform) {
85 }
86 virtual ~InterpolatedTransformTransition() {}
87
88 protected:
89 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
90 }
91
92 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
93 delegate->SetTransformFromAnimation(
94 interpolated_transform_->Interpolate(static_cast<float>(t)));
95 return true;
96 }
97
98 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
99 target->transform = interpolated_transform_->Interpolate(1.0f);
100 }
101
102 virtual void OnAbort() OVERRIDE {}
103
104 private:
105 static AnimatableProperties GetProperties() {
106 AnimatableProperties properties;
107 properties.insert(LayerAnimationElement::TRANSFORM);
108 return properties;
109 }
110
111 scoped_ptr<InterpolatedTransform> interpolated_transform_;
112
113 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition);
114 };
115
116 // BoundsTransition ------------------------------------------------------------
117
118 class BoundsTransition : public LayerAnimationElement {
119 public:
120 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration)
121 : LayerAnimationElement(GetProperties(), duration),
122 target_(target) {
123 }
124 virtual ~BoundsTransition() {}
125
126 protected:
127 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
128 start_ = delegate->GetBoundsForAnimation();
129 }
130
131 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
132 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_));
133 return true;
134 }
135
136 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
137 target->bounds = target_;
138 }
139
140 virtual void OnAbort() OVERRIDE {}
141
142 private:
143 static AnimatableProperties GetProperties() {
144 AnimatableProperties properties;
145 properties.insert(LayerAnimationElement::BOUNDS);
146 return properties;
147 }
148
149 gfx::Rect start_;
150 const gfx::Rect target_;
151
152 DISALLOW_COPY_AND_ASSIGN(BoundsTransition);
153 };
154
155 // OpacityTransition -----------------------------------------------------------
156
157 class OpacityTransition : public LayerAnimationElement {
158 public:
159 OpacityTransition(float target, base::TimeDelta duration)
160 : LayerAnimationElement(GetProperties(), duration),
161 start_(0.0f),
162 target_(target) {
163 }
164 virtual ~OpacityTransition() {}
165
166 protected:
167 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
168 start_ = delegate->GetOpacityForAnimation();
169 }
170
171 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
172 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_));
173 return true;
174 }
175
176 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
177 target->opacity = target_;
178 }
179
180 virtual void OnAbort() OVERRIDE {}
181
182 private:
183 static AnimatableProperties GetProperties() {
184 AnimatableProperties properties;
185 properties.insert(LayerAnimationElement::OPACITY);
186 return properties;
187 }
188
189 float start_;
190 const float target_;
191
192 DISALLOW_COPY_AND_ASSIGN(OpacityTransition);
193 };
194
195 // VisibilityTransition --------------------------------------------------------
196
197 class VisibilityTransition : public LayerAnimationElement {
198 public:
199 VisibilityTransition(bool target, base::TimeDelta duration)
200 : LayerAnimationElement(GetProperties(), duration),
201 start_(false),
202 target_(target) {
203 }
204 virtual ~VisibilityTransition() {}
205
206 protected:
207 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
208 start_ = delegate->GetVisibilityForAnimation();
209 }
210
211 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
212 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_);
213 return t == 1.0;
214 }
215
216 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
217 target->visibility = target_;
218 }
219
220 virtual void OnAbort() OVERRIDE {}
221
222 private:
223 static AnimatableProperties GetProperties() {
224 AnimatableProperties properties;
225 properties.insert(LayerAnimationElement::VISIBILITY);
226 return properties;
227 }
228
229 bool start_;
230 const bool target_;
231
232 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition);
233 };
234
235 } // namespace
236
237 // LayerAnimationElement::TargetValue ------------------------------------------
238
239 LayerAnimationElement::TargetValue::TargetValue()
240 : opacity(0.0f),
241 visibility(false) {
242 }
243
244 LayerAnimationElement::TargetValue::TargetValue(
245 const LayerAnimationDelegate* delegate)
246 : bounds(delegate ? delegate->GetBoundsForAnimation() : gfx::Rect()),
247 transform(delegate ? delegate->GetTransformForAnimation() : Transform()),
248 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f),
249 visibility(delegate ? delegate->GetVisibilityForAnimation() : false) {
250 }
251
252 // LayerAnimationElement -------------------------------------------------------
253
254 LayerAnimationElement::LayerAnimationElement(
255 const AnimatableProperties& properties,
256 base::TimeDelta duration)
257 : first_frame_(true),
258 properties_(properties),
259 duration_(LayerAnimator::disable_animations_for_test()
260 ? base::TimeDelta() : duration),
261 tween_type_(Tween::LINEAR) {
262 }
263
264 LayerAnimationElement::~LayerAnimationElement() {
265 }
266
267 bool LayerAnimationElement::Progress(double t,
268 LayerAnimationDelegate* delegate) {
269 if (first_frame_)
270 OnStart(delegate);
271 bool need_draw = OnProgress(Tween::CalculateValue(tween_type_, t), delegate);
272 first_frame_ = t == 1.0;
273 return need_draw;
274 }
275
276 void LayerAnimationElement::GetTargetValue(TargetValue* target) const {
277 OnGetTarget(target);
278 }
279
280 void LayerAnimationElement::Abort() {
281 first_frame_ = true;
282 OnAbort();
283 }
284
285 // static
286 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
287 const Transform& transform, base::TimeDelta duration) {
288 return new TransformTransition(transform, duration);
289 }
290
291 // static
292 LayerAnimationElement*
293 LayerAnimationElement::CreateInterpolatedTransformElement(
294 InterpolatedTransform* interpolated_transform, base::TimeDelta duration) {
295 return new InterpolatedTransformTransition(interpolated_transform, duration);
296 }
297
298 // static
299 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement(
300 const gfx::Rect& bounds, base::TimeDelta duration) {
301 return new BoundsTransition(bounds, duration);
302 }
303
304 // static
305 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement(
306 float opacity, base::TimeDelta duration) {
307 return new OpacityTransition(opacity, duration);
308 }
309
310 // static
311 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement(
312 bool visibility, base::TimeDelta duration) {
313 return new VisibilityTransition(visibility, duration);
314 }
315
316 // static
317 LayerAnimationElement* LayerAnimationElement::CreatePauseElement(
318 const AnimatableProperties& properties, base::TimeDelta duration) {
319 return new Pause(properties, duration);
320 }
321
322 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_animation_element.h ('k') | ui/gfx/compositor/layer_animation_element_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698