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