Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / animation / tween.h
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.
4
5 #ifndef UI_GFX_ANIMATION_TWEEN_H_
6 #define UI_GFX_ANIMATION_TWEEN_H_
7
8 #include "base/basictypes.h"
9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/gfx/gfx_export.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/transform.h"
13
14 namespace gfx {
15
16 class GFX_EXPORT Tween {
17  public:
18   enum Type {
19     LINEAR,           // Linear.
20     EASE_OUT,         // Fast in, slow out (default).
21     EASE_OUT_2,       // Variant of EASE_OUT that ends slower than EASE_OUT.
22                       // Should be used for fading in or entering a scene.
23     EASE_IN,          // Slow in, fast out.
24     EASE_IN_2,        // Variant of EASE_IN that starts out slower than EASE_IN.
25     EASE_IN_3,        // Variant of EASE_IN that starts out faster than EASE_IN.
26                       // Should be used for fading out or exiting a scene.
27     EASE_IN_OUT,      // Slow in and out, fast in the middle.
28     EASE_IN_OUT_2,    // Variant of EASE_IN_OUT which starts out faster than
29                       // EASE_IN_OUT but ends slower than EASE_IN_OUT.
30     FAST_IN_OUT,      // Fast in and out, slow in the middle.
31     EASE_OUT_SNAP,    // Fast in, slow out, snap to final value.
32     SMOOTH_IN_OUT,    // Smooth, consistent speeds in and out (sine wave).
33     ZERO,             // Returns a value of 0 always.
34   };
35
36   // Returns the value based on the tween type. |state| is from 0-1.
37   static double CalculateValue(Type type, double state);
38
39   // Conveniences for getting a value between a start and end point.
40   static SkColor ColorValueBetween(double value, SkColor start, SkColor target);
41   static double DoubleValueBetween(double value, double start, double target);
42   static float FloatValueBetween(double value, float start, float target);
43
44   // Interpolated between start and target, with every integer in this range
45   // given equal weight.
46   static int IntValueBetween(double value, int start, int target);
47
48   // Interpolates between start and target as real numbers, and rounds the
49   // result to the nearest integer, with ties broken by rounding towards
50   // positive infinity. This gives start and target half the weight of the
51   // other integers in the range. This is the integer interpolation approach
52   // specified by www.w3.org/TR/css3-transitions.
53   static int LinearIntValueBetween(double value, int start, int target);
54   static gfx::Rect RectValueBetween(double value,
55                                     const gfx::Rect& start_bounds,
56                                     const gfx::Rect& target_bounds);
57   static gfx::Transform TransformValueBetween(
58       double value,
59       const gfx::Transform& start_transform,
60       const gfx::Transform& target_transform);
61
62  private:
63   Tween();
64   ~Tween();
65
66   DISALLOW_COPY_AND_ASSIGN(Tween);
67 };
68
69 }  // namespace gfx
70
71 #endif  // UI_GFX_ANIMATION_TWEEN_H_