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 ~FakeFloatAnimationCurve() override
;
29 base::TimeDelta
Duration() const override
;
30 float GetValue(base::TimeDelta now
) const override
;
31 scoped_ptr
<AnimationCurve
> Clone() const override
;
34 base::TimeDelta duration_
;
37 class FakeTransformTransition
: public TransformAnimationCurve
{
39 explicit FakeTransformTransition(double duration
);
40 ~FakeTransformTransition() override
;
42 base::TimeDelta
Duration() const override
;
43 gfx::Transform
GetValue(base::TimeDelta time
) const override
;
44 bool AnimatedBoundsForBox(const gfx::BoxF
& box
,
45 gfx::BoxF
* bounds
) const override
;
46 bool AffectsScale() const override
;
47 bool IsTranslation() const override
;
48 bool PreservesAxisAlignment() const override
;
49 bool MaximumTargetScale(bool forward_direction
,
50 float* max_scale
) const override
;
52 scoped_ptr
<AnimationCurve
> Clone() const override
;
55 base::TimeDelta duration_
;
58 class FakeFloatTransition
: public FloatAnimationCurve
{
60 FakeFloatTransition(double duration
, float from
, float to
);
61 ~FakeFloatTransition() override
;
63 base::TimeDelta
Duration() const override
;
64 float GetValue(base::TimeDelta time
) const override
;
66 scoped_ptr
<AnimationCurve
> Clone() const override
;
69 base::TimeDelta duration_
;
74 class FakeLayerAnimationValueObserver
: public LayerAnimationValueObserver
{
76 FakeLayerAnimationValueObserver();
77 ~FakeLayerAnimationValueObserver() override
;
79 // LayerAnimationValueObserver implementation
80 void OnFilterAnimated(const FilterOperations
& filters
) override
;
81 void OnOpacityAnimated(float opacity
) override
;
82 void OnTransformAnimated(const gfx::Transform
& transform
) override
;
83 void OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) override
;
84 void OnAnimationWaitingForDeletion() override
;
85 bool IsActive() const override
;
87 const FilterOperations
& filters() const { return filters_
; }
88 float opacity() const { return opacity_
; }
89 const gfx::Transform
& transform() const { return transform_
; }
90 gfx::ScrollOffset
scroll_offset() { return scroll_offset_
; }
92 bool animation_waiting_for_deletion() {
93 return animation_waiting_for_deletion_
;
97 FilterOperations filters_
;
99 gfx::Transform transform_
;
100 gfx::ScrollOffset scroll_offset_
;
101 bool animation_waiting_for_deletion_
;
104 class FakeInactiveLayerAnimationValueObserver
105 : public FakeLayerAnimationValueObserver
{
107 bool IsActive() const override
;
110 class FakeLayerAnimationValueProvider
: public LayerAnimationValueProvider
{
112 gfx::ScrollOffset
ScrollOffsetForAnimation() const override
;
114 void set_scroll_offset(const gfx::ScrollOffset
& scroll_offset
) {
115 scroll_offset_
= scroll_offset
;
119 gfx::ScrollOffset scroll_offset_
;
122 int AddOpacityTransitionToController(LayerAnimationController
* controller
,
126 bool use_timing_function
);
128 int AddAnimatedTransformToController(LayerAnimationController
* controller
,
133 int AddAnimatedFilterToController(LayerAnimationController
* controller
,
135 float start_brightness
,
136 float end_brightness
);
138 int AddOpacityTransitionToLayer(Layer
* layer
,
142 bool use_timing_function
);
144 int AddOpacityTransitionToLayer(LayerImpl
* layer
,
148 bool use_timing_function
);
150 int AddAnimatedTransformToLayer(Layer
* layer
,
155 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
160 int AddAnimatedTransformToLayer(Layer
* layer
,
162 TransformOperations start_operations
,
163 TransformOperations operations
);
165 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
167 TransformOperations start_operations
,
168 TransformOperations operations
);
170 int AddAnimatedFilterToLayer(Layer
* layer
,
172 float start_brightness
,
173 float end_brightness
);
175 int AddAnimatedFilterToLayer(LayerImpl
* layer
,
177 float start_brightness
,
178 float end_brightness
);
182 #endif // CC_TEST_ANIMATION_TEST_COMMON_H_