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

Side by Side 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: Fix VS2010 Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/compositor/layer_animation_element.h"
6
7 #include "base/compiler_specific.h"
8 #include "ui/base/animation/tween.h"
9 #include "ui/gfx/compositor/layer_animation_delegate.h"
10 #include "ui/gfx/rect.h"
11 #include "ui/gfx/transform.h"
12
13 namespace ui {
14
15 namespace {
16
17 // Pause -----------------------------------------------------------------------
18 class Pause : public LayerAnimationElement {
19 public:
20 Pause(const AnimatableProperties& properties, base::TimeDelta duration)
21 : LayerAnimationElement(properties, duration) {
22 }
23 virtual ~Pause() {}
24
25 private:
26 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {}
27 virtual void OnProgress(double t,
28 LayerAnimationDelegate* delegate) OVERRIDE {}
29 virtual void OnAbort() OVERRIDE {}
30
31 DISALLOW_COPY_AND_ASSIGN(Pause);
32 };
33
34 // TransformTransition ---------------------------------------------------------
35
36 class TransformTransition : public LayerAnimationElement {
37 public:
38 TransformTransition(const Transform& target, base::TimeDelta duration)
39 : LayerAnimationElement(GetProperties(), duration),
40 target_(target) {
41 }
42 virtual ~TransformTransition() {}
43
44 protected:
45 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
46 start_ = delegate->GetTransformForAnimation();
47 }
48
49 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
50 delegate->SetTransformFromAnimation(
51 Tween::ValueBetween(t, start_, target_));
52 }
53
54 virtual void OnAbort() OVERRIDE {}
55
56 private:
57 static const AnimatableProperties& GetProperties() {
58 static AnimatableProperties properties;
59 if (properties.size() == 0)
60 properties.insert(LayerAnimationElement::TRANSFORM);
61 return properties;
62 }
63
64 Transform start_;
65 const Transform target_;
66
67 DISALLOW_COPY_AND_ASSIGN(TransformTransition);
68 };
69
70 // BoundsTransition ------------------------------------------------------------
71
72 class BoundsTransition : public LayerAnimationElement {
73 public:
74 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration)
75 : LayerAnimationElement(GetProperties(), duration),
76 target_(target) {
77 }
78 virtual ~BoundsTransition() {}
79
80 protected:
81 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
82 start_ = delegate->GetBoundsForAnimation();
83 }
84
85 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
86 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_));
87 }
88
89 virtual void OnAbort() OVERRIDE {}
90
91 private:
92 static const AnimatableProperties& GetProperties() {
93 static AnimatableProperties properties;
94 if (properties.size() == 0)
95 properties.insert(LayerAnimationElement::BOUNDS);
96 return properties;
97 }
98
99 gfx::Rect start_;
100 const gfx::Rect target_;
101
102 DISALLOW_COPY_AND_ASSIGN(BoundsTransition);
103 };
104
105 class OpacityTransition : public LayerAnimationElement {
106 public:
107 OpacityTransition(float target, base::TimeDelta duration)
108 : LayerAnimationElement(GetProperties(), duration),
109 target_(target) {
110 }
111 virtual ~OpacityTransition() {}
112
113 protected:
114 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {
115 start_ = delegate->GetOpacityForAnimation();
116 }
117
118 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE {
119 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_));
120 }
121
122 virtual void OnAbort() OVERRIDE {}
123
124 private:
125 static const AnimatableProperties& GetProperties() {
126 static AnimatableProperties properties;
127 if (properties.size() == 0)
128 properties.insert(LayerAnimationElement::OPACITY);
129 return properties;
130 }
131
132 float start_;
133 const float target_;
134
135 DISALLOW_COPY_AND_ASSIGN(OpacityTransition);
136 };
137
138 } // namespace
139
140 // LayerAnimationElement -------------------------------------------------------
141
142 LayerAnimationElement::LayerAnimationElement(
143 const AnimatableProperties& properties,
144 base::TimeDelta duration)
145 : first_frame_(true),
146 properties_(properties),
147 duration_(duration) {
148 }
149
150 LayerAnimationElement::~LayerAnimationElement() {
151 }
152
153 void LayerAnimationElement::Progress(double t,
154 LayerAnimationDelegate* delegate) {
155 if (first_frame_)
156 OnStart(delegate);
157 OnProgress(t, delegate);
158 first_frame_ = t == 1.0;
159 }
160
161 void LayerAnimationElement::Abort() {
162 first_frame_ = true;
163 OnAbort();
164 }
165
166 // static
167 LayerAnimationElement* LayerAnimationElement::CreateTransformElement(
168 const Transform& transform, base::TimeDelta duration) {
169 return new TransformTransition(transform, duration);
170 }
171
172 // static
173 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement(
174 const gfx::Rect& bounds, base::TimeDelta duration) {
175 return new BoundsTransition(bounds, duration);
176 }
177
178 // static
179 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement(
180 float opacity, base::TimeDelta duration) {
181 return new OpacityTransition(opacity, duration);
182 }
183
184 // static
185 LayerAnimationElement* LayerAnimationElement::CreatePauseElement(
186 const AnimatableProperties& properties, base::TimeDelta duration) {
187 return new Pause(properties, duration);
188 }
189
190 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_animation_element.h ('k') | ui/gfx/compositor/layer_animation_element_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698