Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / compositor / transform_animation_curve_adapter.cc
blob0f697e0bad29ba1c2d432c5bf0b03b10756d5363
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 #include "ui/compositor/transform_animation_curve_adapter.h"
7 #include "cc/base/time_util.h"
9 namespace ui {
11 TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
12 gfx::Tween::Type tween_type,
13 gfx::Transform initial_value,
14 gfx::Transform target_value,
15 base::TimeDelta duration)
16 : tween_type_(tween_type),
17 initial_value_(initial_value),
18 target_value_(target_value),
19 duration_(duration) {
20 gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_);
21 gfx::DecomposeTransform(&decomposed_target_value_, target_value_);
24 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
27 base::TimeDelta TransformAnimationCurveAdapter::Duration() const {
28 return duration_;
31 scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() const {
32 return make_scoped_ptr(new TransformAnimationCurveAdapter(
33 tween_type_, initial_value_, target_value_, duration_));
36 gfx::Transform TransformAnimationCurveAdapter::GetValue(
37 base::TimeDelta t) const {
38 if (t >= duration_)
39 return target_value_;
40 if (t <= base::TimeDelta())
41 return initial_value_;
42 double progress = cc::TimeUtil::Divide(t, duration_);
44 gfx::DecomposedTransform to_return;
45 gfx::BlendDecomposedTransforms(&to_return,
46 decomposed_target_value_,
47 decomposed_initial_value_,
48 gfx::Tween::CalculateValue(tween_type_,
49 progress));
50 return gfx::ComposeTransform(to_return);
53 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
54 const gfx::BoxF& box,
55 gfx::BoxF* bounds) const {
56 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
57 // computing bounds for TransformOperationMatrix, use that to compute
58 // the bounds we need here.
59 return false;
62 bool TransformAnimationCurveAdapter::AffectsScale() const {
63 return !initial_value_.IsIdentityOrTranslation() ||
64 !target_value_.IsIdentityOrTranslation();
67 bool TransformAnimationCurveAdapter::IsTranslation() const {
68 return initial_value_.IsIdentityOrTranslation() &&
69 target_value_.IsIdentityOrTranslation();
72 bool TransformAnimationCurveAdapter::PreservesAxisAlignment() const {
73 return (initial_value_.IsIdentity() ||
74 initial_value_.IsScaleOrTranslation()) &&
75 (target_value_.IsIdentity() || target_value_.IsScaleOrTranslation());
78 bool TransformAnimationCurveAdapter::MaximumTargetScale(
79 bool forward_direction,
80 float* max_scale) const {
81 return false;
84 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
85 TransformAnimationCurveAdapter base_curve,
86 gfx::Transform initial_value,
87 base::TimeDelta duration)
88 : base_curve_(base_curve),
89 initial_value_(initial_value),
90 duration_(duration) {
91 effective_initial_value_ =
92 base_curve_.GetValue(base::TimeDelta()) * initial_value_;
95 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
98 base::TimeDelta InverseTransformCurveAdapter::Duration() const {
99 return duration_;
102 scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
103 return make_scoped_ptr(
104 new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_));
107 gfx::Transform InverseTransformCurveAdapter::GetValue(base::TimeDelta t) const {
108 if (t <= base::TimeDelta())
109 return initial_value_;
111 gfx::Transform base_transform = base_curve_.GetValue(t);
112 // Invert base
113 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
114 bool is_invertible = base_transform.GetInverse(&to_return);
115 DCHECK(is_invertible);
117 to_return.PreconcatTransform(effective_initial_value_);
118 return to_return;
121 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
122 const gfx::BoxF& box,
123 gfx::BoxF* bounds) const {
124 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
125 // computing bounds for TransformOperationMatrix, use that to compute
126 // the bounds we need here.
127 return false;
130 bool InverseTransformCurveAdapter::AffectsScale() const {
131 return !initial_value_.IsIdentityOrTranslation() ||
132 base_curve_.AffectsScale();
135 bool InverseTransformCurveAdapter::IsTranslation() const {
136 return initial_value_.IsIdentityOrTranslation() &&
137 base_curve_.IsTranslation();
140 bool InverseTransformCurveAdapter::PreservesAxisAlignment() const {
141 return (initial_value_.IsIdentity() ||
142 initial_value_.IsScaleOrTranslation()) &&
143 (base_curve_.PreservesAxisAlignment());
146 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction,
147 float* max_scale) const {
148 return false;
151 } // namespace ui