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