OLD | NEW |
---|---|
(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 class Pause : public LayerAnimationElement { | |
18 public: | |
19 Pause(const AnimatableProperties& properties, base::TimeDelta duration) | |
20 : properties_(properties), | |
21 duration_(duration) { | |
22 } | |
23 | |
24 virtual ~Pause() {} | |
25 | |
26 private: | |
27 virtual void Progress(double t, LayerAnimationDelegate* delegate) OVERRIDE {} | |
28 | |
29 virtual void Abort() OVERRIDE {} | |
30 | |
31 virtual const AnimatableProperties& Properties() const OVERRIDE { | |
32 return properties_; | |
33 } | |
34 | |
35 virtual base::TimeDelta Duration() const OVERRIDE { | |
36 return duration_; | |
37 } | |
38 | |
39 AnimatableProperties properties_; | |
sky
2011/10/19 00:06:33
As mentioned, promote these to LayerAnimationEleme
| |
40 base::TimeDelta duration_; | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(Pause); | |
43 }; | |
44 | |
45 class TransitionBase : public LayerAnimationElement { | |
sky
2011/10/19 00:06:33
Add a description of this class. Maybe it should b
| |
46 public: | |
47 TransitionBase(LayerAnimationElement::AnimatableProperty property, | |
48 base::TimeDelta duration) | |
49 : first_frame_(true), | |
50 duration_(duration) { | |
51 properties_.insert(property); | |
52 } | |
53 | |
54 virtual ~TransitionBase() {} | |
55 | |
56 protected: | |
57 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) = 0; | |
58 bool first_frame() const { return first_frame_; } | |
sky
2011/10/19 00:06:33
Add a description.
| |
59 | |
60 private: | |
61 virtual void Progress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | |
62 OnProgress(t, delegate); | |
sky
2011/10/19 00:06:33
It looks like all subclasses care about OnProgress
| |
63 delegate->ScheduleDrawForAnimation(); | |
64 first_frame_ = t == 1.0; // when we've completed, reset to first frame. | |
65 } | |
66 | |
67 virtual void Abort() OVERRIDE { | |
68 // reset. | |
69 first_frame_ = true; | |
70 } | |
71 | |
72 virtual const AnimatableProperties& Properties() const OVERRIDE { | |
73 return properties_; | |
74 } | |
75 | |
76 virtual base::TimeDelta Duration() const OVERRIDE { | |
77 return duration_; | |
78 } | |
79 | |
80 bool first_frame_; | |
81 AnimatableProperties properties_; | |
82 base::TimeDelta duration_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(TransitionBase); | |
85 }; | |
86 | |
87 class TransformTransition : public TransitionBase { | |
88 public: | |
89 TransformTransition(const Transform& target, base::TimeDelta duration) | |
90 : TransitionBase(LayerAnimationElement::TRANSFORM, duration), | |
91 target_(target) { | |
92 } | |
93 virtual ~TransformTransition() {} | |
94 | |
95 protected: | |
96 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | |
97 if (first_frame()) | |
98 start_ = delegate->GetTransformForAnimation(); | |
99 delegate->SetTransformFromAnimation( | |
100 Tween::ValueBetween(t, start_, target_)); | |
101 } | |
102 | |
103 private: | |
104 Transform start_; | |
105 Transform target_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(TransformTransition); | |
108 }; | |
109 | |
110 class BoundsTransition : public TransitionBase { | |
111 public: | |
112 BoundsTransition(const gfx::Rect& target, base::TimeDelta duration) | |
113 : TransitionBase(LayerAnimationElement::BOUNDS, duration), | |
114 target_(target) { | |
115 } | |
116 virtual ~BoundsTransition() {} | |
117 | |
118 protected: | |
119 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | |
120 if (first_frame()) | |
121 start_ = delegate->GetBoundsForAnimation(); | |
122 delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_)); | |
123 } | |
124 | |
125 private: | |
126 gfx::Rect start_; | |
127 gfx::Rect target_; | |
128 }; | |
sky
2011/10/19 00:06:33
DISALLOW_COPY_AND_ASSIGN
| |
129 | |
130 class OpacityTransition : public TransitionBase { | |
131 public: | |
132 OpacityTransition(float target, base::TimeDelta duration) | |
133 : TransitionBase(LayerAnimationElement::OPACITY, duration), | |
134 target_(target) { | |
135 } | |
136 virtual ~OpacityTransition() {} | |
137 | |
138 protected: | |
139 virtual void OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { | |
140 if (first_frame()) | |
141 start_ = delegate->GetOpacityForAnimation(); | |
142 delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_)); | |
143 } | |
144 | |
145 private: | |
146 float start_; | |
147 float target_; | |
148 | |
149 DISALLOW_COPY_AND_ASSIGN(OpacityTransition); | |
150 }; | |
151 | |
152 } // namespace | |
153 | |
154 /* static */ | |
155 LayerAnimationElement* LayerAnimationElement::CreateTransformElement( | |
156 const Transform& transform, base::TimeDelta duration) { | |
157 return new TransformTransition(transform, duration); | |
158 } | |
159 | |
160 /* static */ | |
161 LayerAnimationElement* LayerAnimationElement::CreateBoundsElement( | |
162 const gfx::Rect& bounds, base::TimeDelta duration) { | |
163 return new BoundsTransition(bounds, duration); | |
164 } | |
165 | |
166 /* static */ | |
167 LayerAnimationElement* LayerAnimationElement::CreateOpacityElement( | |
168 float opacity, base::TimeDelta duration) { | |
169 return new OpacityTransition(opacity, duration); | |
170 } | |
171 | |
172 /* static */ | |
173 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( | |
174 const AnimatableProperties& properties, base::TimeDelta duration) { | |
175 return new Pause(properties, duration); | |
176 } | |
177 | |
178 } // namespace ui | |
OLD | NEW |