Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / cc / animation / keyframed_animation_curve.h
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_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_
6 #define CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_
7
8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/timing_function.h"
10 #include "cc/animation/transform_operations.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/base/scoped_ptr_vector.h"
13
14 namespace cc {
15
16 class CC_EXPORT Keyframe {
17  public:
18   double Time() const;
19   const TimingFunction* timing_function() const {
20     return timing_function_.get();
21   }
22
23  protected:
24   Keyframe(double time, scoped_ptr<TimingFunction> timing_function);
25   virtual ~Keyframe();
26
27  private:
28   double time_;
29   scoped_ptr<TimingFunction> timing_function_;
30
31   DISALLOW_COPY_AND_ASSIGN(Keyframe);
32 };
33
34 class CC_EXPORT ColorKeyframe : public Keyframe {
35  public:
36   static scoped_ptr<ColorKeyframe> Create(
37       double time,
38       SkColor value,
39       scoped_ptr<TimingFunction> timing_function);
40   ~ColorKeyframe() override;
41
42   SkColor Value() const;
43
44   scoped_ptr<ColorKeyframe> Clone() const;
45
46  private:
47   ColorKeyframe(double time,
48                 SkColor value,
49                 scoped_ptr<TimingFunction> timing_function);
50
51   SkColor value_;
52 };
53
54 class CC_EXPORT FloatKeyframe : public Keyframe {
55  public:
56   static scoped_ptr<FloatKeyframe> Create(
57       double time,
58       float value,
59       scoped_ptr<TimingFunction> timing_function);
60   ~FloatKeyframe() override;
61
62   float Value() const;
63
64   scoped_ptr<FloatKeyframe> Clone() const;
65
66  private:
67   FloatKeyframe(double time,
68                 float value,
69                 scoped_ptr<TimingFunction> timing_function);
70
71   float value_;
72 };
73
74 class CC_EXPORT TransformKeyframe : public Keyframe {
75  public:
76   static scoped_ptr<TransformKeyframe> Create(
77       double time,
78       const TransformOperations& value,
79       scoped_ptr<TimingFunction> timing_function);
80   ~TransformKeyframe() override;
81
82   const TransformOperations& Value() const;
83
84   scoped_ptr<TransformKeyframe> Clone() const;
85
86  private:
87   TransformKeyframe(
88       double time,
89       const TransformOperations& value,
90       scoped_ptr<TimingFunction> timing_function);
91
92   TransformOperations value_;
93 };
94
95 class CC_EXPORT FilterKeyframe : public Keyframe {
96  public:
97   static scoped_ptr<FilterKeyframe> Create(
98       double time,
99       const FilterOperations& value,
100       scoped_ptr<TimingFunction> timing_function);
101   ~FilterKeyframe() override;
102
103   const FilterOperations& Value() const;
104
105   scoped_ptr<FilterKeyframe> Clone() const;
106
107  private:
108   FilterKeyframe(
109       double time,
110       const FilterOperations& value,
111       scoped_ptr<TimingFunction> timing_function);
112
113   FilterOperations value_;
114 };
115
116 class CC_EXPORT KeyframedColorAnimationCurve : public ColorAnimationCurve {
117  public:
118   // It is required that the keyframes be sorted by time.
119   static scoped_ptr<KeyframedColorAnimationCurve> Create();
120
121   ~KeyframedColorAnimationCurve() override;
122
123   void AddKeyframe(scoped_ptr<ColorKeyframe> keyframe);
124   void SetTimingFunction(scoped_ptr<TimingFunction> timing_function) {
125     timing_function_ = timing_function.Pass();
126   }
127
128   // AnimationCurve implementation
129   double Duration() const override;
130   scoped_ptr<AnimationCurve> Clone() const override;
131
132   // BackgrounColorAnimationCurve implementation
133   SkColor GetValue(double t) const override;
134
135  private:
136   KeyframedColorAnimationCurve();
137
138   // Always sorted in order of increasing time. No two keyframes have the
139   // same time.
140   ScopedPtrVector<ColorKeyframe> keyframes_;
141   scoped_ptr<TimingFunction> timing_function_;
142
143   DISALLOW_COPY_AND_ASSIGN(KeyframedColorAnimationCurve);
144 };
145
146 class CC_EXPORT KeyframedFloatAnimationCurve : public FloatAnimationCurve {
147  public:
148   // It is required that the keyframes be sorted by time.
149   static scoped_ptr<KeyframedFloatAnimationCurve> Create();
150
151   ~KeyframedFloatAnimationCurve() override;
152
153   void AddKeyframe(scoped_ptr<FloatKeyframe> keyframe);
154   void SetTimingFunction(scoped_ptr<TimingFunction> timing_function) {
155     timing_function_ = timing_function.Pass();
156   }
157
158   // AnimationCurve implementation
159   double Duration() const override;
160   scoped_ptr<AnimationCurve> Clone() const override;
161
162   // FloatAnimationCurve implementation
163   float GetValue(double t) const override;
164
165  private:
166   KeyframedFloatAnimationCurve();
167
168   // Always sorted in order of increasing time. No two keyframes have the
169   // same time.
170   ScopedPtrVector<FloatKeyframe> keyframes_;
171   scoped_ptr<TimingFunction> timing_function_;
172
173   DISALLOW_COPY_AND_ASSIGN(KeyframedFloatAnimationCurve);
174 };
175
176 class CC_EXPORT KeyframedTransformAnimationCurve
177     : public TransformAnimationCurve {
178  public:
179   // It is required that the keyframes be sorted by time.
180   static scoped_ptr<KeyframedTransformAnimationCurve> Create();
181
182   ~KeyframedTransformAnimationCurve() override;
183
184   void AddKeyframe(scoped_ptr<TransformKeyframe> keyframe);
185   void SetTimingFunction(scoped_ptr<TimingFunction> timing_function) {
186     timing_function_ = timing_function.Pass();
187   }
188
189   // AnimationCurve implementation
190   double Duration() const override;
191   scoped_ptr<AnimationCurve> Clone() const override;
192
193   // TransformAnimationCurve implementation
194   gfx::Transform GetValue(double t) const override;
195   bool AnimatedBoundsForBox(const gfx::BoxF& box,
196                             gfx::BoxF* bounds) const override;
197   bool AffectsScale() const override;
198   bool IsTranslation() const override;
199   bool MaximumTargetScale(bool forward_direction,
200                           float* max_scale) const override;
201
202  private:
203   KeyframedTransformAnimationCurve();
204
205   // Always sorted in order of increasing time. No two keyframes have the
206   // same time.
207   ScopedPtrVector<TransformKeyframe> keyframes_;
208   scoped_ptr<TimingFunction> timing_function_;
209
210   DISALLOW_COPY_AND_ASSIGN(KeyframedTransformAnimationCurve);
211 };
212
213 class CC_EXPORT KeyframedFilterAnimationCurve
214     : public FilterAnimationCurve {
215  public:
216   // It is required that the keyframes be sorted by time.
217   static scoped_ptr<KeyframedFilterAnimationCurve> Create();
218
219   ~KeyframedFilterAnimationCurve() override;
220
221   void AddKeyframe(scoped_ptr<FilterKeyframe> keyframe);
222   void SetTimingFunction(scoped_ptr<TimingFunction> timing_function) {
223     timing_function_ = timing_function.Pass();
224   }
225
226   // AnimationCurve implementation
227   double Duration() const override;
228   scoped_ptr<AnimationCurve> Clone() const override;
229
230   // FilterAnimationCurve implementation
231   FilterOperations GetValue(double t) const override;
232   bool HasFilterThatMovesPixels() const override;
233
234  private:
235   KeyframedFilterAnimationCurve();
236
237   // Always sorted in order of increasing time. No two keyframes have the
238   // same time.
239   ScopedPtrVector<FilterKeyframe> keyframes_;
240   scoped_ptr<TimingFunction> timing_function_;
241
242   DISALLOW_COPY_AND_ASSIGN(KeyframedFilterAnimationCurve);
243 };
244
245 }  // namespace cc
246
247 #endif  // CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_