OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compositor/layer_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 start_transform.Rotate(-30.0); | 27 start_transform.Rotate(-30.0); |
28 target_transform.Rotate(30.0); | 28 target_transform.Rotate(30.0); |
29 base::TimeTicks start_time; | 29 base::TimeTicks start_time; |
30 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 30 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
31 | 31 |
32 scoped_ptr<LayerAnimationElement> element( | 32 scoped_ptr<LayerAnimationElement> element( |
33 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 33 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
34 | 34 |
35 for (int i = 0; i < 2; ++i) { | 35 for (int i = 0; i < 2; ++i) { |
36 start_time += delta; | 36 start_time += delta; |
37 element->set_start_time(start_time); | 37 element->set_requested_start_time(start_time); |
38 delegate.SetTransformFromAnimation(start_transform); | 38 delegate.SetTransformFromAnimation(start_transform); |
39 element->Progress(start_time, &delegate); | 39 element->Progress(start_time, &delegate); |
40 CheckApproximatelyEqual(start_transform, | 40 CheckApproximatelyEqual(start_transform, |
41 delegate.GetTransformForAnimation()); | 41 delegate.GetTransformForAnimation()); |
42 element->Progress(start_time + delta/2, &delegate); | 42 element->Progress(start_time + delta/2, &delegate); |
43 CheckApproximatelyEqual(middle_transform, | 43 CheckApproximatelyEqual(middle_transform, |
44 delegate.GetTransformForAnimation()); | 44 delegate.GetTransformForAnimation()); |
45 element->Progress(start_time + delta, &delegate); | 45 element->Progress(start_time + delta, &delegate); |
46 CheckApproximatelyEqual(target_transform, | 46 CheckApproximatelyEqual(target_transform, |
47 delegate.GetTransformForAnimation()); | 47 delegate.GetTransformForAnimation()); |
(...skipping 17 matching lines...) Expand all Loading... |
65 start.set_x(-90); | 65 start.set_x(-90); |
66 target.set_x(90); | 66 target.set_x(90); |
67 base::TimeTicks start_time; | 67 base::TimeTicks start_time; |
68 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 68 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
69 | 69 |
70 scoped_ptr<LayerAnimationElement> element( | 70 scoped_ptr<LayerAnimationElement> element( |
71 LayerAnimationElement::CreateBoundsElement(target, delta)); | 71 LayerAnimationElement::CreateBoundsElement(target, delta)); |
72 | 72 |
73 for (int i = 0; i < 2; ++i) { | 73 for (int i = 0; i < 2; ++i) { |
74 start_time += delta; | 74 start_time += delta; |
75 element->set_start_time(start_time); | 75 element->set_requested_start_time(start_time); |
76 delegate.SetBoundsFromAnimation(start); | 76 delegate.SetBoundsFromAnimation(start); |
77 element->Progress(start_time, &delegate); | 77 element->Progress(start_time, &delegate); |
78 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); | 78 CheckApproximatelyEqual(start, delegate.GetBoundsForAnimation()); |
79 element->Progress(start_time + delta/2, &delegate); | 79 element->Progress(start_time + delta/2, &delegate); |
80 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); | 80 CheckApproximatelyEqual(middle, delegate.GetBoundsForAnimation()); |
81 element->Progress(start_time + delta, &delegate); | 81 element->Progress(start_time + delta, &delegate); |
82 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); | 82 CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation()); |
83 } | 83 } |
84 | 84 |
85 LayerAnimationElement::TargetValue target_value(&delegate); | 85 LayerAnimationElement::TargetValue target_value(&delegate); |
(...skipping 12 matching lines...) Expand all Loading... |
98 float start = 0.0; | 98 float start = 0.0; |
99 float middle = 0.5; | 99 float middle = 0.5; |
100 float target = 1.0; | 100 float target = 1.0; |
101 base::TimeTicks start_time; | 101 base::TimeTicks start_time; |
102 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 102 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
103 scoped_ptr<LayerAnimationElement> element( | 103 scoped_ptr<LayerAnimationElement> element( |
104 LayerAnimationElement::CreateOpacityElement(target, delta)); | 104 LayerAnimationElement::CreateOpacityElement(target, delta)); |
105 | 105 |
106 for (int i = 0; i < 2; ++i) { | 106 for (int i = 0; i < 2; ++i) { |
107 start_time += delta; | 107 start_time += delta; |
108 element->set_start_time(start_time); | 108 element->set_requested_start_time(start_time); |
109 delegate.SetOpacityFromAnimation(start); | 109 delegate.SetOpacityFromAnimation(start); |
110 element->Progress(start_time, &delegate); | 110 element->Progress(start_time, &delegate); |
111 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); | 111 EXPECT_FLOAT_EQ(start, delegate.GetOpacityForAnimation()); |
112 element->Progress(start_time + delta/2, &delegate); | 112 element->Progress(start_time + delta/2, &delegate); |
113 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation()); | 113 EXPECT_FLOAT_EQ(middle, delegate.GetOpacityForAnimation()); |
114 element->Progress(start_time + delta, &delegate); | 114 element->Progress(start_time + delta, &delegate); |
115 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); | 115 EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation()); |
116 } | 116 } |
117 | 117 |
118 LayerAnimationElement::TargetValue target_value(&delegate); | 118 LayerAnimationElement::TargetValue target_value(&delegate); |
(...skipping 11 matching lines...) Expand all Loading... |
130 TestLayerAnimationDelegate delegate; | 130 TestLayerAnimationDelegate delegate; |
131 bool start = true; | 131 bool start = true; |
132 bool target = false; | 132 bool target = false; |
133 base::TimeTicks start_time; | 133 base::TimeTicks start_time; |
134 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 134 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
135 scoped_ptr<LayerAnimationElement> element( | 135 scoped_ptr<LayerAnimationElement> element( |
136 LayerAnimationElement::CreateVisibilityElement(target, delta)); | 136 LayerAnimationElement::CreateVisibilityElement(target, delta)); |
137 | 137 |
138 for (int i = 0; i < 2; ++i) { | 138 for (int i = 0; i < 2; ++i) { |
139 start_time += delta; | 139 start_time += delta; |
140 element->set_start_time(start_time); | 140 element->set_requested_start_time(start_time); |
141 delegate.SetVisibilityFromAnimation(start); | 141 delegate.SetVisibilityFromAnimation(start); |
142 element->Progress(start_time, &delegate); | 142 element->Progress(start_time, &delegate); |
143 EXPECT_TRUE(delegate.GetVisibilityForAnimation()); | 143 EXPECT_TRUE(delegate.GetVisibilityForAnimation()); |
144 element->Progress(start_time + delta/2, &delegate); | 144 element->Progress(start_time + delta/2, &delegate); |
145 EXPECT_TRUE(delegate.GetVisibilityForAnimation()); | 145 EXPECT_TRUE(delegate.GetVisibilityForAnimation()); |
146 element->Progress(start_time + delta, &delegate); | 146 element->Progress(start_time + delta, &delegate); |
147 EXPECT_FALSE(delegate.GetVisibilityForAnimation()); | 147 EXPECT_FALSE(delegate.GetVisibilityForAnimation()); |
148 } | 148 } |
149 | 149 |
150 LayerAnimationElement::TargetValue target_value(&delegate); | 150 LayerAnimationElement::TargetValue target_value(&delegate); |
(...skipping 12 matching lines...) Expand all Loading... |
163 float start = 0.0; | 163 float start = 0.0; |
164 float middle = 0.5; | 164 float middle = 0.5; |
165 float target = 1.0; | 165 float target = 1.0; |
166 base::TimeTicks start_time; | 166 base::TimeTicks start_time; |
167 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 167 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
168 scoped_ptr<LayerAnimationElement> element( | 168 scoped_ptr<LayerAnimationElement> element( |
169 LayerAnimationElement::CreateBrightnessElement(target, delta)); | 169 LayerAnimationElement::CreateBrightnessElement(target, delta)); |
170 | 170 |
171 for (int i = 0; i < 2; ++i) { | 171 for (int i = 0; i < 2; ++i) { |
172 start_time += delta; | 172 start_time += delta; |
173 element->set_start_time(start_time); | 173 element->set_requested_start_time(start_time); |
174 delegate.SetBrightnessFromAnimation(start); | 174 delegate.SetBrightnessFromAnimation(start); |
175 element->Progress(start_time, &delegate); | 175 element->Progress(start_time, &delegate); |
176 EXPECT_FLOAT_EQ(start, delegate.GetBrightnessForAnimation()); | 176 EXPECT_FLOAT_EQ(start, delegate.GetBrightnessForAnimation()); |
177 element->Progress(start_time + delta/2, &delegate); | 177 element->Progress(start_time + delta/2, &delegate); |
178 EXPECT_FLOAT_EQ(middle, delegate.GetBrightnessForAnimation()); | 178 EXPECT_FLOAT_EQ(middle, delegate.GetBrightnessForAnimation()); |
179 element->Progress(start_time + delta, &delegate); | 179 element->Progress(start_time + delta, &delegate); |
180 EXPECT_FLOAT_EQ(target, delegate.GetBrightnessForAnimation()); | 180 EXPECT_FLOAT_EQ(target, delegate.GetBrightnessForAnimation()); |
181 } | 181 } |
182 | 182 |
183 LayerAnimationElement::TargetValue target_value(&delegate); | 183 LayerAnimationElement::TargetValue target_value(&delegate); |
(...skipping 12 matching lines...) Expand all Loading... |
196 float start = 0.0; | 196 float start = 0.0; |
197 float middle = 0.5; | 197 float middle = 0.5; |
198 float target = 1.0; | 198 float target = 1.0; |
199 base::TimeTicks start_time; | 199 base::TimeTicks start_time; |
200 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 200 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
201 scoped_ptr<LayerAnimationElement> element( | 201 scoped_ptr<LayerAnimationElement> element( |
202 LayerAnimationElement::CreateGrayscaleElement(target, delta)); | 202 LayerAnimationElement::CreateGrayscaleElement(target, delta)); |
203 | 203 |
204 for (int i = 0; i < 2; ++i) { | 204 for (int i = 0; i < 2; ++i) { |
205 start_time += delta; | 205 start_time += delta; |
206 element->set_start_time(start_time); | 206 element->set_requested_start_time(start_time); |
207 delegate.SetGrayscaleFromAnimation(start); | 207 delegate.SetGrayscaleFromAnimation(start); |
208 element->Progress(start_time, &delegate); | 208 element->Progress(start_time, &delegate); |
209 EXPECT_FLOAT_EQ(start, delegate.GetGrayscaleForAnimation()); | 209 EXPECT_FLOAT_EQ(start, delegate.GetGrayscaleForAnimation()); |
210 element->Progress(start_time + delta/2, &delegate); | 210 element->Progress(start_time + delta/2, &delegate); |
211 EXPECT_FLOAT_EQ(middle, delegate.GetGrayscaleForAnimation()); | 211 EXPECT_FLOAT_EQ(middle, delegate.GetGrayscaleForAnimation()); |
212 element->Progress(start_time + delta, &delegate); | 212 element->Progress(start_time + delta, &delegate); |
213 EXPECT_FLOAT_EQ(target, delegate.GetGrayscaleForAnimation()); | 213 EXPECT_FLOAT_EQ(target, delegate.GetGrayscaleForAnimation()); |
214 } | 214 } |
215 | 215 |
216 LayerAnimationElement::TargetValue target_value(&delegate); | 216 LayerAnimationElement::TargetValue target_value(&delegate); |
(...skipping 17 matching lines...) Expand all Loading... |
234 base::TimeTicks start_time; | 234 base::TimeTicks start_time; |
235 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 235 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
236 | 236 |
237 scoped_ptr<LayerAnimationElement> element( | 237 scoped_ptr<LayerAnimationElement> element( |
238 LayerAnimationElement::CreatePauseElement(properties, delta)); | 238 LayerAnimationElement::CreatePauseElement(properties, delta)); |
239 | 239 |
240 TestLayerAnimationDelegate delegate; | 240 TestLayerAnimationDelegate delegate; |
241 TestLayerAnimationDelegate copy = delegate; | 241 TestLayerAnimationDelegate copy = delegate; |
242 | 242 |
243 start_time += delta; | 243 start_time += delta; |
244 element->set_start_time(start_time); | 244 element->set_requested_start_time(start_time); |
245 element->Progress(start_time + delta, &delegate); | 245 element->Progress(start_time + delta, &delegate); |
246 | 246 |
247 // Nothing should have changed. | 247 // Nothing should have changed. |
248 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | 248 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
249 copy.GetBoundsForAnimation()); | 249 copy.GetBoundsForAnimation()); |
250 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | 250 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
251 copy.GetTransformForAnimation()); | 251 copy.GetTransformForAnimation()); |
252 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | 252 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
253 copy.GetOpacityForAnimation()); | 253 copy.GetOpacityForAnimation()); |
254 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), | 254 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), |
255 copy.GetBrightnessForAnimation()); | 255 copy.GetBrightnessForAnimation()); |
256 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), | 256 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), |
257 copy.GetGrayscaleForAnimation()); | 257 copy.GetGrayscaleForAnimation()); |
258 | 258 |
259 // Pause should last for |delta|. | 259 // Pause should last for |delta|. |
260 base::TimeDelta element_duration; | 260 base::TimeDelta element_duration; |
261 EXPECT_TRUE(element->IsFinished(start_time + delta, &element_duration)); | 261 EXPECT_TRUE(element->IsFinished(start_time + delta, &element_duration)); |
262 EXPECT_EQ(delta, element_duration); | 262 EXPECT_EQ(delta, element_duration); |
263 } | 263 } |
264 | 264 |
265 } // namespace | 265 } // namespace |
266 | 266 |
267 } // namespace ui | 267 } // namespace ui |
OLD | NEW |