[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / ui / gfx / interpolated_transform.h
blobc7e9032dc47145430a51502c512300a47ac04e61
1 // Copyright (c) 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 UI_GFX_INTERPOLATED_TRANSFORM_H_
6 #define UI_GFX_INTERPOLATED_TRANSFORM_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/geometry/point.h"
11 #include "ui/gfx/geometry/point3_f.h"
12 #include "ui/gfx/geometry/vector3d_f.h"
13 #include "ui/gfx/transform.h"
14 #include "ui/gfx/transform_util.h"
16 namespace ui {
18 ///////////////////////////////////////////////////////////////////////////////
19 // class InterpolatedTransform
21 // Abstract base class for transforms that animate over time. These
22 // interpolated transforms can be combined to allow for more sophisticated
23 // animations. For example, you might combine a rotation of 90 degrees between
24 // times 0 and 1, with a scale from 1 to 0.3 between times 0 and 0.25 and a
25 // scale from 0.3 to 1 from between times 0.75 and 1.
27 ///////////////////////////////////////////////////////////////////////////////
28 class GFX_EXPORT InterpolatedTransform {
29 public:
30 InterpolatedTransform();
31 // The interpolated transform varies only when t in (start_time, end_time).
32 // If t <= start_time, Interpolate(t) will return the initial transform, and
33 // if t >= end_time, Interpolate(t) will return the final transform.
34 InterpolatedTransform(float start_time, float end_time);
35 virtual ~InterpolatedTransform();
37 // Returns the interpolated transform at time t. Note: not virtual.
38 gfx::Transform Interpolate(float t) const;
40 // The Intepolate ultimately returns the product of our transform at time t
41 // and our child's transform at time t (if we have one).
43 // This function takes ownership of the passed InterpolatedTransform.
44 void SetChild(InterpolatedTransform* child);
46 // If the interpolated transform is reversed, Interpolate(t) will return
47 // Interpolate(1 - t)
48 void SetReversed(bool reversed) { reversed_ = reversed; }
49 bool Reversed() const { return reversed_; }
51 protected:
52 // Calculates the interpolated transform without considering our child.
53 virtual gfx::Transform InterpolateButDoNotCompose(float t) const = 0;
55 // If time in (start_time_, end_time_], this function linearly interpolates
56 // between start_value and end_value. More precisely it returns
57 // (1 - t) * start_value + t * end_value where
58 // t = (start_time_ - time) / (end_time_ - start_time_).
59 // If time < start_time_ it returns start_value, and if time >= end_time_
60 // it returns end_value.
61 float ValueBetween(float time, float start_value, float end_value) const;
63 float start_time() const { return start_time_; }
64 float end_time() const { return end_time_; }
66 private:
67 const float start_time_;
68 const float end_time_;
70 // The child transform. If you consider an interpolated transform as a
71 // function of t. If, without a child, we are f(t), and our child is
72 // g(t), then with a child we become f'(t) = f(t) * g(t). Using a child
73 // transform, we can chain collections of transforms together.
74 scoped_ptr<InterpolatedTransform> child_;
76 bool reversed_;
78 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransform);
81 ///////////////////////////////////////////////////////////////////////////////
82 // class InterpolatedRotation
84 // Represents an animated rotation.
86 ///////////////////////////////////////////////////////////////////////////////
87 class GFX_EXPORT InterpolatedRotation : public InterpolatedTransform {
88 public:
89 InterpolatedRotation(float start_degrees, float end_degrees);
90 InterpolatedRotation(float start_degrees,
91 float end_degrees,
92 float start_time,
93 float end_time);
94 ~InterpolatedRotation() override;
96 protected:
97 gfx::Transform InterpolateButDoNotCompose(float t) const override;
99 private:
100 const float start_degrees_;
101 const float end_degrees_;
103 DISALLOW_COPY_AND_ASSIGN(InterpolatedRotation);
106 ///////////////////////////////////////////////////////////////////////////////
107 // class InterpolatedAxisAngleRotation
109 // Represents an animated rotation.
111 ///////////////////////////////////////////////////////////////////////////////
112 class GFX_EXPORT InterpolatedAxisAngleRotation : public InterpolatedTransform {
113 public:
114 InterpolatedAxisAngleRotation(const gfx::Vector3dF& axis,
115 float start_degrees,
116 float end_degrees);
117 InterpolatedAxisAngleRotation(const gfx::Vector3dF& axis,
118 float start_degrees,
119 float end_degrees,
120 float start_time,
121 float end_time);
122 ~InterpolatedAxisAngleRotation() override;
124 protected:
125 gfx::Transform InterpolateButDoNotCompose(float t) const override;
127 private:
128 gfx::Vector3dF axis_;
129 const float start_degrees_;
130 const float end_degrees_;
132 DISALLOW_COPY_AND_ASSIGN(InterpolatedAxisAngleRotation);
135 ///////////////////////////////////////////////////////////////////////////////
136 // class InterpolatedScale
138 // Represents an animated scale.
140 ///////////////////////////////////////////////////////////////////////////////
141 class GFX_EXPORT InterpolatedScale : public InterpolatedTransform {
142 public:
143 InterpolatedScale(float start_scale, float end_scale);
144 InterpolatedScale(float start_scale, float end_scale,
145 float start_time, float end_time);
146 InterpolatedScale(const gfx::Point3F& start_scale,
147 const gfx::Point3F& end_scale);
148 InterpolatedScale(const gfx::Point3F& start_scale,
149 const gfx::Point3F& end_scale,
150 float start_time,
151 float end_time);
152 ~InterpolatedScale() override;
154 protected:
155 gfx::Transform InterpolateButDoNotCompose(float t) const override;
157 private:
158 const gfx::Point3F start_scale_;
159 const gfx::Point3F end_scale_;
161 DISALLOW_COPY_AND_ASSIGN(InterpolatedScale);
164 class GFX_EXPORT InterpolatedTranslation : public InterpolatedTransform {
165 public:
166 InterpolatedTranslation(const gfx::Point& start_pos,
167 const gfx::Point& end_pos);
168 InterpolatedTranslation(const gfx::Point& start_pos,
169 const gfx::Point& end_pos,
170 float start_time,
171 float end_time);
172 InterpolatedTranslation(const gfx::Point3F& start_pos,
173 const gfx::Point3F& end_pos);
174 InterpolatedTranslation(const gfx::Point3F& start_pos,
175 const gfx::Point3F& end_pos,
176 float start_time,
177 float end_time);
178 ~InterpolatedTranslation() override;
180 protected:
181 gfx::Transform InterpolateButDoNotCompose(float t) const override;
183 private:
184 const gfx::Point3F start_pos_;
185 const gfx::Point3F end_pos_;
187 DISALLOW_COPY_AND_ASSIGN(InterpolatedTranslation);
190 ///////////////////////////////////////////////////////////////////////////////
191 // class InterpolatedConstantTransform
193 // Represents a transform that is constant over time. This is only useful when
194 // composed with other interpolated transforms.
196 // See InterpolatedTransformAboutPivot for an example of its usage.
198 ///////////////////////////////////////////////////////////////////////////////
199 class GFX_EXPORT InterpolatedConstantTransform : public InterpolatedTransform {
200 public:
201 explicit InterpolatedConstantTransform(const gfx::Transform& transform);
202 ~InterpolatedConstantTransform() override;
204 protected:
205 gfx::Transform InterpolateButDoNotCompose(float t) const override;
207 private:
208 const gfx::Transform transform_;
210 DISALLOW_COPY_AND_ASSIGN(InterpolatedConstantTransform);
213 ///////////////////////////////////////////////////////////////////////////////
214 // class InterpolatedTransformAboutPivot
216 // Represents an animated transform with a transformed origin. Essentially,
217 // at each time, t, the interpolated transform is created by composing
218 // P * T * P^-1 where P is a constant transform to the new origin.
220 ///////////////////////////////////////////////////////////////////////////////
221 class GFX_EXPORT InterpolatedTransformAboutPivot
222 : public InterpolatedTransform {
223 public:
224 // Takes ownership of the passed transform.
225 InterpolatedTransformAboutPivot(const gfx::Point& pivot,
226 InterpolatedTransform* transform);
228 // Takes ownership of the passed transform.
229 InterpolatedTransformAboutPivot(const gfx::Point& pivot,
230 InterpolatedTransform* transform,
231 float start_time,
232 float end_time);
233 ~InterpolatedTransformAboutPivot() override;
235 protected:
236 gfx::Transform InterpolateButDoNotCompose(float t) const override;
238 private:
239 void Init(const gfx::Point& pivot, InterpolatedTransform* transform);
241 scoped_ptr<InterpolatedTransform> transform_;
243 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformAboutPivot);
246 class GFX_EXPORT InterpolatedMatrixTransform : public InterpolatedTransform {
247 public:
248 InterpolatedMatrixTransform(const gfx::Transform& start_transform,
249 const gfx::Transform& end_transform);
251 InterpolatedMatrixTransform(const gfx::Transform& start_transform,
252 const gfx::Transform& end_transform,
253 float start_time,
254 float end_time);
256 ~InterpolatedMatrixTransform() override;
258 protected:
259 gfx::Transform InterpolateButDoNotCompose(float t) const override;
261 private:
262 void Init(const gfx::Transform& start_transform,
263 const gfx::Transform& end_transform);
265 gfx::DecomposedTransform start_decomp_;
266 gfx::DecomposedTransform end_decomp_;
269 } // namespace ui
271 #endif // UI_GFX_INTERPOLATED_TRANSFORM_H_