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..fb52bbb3c14c5829091fb7a1af0f17a8dae6e3ec |
--- /dev/null |
+++ b/ui/gfx/compositor/layer_animation_element.cc |
@@ -0,0 +1,190 @@ |
+// 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 "base/compiler_specific.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 { |
+ |
+// Pause ----------------------------------------------------------------------- |
+class Pause : public LayerAnimationElement { |
+ public: |
+ Pause(const AnimatableProperties& properties, base::TimeDelta duration) |
+ : LayerAnimationElement(properties, duration) { |
+ } |
+ virtual ~Pause() {} |
+ |
+ private: |
+ virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {} |
+ virtual void OnProgress(double t, |
+ LayerAnimationDelegate* delegate) OVERRIDE {} |
+ virtual void OnAbort() OVERRIDE {} |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Pause); |
+}; |
+ |
+// TransformTransition --------------------------------------------------------- |
+ |
+class TransformTransition : public LayerAnimationElement { |
+ public: |
+ TransformTransition(const Transform& target, base::TimeDelta duration) |
+ : LayerAnimationElement(GetProperties(), duration), |
+ target_(target) { |
+ } |
+ virtual ~TransformTransition() {} |
+ |
+ protected: |
+ virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
+ start_ = delegate->GetTransformForAnimation(); |
+ } |
+ |
+ virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
+ delegate->SetTransformFromAnimation( |
+ Tween::ValueBetween(t, start_, target_)); |
+ } |
+ |
+ virtual void OnAbort() OVERRIDE {} |
+ |
+ private: |
+ static const AnimatableProperties& GetProperties() { |
+ static AnimatableProperties properties; |
+ if (properties.size() == 0) |
+ properties.insert(LayerAnimationElement::TRANSFORM); |
+ return properties; |
+ } |
+ |
+ Transform start_; |
+ const Transform target_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TransformTransition); |
+}; |
+ |
+// BoundsTransition ------------------------------------------------------------ |
+ |
+class BoundsTransition : public LayerAnimationElement { |
+ public: |
+ BoundsTransition(const gfx::Rect& target, base::TimeDelta duration) |
+ : LayerAnimationElement(GetProperties(), duration), |
+ target_(target) { |
+ } |
+ virtual ~BoundsTransition() {} |
+ |
+ protected: |
+ virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
+ start_ = delegate->GetBoundsForAnimation(); |
+ } |
+ |
+ virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
+ delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); |
+ } |
+ |
+ virtual void OnAbort() OVERRIDE {} |
+ |
+ private: |
+ static const AnimatableProperties& GetProperties() { |
+ static AnimatableProperties properties; |
+ if (properties.size() == 0) |
+ properties.insert(LayerAnimationElement::BOUNDS); |
+ return properties; |
+ } |
+ |
+ gfx::Rect start_; |
+ const gfx::Rect target_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BoundsTransition); |
+}; |
+ |
+class OpacityTransition : public LayerAnimationElement { |
+ public: |
+ OpacityTransition(float target, base::TimeDelta duration) |
+ : LayerAnimationElement(GetProperties(), duration), |
+ target_(target) { |
+ } |
+ virtual ~OpacityTransition() {} |
+ |
+ protected: |
+ virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
+ start_ = delegate->GetOpacityForAnimation(); |
+ } |
+ |
+ virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
+ delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); |
+ } |
+ |
+ virtual void OnAbort() OVERRIDE {} |
+ |
+ private: |
+ static const AnimatableProperties& GetProperties() { |
+ static AnimatableProperties properties; |
+ if (properties.size() == 0) |
+ properties.insert(LayerAnimationElement::OPACITY); |
+ return properties; |
+ } |
+ |
+ float start_; |
+ const float target_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OpacityTransition); |
+}; |
+ |
+} // namespace |
+ |
+// LayerAnimationElement ------------------------------------------------------- |
+ |
+LayerAnimationElement::LayerAnimationElement( |
+ const AnimatableProperties& properties, |
+ base::TimeDelta duration) |
+ : first_frame_(true), |
+ properties_(properties), |
+ duration_(duration) { |
+} |
+ |
+LayerAnimationElement::~LayerAnimationElement() { |
+} |
+ |
+void LayerAnimationElement::Progress(double t, |
+ LayerAnimationDelegate* delegate) { |
+ if (first_frame_) |
+ OnStart(delegate); |
+ OnProgress(t, delegate); |
+ first_frame_ = t == 1.0; |
+} |
+ |
+void LayerAnimationElement::Abort() { |
+ first_frame_ = true; |
+ OnAbort(); |
+} |
+ |
+// 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( |
+ const AnimatableProperties& properties, base::TimeDelta duration) { |
+ return new Pause(properties, duration); |
+} |
+ |
+} // namespace ui |