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 AnimationStartScale(bool forward_direction
,
50 float* start_scale
) const override
;
51 bool MaximumTargetScale(bool forward_direction
,
52 float* max_scale
) const override
;
54 scoped_ptr
<AnimationCurve
> Clone() const override
;
57 base::TimeDelta duration_
;
60 class FakeFloatTransition
: public FloatAnimationCurve
{
62 FakeFloatTransition(double duration
, float from
, float to
);
63 ~FakeFloatTransition() override
;
65 base::TimeDelta
Duration() const override
;
66 float GetValue(base::TimeDelta time
) const override
;
68 scoped_ptr
<AnimationCurve
> Clone() const override
;
71 base::TimeDelta duration_
;
76 class FakeLayerAnimationValueObserver
: public LayerAnimationValueObserver
{
78 FakeLayerAnimationValueObserver();
79 ~FakeLayerAnimationValueObserver() override
;
81 // LayerAnimationValueObserver implementation
82 void OnFilterAnimated(const FilterOperations
& filters
) override
;
83 void OnOpacityAnimated(float opacity
) override
;
84 void OnTransformAnimated(const gfx::Transform
& transform
) override
;
85 void OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) override
;
86 void OnAnimationWaitingForDeletion() override
;
87 bool IsActive() const override
;
89 const FilterOperations
& filters() const { return filters_
; }
90 float opacity() const { return opacity_
; }
91 const gfx::Transform
& transform() const { return transform_
; }
92 gfx::ScrollOffset
scroll_offset() { return scroll_offset_
; }
94 bool animation_waiting_for_deletion() {
95 return animation_waiting_for_deletion_
;
99 FilterOperations filters_
;
101 gfx::Transform transform_
;
102 gfx::ScrollOffset scroll_offset_
;
103 bool animation_waiting_for_deletion_
;
106 class FakeInactiveLayerAnimationValueObserver
107 : public FakeLayerAnimationValueObserver
{
109 bool IsActive() const override
;
112 class FakeLayerAnimationValueProvider
: public LayerAnimationValueProvider
{
114 gfx::ScrollOffset
ScrollOffsetForAnimation() const override
;
116 void set_scroll_offset(const gfx::ScrollOffset
& scroll_offset
) {
117 scroll_offset_
= scroll_offset
;
121 gfx::ScrollOffset scroll_offset_
;
124 int AddOpacityTransitionToController(LayerAnimationController
* controller
,
128 bool use_timing_function
);
130 int AddAnimatedTransformToController(LayerAnimationController
* controller
,
135 int AddAnimatedFilterToController(LayerAnimationController
* controller
,
137 float start_brightness
,
138 float end_brightness
);
140 int AddOpacityTransitionToLayer(Layer
* layer
,
144 bool use_timing_function
);
146 int AddOpacityTransitionToLayer(LayerImpl
* layer
,
150 bool use_timing_function
);
152 int AddAnimatedTransformToLayer(Layer
* layer
,
157 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
162 int AddAnimatedTransformToLayer(Layer
* layer
,
164 TransformOperations start_operations
,
165 TransformOperations operations
);
167 int AddAnimatedTransformToLayer(LayerImpl
* layer
,
169 TransformOperations start_operations
,
170 TransformOperations operations
);
172 int AddAnimatedFilterToLayer(Layer
* layer
,
174 float start_brightness
,
175 float end_brightness
);
177 int AddAnimatedFilterToLayer(LayerImpl
* layer
,
179 float start_brightness
,
180 float end_brightness
);
184 #endif // CC_TEST_ANIMATION_TEST_COMMON_H_