OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "ui/compositor/layer_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "cc/animation/animation.h" | 8 #include "cc/animation/animation.h" |
9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
10 #include "ui/compositor/float_animation_curve_adapter.h" | 10 #include "ui/compositor/float_animation_curve_adapter.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // The factor by which duration is scaled up or down when | 23 // The factor by which duration is scaled up or down when |
24 // ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or | 24 // ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or |
25 // FAST_DURATION. | 25 // FAST_DURATION. |
26 const int kSlowDurationScaleFactor = 4; | 26 const int kSlowDurationScaleFactor = 4; |
27 const int kFastDurationScaleFactor = 4; | 27 const int kFastDurationScaleFactor = 4; |
28 | 28 |
29 // Pause ----------------------------------------------------------------------- | 29 // Pause ----------------------------------------------------------------------- |
30 class Pause : public LayerAnimationElement { | 30 class Pause : public LayerAnimationElement { |
31 public: | 31 public: |
32 Pause(const AnimatableProperties& properties, base::TimeDelta duration) | 32 Pause(AnimatableProperties properties, base::TimeDelta duration) |
33 : LayerAnimationElement(properties, duration) { | 33 : LayerAnimationElement(properties, duration) { |
34 } | 34 } |
35 virtual ~Pause() {} | 35 virtual ~Pause() {} |
36 | 36 |
37 private: | 37 private: |
38 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} | 38 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} |
39 virtual bool OnProgress(double t, | 39 virtual bool OnProgress(double t, |
40 LayerAnimationDelegate* delegate) OVERRIDE { | 40 LayerAnimationDelegate* delegate) OVERRIDE { |
41 return false; | 41 return false; |
42 } | 42 } |
43 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {} | 43 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {} |
44 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 44 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
45 | 45 |
46 DISALLOW_COPY_AND_ASSIGN(Pause); | 46 DISALLOW_COPY_AND_ASSIGN(Pause); |
47 }; | 47 }; |
48 | 48 |
49 // TransformTransition --------------------------------------------------------- | 49 // TransformTransition --------------------------------------------------------- |
50 | 50 |
51 class TransformTransition : public LayerAnimationElement { | 51 class TransformTransition : public LayerAnimationElement { |
52 public: | 52 public: |
53 TransformTransition(const gfx::Transform& target, base::TimeDelta duration) | 53 TransformTransition(const gfx::Transform& target, base::TimeDelta duration) |
54 : LayerAnimationElement(GetProperties(), duration), | 54 : LayerAnimationElement(TRANSFORM, duration), |
55 target_(target) { | 55 target_(target) { |
56 } | 56 } |
57 virtual ~TransformTransition() {} | 57 virtual ~TransformTransition() {} |
58 | 58 |
59 protected: | 59 protected: |
60 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 60 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
61 start_ = delegate->GetTransformForAnimation(); | 61 start_ = delegate->GetTransformForAnimation(); |
62 } | 62 } |
63 | 63 |
64 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 64 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
65 delegate->SetTransformFromAnimation( | 65 delegate->SetTransformFromAnimation( |
66 gfx::Tween::TransformValueBetween(t, start_, target_)); | 66 gfx::Tween::TransformValueBetween(t, start_, target_)); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 70 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
71 target->transform = target_; | 71 target->transform = target_; |
72 } | 72 } |
73 | 73 |
74 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 74 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
75 | 75 |
76 private: | 76 private: |
77 static AnimatableProperties GetProperties() { | |
78 AnimatableProperties properties; | |
79 properties.insert(LayerAnimationElement::TRANSFORM); | |
80 return properties; | |
81 } | |
82 | |
83 gfx::Transform start_; | 77 gfx::Transform start_; |
84 const gfx::Transform target_; | 78 const gfx::Transform target_; |
85 | 79 |
86 DISALLOW_COPY_AND_ASSIGN(TransformTransition); | 80 DISALLOW_COPY_AND_ASSIGN(TransformTransition); |
87 }; | 81 }; |
88 | 82 |
89 // InterpolatedTransformTransition --------------------------------------------- | 83 // InterpolatedTransformTransition --------------------------------------------- |
90 | 84 |
91 class InterpolatedTransformTransition : public LayerAnimationElement { | 85 class InterpolatedTransformTransition : public LayerAnimationElement { |
92 public: | 86 public: |
93 InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform, | 87 InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform, |
94 base::TimeDelta duration) | 88 base::TimeDelta duration) |
95 : LayerAnimationElement(GetProperties(), duration), | 89 : LayerAnimationElement(TRANSFORM, duration), |
96 interpolated_transform_(interpolated_transform) { | 90 interpolated_transform_(interpolated_transform) { |
97 } | 91 } |
98 virtual ~InterpolatedTransformTransition() {} | 92 virtual ~InterpolatedTransformTransition() {} |
99 | 93 |
100 protected: | 94 protected: |
101 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 95 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
102 } | 96 } |
103 | 97 |
104 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 98 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
105 delegate->SetTransformFromAnimation( | 99 delegate->SetTransformFromAnimation( |
106 interpolated_transform_->Interpolate(static_cast<float>(t))); | 100 interpolated_transform_->Interpolate(static_cast<float>(t))); |
107 return true; | 101 return true; |
108 } | 102 } |
109 | 103 |
110 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 104 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
111 target->transform = interpolated_transform_->Interpolate(1.0f); | 105 target->transform = interpolated_transform_->Interpolate(1.0f); |
112 } | 106 } |
113 | 107 |
114 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 108 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
115 | 109 |
116 private: | 110 private: |
117 static AnimatableProperties GetProperties() { | |
118 AnimatableProperties properties; | |
119 properties.insert(LayerAnimationElement::TRANSFORM); | |
120 return properties; | |
121 } | |
122 | |
123 scoped_ptr<InterpolatedTransform> interpolated_transform_; | 111 scoped_ptr<InterpolatedTransform> interpolated_transform_; |
124 | 112 |
125 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition); | 113 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition); |
126 }; | 114 }; |
127 | 115 |
128 // BoundsTransition ------------------------------------------------------------ | 116 // BoundsTransition ------------------------------------------------------------ |
129 | 117 |
130 class BoundsTransition : public LayerAnimationElement { | 118 class BoundsTransition : public LayerAnimationElement { |
131 public: | 119 public: |
132 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration) | 120 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration) |
133 : LayerAnimationElement(GetProperties(), duration), | 121 : LayerAnimationElement(BOUNDS, duration), |
134 target_(target) { | 122 target_(target) { |
135 } | 123 } |
136 virtual ~BoundsTransition() {} | 124 virtual ~BoundsTransition() {} |
137 | 125 |
138 protected: | 126 protected: |
139 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 127 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
140 start_ = delegate->GetBoundsForAnimation(); | 128 start_ = delegate->GetBoundsForAnimation(); |
141 } | 129 } |
142 | 130 |
143 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 131 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
144 delegate->SetBoundsFromAnimation( | 132 delegate->SetBoundsFromAnimation( |
145 gfx::Tween::RectValueBetween(t, start_, target_)); | 133 gfx::Tween::RectValueBetween(t, start_, target_)); |
146 return true; | 134 return true; |
147 } | 135 } |
148 | 136 |
149 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 137 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
150 target->bounds = target_; | 138 target->bounds = target_; |
151 } | 139 } |
152 | 140 |
153 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 141 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
154 | 142 |
155 private: | 143 private: |
156 static AnimatableProperties GetProperties() { | |
157 AnimatableProperties properties; | |
158 properties.insert(LayerAnimationElement::BOUNDS); | |
159 return properties; | |
160 } | |
161 | |
162 gfx::Rect start_; | 144 gfx::Rect start_; |
163 const gfx::Rect target_; | 145 const gfx::Rect target_; |
164 | 146 |
165 DISALLOW_COPY_AND_ASSIGN(BoundsTransition); | 147 DISALLOW_COPY_AND_ASSIGN(BoundsTransition); |
166 }; | 148 }; |
167 | 149 |
168 // OpacityTransition ----------------------------------------------------------- | 150 // OpacityTransition ----------------------------------------------------------- |
169 | 151 |
170 class OpacityTransition : public LayerAnimationElement { | 152 class OpacityTransition : public LayerAnimationElement { |
171 public: | 153 public: |
172 OpacityTransition(float target, base::TimeDelta duration) | 154 OpacityTransition(float target, base::TimeDelta duration) |
173 : LayerAnimationElement(GetProperties(), duration), | 155 : LayerAnimationElement(OPACITY, duration), |
174 start_(0.0f), | 156 start_(0.0f), |
175 target_(target) { | 157 target_(target) { |
176 } | 158 } |
177 virtual ~OpacityTransition() {} | 159 virtual ~OpacityTransition() {} |
178 | 160 |
179 protected: | 161 protected: |
180 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 162 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
181 start_ = delegate->GetOpacityForAnimation(); | 163 start_ = delegate->GetOpacityForAnimation(); |
182 } | 164 } |
183 | 165 |
184 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 166 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
185 delegate->SetOpacityFromAnimation( | 167 delegate->SetOpacityFromAnimation( |
186 gfx::Tween::FloatValueBetween(t, start_, target_)); | 168 gfx::Tween::FloatValueBetween(t, start_, target_)); |
187 return true; | 169 return true; |
188 } | 170 } |
189 | 171 |
190 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 172 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
191 target->opacity = target_; | 173 target->opacity = target_; |
192 } | 174 } |
193 | 175 |
194 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 176 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
195 | 177 |
196 private: | 178 private: |
197 static AnimatableProperties GetProperties() { | |
198 AnimatableProperties properties; | |
199 properties.insert(LayerAnimationElement::OPACITY); | |
200 return properties; | |
201 } | |
202 | |
203 float start_; | 179 float start_; |
204 const float target_; | 180 const float target_; |
205 | 181 |
206 DISALLOW_COPY_AND_ASSIGN(OpacityTransition); | 182 DISALLOW_COPY_AND_ASSIGN(OpacityTransition); |
207 }; | 183 }; |
208 | 184 |
209 // VisibilityTransition -------------------------------------------------------- | 185 // VisibilityTransition -------------------------------------------------------- |
210 | 186 |
211 class VisibilityTransition : public LayerAnimationElement { | 187 class VisibilityTransition : public LayerAnimationElement { |
212 public: | 188 public: |
213 VisibilityTransition(bool target, base::TimeDelta duration) | 189 VisibilityTransition(bool target, base::TimeDelta duration) |
214 : LayerAnimationElement(GetProperties(), duration), | 190 : LayerAnimationElement(VISIBILITY, duration), |
215 start_(false), | 191 start_(false), |
216 target_(target) { | 192 target_(target) { |
217 } | 193 } |
218 virtual ~VisibilityTransition() {} | 194 virtual ~VisibilityTransition() {} |
219 | 195 |
220 protected: | 196 protected: |
221 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 197 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
222 start_ = delegate->GetVisibilityForAnimation(); | 198 start_ = delegate->GetVisibilityForAnimation(); |
223 } | 199 } |
224 | 200 |
225 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 201 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
226 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_); | 202 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_); |
227 return t == 1.0; | 203 return t == 1.0; |
228 } | 204 } |
229 | 205 |
230 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 206 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
231 target->visibility = target_; | 207 target->visibility = target_; |
232 } | 208 } |
233 | 209 |
234 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 210 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
235 | 211 |
236 private: | 212 private: |
237 static AnimatableProperties GetProperties() { | |
238 AnimatableProperties properties; | |
239 properties.insert(LayerAnimationElement::VISIBILITY); | |
240 return properties; | |
241 } | |
242 | |
243 bool start_; | 213 bool start_; |
244 const bool target_; | 214 const bool target_; |
245 | 215 |
246 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition); | 216 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition); |
247 }; | 217 }; |
248 | 218 |
249 // BrightnessTransition -------------------------------------------------------- | 219 // BrightnessTransition -------------------------------------------------------- |
250 | 220 |
251 class BrightnessTransition : public LayerAnimationElement { | 221 class BrightnessTransition : public LayerAnimationElement { |
252 public: | 222 public: |
253 BrightnessTransition(float target, base::TimeDelta duration) | 223 BrightnessTransition(float target, base::TimeDelta duration) |
254 : LayerAnimationElement(GetProperties(), duration), | 224 : LayerAnimationElement(BRIGHTNESS, duration), |
255 start_(0.0f), | 225 start_(0.0f), |
256 target_(target) { | 226 target_(target) { |
257 } | 227 } |
258 virtual ~BrightnessTransition() {} | 228 virtual ~BrightnessTransition() {} |
259 | 229 |
260 protected: | 230 protected: |
261 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 231 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
262 start_ = delegate->GetBrightnessForAnimation(); | 232 start_ = delegate->GetBrightnessForAnimation(); |
263 } | 233 } |
264 | 234 |
265 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 235 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
266 delegate->SetBrightnessFromAnimation( | 236 delegate->SetBrightnessFromAnimation( |
267 gfx::Tween::FloatValueBetween(t, start_, target_)); | 237 gfx::Tween::FloatValueBetween(t, start_, target_)); |
268 return true; | 238 return true; |
269 } | 239 } |
270 | 240 |
271 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 241 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
272 target->brightness = target_; | 242 target->brightness = target_; |
273 } | 243 } |
274 | 244 |
275 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 245 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
276 | 246 |
277 private: | 247 private: |
278 static AnimatableProperties GetProperties() { | |
279 AnimatableProperties properties; | |
280 properties.insert(LayerAnimationElement::BRIGHTNESS); | |
281 return properties; | |
282 } | |
283 | |
284 float start_; | 248 float start_; |
285 const float target_; | 249 const float target_; |
286 | 250 |
287 DISALLOW_COPY_AND_ASSIGN(BrightnessTransition); | 251 DISALLOW_COPY_AND_ASSIGN(BrightnessTransition); |
288 }; | 252 }; |
289 | 253 |
290 // GrayscaleTransition --------------------------------------------------------- | 254 // GrayscaleTransition --------------------------------------------------------- |
291 | 255 |
292 class GrayscaleTransition : public LayerAnimationElement { | 256 class GrayscaleTransition : public LayerAnimationElement { |
293 public: | 257 public: |
294 GrayscaleTransition(float target, base::TimeDelta duration) | 258 GrayscaleTransition(float target, base::TimeDelta duration) |
295 : LayerAnimationElement(GetProperties(), duration), | 259 : LayerAnimationElement(GRAYSCALE, duration), |
296 start_(0.0f), | 260 start_(0.0f), |
297 target_(target) { | 261 target_(target) { |
298 } | 262 } |
299 virtual ~GrayscaleTransition() {} | 263 virtual ~GrayscaleTransition() {} |
300 | 264 |
301 protected: | 265 protected: |
302 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 266 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
303 start_ = delegate->GetGrayscaleForAnimation(); | 267 start_ = delegate->GetGrayscaleForAnimation(); |
304 } | 268 } |
305 | 269 |
306 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 270 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
307 delegate->SetGrayscaleFromAnimation( | 271 delegate->SetGrayscaleFromAnimation( |
308 gfx::Tween::FloatValueBetween(t, start_, target_)); | 272 gfx::Tween::FloatValueBetween(t, start_, target_)); |
309 return true; | 273 return true; |
310 } | 274 } |
311 | 275 |
312 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 276 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
313 target->grayscale = target_; | 277 target->grayscale = target_; |
314 } | 278 } |
315 | 279 |
316 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 280 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
317 | 281 |
318 private: | 282 private: |
319 static AnimatableProperties GetProperties() { | |
320 AnimatableProperties properties; | |
321 properties.insert(LayerAnimationElement::GRAYSCALE); | |
322 return properties; | |
323 } | |
324 | |
325 float start_; | 283 float start_; |
326 const float target_; | 284 const float target_; |
327 | 285 |
328 DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition); | 286 DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition); |
329 }; | 287 }; |
330 | 288 |
331 // ColorTransition ------------------------------------------------------------- | 289 // ColorTransition ------------------------------------------------------------- |
332 | 290 |
333 class ColorTransition : public LayerAnimationElement { | 291 class ColorTransition : public LayerAnimationElement { |
334 public: | 292 public: |
335 ColorTransition(SkColor target, base::TimeDelta duration) | 293 ColorTransition(SkColor target, base::TimeDelta duration) |
336 : LayerAnimationElement(GetProperties(), duration), | 294 : LayerAnimationElement(COLOR, duration), |
337 start_(SK_ColorBLACK), | 295 start_(SK_ColorBLACK), |
338 target_(target) { | 296 target_(target) { |
339 } | 297 } |
340 virtual ~ColorTransition() {} | 298 virtual ~ColorTransition() {} |
341 | 299 |
342 protected: | 300 protected: |
343 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 301 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
344 start_ = delegate->GetColorForAnimation(); | 302 start_ = delegate->GetColorForAnimation(); |
345 } | 303 } |
346 | 304 |
347 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 305 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
348 delegate->SetColorFromAnimation( | 306 delegate->SetColorFromAnimation( |
349 gfx::Tween::ColorValueBetween(t, start_, target_)); | 307 gfx::Tween::ColorValueBetween(t, start_, target_)); |
350 return true; | 308 return true; |
351 } | 309 } |
352 | 310 |
353 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 311 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
354 target->color = target_; | 312 target->color = target_; |
355 } | 313 } |
356 | 314 |
357 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} | 315 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
358 | 316 |
359 private: | 317 private: |
360 static AnimatableProperties GetProperties() { | |
361 AnimatableProperties properties; | |
362 properties.insert(LayerAnimationElement::COLOR); | |
363 return properties; | |
364 } | |
365 | |
366 SkColor start_; | 318 SkColor start_; |
367 const SkColor target_; | 319 const SkColor target_; |
368 | 320 |
369 DISALLOW_COPY_AND_ASSIGN(ColorTransition); | 321 DISALLOW_COPY_AND_ASSIGN(ColorTransition); |
370 }; | 322 }; |
371 | 323 |
372 // ThreadedLayerAnimationElement ----------------------------------------------- | 324 // ThreadedLayerAnimationElement ----------------------------------------------- |
373 | 325 |
374 class ThreadedLayerAnimationElement : public LayerAnimationElement { | 326 class ThreadedLayerAnimationElement : public LayerAnimationElement { |
375 public: | 327 public: |
376 ThreadedLayerAnimationElement(const AnimatableProperties& properties, | 328 ThreadedLayerAnimationElement(AnimatableProperties properties, |
377 base::TimeDelta duration) | 329 base::TimeDelta duration) |
378 : LayerAnimationElement(properties, duration) { | 330 : LayerAnimationElement(properties, duration) { |
379 } | 331 } |
380 virtual ~ThreadedLayerAnimationElement() {} | 332 virtual ~ThreadedLayerAnimationElement() {} |
381 | 333 |
382 virtual bool IsThreaded() const OVERRIDE { | 334 virtual bool IsThreaded() const OVERRIDE { |
383 return (duration() != base::TimeDelta()); | 335 return (duration() != base::TimeDelta()); |
384 } | 336 } |
385 | 337 |
386 protected: | 338 protected: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 378 |
427 private: | 379 private: |
428 DISALLOW_COPY_AND_ASSIGN(ThreadedLayerAnimationElement); | 380 DISALLOW_COPY_AND_ASSIGN(ThreadedLayerAnimationElement); |
429 }; | 381 }; |
430 | 382 |
431 // ThreadedOpacityTransition --------------------------------------------------- | 383 // ThreadedOpacityTransition --------------------------------------------------- |
432 | 384 |
433 class ThreadedOpacityTransition : public ThreadedLayerAnimationElement { | 385 class ThreadedOpacityTransition : public ThreadedLayerAnimationElement { |
434 public: | 386 public: |
435 ThreadedOpacityTransition(float target, base::TimeDelta duration) | 387 ThreadedOpacityTransition(float target, base::TimeDelta duration) |
436 : ThreadedLayerAnimationElement(GetProperties(), duration), | 388 : ThreadedLayerAnimationElement(OPACITY, duration), |
437 start_(0.0f), | 389 start_(0.0f), |
438 target_(target) { | 390 target_(target) { |
439 } | 391 } |
440 virtual ~ThreadedOpacityTransition() {} | 392 virtual ~ThreadedOpacityTransition() {} |
441 | 393 |
442 protected: | 394 protected: |
443 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 395 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
444 start_ = delegate->GetOpacityForAnimation(); | 396 start_ = delegate->GetOpacityForAnimation(); |
445 } | 397 } |
446 | 398 |
(...skipping 23 matching lines...) Expand all Loading... |
470 animation_group_id(), | 422 animation_group_id(), |
471 cc::Animation::Opacity)); | 423 cc::Animation::Opacity)); |
472 return animation.Pass(); | 424 return animation.Pass(); |
473 } | 425 } |
474 | 426 |
475 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 427 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
476 target->opacity = target_; | 428 target->opacity = target_; |
477 } | 429 } |
478 | 430 |
479 private: | 431 private: |
480 static AnimatableProperties GetProperties() { | |
481 AnimatableProperties properties; | |
482 properties.insert(LayerAnimationElement::OPACITY); | |
483 return properties; | |
484 } | |
485 | |
486 float start_; | 432 float start_; |
487 const float target_; | 433 const float target_; |
488 | 434 |
489 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); | 435 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); |
490 }; | 436 }; |
491 | 437 |
492 // ThreadedTransformTransition ------------------------------------------------- | 438 // ThreadedTransformTransition ------------------------------------------------- |
493 | 439 |
494 class ThreadedTransformTransition : public ThreadedLayerAnimationElement { | 440 class ThreadedTransformTransition : public ThreadedLayerAnimationElement { |
495 public: | 441 public: |
496 ThreadedTransformTransition(const gfx::Transform& target, | 442 ThreadedTransformTransition(const gfx::Transform& target, |
497 base::TimeDelta duration) | 443 base::TimeDelta duration) |
498 : ThreadedLayerAnimationElement(GetProperties(), duration), | 444 : ThreadedLayerAnimationElement(TRANSFORM, duration), |
499 target_(target) { | 445 target_(target) { |
500 } | 446 } |
501 virtual ~ThreadedTransformTransition() {} | 447 virtual ~ThreadedTransformTransition() {} |
502 | 448 |
503 protected: | 449 protected: |
504 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 450 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
505 start_ = delegate->GetTransformForAnimation(); | 451 start_ = delegate->GetTransformForAnimation(); |
506 float device_scale_factor = delegate->GetDeviceScaleFactor(); | 452 float device_scale_factor = delegate->GetDeviceScaleFactor(); |
507 cc_start_ = Layer::ConvertTransformToCCTransform(start_, | 453 cc_start_ = Layer::ConvertTransformToCCTransform(start_, |
508 device_scale_factor); | 454 device_scale_factor); |
(...skipping 27 matching lines...) Expand all Loading... |
536 animation_group_id(), | 482 animation_group_id(), |
537 cc::Animation::Transform)); | 483 cc::Animation::Transform)); |
538 return animation.Pass(); | 484 return animation.Pass(); |
539 } | 485 } |
540 | 486 |
541 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 487 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
542 target->transform = target_; | 488 target->transform = target_; |
543 } | 489 } |
544 | 490 |
545 private: | 491 private: |
546 static AnimatableProperties GetProperties() { | |
547 AnimatableProperties properties; | |
548 properties.insert(LayerAnimationElement::TRANSFORM); | |
549 return properties; | |
550 } | |
551 | |
552 gfx::Transform start_; | 492 gfx::Transform start_; |
553 gfx::Transform cc_start_; | 493 gfx::Transform cc_start_; |
554 const gfx::Transform target_; | 494 const gfx::Transform target_; |
555 gfx::Transform cc_target_; | 495 gfx::Transform cc_target_; |
556 | 496 |
557 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); | 497 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition); |
558 }; | 498 }; |
559 | 499 |
560 // InverseTransformTransision -------------------------------------------------- | 500 // InverseTransformTransision -------------------------------------------------- |
561 | 501 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 gfx::Transform ComputeWithBaseTransform(gfx::Transform start, | 585 gfx::Transform ComputeWithBaseTransform(gfx::Transform start, |
646 gfx::Transform target) const { | 586 gfx::Transform target) const { |
647 gfx::Transform to_return(gfx::Transform::kSkipInitialization); | 587 gfx::Transform to_return(gfx::Transform::kSkipInitialization); |
648 bool success = target.GetInverse(&to_return); | 588 bool success = target.GetInverse(&to_return); |
649 DCHECK(success) << "Target transform must be invertible."; | 589 DCHECK(success) << "Target transform must be invertible."; |
650 | 590 |
651 to_return.PreconcatTransform(start); | 591 to_return.PreconcatTransform(start); |
652 return to_return; | 592 return to_return; |
653 } | 593 } |
654 | 594 |
655 static AnimatableProperties GetProperties() { | |
656 AnimatableProperties properties; | |
657 properties.insert(LayerAnimationElement::TRANSFORM); | |
658 return properties; | |
659 } | |
660 | |
661 template <typename T> | 595 template <typename T> |
662 static T CheckAndCast(const LayerAnimationElement* element) { | 596 static T CheckAndCast(const LayerAnimationElement* element) { |
663 const AnimatableProperties& properties = element->properties(); | 597 AnimatableProperties properties = element->properties(); |
664 DCHECK(properties.find(TRANSFORM) != properties.end()); | 598 DCHECK(properties & TRANSFORM); |
665 return static_cast<T>(element); | 599 return static_cast<T>(element); |
666 } | 600 } |
667 | 601 |
668 gfx::Transform effective_start_; | 602 gfx::Transform effective_start_; |
669 gfx::Transform computed_target_transform_; | 603 gfx::Transform computed_target_transform_; |
670 | 604 |
671 const gfx::Transform base_transform_; | 605 const gfx::Transform base_transform_; |
672 gfx::Transform base_target_; | 606 gfx::Transform base_target_; |
673 | 607 |
674 scoped_ptr<cc::AnimationCurve> animation_curve_; | 608 scoped_ptr<cc::AnimationCurve> animation_curve_; |
(...skipping 23 matching lines...) Expand all Loading... |
698 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f), | 632 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f), |
699 visibility(delegate ? delegate->GetVisibilityForAnimation() : false), | 633 visibility(delegate ? delegate->GetVisibilityForAnimation() : false), |
700 brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f), | 634 brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f), |
701 grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f), | 635 grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f), |
702 color(delegate ? delegate->GetColorForAnimation() : 0.0f) { | 636 color(delegate ? delegate->GetColorForAnimation() : 0.0f) { |
703 } | 637 } |
704 | 638 |
705 // LayerAnimationElement ------------------------------------------------------- | 639 // LayerAnimationElement ------------------------------------------------------- |
706 | 640 |
707 LayerAnimationElement::LayerAnimationElement( | 641 LayerAnimationElement::LayerAnimationElement( |
708 const AnimatableProperties& properties, | 642 AnimatableProperties properties, base::TimeDelta duration) |
709 base::TimeDelta duration) | |
710 : first_frame_(true), | 643 : first_frame_(true), |
711 properties_(properties), | 644 properties_(properties), |
712 duration_(GetEffectiveDuration(duration)), | 645 duration_(GetEffectiveDuration(duration)), |
713 tween_type_(gfx::Tween::LINEAR), | 646 tween_type_(gfx::Tween::LINEAR), |
714 animation_id_(cc::AnimationIdProvider::NextAnimationId()), | 647 animation_id_(cc::AnimationIdProvider::NextAnimationId()), |
715 animation_group_id_(0), | 648 animation_group_id_(0), |
716 last_progressed_fraction_(0.0), | 649 last_progressed_fraction_(0.0), |
717 weak_ptr_factory_(this) { | 650 weak_ptr_factory_(this) { |
718 } | 651 } |
719 | 652 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 | 846 |
914 // static | 847 // static |
915 LayerAnimationElement* LayerAnimationElement::CreateGrayscaleElement( | 848 LayerAnimationElement* LayerAnimationElement::CreateGrayscaleElement( |
916 float grayscale, | 849 float grayscale, |
917 base::TimeDelta duration) { | 850 base::TimeDelta duration) { |
918 return new GrayscaleTransition(grayscale, duration); | 851 return new GrayscaleTransition(grayscale, duration); |
919 } | 852 } |
920 | 853 |
921 // static | 854 // static |
922 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( | 855 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( |
923 const AnimatableProperties& properties, | 856 AnimatableProperties properties, |
924 base::TimeDelta duration) { | 857 base::TimeDelta duration) { |
925 return new Pause(properties, duration); | 858 return new Pause(properties, duration); |
926 } | 859 } |
927 | 860 |
928 // static | 861 // static |
929 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 862 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
930 SkColor color, | 863 SkColor color, |
931 base::TimeDelta duration) { | 864 base::TimeDelta duration) { |
932 return new ColorTransition(color, duration); | 865 return new ColorTransition(color, duration); |
933 } | 866 } |
934 | 867 |
935 } // namespace ui | 868 } // namespace ui |
OLD | NEW |