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"
17 class AnimationPlayer
;
24 class FakeFloatAnimationCurve
: public FloatAnimationCurve
{
26 FakeFloatAnimationCurve();
27 explicit FakeFloatAnimationCurve(double duration
);
28 ~FakeFloatAnimationCurve() override
;
30 base::TimeDelta
Duration() const override
;
31 float GetValue(base::TimeDelta now
) const override
;
32 scoped_ptr
<AnimationCurve
> Clone() const override
;
35 base::TimeDelta duration_
;
38 class FakeTransformTransition
: public TransformAnimationCurve
{
40 explicit FakeTransformTransition(double duration
);
41 ~FakeTransformTransition() override
;
43 base::TimeDelta
Duration() const override
;
44 gfx::Transform
GetValue(base::TimeDelta time
) const override
;
45 bool AnimatedBoundsForBox(const gfx::BoxF
& box
,
46 gfx::BoxF
* bounds
) const override
;
47 bool AffectsScale() const override
;
48 bool IsTranslation() const override
;
49 bool PreservesAxisAlignment() const override
;
50 bool AnimationStartScale(bool forward_direction
,
51 float* start_scale
) const override
;
52 bool MaximumTargetScale(bool forward_direction
,
53 float* max_scale
) const override
;
55 scoped_ptr
<AnimationCurve
> Clone() const override
;
58 base::TimeDelta duration_
;
61 class FakeFloatTransition
: public FloatAnimationCurve
{
63 FakeFloatTransition(double duration
, float from
, float to
);
64 ~FakeFloatTransition() override
;
66 base::TimeDelta
Duration() const override
;
67 float GetValue(base::TimeDelta time
) const override
;
69 scoped_ptr
<AnimationCurve
> Clone() const override
;
72 base::TimeDelta duration_
;
77 class FakeLayerAnimationValueObserver
: public LayerAnimationValueObserver
{
79 FakeLayerAnimationValueObserver();
80 ~FakeLayerAnimationValueObserver() override
;
82 // LayerAnimationValueObserver implementation
83 void OnFilterAnimated(const FilterOperations
& filters
) override
;
84 void OnOpacityAnimated(float opacity
) override
;
85 void OnTransformAnimated(const gfx::Transform
& transform
) override
;
86 void OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) override
;
87 void OnAnimationWaitingForDeletion() override
;
88 void OnTransformIsPotentiallyAnimatingChanged(bool is_animating
) override
;
89 bool IsActive() const override
;
91 const FilterOperations
& filters() const { return filters_
; }
92 float opacity() const { return opacity_
; }
93 const gfx::Transform
& transform() const { return transform_
; }
94 gfx::ScrollOffset
scroll_offset() { return scroll_offset_
; }
96 bool animation_waiting_for_deletion() {
97 return animation_waiting_for_deletion_
;
100 bool transform_is_animating() { return transform_is_animating_
; }
103 FilterOperations filters_
;
105 gfx::Transform transform_
;
106 gfx::ScrollOffset scroll_offset_
;
107 bool animation_waiting_for_deletion_
;
108 bool transform_is_animating_
;
111 class FakeInactiveLayerAnimationValueObserver
112 : public FakeLayerAnimationValueObserver
{
114 bool IsActive() const override
;
117 class FakeLayerAnimationValueProvider
: public LayerAnimationValueProvider
{
119 gfx::ScrollOffset
ScrollOffsetForAnimation() const override
;
121 void set_scroll_offset(const gfx::ScrollOffset
& scroll_offset
) {
122 scroll_offset_
= scroll_offset
;
126 gfx::ScrollOffset scroll_offset_
;
129 int AddOpacityTransitionToController(LayerAnimationController
* controller
,
133 bool use_timing_function
);
135 int AddAnimatedTransformToController(LayerAnimationController
* controller
,
140 int AddAnimatedFilterToController(LayerAnimationController
* controller
,
142 float start_brightness
,
143 float end_brightness
);
145 int AddOpacityTransitionToLayer(Layer
* layer
,
149 bool use_timing_function
);
151 int AddOpacityTransitionToLayer(LayerImpl
* layer
,
155 bool use_timing_function
);
157 int AddAnimatedTransformToLayer(Layer
* layer
,
162 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
167 int AddAnimatedTransformToLayer(Layer
* layer
,
169 TransformOperations start_operations
,
170 TransformOperations operations
);
172 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
174 TransformOperations start_operations
,
175 TransformOperations operations
);
177 int AddAnimatedFilterToLayer(Layer
* layer
,
179 float start_brightness
,
180 float end_brightness
);
182 int AddAnimatedFilterToLayer(LayerImpl
* layer
,
184 float start_brightness
,
185 float end_brightness
);
187 int AddAnimatedTransformToPlayer(AnimationPlayer
* player
,
192 int AddOpacityTransitionToPlayer(AnimationPlayer
* player
,
196 bool use_timing_function
);
198 int AddAnimatedFilterToPlayer(AnimationPlayer
* player
,
200 float start_brightness
,
201 float end_brightness
);
203 int AddOpacityStepsToController(LayerAnimationController
* target
,
211 #endif // CC_TEST_ANIMATION_TEST_COMMON_H_