Upstream version 11.40.277.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_IN,            // Slow in, fast out.
22     EASE_IN_2,          // Variant of EASE_IN that starts out slower than
23                         // EASE_IN.
24     EASE_IN_OUT,        // Slow in and out, fast in the middle.
25     FAST_IN_OUT,        // Fast in and out, slow in the middle.
26     EASE_OUT_SNAP,      // Fast in, slow out, snap to final value.
27     SMOOTH_IN_OUT,      // Smooth, consistent speeds in and out (sine wave).
28     FAST_OUT_SLOW_IN,   // Variant of EASE_IN_OUT which should be used in most
29                         // cases.
30     LINEAR_OUT_SLOW_IN, // Variant of EASE_OUT which should be used for
31                         // fading in from 0% or motion when entering a scene.
32     FAST_OUT_LINEAR_IN, // Variant of EASE_IN which should should be used for
33                         // fading out to 0% or motion when exiting a scene.
34     ZERO,               // Returns a value of 0 always.
35   };
36
37   // Returns the value based on the tween type. |state| is from 0-1.
38   static double CalculateValue(Type type, double state);
39
40   // Conveniences for getting a value between a start and end point.
41   static SkColor ColorValueBetween(double value, SkColor start, SkColor target);
42   static double DoubleValueBetween(double value, double start, double target);
43   static float FloatValueBetween(double value, float start, float target);
44
45   // Interpolated between start and target, with every integer in this range
46   // given equal weight.
47   static int IntValueBetween(double value, int start, int target);
48
49   // Interpolates between start and target as real numbers, and rounds the
50   // result to the nearest integer, with ties broken by rounding towards
51   // positive infinity. This gives start and target half the weight of the
52   // other integers in the range. This is the integer interpolation approach
53   // specified by www.w3.org/TR/css3-transitions.
54   static int LinearIntValueBetween(double value, int start, int target);
55   static gfx::Rect RectValueBetween(double value,
56                                     const gfx::Rect& start_bounds,
57                                     const gfx::Rect& target_bounds);
58   static gfx::Transform TransformValueBetween(
59       double value,
60       const gfx::Transform& start_transform,
61       const gfx::Transform& target_transform);
62
63  private:
64   Tween();
65   ~Tween();
66
67   DISALLOW_COPY_AND_ASSIGN(Tween);
68 };
69
70 }  // namespace gfx
71
72 #endif  // UI_GFX_ANIMATION_TWEEN_H_