• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CC_TEST_ANIMATION_TEST_COMMON_H_
6 #define CC_TEST_ANIMATION_TEST_COMMON_H_
7 
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"
15 
16 namespace cc {
17 class LayerImpl;
18 class Layer;
19 }
20 
21 namespace cc {
22 
23 class FakeFloatAnimationCurve : public FloatAnimationCurve {
24  public:
25   FakeFloatAnimationCurve();
26   explicit FakeFloatAnimationCurve(double duration);
27   virtual ~FakeFloatAnimationCurve();
28 
29   virtual double Duration() const OVERRIDE;
30   virtual float GetValue(double now) const OVERRIDE;
31   virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
32 
33  private:
34   double duration_;
35 };
36 
37 class FakeTransformTransition : public TransformAnimationCurve {
38  public:
39   explicit FakeTransformTransition(double duration);
40   virtual ~FakeTransformTransition();
41 
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 
47   virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
48 
49  private:
50   double duration_;
51 };
52 
53 class FakeFloatTransition : public FloatAnimationCurve {
54  public:
55   FakeFloatTransition(double duration, float from, float to);
56   virtual ~FakeFloatTransition();
57 
58   virtual double Duration() const OVERRIDE;
59   virtual float GetValue(double time) const OVERRIDE;
60 
61   virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
62 
63  private:
64   double duration_;
65   float from_;
66   float to_;
67 };
68 
69 class FakeLayerAnimationValueObserver : public LayerAnimationValueObserver {
70  public:
71   FakeLayerAnimationValueObserver();
72   virtual ~FakeLayerAnimationValueObserver();
73 
74   // LayerAnimationValueObserver implementation
75   virtual void OnFilterAnimated(const FilterOperations& filters) OVERRIDE;
76   virtual void OnOpacityAnimated(float opacity) OVERRIDE;
77   virtual void OnTransformAnimated(const gfx::Transform& transform) OVERRIDE;
78   virtual void OnScrollOffsetAnimated(gfx::Vector2dF scroll_offset) OVERRIDE;
79   virtual void OnAnimationWaitingForDeletion() OVERRIDE;
80   virtual bool IsActive() const OVERRIDE;
81 
filters()82   const FilterOperations& filters() const { return filters_; }
opacity()83   float opacity() const  { return opacity_; }
transform()84   const gfx::Transform& transform() const { return transform_; }
scroll_offset()85   gfx::Vector2dF scroll_offset() { return scroll_offset_; }
86 
animation_waiting_for_deletion()87   bool animation_waiting_for_deletion() {
88     return animation_waiting_for_deletion_;
89   }
90 
91  private:
92   FilterOperations filters_;
93   float opacity_;
94   gfx::Transform transform_;
95   gfx::Vector2dF scroll_offset_;
96   bool animation_waiting_for_deletion_;
97 };
98 
99 class FakeInactiveLayerAnimationValueObserver
100     : public FakeLayerAnimationValueObserver {
101  public:
102   virtual bool IsActive() const OVERRIDE;
103 };
104 
105 class FakeLayerAnimationValueProvider : public LayerAnimationValueProvider {
106  public:
107   virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE;
108 
set_scroll_offset(gfx::Vector2dF scroll_offset)109   void set_scroll_offset(gfx::Vector2dF scroll_offset) {
110     scroll_offset_ = scroll_offset;
111   }
112 
113  private:
114   gfx::Vector2dF scroll_offset_;
115 };
116 
117 int AddOpacityTransitionToController(LayerAnimationController* controller,
118                                      double duration,
119                                      float start_opacity,
120                                      float end_opacity,
121                                      bool use_timing_function);
122 
123 int AddAnimatedTransformToController(LayerAnimationController* controller,
124                                      double duration,
125                                      int delta_x,
126                                      int delta_y);
127 
128 int AddAnimatedFilterToController(LayerAnimationController* controller,
129                                   double duration,
130                                   float start_brightness,
131                                   float end_brightness);
132 
133 int AddOpacityTransitionToLayer(Layer* layer,
134                                 double duration,
135                                 float start_opacity,
136                                 float end_opacity,
137                                 bool use_timing_function);
138 
139 int AddOpacityTransitionToLayer(LayerImpl* layer,
140                                 double duration,
141                                 float start_opacity,
142                                 float end_opacity,
143                                 bool use_timing_function);
144 
145 int AddAnimatedTransformToLayer(Layer* layer,
146                                 double duration,
147                                 int delta_x,
148                                 int delta_y);
149 
150 int AddAnimatedTransformToLayer(LayerImpl* layer,
151                                 double duration,
152                                 int delta_x,
153                                 int delta_y);
154 
155 int AddAnimatedFilterToLayer(Layer* layer,
156                              double duration,
157                              float start_brightness,
158                              float end_brightness);
159 
160 int AddAnimatedFilterToLayer(LayerImpl* layer,
161                              double duration,
162                              float start_brightness,
163                              float end_brightness);
164 
165 }  // namespace cc
166 
167 #endif  // CC_TEST_ANIMATION_TEST_COMMON_H_
168