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 virtual bool AffectsScale() const OVERRIDE; 47 virtual bool IsTranslation() const OVERRIDE; 48 virtual bool MaximumScale(float* max_scale) const OVERRIDE; 49 50 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE; 51 52 private: 53 double duration_; 54 }; 55 56 class FakeFloatTransition : public FloatAnimationCurve { 57 public: 58 FakeFloatTransition(double duration, float from, float to); 59 virtual ~FakeFloatTransition(); 60 61 virtual double Duration() const OVERRIDE; 62 virtual float GetValue(double time) const OVERRIDE; 63 64 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE; 65 66 private: 67 double duration_; 68 float from_; 69 float to_; 70 }; 71 72 class FakeLayerAnimationValueObserver : public LayerAnimationValueObserver { 73 public: 74 FakeLayerAnimationValueObserver(); 75 virtual ~FakeLayerAnimationValueObserver(); 76 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; 85 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_; } 90 91 bool animation_waiting_for_deletion() { 92 return animation_waiting_for_deletion_; 93 } 94 95 private: 96 FilterOperations filters_; 97 float opacity_; 98 gfx::Transform transform_; 99 gfx::Vector2dF scroll_offset_; 100 bool animation_waiting_for_deletion_; 101 }; 102 103 class FakeInactiveLayerAnimationValueObserver 104 : public FakeLayerAnimationValueObserver { 105 public: 106 virtual bool IsActive() const OVERRIDE; 107 }; 108 109 class FakeLayerAnimationValueProvider : public LayerAnimationValueProvider { 110 public: 111 virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE; 112 113 void set_scroll_offset(const gfx::Vector2dF& scroll_offset) { 114 scroll_offset_ = scroll_offset; 115 } 116 117 private: 118 gfx::Vector2dF scroll_offset_; 119 }; 120 121 int AddOpacityTransitionToController(LayerAnimationController* controller, 122 double duration, 123 float start_opacity, 124 float end_opacity, 125 bool use_timing_function); 126 127 int AddAnimatedTransformToController(LayerAnimationController* controller, 128 double duration, 129 int delta_x, 130 int delta_y); 131 132 int AddAnimatedFilterToController(LayerAnimationController* controller, 133 double duration, 134 float start_brightness, 135 float end_brightness); 136 137 int AddOpacityTransitionToLayer(Layer* layer, 138 double duration, 139 float start_opacity, 140 float end_opacity, 141 bool use_timing_function); 142 143 int AddOpacityTransitionToLayer(LayerImpl* layer, 144 double duration, 145 float start_opacity, 146 float end_opacity, 147 bool use_timing_function); 148 149 int AddAnimatedTransformToLayer(Layer* layer, 150 double duration, 151 int delta_x, 152 int delta_y); 153 154 int AddAnimatedTransformToLayer(LayerImpl* layer, 155 double duration, 156 int delta_x, 157 int delta_y); 158 159 int AddAnimatedTransformToLayer(Layer* layer, 160 double duration, 161 TransformOperations start_operations, 162 TransformOperations operations); 163 164 int AddAnimatedTransformToLayer(LayerImpl* layer, 165 double duration, 166 TransformOperations start_operations, 167 TransformOperations operations); 168 169 int AddAnimatedFilterToLayer(Layer* layer, 170 double duration, 171 float start_brightness, 172 float end_brightness); 173 174 int AddAnimatedFilterToLayer(LayerImpl* layer, 175 double duration, 176 float start_brightness, 177 float end_brightness); 178 179 } // namespace cc 180 181 #endif // CC_TEST_ANIMATION_TEST_COMMON_H_ 182