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 #ifndef CC_TEST_ANIMATION_TEST_COMMON_H_
6 #define CC_TEST_ANIMATION_TEST_COMMON_H_
8 #include "cc/animation/animation.h"
9 #include "cc/animation/animation_curve.h"
10 #include "cc/animation/layer_animation_controller.h"
11 #include "cc/animation/layer_animation_value_observer.h"
12 #include "cc/animation/layer_animation_value_provider.h"
13 #include "cc/output/filter_operations.h"
14 #include "cc/test/geometry_test_utils.h"
23 class FakeFloatAnimationCurve
: public FloatAnimationCurve
{
25 FakeFloatAnimationCurve();
26 explicit FakeFloatAnimationCurve(double duration
);
27 virtual ~FakeFloatAnimationCurve();
29 virtual double Duration() const OVERRIDE
;
30 virtual float GetValue(double now
) const OVERRIDE
;
31 virtual scoped_ptr
<AnimationCurve
> Clone() const OVERRIDE
;
37 class FakeTransformTransition
: public TransformAnimationCurve
{
39 explicit FakeTransformTransition(double duration
);
40 virtual ~FakeTransformTransition();
42 virtual double Duration() const OVERRIDE
;
43 virtual gfx::Transform
GetValue(double time
) const OVERRIDE
;
44 virtual bool AnimatedBoundsForBox(const gfx::BoxF
& box
,
45 gfx::BoxF
* bounds
) const OVERRIDE
;
46 virtual bool AffectsScale() const OVERRIDE
;
47 virtual bool IsTranslation() const OVERRIDE
;
48 virtual bool MaximumScale(float* max_scale
) const OVERRIDE
;
50 virtual scoped_ptr
<AnimationCurve
> Clone() const OVERRIDE
;
56 class FakeFloatTransition
: public FloatAnimationCurve
{
58 FakeFloatTransition(double duration
, float from
, float to
);
59 virtual ~FakeFloatTransition();
61 virtual double Duration() const OVERRIDE
;
62 virtual float GetValue(double time
) const OVERRIDE
;
64 virtual scoped_ptr
<AnimationCurve
> Clone() const OVERRIDE
;
72 class FakeLayerAnimationValueObserver
: public LayerAnimationValueObserver
{
74 FakeLayerAnimationValueObserver();
75 virtual ~FakeLayerAnimationValueObserver();
77 // LayerAnimationValueObserver implementation
78 virtual void OnFilterAnimated(const FilterOperations
& filters
) OVERRIDE
;
79 virtual void OnOpacityAnimated(float opacity
) OVERRIDE
;
80 virtual void OnTransformAnimated(const gfx::Transform
& transform
) OVERRIDE
;
81 virtual void OnScrollOffsetAnimated(
82 const gfx::Vector2dF
& scroll_offset
) OVERRIDE
;
83 virtual void OnAnimationWaitingForDeletion() OVERRIDE
;
84 virtual bool IsActive() const OVERRIDE
;
86 const FilterOperations
& filters() const { return filters_
; }
87 float opacity() const { return opacity_
; }
88 const gfx::Transform
& transform() const { return transform_
; }
89 gfx::Vector2dF
scroll_offset() { return scroll_offset_
; }
91 bool animation_waiting_for_deletion() {
92 return animation_waiting_for_deletion_
;
96 FilterOperations filters_
;
98 gfx::Transform transform_
;
99 gfx::Vector2dF scroll_offset_
;
100 bool animation_waiting_for_deletion_
;
103 class FakeInactiveLayerAnimationValueObserver
104 : public FakeLayerAnimationValueObserver
{
106 virtual bool IsActive() const OVERRIDE
;
109 class FakeLayerAnimationValueProvider
: public LayerAnimationValueProvider
{
111 virtual gfx::Vector2dF
ScrollOffsetForAnimation() const OVERRIDE
;
113 void set_scroll_offset(const gfx::Vector2dF
& scroll_offset
) {
114 scroll_offset_
= scroll_offset
;
118 gfx::Vector2dF scroll_offset_
;
121 int AddOpacityTransitionToController(LayerAnimationController
* controller
,
125 bool use_timing_function
);
127 int AddAnimatedTransformToController(LayerAnimationController
* controller
,
132 int AddAnimatedFilterToController(LayerAnimationController
* controller
,
134 float start_brightness
,
135 float end_brightness
);
137 int AddOpacityTransitionToLayer(Layer
* layer
,
141 bool use_timing_function
);
143 int AddOpacityTransitionToLayer(LayerImpl
* layer
,
147 bool use_timing_function
);
149 int AddAnimatedTransformToLayer(Layer
* layer
,
154 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
159 int AddAnimatedTransformToLayer(Layer
* layer
,
161 TransformOperations start_operations
,
162 TransformOperations operations
);
164 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
166 TransformOperations start_operations
,
167 TransformOperations operations
);
169 int AddAnimatedFilterToLayer(Layer
* layer
,
171 float start_brightness
,
172 float end_brightness
);
174 int AddAnimatedFilterToLayer(LayerImpl
* layer
,
176 float start_brightness
,
177 float end_brightness
);
181 #endif // CC_TEST_ANIMATION_TEST_COMMON_H_