Don't send touch move events within the slop region in Aura.
[chromium-blink-merge.git] / ui / compositor / layer_animation_element.cc
bloba8f628a7ddb21ec9ba2d603db9fb7ba0cf175c68
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.
5 #include "ui/compositor/layer_animation_element.h"
7 #include "base/compiler_specific.h"
8 #include "cc/animation/animation.h"
9 #include "cc/animation/animation_id_provider.h"
10 #include "ui/compositor/float_animation_curve_adapter.h"
11 #include "ui/compositor/layer.h"
12 #include "ui/compositor/layer_animation_delegate.h"
13 #include "ui/compositor/layer_animator.h"
14 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
15 #include "ui/compositor/transform_animation_curve_adapter.h"
16 #include "ui/gfx/animation/tween.h"
17 #include "ui/gfx/interpolated_transform.h"
19 namespace ui {
21 namespace {
23 // The factor by which duration is scaled up or down when
24 // ScopedAnimationDurationScaleMode::duration_scale_mode() is SLOW_DURATION or
25 // FAST_DURATION.
26 const int kSlowDurationScaleFactor = 4;
27 const int kFastDurationScaleFactor = 4;
29 // Pause -----------------------------------------------------------------------
30 class Pause : public LayerAnimationElement {
31 public:
32 Pause(AnimatableProperties properties, base::TimeDelta duration)
33 : LayerAnimationElement(properties, duration) {
35 virtual ~Pause() {}
37 private:
38 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {}
39 virtual bool OnProgress(double t,
40 LayerAnimationDelegate* delegate) OVERRIDE {
41 return false;
43 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {}
44 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
46 DISALLOW_COPY_AND_ASSIGN(Pause);
49 // TransformTransition ---------------------------------------------------------
51 class TransformTransition : public LayerAnimationElement {
52 public:
53 TransformTransition(const gfx::Transform& target, base::TimeDelta duration)
54 : LayerAnimationElement(TRANSFORM, duration),
55 target_(target) {
57 virtual ~TransformTransition() {}
59 protected:
60 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
61 start_ = delegate->GetTransformForAnimation();
64 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
65 delegate->SetTransformFromAnimation(
66 gfx::Tween::TransformValueBetween(t, start_, target_));
67 return true;
70 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
71 target->transform = target_;
74 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
76 private:
77 gfx::Transform start_;
78 const gfx::Transform target_;
80 DISALLOW_COPY_AND_ASSIGN(TransformTransition);
83 // InterpolatedTransformTransition ---------------------------------------------
85 class InterpolatedTransformTransition : public LayerAnimationElement {
86 public:
87 InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform,
88 base::TimeDelta duration)
89 : LayerAnimationElement(TRANSFORM, duration),
90 interpolated_transform_(interpolated_transform) {
92 virtual ~InterpolatedTransformTransition() {}
94 protected:
95 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
98 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
99 delegate->SetTransformFromAnimation(
100 interpolated_transform_->Interpolate(static_cast<float>(t)));
101 return true;
104 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
105 target->transform = interpolated_transform_->Interpolate(1.0f);
108 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
110 private:
111 scoped_ptr<InterpolatedTransform> interpolated_transform_;
113 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition);
116 // BoundsTransition ------------------------------------------------------------
118 class BoundsTransition : public LayerAnimationElement {
119 public:
120 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration)
121 : LayerAnimationElement(BOUNDS, duration),
122 target_(target) {
124 virtual ~BoundsTransition() {}
126 protected:
127 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
128 start_ = delegate->GetBoundsForAnimation();
131 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
132 delegate->SetBoundsFromAnimation(
133 gfx::Tween::RectValueBetween(t, start_, target_));
134 return true;
137 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
138 target->bounds = target_;
141 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
143 private:
144 gfx::Rect start_;
145 const gfx::Rect target_;
147 DISALLOW_COPY_AND_ASSIGN(BoundsTransition);
150 // OpacityTransition -----------------------------------------------------------
152 class OpacityTransition : public LayerAnimationElement {
153 public:
154 OpacityTransition(float target, base::TimeDelta duration)
155 : LayerAnimationElement(OPACITY, duration),
156 start_(0.0f),
157 target_(target) {
159 virtual ~OpacityTransition() {}
161 protected:
162 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
163 start_ = delegate->GetOpacityForAnimation();
166 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
167 delegate->SetOpacityFromAnimation(
168 gfx::Tween::FloatValueBetween(t, start_, target_));
169 return true;
172 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
173 target->opacity = target_;
176 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
178 private:
179 float start_;
180 const float target_;
182 DISALLOW_COPY_AND_ASSIGN(OpacityTransition);
185 // VisibilityTransition --------------------------------------------------------
187 class VisibilityTransition : public LayerAnimationElement {
188 public:
189 VisibilityTransition(bool target, base::TimeDelta duration)
190 : LayerAnimationElement(VISIBILITY, duration),
191 start_(false),
192 target_(target) {
194 virtual ~VisibilityTransition() {}
196 protected:
197 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
198 start_ = delegate->GetVisibilityForAnimation();
201 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
202 delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_);
203 return t == 1.0;
206 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
207 target->visibility = target_;
210 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
212 private:
213 bool start_;
214 const bool target_;
216 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition);
219 // BrightnessTransition --------------------------------------------------------
221 class BrightnessTransition : public LayerAnimationElement {
222 public:
223 BrightnessTransition(float target, base::TimeDelta duration)
224 : LayerAnimationElement(BRIGHTNESS, duration),
225 start_(0.0f),
226 target_(target) {
228 virtual ~BrightnessTransition() {}
230 protected:
231 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
232 start_ = delegate->GetBrightnessForAnimation();
235 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
236 delegate->SetBrightnessFromAnimation(
237 gfx::Tween::FloatValueBetween(t, start_, target_));
238 return true;
241 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
242 target->brightness = target_;
245 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
247 private:
248 float start_;
249 const float target_;
251 DISALLOW_COPY_AND_ASSIGN(BrightnessTransition);
254 // GrayscaleTransition ---------------------------------------------------------
256 class GrayscaleTransition : public LayerAnimationElement {
257 public:
258 GrayscaleTransition(float target, base::TimeDelta duration)
259 : LayerAnimationElement(GRAYSCALE, duration),
260 start_(0.0f),
261 target_(target) {
263 virtual ~GrayscaleTransition() {}
265 protected:
266 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
267 start_ = delegate->GetGrayscaleForAnimation();
270 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
271 delegate->SetGrayscaleFromAnimation(
272 gfx::Tween::FloatValueBetween(t, start_, target_));
273 return true;
276 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
277 target->grayscale = target_;
280 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
282 private:
283 float start_;
284 const float target_;
286 DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition);
289 // ColorTransition -------------------------------------------------------------
291 class ColorTransition : public LayerAnimationElement {
292 public:
293 ColorTransition(SkColor target, base::TimeDelta duration)
294 : LayerAnimationElement(COLOR, duration),
295 start_(SK_ColorBLACK),
296 target_(target) {
298 virtual ~ColorTransition() {}
300 protected:
301 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
302 start_ = delegate->GetColorForAnimation();
305 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
306 delegate->SetColorFromAnimation(
307 gfx::Tween::ColorValueBetween(t, start_, target_));
308 return true;
311 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
312 target->color = target_;
315 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
317 private:
318 SkColor start_;
319 const SkColor target_;
321 DISALLOW_COPY_AND_ASSIGN(ColorTransition);
324 // ThreadedLayerAnimationElement -----------------------------------------------
326 class ThreadedLayerAnimationElement : public LayerAnimationElement {
327 public:
328 ThreadedLayerAnimationElement(AnimatableProperties properties,
329 base::TimeDelta duration)
330 : LayerAnimationElement(properties, duration) {
332 virtual ~ThreadedLayerAnimationElement() {}
334 virtual bool IsThreaded() const OVERRIDE {
335 return (duration() != base::TimeDelta());
338 protected:
339 explicit ThreadedLayerAnimationElement(const LayerAnimationElement& element)
340 : LayerAnimationElement(element) {
343 virtual bool OnProgress(double t,
344 LayerAnimationDelegate* delegate) OVERRIDE {
345 if (t < 1.0)
346 return false;
348 if (Started()) {
349 delegate->RemoveThreadedAnimation(animation_id());
352 OnEnd(delegate);
353 return true;
356 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
357 if (delegate && Started()) {
358 delegate->RemoveThreadedAnimation(animation_id());
362 virtual void RequestEffectiveStart(
363 LayerAnimationDelegate* delegate) OVERRIDE {
364 DCHECK(animation_group_id());
365 if (duration() == base::TimeDelta()) {
366 set_effective_start_time(requested_start_time());
367 return;
369 set_effective_start_time(base::TimeTicks());
370 scoped_ptr<cc::Animation> animation = CreateCCAnimation();
371 animation->set_needs_synchronized_start_time(true);
372 delegate->AddThreadedAnimation(animation.Pass());
375 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0;
377 virtual scoped_ptr<cc::Animation> CreateCCAnimation() = 0;
379 private:
380 DISALLOW_COPY_AND_ASSIGN(ThreadedLayerAnimationElement);
383 // ThreadedOpacityTransition ---------------------------------------------------
385 class ThreadedOpacityTransition : public ThreadedLayerAnimationElement {
386 public:
387 ThreadedOpacityTransition(float target, base::TimeDelta duration)
388 : ThreadedLayerAnimationElement(OPACITY, duration),
389 start_(0.0f),
390 target_(target) {
392 virtual ~ThreadedOpacityTransition() {}
394 protected:
395 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
396 start_ = delegate->GetOpacityForAnimation();
399 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
400 if (delegate && Started()) {
401 ThreadedLayerAnimationElement::OnAbort(delegate);
402 delegate->SetOpacityFromAnimation(gfx::Tween::FloatValueBetween(
403 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
404 start_,
405 target_));
409 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
410 delegate->SetOpacityFromAnimation(target_);
413 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
414 scoped_ptr<cc::AnimationCurve> animation_curve(
415 new FloatAnimationCurveAdapter(tween_type(),
416 start_,
417 target_,
418 duration()));
419 scoped_ptr<cc::Animation> animation(
420 cc::Animation::Create(animation_curve.Pass(),
421 animation_id(),
422 animation_group_id(),
423 cc::Animation::Opacity));
424 return animation.Pass();
427 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
428 target->opacity = target_;
431 private:
432 float start_;
433 const float target_;
435 DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition);
438 // ThreadedTransformTransition -------------------------------------------------
440 class ThreadedTransformTransition : public ThreadedLayerAnimationElement {
441 public:
442 ThreadedTransformTransition(const gfx::Transform& target,
443 base::TimeDelta duration)
444 : ThreadedLayerAnimationElement(TRANSFORM, duration),
445 target_(target) {
447 virtual ~ThreadedTransformTransition() {}
449 protected:
450 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
451 start_ = delegate->GetTransformForAnimation();
452 float device_scale_factor = delegate->GetDeviceScaleFactor();
453 cc_start_ = Layer::ConvertTransformToCCTransform(start_,
454 device_scale_factor);
455 cc_target_ = Layer::ConvertTransformToCCTransform(target_,
456 device_scale_factor);
459 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
460 if (delegate && Started()) {
461 ThreadedLayerAnimationElement::OnAbort(delegate);
462 delegate->SetTransformFromAnimation(gfx::Tween::TransformValueBetween(
463 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
464 start_,
465 target_));
469 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
470 delegate->SetTransformFromAnimation(target_);
473 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
474 scoped_ptr<cc::AnimationCurve> animation_curve(
475 new TransformAnimationCurveAdapter(tween_type(),
476 cc_start_,
477 cc_target_,
478 duration()));
479 scoped_ptr<cc::Animation> animation(
480 cc::Animation::Create(animation_curve.Pass(),
481 animation_id(),
482 animation_group_id(),
483 cc::Animation::Transform));
484 return animation.Pass();
487 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
488 target->transform = target_;
491 private:
492 gfx::Transform start_;
493 gfx::Transform cc_start_;
494 const gfx::Transform target_;
495 gfx::Transform cc_target_;
497 DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition);
500 // InverseTransformTransision --------------------------------------------------
502 class InverseTransformTransition : public ThreadedLayerAnimationElement {
503 public:
504 InverseTransformTransition(const gfx::Transform& base_transform,
505 const LayerAnimationElement* uninverted_transition)
506 : ThreadedLayerAnimationElement(*uninverted_transition),
507 base_transform_(base_transform),
508 uninverted_transition_(
509 CheckAndCast<const ThreadedTransformTransition*>(
510 uninverted_transition)) {
512 virtual ~InverseTransformTransition() {}
514 static InverseTransformTransition* Clone(const LayerAnimationElement* other) {
515 const InverseTransformTransition* other_inverse =
516 CheckAndCast<const InverseTransformTransition*>(other);
517 return new InverseTransformTransition(
518 other_inverse->base_transform_, other_inverse->uninverted_transition_);
521 protected:
522 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
523 gfx::Transform start(delegate->GetTransformForAnimation());
524 effective_start_ = base_transform_ * start;
526 TargetValue target;
527 uninverted_transition_->GetTargetValue(&target);
528 base_target_ = target.transform;
530 set_tween_type(uninverted_transition_->tween_type());
532 float device_scale_factor = delegate->GetDeviceScaleFactor();
533 const gfx::Transform cc_base_start = Layer::ConvertTransformToCCTransform(
534 base_transform_,
535 device_scale_factor);
536 const gfx::Transform cc_base_target = Layer::ConvertTransformToCCTransform(
537 base_target_,
538 device_scale_factor);
539 TransformAnimationCurveAdapter base_curve(tween_type(),
540 cc_base_start,
541 cc_base_target,
542 duration());
544 const gfx::Transform cc_start = Layer::ConvertTransformToCCTransform(
545 start, device_scale_factor);
546 animation_curve_.reset(new InverseTransformCurveAdapter(
547 base_curve, cc_start, duration()));
548 computed_target_transform_ = ComputeWithBaseTransform(effective_start_,
549 base_target_);
552 virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
553 if (delegate && Started()) {
554 ThreadedLayerAnimationElement::OnAbort(delegate);
555 delegate->SetTransformFromAnimation(ComputeCurrentTransform());
559 virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
560 delegate->SetTransformFromAnimation(computed_target_transform_);
563 virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
564 scoped_ptr<cc::Animation> animation(
565 cc::Animation::Create(animation_curve_->Clone(),
566 animation_id(),
567 animation_group_id(),
568 cc::Animation::Transform));
569 return animation.Pass();
572 virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
573 target->transform = computed_target_transform_;
576 private:
577 gfx::Transform ComputeCurrentTransform() const {
578 gfx::Transform base_current = gfx::Tween::TransformValueBetween(
579 gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
580 base_transform_,
581 base_target_);
582 return ComputeWithBaseTransform(effective_start_, base_current);
585 gfx::Transform ComputeWithBaseTransform(gfx::Transform start,
586 gfx::Transform target) const {
587 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
588 bool success = target.GetInverse(&to_return);
589 DCHECK(success) << "Target transform must be invertible.";
591 to_return.PreconcatTransform(start);
592 return to_return;
595 template <typename T>
596 static T CheckAndCast(const LayerAnimationElement* element) {
597 AnimatableProperties properties = element->properties();
598 DCHECK(properties & TRANSFORM);
599 return static_cast<T>(element);
602 gfx::Transform effective_start_;
603 gfx::Transform computed_target_transform_;
605 const gfx::Transform base_transform_;
606 gfx::Transform base_target_;
608 scoped_ptr<cc::AnimationCurve> animation_curve_;
610 const ThreadedTransformTransition* const uninverted_transition_;
612 DISALLOW_COPY_AND_ASSIGN(InverseTransformTransition);
615 } // namespace
617 // LayerAnimationElement::TargetValue ------------------------------------------
619 LayerAnimationElement::TargetValue::TargetValue()
620 : opacity(0.0f),
621 visibility(false),
622 brightness(0.0f),
623 grayscale(0.0f),
624 color(SK_ColorBLACK) {
627 LayerAnimationElement::TargetValue::TargetValue(
628 const LayerAnimationDelegate* delegate)
629 : bounds(delegate ? delegate->GetBoundsForAnimation() : gfx::Rect()),
630 transform(delegate ?
631 delegate->GetTransformForAnimation() : gfx::Transform()),
632 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f),
633 visibility(delegate ? delegate->GetVisibilityForAnimation() : false),
634 brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f),
635 grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f),
636 color(delegate ? delegate->GetColorForAnimation() : 0.0f) {
639 // LayerAnimationElement -------------------------------------------------------
641 LayerAnimationElement::LayerAnimationElement(
642 AnimatableProperties properties, base::TimeDelta duration)
643 : first_frame_(true),
644 properties_(properties),
645 duration_(GetEffectiveDuration(duration)),
646 tween_type_(gfx::Tween::LINEAR),
647 animation_id_(cc::AnimationIdProvider::NextAnimationId()),
648 animation_group_id_(0),
649 last_progressed_fraction_(0.0),
650 weak_ptr_factory_(this) {
653 LayerAnimationElement::LayerAnimationElement(
654 const LayerAnimationElement &element)
655 : first_frame_(element.first_frame_),
656 properties_(element.properties_),
657 duration_(element.duration_),
658 tween_type_(element.tween_type_),
659 animation_id_(cc::AnimationIdProvider::NextAnimationId()),
660 animation_group_id_(element.animation_group_id_),
661 last_progressed_fraction_(element.last_progressed_fraction_),
662 weak_ptr_factory_(this) {
665 LayerAnimationElement::~LayerAnimationElement() {
668 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate,
669 int animation_group_id) {
670 DCHECK(requested_start_time_ != base::TimeTicks());
671 DCHECK(first_frame_);
672 animation_group_id_ = animation_group_id;
673 last_progressed_fraction_ = 0.0;
674 OnStart(delegate);
675 RequestEffectiveStart(delegate);
676 first_frame_ = false;
679 bool LayerAnimationElement::Progress(base::TimeTicks now,
680 LayerAnimationDelegate* delegate) {
681 DCHECK(requested_start_time_ != base::TimeTicks());
682 DCHECK(!first_frame_);
684 bool need_draw;
685 double t = 1.0;
687 if ((effective_start_time_ == base::TimeTicks()) ||
688 (now < effective_start_time_)) {
689 // This hasn't actually started yet.
690 need_draw = false;
691 last_progressed_fraction_ = 0.0;
692 return need_draw;
695 base::TimeDelta elapsed = now - effective_start_time_;
696 if ((duration_ > base::TimeDelta()) && (elapsed < duration_))
697 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF();
698 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
699 need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate);
700 if (!alive)
701 return need_draw;
702 first_frame_ = t == 1.0;
703 last_progressed_fraction_ = t;
704 return need_draw;
707 bool LayerAnimationElement::IsFinished(base::TimeTicks time,
708 base::TimeDelta* total_duration) {
709 // If an effective start has been requested but the effective start time
710 // hasn't yet been set, the animation is not finished, regardless of the
711 // value of |time|.
712 if (!first_frame_ && (effective_start_time_ == base::TimeTicks()))
713 return false;
715 base::TimeDelta queueing_delay;
716 if (!first_frame_)
717 queueing_delay = effective_start_time_ - requested_start_time_;
719 base::TimeDelta elapsed = time - requested_start_time_;
720 if (elapsed >= duration_ + queueing_delay) {
721 *total_duration = duration_ + queueing_delay;
722 return true;
724 return false;
727 bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) {
728 if (first_frame_)
729 OnStart(delegate);
730 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
731 bool need_draw = OnProgress(1.0, delegate);
732 if (!alive)
733 return need_draw;
734 last_progressed_fraction_ = 1.0;
735 first_frame_ = true;
736 return need_draw;
739 void LayerAnimationElement::GetTargetValue(TargetValue* target) const {
740 OnGetTarget(target);
743 bool LayerAnimationElement::IsThreaded() const {
744 return false;
747 void LayerAnimationElement::Abort(LayerAnimationDelegate* delegate) {
748 OnAbort(delegate);
749 first_frame_ = true;
752 void LayerAnimationElement::RequestEffectiveStart(
753 LayerAnimationDelegate* delegate) {
754 DCHECK(requested_start_time_ != base::TimeTicks());
755 effective_start_time_ = requested_start_time_;
758 // static
759 LayerAnimationElement::AnimatableProperty
760 LayerAnimationElement::ToAnimatableProperty(
761 cc::Animation::TargetProperty property) {
762 switch (property) {
763 case cc::Animation::Transform:
764 return TRANSFORM;
765 case cc::Animation::Opacity:
766 return OPACITY;
767 default:
768 NOTREACHED();
769 return AnimatableProperty();
773 // static
774 base::TimeDelta LayerAnimationElement::GetEffectiveDuration(
775 const base::TimeDelta& duration) {
776 switch (ScopedAnimationDurationScaleMode::duration_scale_mode()) {
777 case ScopedAnimationDurationScaleMode::NORMAL_DURATION:
778 return duration;
779 case ScopedAnimationDurationScaleMode::FAST_DURATION:
780 return duration / kFastDurationScaleFactor;
781 case ScopedAnimationDurationScaleMode::SLOW_DURATION:
782 return duration * kSlowDurationScaleFactor;
783 case ScopedAnimationDurationScaleMode::ZERO_DURATION:
784 return base::TimeDelta();
785 default:
786 NOTREACHED();
787 return base::TimeDelta();
791 // static
792 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
793 const gfx::Transform& transform,
794 base::TimeDelta duration) {
795 return new ThreadedTransformTransition(transform, duration);
798 // static
799 LayerAnimationElement* LayerAnimationElement::CreateInverseTransformElement(
800 const gfx::Transform& base_transform,
801 const LayerAnimationElement* uninverted_transition) {
802 return new InverseTransformTransition(base_transform, uninverted_transition);
805 // static
806 LayerAnimationElement* LayerAnimationElement::CloneInverseTransformElement(
807 const LayerAnimationElement* other) {
808 return InverseTransformTransition::Clone(other);
811 // static
812 LayerAnimationElement*
813 LayerAnimationElement::CreateInterpolatedTransformElement(
814 InterpolatedTransform* interpolated_transform,
815 base::TimeDelta duration) {
816 return new InterpolatedTransformTransition(interpolated_transform, duration);
819 // static
820 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement(
821 const gfx::Rect& bounds,
822 base::TimeDelta duration) {
823 return new BoundsTransition(bounds, duration);
826 // static
827 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement(
828 float opacity,
829 base::TimeDelta duration) {
830 return new ThreadedOpacityTransition(opacity, duration);
833 // static
834 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement(
835 bool visibility,
836 base::TimeDelta duration) {
837 return new VisibilityTransition(visibility, duration);
840 // static
841 LayerAnimationElement* LayerAnimationElement::CreateBrightnessElement(
842 float brightness,
843 base::TimeDelta duration) {
844 return new BrightnessTransition(brightness, duration);
847 // static
848 LayerAnimationElement* LayerAnimationElement::CreateGrayscaleElement(
849 float grayscale,
850 base::TimeDelta duration) {
851 return new GrayscaleTransition(grayscale, duration);
854 // static
855 LayerAnimationElement* LayerAnimationElement::CreatePauseElement(
856 AnimatableProperties properties,
857 base::TimeDelta duration) {
858 return new Pause(properties, duration);
861 // static
862 LayerAnimationElement* LayerAnimationElement::CreateColorElement(
863 SkColor color,
864 base::TimeDelta duration) {
865 return new ColorTransition(color, duration);
868 } // namespace ui