Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / ui / compositor / transform_animation_curve_adapter.cc
blob5439e0a1ac7a7ccd23816105f15107d93a6114b2
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::AnimationStartScale(
79 bool forward_direction,
80 float* start_scale) const {
81 return false;
84 bool TransformAnimationCurveAdapter::MaximumTargetScale(
85 bool forward_direction,
86 float* max_scale) const {
87 return false;
90 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
91 TransformAnimationCurveAdapter base_curve,
92 gfx::Transform initial_value,
93 base::TimeDelta duration)
94 : base_curve_(base_curve),
95 initial_value_(initial_value),
96 duration_(duration) {
97 effective_initial_value_ =
98 base_curve_.GetValue(base::TimeDelta()) * initial_value_;
101 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
104 base::TimeDelta InverseTransformCurveAdapter::Duration() const {
105 return duration_;
108 scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
109 return make_scoped_ptr(
110 new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_));
113 gfx::Transform InverseTransformCurveAdapter::GetValue(base::TimeDelta t) const {
114 if (t <= base::TimeDelta())
115 return initial_value_;
117 gfx::Transform base_transform = base_curve_.GetValue(t);
118 // Invert base
119 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
120 bool is_invertible = base_transform.GetInverse(&to_return);
121 DCHECK(is_invertible);
123 to_return.PreconcatTransform(effective_initial_value_);
124 return to_return;
127 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
128 const gfx::BoxF& box,
129 gfx::BoxF* bounds) const {
130 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
131 // computing bounds for TransformOperationMatrix, use that to compute
132 // the bounds we need here.
133 return false;
136 bool InverseTransformCurveAdapter::AffectsScale() const {
137 return !initial_value_.IsIdentityOrTranslation() ||
138 base_curve_.AffectsScale();
141 bool InverseTransformCurveAdapter::IsTranslation() const {
142 return initial_value_.IsIdentityOrTranslation() &&
143 base_curve_.IsTranslation();
146 bool InverseTransformCurveAdapter::PreservesAxisAlignment() const {
147 return (initial_value_.IsIdentity() ||
148 initial_value_.IsScaleOrTranslation()) &&
149 (base_curve_.PreservesAxisAlignment());
152 bool InverseTransformCurveAdapter::AnimationStartScale(
153 bool forward_direction,
154 float* start_scale) const {
155 return false;
158 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction,
159 float* max_scale) const {
160 return false;
163 } // namespace ui