Make a copy of HttpResponseHeaders in StreamHandleImpl.
[chromium-blink-merge.git] / cc / test / animation_test_common.cc
blob404e161d880494164da9d9a50426c262939422d6
1 // Copyright 2012 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.
5 #include "cc/test/animation_test_common.h"
7 #include "cc/animation/animation_id_provider.h"
8 #include "cc/animation/keyframed_animation_curve.h"
9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/animation/transform_operations.h"
11 #include "cc/layers/layer.h"
12 #include "cc/layers/layer_impl.h"
14 using cc::Animation;
15 using cc::AnimationCurve;
16 using cc::EaseTimingFunction;
17 using cc::FloatKeyframe;
18 using cc::KeyframedFloatAnimationCurve;
19 using cc::KeyframedTransformAnimationCurve;
20 using cc::TimingFunction;
21 using cc::TransformKeyframe;
23 namespace cc {
25 template <class Target>
26 int AddOpacityTransition(Target* target,
27 double duration,
28 float start_opacity,
29 float end_opacity,
30 bool use_timing_function) {
31 scoped_ptr<KeyframedFloatAnimationCurve>
32 curve(KeyframedFloatAnimationCurve::Create());
34 scoped_ptr<TimingFunction> func;
35 if (!use_timing_function)
36 func = EaseTimingFunction::Create();
37 if (duration > 0.0)
38 curve->AddKeyframe(FloatKeyframe::Create(0.0, start_opacity, func.Pass()));
39 curve->AddKeyframe(FloatKeyframe::Create(
40 duration, end_opacity, scoped_ptr<TimingFunction>()));
42 int id = AnimationIdProvider::NextAnimationId();
44 scoped_ptr<Animation> animation(Animation::Create(
45 curve.PassAs<AnimationCurve>(),
46 id,
47 AnimationIdProvider::NextGroupId(),
48 Animation::Opacity));
49 animation->set_needs_synchronized_start_time(true);
51 target->AddAnimation(animation.Pass());
52 return id;
55 template <class Target>
56 int AddAnimatedTransform(Target* target,
57 double duration,
58 TransformOperations start_operations,
59 TransformOperations operations) {
60 scoped_ptr<KeyframedTransformAnimationCurve>
61 curve(KeyframedTransformAnimationCurve::Create());
63 if (duration > 0.0) {
64 curve->AddKeyframe(TransformKeyframe::Create(
65 0.0, start_operations, scoped_ptr<TimingFunction>()));
68 curve->AddKeyframe(TransformKeyframe::Create(
69 duration, operations, scoped_ptr<TimingFunction>()));
71 int id = AnimationIdProvider::NextAnimationId();
73 scoped_ptr<Animation> animation(Animation::Create(
74 curve.PassAs<AnimationCurve>(),
75 id,
76 AnimationIdProvider::NextGroupId(),
77 Animation::Transform));
78 animation->set_needs_synchronized_start_time(true);
80 target->AddAnimation(animation.Pass());
81 return id;
84 template <class Target>
85 int AddAnimatedTransform(Target* target,
86 double duration,
87 int delta_x,
88 int delta_y) {
89 TransformOperations start_operations;
90 if (duration > 0.0) {
91 start_operations.AppendTranslate(delta_x, delta_y, 0.0);
94 TransformOperations operations;
95 operations.AppendTranslate(delta_x, delta_y, 0.0);
96 return AddAnimatedTransform(target, duration, start_operations, operations);
99 template <class Target>
100 int AddAnimatedFilter(Target* target,
101 double duration,
102 float start_brightness,
103 float end_brightness) {
104 scoped_ptr<KeyframedFilterAnimationCurve>
105 curve(KeyframedFilterAnimationCurve::Create());
107 if (duration > 0.0) {
108 FilterOperations start_filters;
109 start_filters.Append(
110 FilterOperation::CreateBrightnessFilter(start_brightness));
111 curve->AddKeyframe(FilterKeyframe::Create(
112 0.0, start_filters, scoped_ptr<TimingFunction>()));
115 FilterOperations filters;
116 filters.Append(FilterOperation::CreateBrightnessFilter(end_brightness));
117 curve->AddKeyframe(
118 FilterKeyframe::Create(duration, filters, scoped_ptr<TimingFunction>()));
120 int id = AnimationIdProvider::NextAnimationId();
122 scoped_ptr<Animation> animation(Animation::Create(
123 curve.PassAs<AnimationCurve>(),
125 AnimationIdProvider::NextGroupId(),
126 Animation::Filter));
127 animation->set_needs_synchronized_start_time(true);
129 target->AddAnimation(animation.Pass());
130 return id;
133 FakeFloatAnimationCurve::FakeFloatAnimationCurve()
134 : duration_(1.0) {}
136 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration)
137 : duration_(duration) {}
139 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() {}
141 double FakeFloatAnimationCurve::Duration() const {
142 return duration_;
145 float FakeFloatAnimationCurve::GetValue(double now) const {
146 return 0.0f;
149 scoped_ptr<AnimationCurve> FakeFloatAnimationCurve::Clone() const {
150 return make_scoped_ptr(new FakeFloatAnimationCurve).PassAs<AnimationCurve>();
153 FakeTransformTransition::FakeTransformTransition(double duration)
154 : duration_(duration) {}
156 FakeTransformTransition::~FakeTransformTransition() {}
158 double FakeTransformTransition::Duration() const {
159 return duration_;
162 gfx::Transform FakeTransformTransition::GetValue(double time) const {
163 return gfx::Transform();
166 bool FakeTransformTransition::AnimatedBoundsForBox(const gfx::BoxF& box,
167 gfx::BoxF* bounds) const {
168 return false;
171 bool FakeTransformTransition::AffectsScale() const { return false; }
173 bool FakeTransformTransition::IsTranslation() const { return true; }
175 bool FakeTransformTransition::MaximumScale(float* max_scale) const {
176 *max_scale = 1.f;
177 return true;
180 scoped_ptr<AnimationCurve> FakeTransformTransition::Clone() const {
181 return make_scoped_ptr(new FakeTransformTransition(*this))
182 .PassAs<AnimationCurve>();
186 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to)
187 : duration_(duration), from_(from), to_(to) {}
189 FakeFloatTransition::~FakeFloatTransition() {}
191 double FakeFloatTransition::Duration() const {
192 return duration_;
195 float FakeFloatTransition::GetValue(double time) const {
196 time /= duration_;
197 if (time >= 1.0)
198 time = 1.0;
199 return (1.0 - time) * from_ + time * to_;
202 FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver()
203 : opacity_(0.0f),
204 animation_waiting_for_deletion_(false) {}
206 FakeLayerAnimationValueObserver::~FakeLayerAnimationValueObserver() {}
208 void FakeLayerAnimationValueObserver::OnFilterAnimated(
209 const FilterOperations& filters) {
210 filters_ = filters;
213 void FakeLayerAnimationValueObserver::OnOpacityAnimated(float opacity) {
214 opacity_ = opacity;
217 void FakeLayerAnimationValueObserver::OnTransformAnimated(
218 const gfx::Transform& transform) {
219 transform_ = transform;
222 void FakeLayerAnimationValueObserver::OnScrollOffsetAnimated(
223 const gfx::Vector2dF& scroll_offset) {
224 scroll_offset_ = scroll_offset;
227 void FakeLayerAnimationValueObserver::OnAnimationWaitingForDeletion() {
228 animation_waiting_for_deletion_ = true;
231 bool FakeLayerAnimationValueObserver::IsActive() const {
232 return true;
235 bool FakeInactiveLayerAnimationValueObserver::IsActive() const {
236 return false;
239 gfx::Vector2dF FakeLayerAnimationValueProvider::ScrollOffsetForAnimation()
240 const {
241 return scroll_offset_;
244 scoped_ptr<AnimationCurve> FakeFloatTransition::Clone() const {
245 return make_scoped_ptr(new FakeFloatTransition(*this))
246 .PassAs<AnimationCurve>();
249 int AddOpacityTransitionToController(LayerAnimationController* controller,
250 double duration,
251 float start_opacity,
252 float end_opacity,
253 bool use_timing_function) {
254 return AddOpacityTransition(controller,
255 duration,
256 start_opacity,
257 end_opacity,
258 use_timing_function);
261 int AddAnimatedTransformToController(LayerAnimationController* controller,
262 double duration,
263 int delta_x,
264 int delta_y) {
265 return AddAnimatedTransform(controller,
266 duration,
267 delta_x,
268 delta_y);
271 int AddAnimatedFilterToController(LayerAnimationController* controller,
272 double duration,
273 float start_brightness,
274 float end_brightness) {
275 return AddAnimatedFilter(
276 controller, duration, start_brightness, end_brightness);
279 int AddOpacityTransitionToLayer(Layer* layer,
280 double duration,
281 float start_opacity,
282 float end_opacity,
283 bool use_timing_function) {
284 return AddOpacityTransition(layer,
285 duration,
286 start_opacity,
287 end_opacity,
288 use_timing_function);
291 int AddOpacityTransitionToLayer(LayerImpl* layer,
292 double duration,
293 float start_opacity,
294 float end_opacity,
295 bool use_timing_function) {
296 return AddOpacityTransition(layer->layer_animation_controller(),
297 duration,
298 start_opacity,
299 end_opacity,
300 use_timing_function);
303 int AddAnimatedTransformToLayer(Layer* layer,
304 double duration,
305 int delta_x,
306 int delta_y) {
307 return AddAnimatedTransform(layer, duration, delta_x, delta_y);
310 int AddAnimatedTransformToLayer(LayerImpl* layer,
311 double duration,
312 int delta_x,
313 int delta_y) {
314 return AddAnimatedTransform(layer->layer_animation_controller(),
315 duration,
316 delta_x,
317 delta_y);
320 int AddAnimatedTransformToLayer(Layer* layer,
321 double duration,
322 TransformOperations start_operations,
323 TransformOperations operations) {
324 return AddAnimatedTransform(layer, duration, start_operations, operations);
327 int AddAnimatedTransformToLayer(LayerImpl* layer,
328 double duration,
329 TransformOperations start_operations,
330 TransformOperations operations) {
331 return AddAnimatedTransform(layer->layer_animation_controller(),
332 duration,
333 start_operations,
334 operations);
337 int AddAnimatedFilterToLayer(Layer* layer,
338 double duration,
339 float start_brightness,
340 float end_brightness) {
341 return AddAnimatedFilter(layer, duration, start_brightness, end_brightness);
344 int AddAnimatedFilterToLayer(LayerImpl* layer,
345 double duration,
346 float start_brightness,
347 float end_brightness) {
348 return AddAnimatedFilter(layer->layer_animation_controller(),
349 duration,
350 start_brightness,
351 end_brightness);
354 } // namespace cc