15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animation_element.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/animation/animation.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/animation/animation_id_provider.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/float_animation_curve_adapter.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/layer.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animation_delegate.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animator.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/scoped_animation_duration_scale_mode.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/transform_animation_curve_adapter.h"
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/tween.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/interpolated_transform.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// The factor by which duration is scaled up or down when using
245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// ScopedAnimationDurationScaleMode.
255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const int kSlowDurationScaleMultiplier = 4;
265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const int kFastDurationScaleDivisor = 4;
275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const int kNonZeroDurationScaleDivisor = 20;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Pause -----------------------------------------------------------------------
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Pause : public LayerAnimationElement {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Pause(AnimatableProperties properties, base::TimeDelta duration)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : LayerAnimationElement(properties, duration) {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~Pause() {}
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          LayerAnimationDelegate* delegate) OVERRIDE {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {}
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(Pause);
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TransformTransition ---------------------------------------------------------
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TransformTransition : public LayerAnimationElement {
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TransformTransition(const gfx::Transform& target, base::TimeDelta duration)
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(TRANSFORM, duration),
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        target_(target) {
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~TransformTransition() {}
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    start_ = delegate->GetTransformForAnimation();
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate->SetTransformFromAnimation(
664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        gfx::Tween::TransformValueBetween(t, start_, target_));
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->transform = target_;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Transform start_;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const gfx::Transform target_;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TransformTransition);
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// InterpolatedTransformTransition ---------------------------------------------
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InterpolatedTransformTransition : public LayerAnimationElement {
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InterpolatedTransformTransition(InterpolatedTransform* interpolated_transform,
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  base::TimeDelta duration)
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(TRANSFORM, duration),
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        interpolated_transform_(interpolated_transform) {
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~InterpolatedTransformTransition() {}
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate->SetTransformFromAnimation(
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        interpolated_transform_->Interpolate(static_cast<float>(t)));
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->transform = interpolated_transform_->Interpolate(1.0f);
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<InterpolatedTransform> interpolated_transform_;
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformTransition);
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BoundsTransition ------------------------------------------------------------
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BoundsTransition : public LayerAnimationElement {
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BoundsTransition(const gfx::Rect& target, base::TimeDelta duration)
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(BOUNDS, duration),
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        target_(target) {
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~BoundsTransition() {}
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    start_ = delegate->GetBoundsForAnimation();
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
132d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    delegate->SetBoundsFromAnimation(
1334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        gfx::Tween::RectValueBetween(t, start_, target_));
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->bounds = target_;
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect start_;
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const gfx::Rect target_;
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(BoundsTransition);
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OpacityTransition -----------------------------------------------------------
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class OpacityTransition : public LayerAnimationElement {
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OpacityTransition(float target, base::TimeDelta duration)
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(OPACITY, duration),
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        start_(0.0f),
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        target_(target) {
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~OpacityTransition() {}
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    start_ = delegate->GetOpacityForAnimation();
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
167d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    delegate->SetOpacityFromAnimation(
1684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        gfx::Tween::FloatValueBetween(t, start_, target_));
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->opacity = target_;
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float start_;
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const float target_;
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(OpacityTransition);
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// VisibilityTransition --------------------------------------------------------
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VisibilityTransition : public LayerAnimationElement {
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  VisibilityTransition(bool target, base::TimeDelta duration)
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(VISIBILITY, duration),
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        start_(false),
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        target_(target) {
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~VisibilityTransition() {}
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    start_ = delegate->GetVisibilityForAnimation();
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate->SetVisibilityFromAnimation(t == 1.0 ? target_ : start_);
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return t == 1.0;
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->visibility = target_;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool start_;
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const bool target_;
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(VisibilityTransition);
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BrightnessTransition --------------------------------------------------------
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrightnessTransition : public LayerAnimationElement {
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrightnessTransition(float target, base::TimeDelta duration)
2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(BRIGHTNESS, duration),
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        start_(0.0f),
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        target_(target) {
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~BrightnessTransition() {}
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    start_ = delegate->GetBrightnessForAnimation();
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate->SetBrightnessFromAnimation(
2374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        gfx::Tween::FloatValueBetween(t, start_, target_));
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->brightness = target_;
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float start_;
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const float target_;
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(BrightnessTransition);
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// GrayscaleTransition ---------------------------------------------------------
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GrayscaleTransition : public LayerAnimationElement {
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GrayscaleTransition(float target, base::TimeDelta duration)
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(GRAYSCALE, duration),
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        start_(0.0f),
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        target_(target) {
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~GrayscaleTransition() {}
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    start_ = delegate->GetGrayscaleForAnimation();
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    delegate->SetGrayscaleFromAnimation(
2724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        gfx::Tween::FloatValueBetween(t, start_, target_));
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->grayscale = target_;
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float start_;
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const float target_;
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition);
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ColorTransition -------------------------------------------------------------
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ColorTransition : public LayerAnimationElement {
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ColorTransition(SkColor target, base::TimeDelta duration)
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : LayerAnimationElement(COLOR, duration),
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        start_(SK_ColorBLACK),
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        target_(target) {
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ColorTransition() {}
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    start_ = delegate->GetColorForAnimation();
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
3061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    delegate->SetColorFromAnimation(
3071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        gfx::Tween::ColorValueBetween(t, start_, target_));
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    target->color = target_;
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {}
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SkColor start_;
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const SkColor target_;
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ColorTransition);
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ThreadedLayerAnimationElement -----------------------------------------------
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ThreadedLayerAnimationElement : public LayerAnimationElement {
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ThreadedLayerAnimationElement(AnimatableProperties properties,
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                base::TimeDelta duration)
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : LayerAnimationElement(properties, duration) {
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~ThreadedLayerAnimationElement() {}
3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsThreaded() const OVERRIDE {
3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return (duration() != base::TimeDelta());
3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
33958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  explicit ThreadedLayerAnimationElement(const LayerAnimationElement& element)
34058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    : LayerAnimationElement(element) {
34158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
34258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool OnProgress(double t,
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                          LayerAnimationDelegate* delegate) OVERRIDE {
3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (t < 1.0)
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return false;
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (Started()) {
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      delegate->RemoveThreadedAnimation(animation_id());
3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    OnEnd(delegate);
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (delegate && Started()) {
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      delegate->RemoveThreadedAnimation(animation_id());
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RequestEffectiveStart(
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      LayerAnimationDelegate* delegate) OVERRIDE {
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DCHECK(animation_group_id());
3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (duration() == base::TimeDelta()) {
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      set_effective_start_time(requested_start_time());
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return;
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    set_effective_start_time(base::TimeTicks());
3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    scoped_ptr<cc::Animation> animation = CreateCCAnimation();
3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    animation->set_needs_synchronized_start_time(true);
3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    delegate->AddThreadedAnimation(animation.Pass());
3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnEnd(LayerAnimationDelegate* delegate) = 0;
3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual scoped_ptr<cc::Animation> CreateCCAnimation() = 0;
3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ThreadedLayerAnimationElement);
3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ThreadedOpacityTransition ---------------------------------------------------
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ThreadedOpacityTransition : public ThreadedLayerAnimationElement {
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ThreadedOpacityTransition(float target, base::TimeDelta duration)
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : ThreadedLayerAnimationElement(OPACITY, duration),
3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        start_(0.0f),
3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        target_(target) {
3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~ThreadedOpacityTransition() {}
3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    start_ = delegate->GetOpacityForAnimation();
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (delegate && Started()) {
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ThreadedLayerAnimationElement::OnAbort(delegate);
4024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      delegate->SetOpacityFromAnimation(gfx::Tween::FloatValueBetween(
403d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)          gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
404d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)              start_,
405d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)              target_));
4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    delegate->SetOpacityFromAnimation(target_);
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    scoped_ptr<cc::AnimationCurve> animation_curve(
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        new FloatAnimationCurveAdapter(tween_type(),
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                       start_,
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                       target_,
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                       duration()));
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    scoped_ptr<cc::Animation> animation(
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        cc::Animation::Create(animation_curve.Pass(),
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              animation_id(),
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              animation_group_id(),
4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              cc::Animation::Opacity));
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return animation.Pass();
4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    target->opacity = target_;
4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  float start_;
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const float target_;
4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ThreadedOpacityTransition);
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ThreadedTransformTransition -------------------------------------------------
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ThreadedTransformTransition : public ThreadedLayerAnimationElement {
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ThreadedTransformTransition(const gfx::Transform& target,
4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              base::TimeDelta duration)
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : ThreadedLayerAnimationElement(TRANSFORM, duration),
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        target_(target) {
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~ThreadedTransformTransition() {}
4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    start_ = delegate->GetTransformForAnimation();
4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
4557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    if (delegate && Started()) {
4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ThreadedLayerAnimationElement::OnAbort(delegate);
4574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      delegate->SetTransformFromAnimation(gfx::Tween::TransformValueBetween(
458d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)          gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          start_,
4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)          target_));
4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    delegate->SetTransformFromAnimation(target_);
4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    scoped_ptr<cc::AnimationCurve> animation_curve(
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        new TransformAnimationCurveAdapter(tween_type(),
471cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                           start_,
472cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                           target_,
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                           duration()));
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    scoped_ptr<cc::Animation> animation(
4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        cc::Animation::Create(animation_curve.Pass(),
4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              animation_id(),
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              animation_group_id(),
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              cc::Animation::Transform));
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return animation.Pass();
4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    target->transform = target_;
4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Transform start_;
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const gfx::Transform target_;
4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ThreadedTransformTransition);
4912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
49358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// InverseTransformTransision --------------------------------------------------
49458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
49558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class InverseTransformTransition : public ThreadedLayerAnimationElement {
49658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) public:
49758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  InverseTransformTransition(const gfx::Transform& base_transform,
49858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                             const LayerAnimationElement* uninverted_transition)
49958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      : ThreadedLayerAnimationElement(*uninverted_transition),
50058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        base_transform_(base_transform),
501d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        uninverted_transition_(
502d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)            CheckAndCast<const ThreadedTransformTransition*>(
503d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)              uninverted_transition)) {
50458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
50558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual ~InverseTransformTransition() {}
50658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
507d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static InverseTransformTransition* Clone(const LayerAnimationElement* other) {
508d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const InverseTransformTransition* other_inverse =
509d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      CheckAndCast<const InverseTransformTransition*>(other);
510d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return new InverseTransformTransition(
511d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        other_inverse->base_transform_, other_inverse->uninverted_transition_);
512d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
513d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
51458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) protected:
51558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
51658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    gfx::Transform start(delegate->GetTransformForAnimation());
51758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    effective_start_ = base_transform_ * start;
51858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
51958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    TargetValue target;
52058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    uninverted_transition_->GetTargetValue(&target);
52158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    base_target_ = target.transform;
52258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
52358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    set_tween_type(uninverted_transition_->tween_type());
52458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
52558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    TransformAnimationCurveAdapter base_curve(tween_type(),
526cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                              base_transform_,
527cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                              base_target_,
52858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                              duration());
52958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
53058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    animation_curve_.reset(new InverseTransformCurveAdapter(
531cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        base_curve, start, duration()));
53258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    computed_target_transform_ = ComputeWithBaseTransform(effective_start_,
53358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                                          base_target_);
53458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
53558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
53658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) OVERRIDE {
53758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    if (delegate && Started()) {
53858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      ThreadedLayerAnimationElement::OnAbort(delegate);
53958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      delegate->SetTransformFromAnimation(ComputeCurrentTransform());
54058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
54158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
54258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
54358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void OnEnd(LayerAnimationDelegate* delegate) OVERRIDE {
54458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    delegate->SetTransformFromAnimation(computed_target_transform_);
54558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
54658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
54758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual scoped_ptr<cc::Animation> CreateCCAnimation() OVERRIDE {
54858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    scoped_ptr<cc::Animation> animation(
54958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        cc::Animation::Create(animation_curve_->Clone(),
55058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                              animation_id(),
55158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                              animation_group_id(),
55258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                              cc::Animation::Transform));
55358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return animation.Pass();
55458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
55558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
55658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
55758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    target->transform = computed_target_transform_;
55858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
55958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
56058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) private:
56158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform ComputeCurrentTransform() const {
5624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    gfx::Transform base_current = gfx::Tween::TransformValueBetween(
563d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        gfx::Tween::CalculateValue(tween_type(), last_progressed_fraction()),
56458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        base_transform_,
56558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        base_target_);
56658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return ComputeWithBaseTransform(effective_start_, base_current);
56758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
56858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
56958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform ComputeWithBaseTransform(gfx::Transform start,
57058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                          gfx::Transform target) const {
57158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    gfx::Transform to_return(gfx::Transform::kSkipInitialization);
572d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    bool success = target.GetInverse(&to_return);
573d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    DCHECK(success) << "Target transform must be invertible.";
57458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
57558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    to_return.PreconcatTransform(start);
57658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return to_return;
57758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
57858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
579d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  template <typename T>
580d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static T CheckAndCast(const LayerAnimationElement* element) {
5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AnimatableProperties properties = element->properties();
5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    DCHECK(properties & TRANSFORM);
583d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return static_cast<T>(element);
58458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  }
58558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
58658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform effective_start_;
58758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform computed_target_transform_;
58858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
58958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const gfx::Transform base_transform_;
59058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform base_target_;
59158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
59258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<cc::AnimationCurve> animation_curve_;
59358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
59458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const ThreadedTransformTransition* const uninverted_transition_;
59558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
59658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(InverseTransformTransition);
59758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)};
59858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LayerAnimationElement::TargetValue ------------------------------------------
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement::TargetValue::TargetValue()
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : opacity(0.0f),
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      visibility(false),
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      brightness(0.0f),
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      grayscale(0.0f),
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      color(SK_ColorBLACK) {
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement::TargetValue::TargetValue(
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const LayerAnimationDelegate* delegate)
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : bounds(delegate ? delegate->GetBoundsForAnimation() : gfx::Rect()),
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      transform(delegate ?
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                delegate->GetTransformForAnimation() : gfx::Transform()),
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f),
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      visibility(delegate ? delegate->GetVisibilityForAnimation() : false),
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f),
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f),
6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      color(delegate ? delegate->GetColorForAnimation() : 0.0f) {
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LayerAnimationElement -------------------------------------------------------
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement::LayerAnimationElement(
6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AnimatableProperties properties, base::TimeDelta duration)
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : first_frame_(true),
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      properties_(properties),
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      duration_(GetEffectiveDuration(duration)),
630d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      tween_type_(gfx::Tween::LINEAR),
6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      animation_id_(cc::AnimationIdProvider::NextAnimationId()),
6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      animation_group_id_(0),
6334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      last_progressed_fraction_(0.0),
6344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      weak_ptr_factory_(this) {
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
63758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)LayerAnimationElement::LayerAnimationElement(
63858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const LayerAnimationElement &element)
63958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    : first_frame_(element.first_frame_),
64058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      properties_(element.properties_),
64158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      duration_(element.duration_),
64258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      tween_type_(element.tween_type_),
64358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      animation_id_(cc::AnimationIdProvider::NextAnimationId()),
64458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      animation_group_id_(element.animation_group_id_),
6454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      last_progressed_fraction_(element.last_progressed_fraction_),
6464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      weak_ptr_factory_(this) {
64758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
64858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement::~LayerAnimationElement() {
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void LayerAnimationElement::Start(LayerAnimationDelegate* delegate,
6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                  int animation_group_id) {
6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(requested_start_time_ != base::TimeTicks());
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(first_frame_);
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  animation_group_id_ = animation_group_id;
6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  last_progressed_fraction_ = 0.0;
6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  OnStart(delegate);
6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RequestEffectiveStart(delegate);
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  first_frame_ = false;
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool LayerAnimationElement::Progress(base::TimeTicks now,
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     LayerAnimationDelegate* delegate) {
6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(requested_start_time_ != base::TimeTicks());
6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(!first_frame_);
6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool need_draw;
6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  double t = 1.0;
6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
671c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if ((effective_start_time_ == base::TimeTicks()) ||
672c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      (now < effective_start_time_))  {
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // This hasn't actually started yet.
6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    need_draw = false;
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    last_progressed_fraction_ = 0.0;
6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return need_draw;
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeDelta elapsed = now - effective_start_time_;
6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if ((duration_ > base::TimeDelta()) && (elapsed < duration_))
6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    t = elapsed.InMillisecondsF() / duration_.InMillisecondsF();
6824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
683d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate);
6844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!alive)
6854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return need_draw;
6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  first_frame_ = t == 1.0;
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  last_progressed_fraction_ = t;
6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return need_draw;
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool LayerAnimationElement::IsFinished(base::TimeTicks time,
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                       base::TimeDelta* total_duration) {
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If an effective start has been requested but the effective start time
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // hasn't yet been set, the animation is not finished, regardless of the
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // value of |time|.
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!first_frame_ && (effective_start_time_ == base::TimeTicks()))
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return false;
6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeDelta queueing_delay;
7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!first_frame_)
7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    queueing_delay = effective_start_time_ - requested_start_time_;
7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeDelta elapsed = time - requested_start_time_;
7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (elapsed >= duration_ + queueing_delay) {
7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    *total_duration = duration_ + queueing_delay;
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return true;
7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return false;
7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool LayerAnimationElement::ProgressToEnd(LayerAnimationDelegate* delegate) {
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (first_frame_)
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OnStart(delegate);
7144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool need_draw = OnProgress(1.0, delegate);
7164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!alive)
7174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return need_draw;
7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  last_progressed_fraction_ = 1.0;
7192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  first_frame_ = true;
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return need_draw;
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void LayerAnimationElement::GetTargetValue(TargetValue* target) const {
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OnGetTarget(target);
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool LayerAnimationElement::IsThreaded() const {
7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return false;
7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void LayerAnimationElement::Abort(LayerAnimationDelegate* delegate) {
7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  OnAbort(delegate);
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  first_frame_ = true;
7342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void LayerAnimationElement::RequestEffectiveStart(
7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LayerAnimationDelegate* delegate) {
7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DCHECK(requested_start_time_ != base::TimeTicks());
7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  effective_start_time_ = requested_start_time_;
7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static
7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)LayerAnimationElement::AnimatableProperty
7442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)LayerAnimationElement::ToAnimatableProperty(
7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    cc::Animation::TargetProperty property) {
7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  switch (property) {
7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case cc::Animation::Transform:
7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return TRANSFORM;
7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case cc::Animation::Opacity:
7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return OPACITY;
7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    default:
7522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NOTREACHED();
7532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return AnimatableProperty();
7542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)base::TimeDelta LayerAnimationElement::GetEffectiveDuration(
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const base::TimeDelta& duration) {
7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  switch (ScopedAnimationDurationScaleMode::duration_scale_mode()) {
7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case ScopedAnimationDurationScaleMode::NORMAL_DURATION:
7622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return duration;
7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case ScopedAnimationDurationScaleMode::FAST_DURATION:
7645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      return duration / kFastDurationScaleDivisor;
7652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case ScopedAnimationDurationScaleMode::SLOW_DURATION:
7665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      return duration * kSlowDurationScaleMultiplier;
7675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    case ScopedAnimationDurationScaleMode::NON_ZERO_DURATION:
7685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      return duration / kNonZeroDurationScaleDivisor;
7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    case ScopedAnimationDurationScaleMode::ZERO_DURATION:
7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return base::TimeDelta();
7712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    default:
7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NOTREACHED();
7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return base::TimeDelta();
7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Transform& transform,
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return new ThreadedTransformTransition(transform, duration);
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
78558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateInverseTransformElement(
78658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const gfx::Transform& base_transform,
78758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const LayerAnimationElement* uninverted_transition) {
78858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  return new InverseTransformTransition(base_transform, uninverted_transition);
78958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
79058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
79158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// static
792d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CloneInverseTransformElement(
793d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const LayerAnimationElement* other) {
794d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return InverseTransformTransition::Clone(other);
795d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
796d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
797d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// static
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement*
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement::CreateInterpolatedTransformElement(
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    InterpolatedTransform* interpolated_transform,
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new InterpolatedTransformTransition(interpolated_transform, duration);
8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateBoundsElement(
8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Rect& bounds,
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new BoundsTransition(bounds, duration);
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateOpacityElement(
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float opacity,
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return new ThreadedOpacityTransition(opacity, duration);
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement(
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool visibility,
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new VisibilityTransition(visibility, duration);
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateBrightnessElement(
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float brightness,
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new BrightnessTransition(brightness, duration);
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateGrayscaleElement(
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float grayscale,
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new GrayscaleTransition(grayscale, duration);
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreatePauseElement(
8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    AnimatableProperties properties,
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new Pause(properties, duration);
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)LayerAnimationElement* LayerAnimationElement::CreateColorElement(
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SkColor color,
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::TimeDelta duration) {
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return new ColorTransition(color, duration);
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ui
855