Chromium Code Reviews| Index: ui/gfx/compositor/layer_animation_element.cc |
| diff --git a/ui/gfx/compositor/layer_animation_element.cc b/ui/gfx/compositor/layer_animation_element.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9b6ad945c43c6288f57f2d6f37af94a6597de254 |
| --- /dev/null |
| +++ b/ui/gfx/compositor/layer_animation_element.cc |
| @@ -0,0 +1,167 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/compositor/layer_animation_element.h" |
| + |
| +#include "ui/base/animation/tween.h" |
| +#include "ui/gfx/compositor/layer_animation_delegate.h" |
| +#include "ui/gfx/rect.h" |
| +#include "ui/gfx/transform.h" |
| + |
| +namespace ui { |
| + |
| +namespace { |
| + |
| +class TransitionBase : public LayerAnimationElement { |
| + public: |
| + TransitionBase(LayerAnimationElement::AnimatableProperty property, |
| + base::TimeDelta duration) |
| + : first_frame_(true), |
| + duration_(duration) { |
| + properties_.insert(property); |
| + } |
| + |
| + virtual ~TransitionBase() {} |
| + |
| + protected: |
| + virtual void OnProgress(double t, LayerAnimationDelegate* delegate) = 0; |
| + bool first_frame() const { return first_frame_; } |
| + |
| + private: |
| + virtual void Progress(double t, LayerAnimationDelegate* delegate) { |
|
sky
2011/10/14 16:39:52
Use OVERRIDE on all these.
|
| + OnProgress(t, delegate); |
| + delegate->ScheduleDrawForAnimation(); |
| + first_frame_ = t == 1.0; // when we've completed, reset to first frame. |
| + } |
| + |
| + virtual void Abort() { |
| + // reset. |
| + first_frame_ = true; |
| + } |
| + |
| + virtual const AnimatableProperties& Properties() const { |
| + return properties_; |
| + } |
| + |
| + virtual base::TimeDelta Duration() const { |
| + return duration_; |
| + } |
| + |
| + bool first_frame_; |
| + AnimatableProperties properties_; |
| + base::TimeDelta duration_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TransitionBase); |
| +}; |
| + |
| +class TransformTransition : public TransitionBase { |
| + public: |
| + TransformTransition(const Transform& target, base::TimeDelta duration) |
| + : TransitionBase(LayerAnimationElement::TRANSFORM, duration), |
| + target_(target) { |
| + } |
| + virtual ~TransformTransition() {} |
| + |
| + protected: |
| + virtual void OnProgress(double t, LayerAnimationDelegate* delegate) { |
| + if (first_frame()) |
| + start_ = delegate->GetTransformForAnimation(); |
| + delegate->SetTransformFromAnimation( |
| + Tween::ValueBetween(t, start_, target_)); |
| + } |
| + |
| + private: |
| + Transform start_; |
| + Transform target_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TransformTransition); |
| +}; |
| + |
| +class BoundsTransition : public TransitionBase { |
| + public: |
| + BoundsTransition(const gfx::Rect& target, base::TimeDelta duration) |
| + : TransitionBase(LayerAnimationElement::BOUNDS, duration), |
| + target_(target) { |
| + } |
| + virtual ~BoundsTransition() {} |
| + |
| + protected: |
| + virtual void OnProgress(double t, LayerAnimationDelegate* delegate) { |
| + if (first_frame()) |
| + start_ = delegate->GetBoundsForAnimation(); |
| + delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); |
| + } |
| + |
| + private: |
| + gfx::Rect start_; |
| + gfx::Rect target_; |
| +}; |
| + |
| +class OpacityTransition : public TransitionBase { |
| + public: |
| + OpacityTransition(float target, base::TimeDelta duration) |
| + : TransitionBase(LayerAnimationElement::OPACITY, duration), |
| + target_(target) { |
| + } |
| + virtual ~OpacityTransition() {} |
| + |
| + protected: |
| + virtual void OnProgress(double t, LayerAnimationDelegate* delegate) { |
| + if (first_frame()) |
| + start_ = delegate->GetOpacityForAnimation(); |
| + delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); |
| + } |
| + |
| + private: |
| + float start_; |
| + float target_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OpacityTransition); |
| +}; |
| + |
| +class Pause : public TransitionBase { |
| + public: |
| + Pause(LayerAnimationElement::AnimatableProperty property, |
| + base::TimeDelta duration) |
| + : TransitionBase(property, duration) { |
| + } |
| + virtual ~Pause() {} |
| + |
| + protected: |
| + virtual void OnProgress(double t, LayerAnimationDelegate* delegate) {} |
| + |
| + private: |
| + float start_; |
| + float target_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Pause); |
| +}; |
| + |
| +} // namespace |
| + |
| +/* static */ |
| +LayerAnimationElement* LayerAnimationElement::CreateTransformElement( |
| + const Transform& transform, base::TimeDelta duration) { |
| + return new TransformTransition(transform, duration); |
| +} |
| + |
| +/* static */ |
| +LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( |
| + const gfx::Rect& bounds, base::TimeDelta duration) { |
| + return new BoundsTransition(bounds, duration); |
| +} |
| + |
| +/* static */ |
| +LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( |
| + float opacity, base::TimeDelta duration) { |
| + return new OpacityTransition(opacity, duration); |
| +} |
| + |
| +/* static */ |
| +LayerAnimationElement* LayerAnimationElement::CreatePauseElement( |
| + AnimatableProperty property, base::TimeDelta duration) { |
| + return new Pause(property, duration); |
| +} |
| + |
| +} // namespace ui |