Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / compositor / transform_animation_curve_adapter.cc
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 #include "ui/compositor/transform_animation_curve_adapter.h"
6
7 namespace ui {
8
9 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
10     gfx::Tween::Type tween_type,
11     gfx::Transform initial_value,
12     gfx::Transform target_value,
13     base::TimeDelta duration)
14     : tween_type_(tween_type),
15       initial_value_(initial_value),
16       target_value_(target_value),
17       duration_(duration) {
18   gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_);
19   gfx::DecomposeTransform(&decomposed_target_value_, target_value_);
20 }
21
22 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
23 }
24
25 double TransformAnimationCurveAdapter::Duration() const {
26   return duration_.InSecondsF();
27 }
28
29 scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() const {
30   return make_scoped_ptr(new TransformAnimationCurveAdapter(
31       tween_type_, initial_value_, target_value_, duration_));
32 }
33
34 gfx::Transform TransformAnimationCurveAdapter::GetValue(
35     double t) const {
36   if (t >= duration_.InSecondsF())
37     return target_value_;
38   if (t <= 0.0)
39     return initial_value_;
40   double progress = t / duration_.InSecondsF();
41
42   gfx::DecomposedTransform to_return;
43   gfx::BlendDecomposedTransforms(&to_return,
44                                  decomposed_target_value_,
45                                  decomposed_initial_value_,
46                                  gfx::Tween::CalculateValue(tween_type_,
47                                                             progress));
48   return gfx::ComposeTransform(to_return);
49 }
50
51 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
52     const gfx::BoxF& box,
53     gfx::BoxF* bounds) const {
54   // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
55   // computing bounds for TransformOperationMatrix, use that to compute
56   // the bounds we need here.
57   return false;
58 }
59
60 bool TransformAnimationCurveAdapter::AffectsScale() const {
61   return !initial_value_.IsIdentityOrTranslation() ||
62          !target_value_.IsIdentityOrTranslation();
63 }
64
65 bool TransformAnimationCurveAdapter::IsTranslation() const {
66   return initial_value_.IsIdentityOrTranslation() &&
67          target_value_.IsIdentityOrTranslation();
68 }
69
70 bool TransformAnimationCurveAdapter::MaximumTargetScale(
71     bool forward_direction,
72     float* max_scale) const {
73   return false;
74 }
75
76 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
77     TransformAnimationCurveAdapter base_curve,
78     gfx::Transform initial_value,
79     base::TimeDelta duration)
80     : base_curve_(base_curve),
81       initial_value_(initial_value),
82       duration_(duration) {
83   effective_initial_value_ = base_curve_.GetValue(0.0) * initial_value_;
84 }
85
86 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
87 }
88
89 double InverseTransformCurveAdapter::Duration() const {
90   return duration_.InSeconds();
91 }
92
93 scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
94   return make_scoped_ptr(
95       new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_));
96 }
97
98 gfx::Transform InverseTransformCurveAdapter::GetValue(
99     double t) const {
100   if (t <= 0.0)
101     return initial_value_;
102
103   gfx::Transform base_transform = base_curve_.GetValue(t);
104   // Invert base
105   gfx::Transform to_return(gfx::Transform::kSkipInitialization);
106   bool is_invertible = base_transform.GetInverse(&to_return);
107   DCHECK(is_invertible);
108
109   to_return.PreconcatTransform(effective_initial_value_);
110   return to_return;
111 }
112
113 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
114     const gfx::BoxF& box,
115     gfx::BoxF* bounds) const {
116   // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
117   // computing bounds for TransformOperationMatrix, use that to compute
118   // the bounds we need here.
119   return false;
120 }
121
122 bool InverseTransformCurveAdapter::AffectsScale() const {
123   return !initial_value_.IsIdentityOrTranslation() ||
124          base_curve_.AffectsScale();
125 }
126
127 bool InverseTransformCurveAdapter::IsTranslation() const {
128   return initial_value_.IsIdentityOrTranslation() &&
129          base_curve_.IsTranslation();
130 }
131
132 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction,
133                                                       float* max_scale) const {
134   return false;
135 }
136
137 }  // namespace ui