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 { | |
sky
2013/02/19 17:06:56
virtual OVERRIDE
ajuma
2013/02/20 16:09:10
Done.
| |
384 return (duration() != base::TimeDelta()); | |
sky
2013/02/19 17:06:56
Should whether a LayerAnimationElement is threaded
ajuma
2013/02/20 16:09:10
No. Simply checking for non-zero duration in Layer
| |
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 set_animation_id(0); | |
406 } | |
407 } | |
408 | |
409 virtual void RequestEffectiveStart( | |
410 LayerAnimationDelegate* delegate) OVERRIDE { | |
411 DCHECK(animation_group_id()); | |
412 set_animation_id(cc::AnimationIdProvider::NextAnimationId()); | |
413 set_effective_start_time(base::TimeTicks()); | |
414 scoped_ptr<cc::Animation> animation = CreateCCAnimation(); | |
415 animation->setNeedsSynchronizedStartTime(true); | |
416 delegate->AddThreadedAnimation(animation.Pass()); | |
417 } | |
418 | |
419 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0; | |
420 | |
421 virtual scoped_ptr<cc::Animation> CreateCCAnimation() = 0; | |
422 | |
423 private: | |
424 | |
sky
2013/02/19 17:06:56
nit: remove newline.
ajuma
2013/02/20 16:09:10
Done.
| |
425 DISALLOW_COPY_AND_ASSIGN(ThreadedLayerAnimationElement); | |
426 }; | |
427 | |
428 // ThreadedOpacityTransition --------------------------------------------------- | |
429 | |
430 class ThreadedOpacityTransition : public ThreadedLayerAnimationElement { | |
431 public: | |
432 ThreadedOpacityTransition(float target, base::TimeDelta duration) | |
433 : ThreadedLayerAnimationElement(GetProperties(), duration), | |
434 start_(0.0f), | |
435 target_(target) { | |
436 } | |
437 virtual ~ThreadedOpacityTransition() {} | |
438 | |
439 protected: | |
440 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { | |
441 start_ = delegate->GetOpacityForAnimation(); | |
442 } | |
443 | |
444 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE { | |
445 if (delegate && animation_id()) { | |
446 ThreadedLayerAnimationElement::OnAbort(delegate); | |
447 delegate->SetOpacityFromAnimation( | |
448 Tween::ValueBetween(last_progressed_fraction(), start_, target_)); | |
449 } | |
450 } | |
451 | |
452 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE { | |
453 delegate->SetOpacityFromAnimation(target_); | |
454 } | |
455 | |
456 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE { | |
457 scoped_ptr<cc::AnimationCurve> animation_curve( | |
458 new FloatAnimationCurveAdapter(tween_type(), | |
459 start_, | |
460 target_, | |
461 duration())); | |
462 scoped_ptr<cc::Animation> animation( | |
463 cc::Animation::create(animation_curve.Pass(), | |
464 animation_id(), | |
465 animation_group_id(), | |
466 cc::Animation::Opacity)); | |
467 return animation.Pass(); | |
468 } | |
469 | |
470 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { | |
471 target->opacity = target_; | |
472 } | |
473 | |
474 private: | |
475 static AnimatableProperties GetProperties() { | |
476 AnimatableProperties properties; | |
477 properties.insert(LayerAnimationElement::OPACITY); | |
478 return properties; | |
479 } | |
480 | |
481 float start_; | |
482 const float target_; | |
483 | |
484 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition); | |
485 }; | |
486 | |
370 } // namespace | 487 } // namespace |
371 | 488 |
372 // LayerAnimationElement::TargetValue ------------------------------------------ | 489 // LayerAnimationElement::TargetValue ------------------------------------------ |
373 | 490 |
374 LayerAnimationElement::TargetValue::TargetValue() | 491 LayerAnimationElement::TargetValue::TargetValue() |
375 : opacity(0.0f), | 492 : opacity(0.0f), |
376 visibility(false), | 493 visibility(false), |
377 brightness(0.0f), | 494 brightness(0.0f), |
378 grayscale(0.0f), | 495 grayscale(0.0f), |
379 color(SK_ColorBLACK) { | 496 color(SK_ColorBLACK) { |
(...skipping 12 matching lines...) Expand all Loading... | |
392 } | 509 } |
393 | 510 |
394 // LayerAnimationElement ------------------------------------------------------- | 511 // LayerAnimationElement ------------------------------------------------------- |
395 | 512 |
396 LayerAnimationElement::LayerAnimationElement( | 513 LayerAnimationElement::LayerAnimationElement( |
397 const AnimatableProperties& properties, | 514 const AnimatableProperties& properties, |
398 base::TimeDelta duration) | 515 base::TimeDelta duration) |
399 : first_frame_(true), | 516 : first_frame_(true), |
400 properties_(properties), | 517 properties_(properties), |
401 duration_(GetEffectiveDuration(duration)), | 518 duration_(GetEffectiveDuration(duration)), |
402 tween_type_(Tween::LINEAR) { | 519 tween_type_(Tween::LINEAR), |
520 animation_id_(0), | |
521 animation_group_id_(0), | |
522 last_progressed_fraction_(0.0) { | |
403 } | 523 } |
404 | 524 |
405 LayerAnimationElement::~LayerAnimationElement() { | 525 LayerAnimationElement::~LayerAnimationElement() { |
406 } | 526 } |
407 | 527 |
528 void LayerAnimationElement::ProgressToEffectiveStart( | |
529 LayerAnimationDelegate* delegate) { | |
530 DCHECK(first_frame_); | |
531 last_progressed_fraction_ = 0.0; | |
532 if (!IsThreaded()) | |
533 return; | |
534 | |
535 OnStart(delegate); | |
536 RequestEffectiveStart(delegate); | |
537 first_frame_ = false; | |
538 } | |
539 | |
408 bool LayerAnimationElement::Progress(base::TimeTicks now, | 540 bool LayerAnimationElement::Progress(base::TimeTicks now, |
409 LayerAnimationDelegate* delegate) { | 541 LayerAnimationDelegate* delegate) { |
410 DCHECK(start_time_ != base::TimeTicks()); | 542 DCHECK(requested_start_time_ != base::TimeTicks()); |
411 base::TimeDelta elapsed = now - start_time_; | |
412 if (first_frame_) | 543 if (first_frame_) |
413 OnStart(delegate); | 544 OnStart(delegate); |
545 | |
546 bool need_draw; | |
414 double t = 1.0; | 547 double t = 1.0; |
548 | |
549 if (first_frame_ && (now - requested_start_time_ >= duration_)) { | |
550 // This can be finished immediately, without waiting for an effective start. | |
551 need_draw = OnProgress(t, delegate); | |
552 last_progressed_fraction_ = t; | |
553 return need_draw; | |
554 } | |
555 | |
556 if (first_frame_) { | |
557 RequestEffectiveStart(delegate); | |
558 first_frame_ = false; | |
559 } | |
560 | |
561 if (effective_start_time_ == base::TimeTicks()) { | |
562 // This hasn't actually started yet. | |
563 need_draw = false; | |
564 last_progressed_fraction_ = 0.0; | |
565 return need_draw; | |
566 } | |
567 | |
568 base::TimeDelta elapsed = now - effective_start_time_; | |
415 if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) | 569 if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) |
416 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); | 570 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); |
417 bool need_draw = OnProgress(Tween::CalculateValue(tween_type_, t), delegate); | 571 need_draw = OnProgress(Tween::CalculateValue(tween_type_, t), delegate); |
418 first_frame_ = t == 1.0; | 572 first_frame_ = t == 1.0; |
573 last_progressed_fraction_ = t; | |
419 return need_draw; | 574 return need_draw; |
420 } | 575 } |
421 | 576 |
422 bool LayerAnimationElement::IsFinished(base::TimeTicks time, | 577 bool LayerAnimationElement::IsFinished(base::TimeTicks time, |
423 base::TimeDelta* total_duration) { | 578 base::TimeDelta* total_duration) { |
424 base::TimeDelta elapsed = time - start_time_; | 579 // If an effective start has been requested but the effective start time |
425 if (elapsed >= duration_) { | 580 // hasn't yet been set, the animation is not finished, regardless of the |
426 *total_duration = duration_; | 581 // value of |time|. |
582 if (!first_frame_ && (effective_start_time_ == base::TimeTicks())) | |
583 return false; | |
584 | |
585 base::TimeDelta queueing_delay; | |
586 if (!first_frame_) | |
587 queueing_delay = effective_start_time_ - requested_start_time_; | |
588 | |
589 base::TimeDelta elapsed = time - requested_start_time_; | |
590 if (elapsed >= duration_ + queueing_delay) { | |
591 *total_duration = duration_ + queueing_delay; | |
427 return true; | 592 return true; |
428 } | 593 } |
429 return false; | 594 return false; |
430 } | 595 } |
431 | 596 |
432 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) { | 597 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) { |
433 if (first_frame_) | 598 if (first_frame_) |
434 OnStart(delegate); | 599 OnStart(delegate); |
435 bool need_draw = OnProgress(1.0, delegate); | 600 bool need_draw = OnProgress(1.0, delegate); |
601 last_progressed_fraction_ = 1.0; | |
436 first_frame_ = true; | 602 first_frame_ = true; |
437 return need_draw; | 603 return need_draw; |
438 } | 604 } |
439 | 605 |
440 void LayerAnimationElement::GetTargetValue(TargetValue* target) const { | 606 void LayerAnimationElement::GetTargetValue(TargetValue* target) const { |
441 OnGetTarget(target); | 607 OnGetTarget(target); |
442 } | 608 } |
443 | 609 |
444 void LayerAnimationElement::Abort() { | 610 bool LayerAnimationElement::IsThreaded() const { |
611 return false; | |
612 } | |
613 | |
614 void LayerAnimationElement::Abort(LayerAnimationDelegate* delegate) { | |
445 first_frame_ = true; | 615 first_frame_ = true; |
446 OnAbort(); | 616 OnAbort(delegate); |
617 } | |
618 | |
619 void LayerAnimationElement::RequestEffectiveStart( | |
620 LayerAnimationDelegate* delegate) { | |
621 DCHECK(requested_start_time_ != base::TimeTicks()); | |
622 effective_start_time_ = requested_start_time_; | |
447 } | 623 } |
448 | 624 |
449 // static | 625 // static |
626 LayerAnimationElement::AnimatableProperty | |
627 LayerAnimationElement::ToAnimatableProperty( | |
628 cc::Animation::TargetProperty property) { | |
629 switch (property) { | |
630 case cc::Animation::Transform: | |
631 return TRANSFORM; | |
632 case cc::Animation::Opacity: | |
633 return OPACITY; | |
634 default: | |
635 NOTREACHED(); | |
636 return AnimatableProperty(); | |
637 } | |
638 } | |
639 | |
640 // static | |
450 base::TimeDelta LayerAnimationElement::GetEffectiveDuration( | 641 base::TimeDelta LayerAnimationElement::GetEffectiveDuration( |
451 const base::TimeDelta& duration) { | 642 const base::TimeDelta& duration) { |
452 if (LayerAnimator::disable_animations_for_test()) | 643 if (LayerAnimator::disable_animations_for_test()) |
453 return base::TimeDelta(); | 644 return base::TimeDelta(); |
454 | 645 |
455 if (LayerAnimator::slow_animation_mode()) | 646 if (LayerAnimator::slow_animation_mode()) |
456 return duration * LayerAnimator::slow_animation_scale_factor(); | 647 return duration * LayerAnimator::slow_animation_scale_factor(); |
457 | 648 |
458 return duration; | 649 return duration; |
459 } | 650 } |
(...skipping 17 matching lines...) Expand all Loading... | |
477 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( | 668 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( |
478 const gfx::Rect& bounds, | 669 const gfx::Rect& bounds, |
479 base::TimeDelta duration) { | 670 base::TimeDelta duration) { |
480 return new BoundsTransition(bounds, duration); | 671 return new BoundsTransition(bounds, duration); |
481 } | 672 } |
482 | 673 |
483 // static | 674 // static |
484 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( | 675 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( |
485 float opacity, | 676 float opacity, |
486 base::TimeDelta duration) { | 677 base::TimeDelta duration) { |
487 return new OpacityTransition(opacity, duration); | 678 return new ThreadedOpacityTransition(opacity, duration); |
488 } | 679 } |
489 | 680 |
490 // static | 681 // static |
491 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement( | 682 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement( |
492 bool visibility, | 683 bool visibility, |
493 base::TimeDelta duration) { | 684 base::TimeDelta duration) { |
494 return new VisibilityTransition(visibility, duration); | 685 return new VisibilityTransition(visibility, duration); |
495 } | 686 } |
496 | 687 |
497 // static | 688 // static |
(...skipping 18 matching lines...) Expand all Loading... | |
516 } | 707 } |
517 | 708 |
518 // static | 709 // static |
519 LayerAnimationElement* LayerAnimationElement::CreateColorElement( | 710 LayerAnimationElement* LayerAnimationElement::CreateColorElement( |
520 SkColor color, | 711 SkColor color, |
521 base::TimeDelta duration) { | 712 base::TimeDelta duration) { |
522 return new ColorTransition(color, duration); | 713 return new ColorTransition(color, duration); |
523 } | 714 } |
524 | 715 |
525 } // namespace ui | 716 } // namespace ui |
OLD | NEW |