Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: ui/gfx/compositor/layer_animation_element.cc

Issue 8247009: Explicit animation support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added new preemption strategy: replace queued animations. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5b83150cbd5eb936c0f9fd2e0bdca0e423f57cd4
--- /dev/null
+++ b/ui/gfx/compositor/layer_animation_element.cc
@@ -0,0 +1,178 @@
+// 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 {
+
+class Pause : public LayerAnimationElement {
+ public:
+ Pause(const AnimatableProperties& properties, base::TimeDelta duration)
+ : properties_(properties),
+ duration_(duration) {
+ }
+
+ virtual ~Pause() {}
+
+ private:
+ virtual void Progress(double t, LayerAnimationDelegate* delegate) OVERRIDE {}
+
+ virtual void Abort() OVERRIDE {}
+
+ virtual const AnimatableProperties& Properties() const OVERRIDE {
+ return properties_;
+ }
+
+ virtual base::TimeDelta Duration() const OVERRIDE {
+ return duration_;
+ }
+
+ AnimatableProperties properties_;
sky 2011/10/19 00:06:33 As mentioned, promote these to LayerAnimationEleme
+ base::TimeDelta duration_;
+
+ DISALLOW_COPY_AND_ASSIGN(Pause);
+};
+
+class TransitionBase : public LayerAnimationElement {
sky 2011/10/19 00:06:33 Add a description of this class. Maybe it should b
+ 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_; }
sky 2011/10/19 00:06:33 Add a description.
+
+ private:
+ virtual void Progress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
+ OnProgress(t, delegate);
sky 2011/10/19 00:06:33 It looks like all subclasses care about OnProgress
+ delegate->ScheduleDrawForAnimation();
+ first_frame_ = t == 1.0; // when we've completed, reset to first frame.
+ }
+
+ virtual void Abort() OVERRIDE {
+ // reset.
+ first_frame_ = true;
+ }
+
+ virtual const AnimatableProperties& Properties() const OVERRIDE {
+ return properties_;
+ }
+
+ virtual base::TimeDelta Duration() const OVERRIDE {
+ 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) OVERRIDE {
+ 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) OVERRIDE {
+ if (first_frame())
+ start_ = delegate->GetBoundsForAnimation();
+ delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_));
+ }
+
+ private:
+ gfx::Rect start_;
+ gfx::Rect target_;
+};
sky 2011/10/19 00:06:33 DISALLOW_COPY_AND_ASSIGN
+
+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) OVERRIDE {
+ if (first_frame())
+ start_ = delegate->GetOpacityForAnimation();
+ delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_));
+ }
+
+ private:
+ float start_;
+ float target_;
+
+ DISALLOW_COPY_AND_ASSIGN(OpacityTransition);
+};
+
+} // 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(
+ const AnimatableProperties& properties, base::TimeDelta duration) {
+ return new Pause(properties, duration);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698