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.h" | |
9 #include "cc/animation_id_provider.h" | |
8 #include "ui/base/animation/tween.h" | 10 #include "ui/base/animation/tween.h" |
11 #include "ui/compositor/float_animation_curve_adapter.h" | |
9 #include "ui/compositor/layer_animation_delegate.h" | 12 #include "ui/compositor/layer_animation_delegate.h" |
10 #include "ui/compositor/layer_animator.h" | 13 #include "ui/compositor/layer_animator.h" |
11 #include "ui/gfx/interpolated_transform.h" | 14 #include "ui/gfx/interpolated_transform.h" |
12 | 15 |
13 namespace ui { | 16 namespace ui { |
14 | 17 |
15 namespace { | 18 namespace { |
16 | 19 |
17 // Pause ----------------------------------------------------------------------- | 20 // Pause ----------------------------------------------------------------------- |
18 class Pause : public LayerAnimationElement { | 21 class Pause : public LayerAnimationElement { |
19 public: | 22 public: |
20 Pause(const AnimatableProperties& properties, base::TimeDelta duration) | 23 Pause(const AnimatableProperties& properties, base::TimeDelta duration) |
21 : LayerAnimationElement(properties, duration) { | 24 : LayerAnimationElement(properties, duration) { |
22 } | 25 } |
23 virtual ~Pause() {} | 26 virtual ~Pause() {} |
24 | 27 |
25 private: | 28 private: |
26 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} | 29 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} |
27 virtual bool OnProgress(double t, | 30 virtual bool OnProgress(double t, |
28 LayerAnimationDelegate* delegate) OVERRIDE { | 31 LayerAnimationDelegate* delegate) OVERRIDE { |
29 return false; | 32 return false; |
30 } | 33 } |
31 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {} | 34 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {} |
32 virtual void OnAbort() OVERRIDE {} | 35 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
33 | 36 |
34 DISALLOW_COPY_AND_ASSIGN(Pause); | 37 DISALLOW_COPY_AND_ASSIGN(Pause); |
35 }; | 38 }; |
36 | 39 |
37 // TransformTransition --------------------------------------------------------- | 40 // TransformTransition --------------------------------------------------------- |
38 | 41 |
39 class TransformTransition : public LayerAnimationElement { | 42 class TransformTransition : public LayerAnimationElement { |
40 public: | 43 public: |
41 TransformTransition(const gfx::Transform& target, base::TimeDelta duration) | 44 TransformTransition(const gfx::Transform& target, base::TimeDelta duration) |
42 : LayerAnimationElement(GetProperties(), duration), | 45 : LayerAnimationElement(GetProperties(), duration), |
43 target_(target) { | 46 target_(target) { |
44 } | 47 } |
45 virtual ~TransformTransition() {} | 48 virtual ~TransformTransition() {} |
46 | 49 |
47 protected: | 50 protected: |
48 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | 51 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
49 start_ = delegate->GetTransformForAnimation(); | 52 start_ = delegate->GetTransformForAnimation(); |
50 } | 53 } |
51 | 54 |
52 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 55 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
53 delegate->SetTransformFromAnimation( | 56 delegate->SetTransformFromAnimation( |
54 Tween::ValueBetween(t, start_, target_)); | 57 Tween::ValueBetween(t, start_, target_)); |
55 return true; | 58 return true; |
56 } | 59 } |
57 | 60 |
58 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 61 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
59 target->transform = target_; | 62 target->transform = target_; |
60 } | 63 } |
61 | 64 |
62 virtual void OnAbort() OVERRIDE {} | 65 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
63 | 66 |
64 private: | 67 private: |
65 static AnimatableProperties GetProperties() { | 68 static AnimatableProperties GetProperties() { |
66 AnimatableProperties properties; | 69 AnimatableProperties properties; |
67 properties.insert(LayerAnimationElement::TRANSFORM); | 70 properties.insert(LayerAnimationElement::TRANSFORM); |
68 return properties; | 71 return properties; |
69 } | 72 } |
70 | 73 |
71 gfx::Transform start_; | 74 gfx::Transform start_; |
72 const gfx::Transform target_; | 75 const gfx::Transform target_; |
(...skipping 19 matching lines...) Expand all Loading... | |
92 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 95 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
93 delegate->SetTransformFromAnimation( | 96 delegate->SetTransformFromAnimation( |
94 interpolated_transform_->Interpolate(static_cast<float>(t))); | 97 interpolated_transform_->Interpolate(static_cast<float>(t))); |
95 return true; | 98 return true; |
96 } | 99 } |
97 | 100 |
98 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 101 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
99 target->transform = interpolated_transform_->Interpolate(1.0f); | 102 target->transform = interpolated_transform_->Interpolate(1.0f); |
100 } | 103 } |
101 | 104 |
102 virtual void OnAbort() OVERRIDE {} | 105 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
103 | 106 |
104 private: | 107 private: |
105 static AnimatableProperties GetProperties() { | 108 static AnimatableProperties GetProperties() { |
106 AnimatableProperties properties; | 109 AnimatableProperties properties; |
107 properties.insert(LayerAnimationElement::TRANSFORM); | 110 properties.insert(LayerAnimationElement::TRANSFORM); |
108 return properties; | 111 return properties; |
109 } | 112 } |
110 | 113 |
111 scoped_ptr<InterpolatedTransform> interpolated_transform_; | 114 scoped_ptr<InterpolatedTransform> interpolated_transform_; |
112 | 115 |
(...skipping 17 matching lines...) Expand all Loading... | |
130 | 133 |
131 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 134 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
132 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); | 135 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); |
133 return true; | 136 return true; |
134 } | 137 } |
135 | 138 |
136 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 139 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
137 target->bounds = target_; | 140 target->bounds = target_; |
138 } | 141 } |
139 | 142 |
140 virtual void OnAbort() OVERRIDE {} | 143 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
141 | 144 |
142 private: | 145 private: |
143 static AnimatableProperties GetProperties() { | 146 static AnimatableProperties GetProperties() { |
144 AnimatableProperties properties; | 147 AnimatableProperties properties; |
145 properties.insert(LayerAnimationElement::BOUNDS); | 148 properties.insert(LayerAnimationElement::BOUNDS); |
146 return properties; | 149 return properties; |
147 } | 150 } |
148 | 151 |
149 gfx::Rect start_; | 152 gfx::Rect start_; |
150 const gfx::Rect target_; | 153 const gfx::Rect target_; |
(...skipping 19 matching lines...) Expand all Loading... | |
170 | 173 |
171 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 174 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
172 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); | 175 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); |
173 return true; | 176 return true; |
174 } | 177 } |
175 | 178 |
176 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 179 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
177 target->opacity = target_; | 180 target->opacity = target_; |
178 } | 181 } |
179 | 182 |
180 virtual void OnAbort() OVERRIDE {} | 183 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
181 | 184 |
182 private: | 185 private: |
183 static AnimatableProperties GetProperties() { | 186 static AnimatableProperties GetProperties() { |
184 AnimatableProperties properties; | 187 AnimatableProperties properties; |
185 properties.insert(LayerAnimationElement::OPACITY); | 188 properties.insert(LayerAnimationElement::OPACITY); |
186 return properties; | 189 return properties; |
187 } | 190 } |
188 | 191 |
189 float start_; | 192 float start_; |
190 const float target_; | 193 const float target_; |
(...skipping 19 matching lines...) Expand all Loading... | |
210 | 213 |
211 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 214 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
212 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_); | 215 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_); |
213 return t == 1.0; | 216 return t == 1.0; |
214 } | 217 } |
215 | 218 |
216 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 219 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
217 target->visibility = target_; | 220 target->visibility = target_; |
218 } | 221 } |
219 | 222 |
220 virtual void OnAbort() OVERRIDE {} | 223 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
221 | 224 |
222 private: | 225 private: |
223 static AnimatableProperties GetProperties() { | 226 static AnimatableProperties GetProperties() { |
224 AnimatableProperties properties; | 227 AnimatableProperties properties; |
225 properties.insert(LayerAnimationElement::VISIBILITY); | 228 properties.insert(LayerAnimationElement::VISIBILITY); |
226 return properties; | 229 return properties; |
227 } | 230 } |
228 | 231 |
229 bool start_; | 232 bool start_; |
230 const bool target_; | 233 const bool target_; |
(...skipping 20 matching lines...) Expand all Loading... | |
251 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 254 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
252 delegate->SetBrightnessFromAnimation( | 255 delegate->SetBrightnessFromAnimation( |
253 Tween::ValueBetween(t, start_, target_)); | 256 Tween::ValueBetween(t, start_, target_)); |
254 return true; | 257 return true; |
255 } | 258 } |
256 | 259 |
257 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 260 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
258 target->brightness = target_; | 261 target->brightness = target_; |
259 } | 262 } |
260 | 263 |
261 virtual void OnAbort() OVERRIDE {} | 264 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
262 | 265 |
263 private: | 266 private: |
264 static AnimatableProperties GetProperties() { | 267 static AnimatableProperties GetProperties() { |
265 AnimatableProperties properties; | 268 AnimatableProperties properties; |
266 properties.insert(LayerAnimationElement::BRIGHTNESS); | 269 properties.insert(LayerAnimationElement::BRIGHTNESS); |
267 return properties; | 270 return properties; |
268 } | 271 } |
269 | 272 |
270 float start_; | 273 float start_; |
271 const float target_; | 274 const float target_; |
(...skipping 20 matching lines...) Expand all Loading... | |
292 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | 295 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
293 delegate->SetGrayscaleFromAnimation( | 296 delegate->SetGrayscaleFromAnimation( |
294 Tween::ValueBetween(t, start_, target_)); | 297 Tween::ValueBetween(t, start_, target_)); |
295 return true; | 298 return true; |
296 } | 299 } |
297 | 300 |
298 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 301 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
299 target->grayscale = target_; | 302 target->grayscale = target_; |
300 } | 303 } |
301 | 304 |
302 virtual void OnAbort() OVERRIDE {} | 305 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
303 | 306 |
304 private: | 307 private: |
305 static AnimatableProperties GetProperties() { | 308 static AnimatableProperties GetProperties() { |
306 AnimatableProperties properties; | 309 AnimatableProperties properties; |
307 properties.insert(LayerAnimationElement::GRAYSCALE); | 310 properties.insert(LayerAnimationElement::GRAYSCALE); |
308 return properties; | 311 return properties; |
309 } | 312 } |
310 | 313 |
311 float start_; | 314 float start_; |
312 const float target_; | 315 const float target_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 Tween::ValueBetween(t, | 348 Tween::ValueBetween(t, |
346 static_cast<int>(SkColorGetB(start_)), | 349 static_cast<int>(SkColorGetB(start_)), |
347 static_cast<int>(SkColorGetB(target_))))); | 350 static_cast<int>(SkColorGetB(target_))))); |
348 return true; | 351 return true; |
349 } | 352 } |
350 | 353 |
351 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | 354 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
352 target->color = target_; | 355 target->color = target_; |
353 } | 356 } |
354 | 357 |
355 virtual void OnAbort() OVERRIDE {} | 358 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {} |
356 | 359 |
357 private: | 360 private: |
358 static AnimatableProperties GetProperties() { | 361 static AnimatableProperties GetProperties() { |
359 AnimatableProperties properties; | 362 AnimatableProperties properties; |
360 properties.insert(LayerAnimationElement::COLOR); | 363 properties.insert(LayerAnimationElement::COLOR); |
361 return properties; | 364 return properties; |
362 } | 365 } |
363 | 366 |
364 SkColor start_; | 367 SkColor start_; |
365 const SkColor target_; | 368 const SkColor target_; |
366 | 369 |
367 DISALLOW_COPY_AND_ASSIGN(ColorTransition); | 370 DISALLOW_COPY_AND_ASSIGN(ColorTransition); |
368 }; | 371 }; |
369 | 372 |
373 // ThreadedLayerAnimationElement ----------------------------------------------- | |
374 | |
375 class ThreadedLayerAnimationElement : public LayerAnimationElement { | |
376 public: | |
377 ThreadedLayerAnimationElement(const AnimatableProperties& properties, | |
378 base::TimeDelta duration) | |
379 : LayerAnimationElement(properties, duration) { | |
380 } | |
381 virtual ~ThreadedLayerAnimationElement() {} | |
382 | |
383 bool IsThreaded() const { | |
384 return (duration() != base::TimeDelta()); | |
385 } | |
386 | |
387 protected: | |
388 virtual bool OnProgress(double t, | |
389 LayerAnimationDelegate* delegate) OVERRIDE { | |
390 if (t < 1.0) | |
391 return false; | |
392 | |
393 if (animation_id()) { | |
394 delegate->RemoveThreadedAnimation(animation_id()); | |
395 set_animation_id(0); | |
396 } | |
397 | |
398 OnEnd(delegate); | |
399 return true; | |
400 } | |
401 | |
402 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { | |
403 if (delegate && animation_id()) | |
404 delegate->RemoveThreadedAnimation(animation_id()); | |
405 } | |
406 | |
407 virtual void RequestEffectiveStart( | |
408 LayerAnimationDelegate* delegate) OVERRIDE { | |
409 DCHECK(animation_group_id()); | |
410 set_animation_id(cc::AnimationIdProvider::NextAnimationId()); | |
411 set_effective_start_time(base::TimeTicks()); | |
412 scoped_ptr<cc::Animation> animation = CreateCCAnimation(); | |
413 animation->setNeedsSynchronizedStartTime(true); | |
414 delegate->AddThreadedAnimation(animation.Pass()); | |
415 } | |
416 | |
417 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0; | |
418 | |
419 virtual scoped_ptr<cc::Animation> CreateCCAnimation() = 0; | |
420 | |
421 private: | |
422 | |
423 DISALLOW_COPY_AND_ASSIGN(ThreadedLayerAnimationElement); | |
424 }; | |
425 | |
426 // ThreadedOpacityTransition --------------------------------------------------- | |
427 | |
428 class ThreadedOpacityTransition : public ThreadedLayerAnimationElement { | |
429 public: | |
430 ThreadedOpacityTransition(float target, base::TimeDelta duration) | |
431 : ThreadedLayerAnimationElement(GetProperties(), duration), | |
432 start_(0.0f), | |
433 target_(target) { | |
434 } | |
435 virtual ~ThreadedOpacityTransition() {} | |
436 | |
437 protected: | |
438 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | |
439 start_ = delegate->GetOpacityForAnimation(); | |
440 } | |
441 | |
442 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { | |
443 delegate->SetOpacityFromAnimation(target_); | |
444 } | |
445 | |
446 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { | |
447 scoped_ptr<cc::AnimationCurve> animation_curve( | |
448 new FloatAnimationCurveAdapter(tween_type(), | |
449 start_, | |
450 target_, | |
451 duration())); | |
452 scoped_ptr<cc::Animation> animation( | |
453 cc::Animation::create(animation_curve.Pass(), | |
454 animation_id(), | |
455 animation_group_id(), | |
456 cc::Animation::Opacity)); | |
457 return animation.Pass(); | |
458 } | |
459 | |
460 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | |
461 target->opacity = target_; | |
462 } | |
463 | |
464 private: | |
465 static AnimatableProperties GetProperties() { | |
466 AnimatableProperties properties; | |
467 properties.insert(LayerAnimationElement::OPACITY); | |
468 return properties; | |
469 } | |
470 | |
471 float start_; | |
472 const float target_; | |
473 | |
474 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); | |
475 }; | |
476 | |
370 } // namespace | 477 } // namespace |
371 | 478 |
372 // LayerAnimationElement::TargetValue ------------------------------------------ | 479 // LayerAnimationElement::TargetValue ------------------------------------------ |
373 | 480 |
374 LayerAnimationElement::TargetValue::TargetValue() | 481 LayerAnimationElement::TargetValue::TargetValue() |
375 : opacity(0.0f), | 482 : opacity(0.0f), |
376 visibility(false), | 483 visibility(false), |
377 brightness(0.0f), | 484 brightness(0.0f), |
378 grayscale(0.0f), | 485 grayscale(0.0f), |
379 color(SK_ColorBLACK) { | 486 color(SK_ColorBLACK) { |
(...skipping 12 matching lines...) Expand all Loading... | |
392 } | 499 } |
393 | 500 |
394 // LayerAnimationElement ------------------------------------------------------- | 501 // LayerAnimationElement ------------------------------------------------------- |
395 | 502 |
396 LayerAnimationElement::LayerAnimationElement( | 503 LayerAnimationElement::LayerAnimationElement( |
397 const AnimatableProperties& properties, | 504 const AnimatableProperties& properties, |
398 base::TimeDelta duration) | 505 base::TimeDelta duration) |
399 : first_frame_(true), | 506 : first_frame_(true), |
400 properties_(properties), | 507 properties_(properties), |
401 duration_(GetEffectiveDuration(duration)), | 508 duration_(GetEffectiveDuration(duration)), |
402 tween_type_(Tween::LINEAR) { | 509 tween_type_(Tween::LINEAR), |
510 animation_id_(0), | |
511 animation_group_id_(0) { | |
403 } | 512 } |
404 | 513 |
405 LayerAnimationElement::~LayerAnimationElement() { | 514 LayerAnimationElement::~LayerAnimationElement() { |
406 } | 515 } |
407 | 516 |
517 void LayerAnimationElement::ProgressToEffectiveStart( | |
518 LayerAnimationDelegate* delegate) { | |
519 DCHECK(first_frame_); | |
520 if (!IsThreaded()) | |
521 return; | |
522 | |
523 OnStart(delegate); | |
524 RequestEffectiveStart(delegate); | |
525 first_frame_ = false; | |
526 } | |
527 | |
408 bool LayerAnimationElement::Progress(base::TimeTicks now, | 528 bool LayerAnimationElement::Progress(base::TimeTicks now, |
409 LayerAnimationDelegate* delegate) { | 529 LayerAnimationDelegate* delegate) { |
410 DCHECK(start_time_ != base::TimeTicks()); | 530 DCHECK(requested_start_time_ != base::TimeTicks()); |
411 base::TimeDelta elapsed = now - start_time_; | |
412 if (first_frame_) | 531 if (first_frame_) |
413 OnStart(delegate); | 532 OnStart(delegate); |
533 | |
534 bool need_draw; | |
414 double t = 1.0; | 535 double t = 1.0; |
536 | |
537 if (first_frame_ && (now - requested_start_time_ >= duration_)) { | |
538 // This can be finished immediately, without waiting for an effective start. | |
539 need_draw = OnProgress(Tween::CalculateValue(tween_type_, t), delegate); | |
Ian Vollick
2013/01/25 15:11:47
I think you can just call OnProgress(t, delegate)
ajuma
2013/01/29 18:31:23
Done.
| |
540 return need_draw; | |
541 } | |
542 | |
543 if (first_frame_) { | |
544 RequestEffectiveStart(delegate); | |
Ian Vollick
2013/01/25 15:11:47
Just double checking -- it's not possible to call
ajuma
2013/01/29 18:31:23
Right, calling Progress before ProgressToEffective
| |
545 first_frame_ = false; | |
546 } | |
547 | |
548 if (effective_start_time_ == base::TimeTicks()) { | |
549 // This hasn't actually started yet. | |
550 need_draw = false; | |
551 return need_draw; | |
552 } | |
553 | |
554 base::TimeDelta elapsed = now - effective_start_time_; | |
415 if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) | 555 if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) |
416 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); | 556 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); |
417 bool need_draw = OnProgress(Tween::CalculateValue(tween_type_, t), delegate); | 557 need_draw = OnProgress(Tween::CalculateValue(tween_type_, t), delegate); |
418 first_frame_ = t == 1.0; | 558 first_frame_ = t == 1.0; |
419 return need_draw; | 559 return need_draw; |
420 } | 560 } |
421 | 561 |
422 bool LayerAnimationElement::IsFinished(base::TimeTicks time, | 562 bool LayerAnimationElement::IsFinished(base::TimeTicks time, |
423 base::TimeDelta* total_duration) { | 563 base::TimeDelta* total_duration) { |
424 base::TimeDelta elapsed = time - start_time_; | 564 // If an effective start has been requested but the effective start time |
425 if (elapsed >= duration_) { | 565 // hasn't yet been set, the animation is not finished, regardless of the |
426 *total_duration = duration_; | 566 // value of |time|. |
567 if (!first_frame_ && (effective_start_time_ == base::TimeTicks())) | |
568 return false; | |
569 | |
570 base::TimeDelta queueing_delay; | |
571 if (!first_frame_) | |
572 queueing_delay = effective_start_time_ - requested_start_time_; | |
573 | |
574 base::TimeDelta elapsed = time - requested_start_time_; | |
575 if (elapsed >= duration_ + queueing_delay) { | |
576 *total_duration = duration_ + queueing_delay; | |
427 return true; | 577 return true; |
428 } | 578 } |
429 return false; | 579 return false; |
430 } | 580 } |
431 | 581 |
432 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) { | 582 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) { |
433 if (first_frame_) | 583 if (first_frame_) |
434 OnStart(delegate); | 584 OnStart(delegate); |
435 bool need_draw = OnProgress(1.0, delegate); | 585 bool need_draw = OnProgress(1.0, delegate); |
436 first_frame_ = true; | 586 first_frame_ = true; |
437 return need_draw; | 587 return need_draw; |
438 } | 588 } |
439 | 589 |
440 void LayerAnimationElement::GetTargetValue(TargetValue* target) const { | 590 void LayerAnimationElement::GetTargetValue(TargetValue* target) const { |
441 OnGetTarget(target); | 591 OnGetTarget(target); |
442 } | 592 } |
443 | 593 |
444 void LayerAnimationElement::Abort() { | 594 bool LayerAnimationElement::IsThreaded() const { |
595 return false; | |
596 } | |
597 | |
598 void LayerAnimationElement::Abort(LayerAnimationDelegate* delegate) { | |
445 first_frame_ = true; | 599 first_frame_ = true; |
446 OnAbort(); | 600 OnAbort(delegate); |
601 } | |
602 | |
603 void LayerAnimationElement::RequestEffectiveStart( | |
604 LayerAnimationDelegate* delegate) { | |
605 DCHECK(requested_start_time_ != base::TimeTicks()); | |
606 effective_start_time_ = requested_start_time_; | |
447 } | 607 } |
448 | 608 |
449 // static | 609 // static |
610 LayerAnimationElement::AnimatableProperty | |
611 LayerAnimationElement::ToAnimatableProperty( | |
612 cc::Animation::TargetProperty property) { | |
613 switch (property) { | |
614 case cc::Animation::Transform: | |
615 return TRANSFORM; | |
616 case cc::Animation::Opacity: | |
617 return OPACITY; | |
618 default: | |
619 NOTREACHED(); | |
620 return AnimatableProperty(); | |
621 } | |
622 } | |
623 | |
624 // static | |
450 base::TimeDelta LayerAnimationElement::GetEffectiveDuration( | 625 base::TimeDelta LayerAnimationElement::GetEffectiveDuration( |
451 const base::TimeDelta& duration) { | 626 const base::TimeDelta& duration) { |
452 if (LayerAnimator::disable_animations_for_test()) | 627 if (LayerAnimator::disable_animations_for_test()) |
453 return base::TimeDelta(); | 628 return base::TimeDelta(); |
454 | 629 |
455 if (LayerAnimator::slow_animation_mode()) | 630 if (LayerAnimator::slow_animation_mode()) |
456 return duration * LayerAnimator::slow_animation_scale_factor(); | 631 return duration * LayerAnimator::slow_animation_scale_factor(); |
457 | 632 |
458 return duration; | 633 return duration; |
459 } | 634 } |
(...skipping 17 matching lines...) Expand all Loading... | |
477 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( | 652 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( |
478 const gfx::Rect& bounds, | 653 const gfx::Rect& bounds, |
479 base::TimeDelta duration) { | 654 base::TimeDelta duration) { |
480 return new BoundsTransition(bounds, duration); | 655 return new BoundsTransition(bounds, duration); |
481 } | 656 } |
482 | 657 |
483 // static | 658 // static |
484 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( | 659 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( |
485 float opacity, | 660 float opacity, |
486 base::TimeDelta duration) { | 661 base::TimeDelta duration) { |
487 return new OpacityTransition(opacity, duration); | 662 return new ThreadedOpacityTransition(opacity, duration); |
488 } | 663 } |
489 | 664 |
490 // static | 665 // static |
491 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement( | 666 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement( |
492 bool visibility, | 667 bool visibility, |
493 base::TimeDelta duration) { | 668 base::TimeDelta duration) { |
494 return new VisibilityTransition(visibility, duration); | 669 return new VisibilityTransition(visibility, duration); |
495 } | 670 } |
496 | 671 |
497 // static | 672 // static |
(...skipping 18 matching lines...) Expand all Loading... | |
516 } | 691 } |
517 | 692 |
518 // static | 693 // static |
519 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 694 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
520 SkColor color, | 695 SkColor color, |
521 base::TimeDelta duration) { | 696 base::TimeDelta duration) { |
522 return new ColorTransition(color, duration); | 697 return new ColorTransition(color, duration); |
523 } | 698 } |
524 | 699 |
525 } // namespace ui | 700 } // namespace ui |
OLD | NEW |