Omnibox: Fixes Allow-To-Be-Default-Match Code for HistoryQuick Provider
[chromium-blink-merge.git] / ui / compositor / transform_animation_curve_adapter.cc
blob49feb6af746113450c6a60c3bd5c41c75c2540e0
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 namespace ui {
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_);
22 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
25 double TransformAnimationCurveAdapter::Duration() const {
26 return duration_.InSecondsF();
29 scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() const {
30 scoped_ptr<TransformAnimationCurveAdapter> to_return(
31 new TransformAnimationCurveAdapter(tween_type_,
32 initial_value_,
33 target_value_,
34 duration_));
35 return to_return.PassAs<cc::AnimationCurve>();
38 gfx::Transform TransformAnimationCurveAdapter::GetValue(
39 double t) const {
40 if (t >= duration_.InSecondsF())
41 return target_value_;
42 if (t <= 0.0)
43 return initial_value_;
44 double progress = t / duration_.InSecondsF();
46 gfx::DecomposedTransform to_return;
47 gfx::BlendDecomposedTransforms(&to_return,
48 decomposed_target_value_,
49 decomposed_initial_value_,
50 gfx::Tween::CalculateValue(tween_type_,
51 progress));
52 return gfx::ComposeTransform(to_return);
55 bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
56 const gfx::BoxF& box,
57 gfx::BoxF* bounds) const {
58 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
59 // computing bounds for TransformOperationMatrix, use that to compute
60 // the bounds we need here.
61 return false;
64 InverseTransformCurveAdapter::InverseTransformCurveAdapter(
65 TransformAnimationCurveAdapter base_curve,
66 gfx::Transform initial_value,
67 base::TimeDelta duration)
68 : base_curve_(base_curve),
69 initial_value_(initial_value),
70 duration_(duration) {
71 effective_initial_value_ = base_curve_.GetValue(0.0) * initial_value_;
74 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
77 double InverseTransformCurveAdapter::Duration() const {
78 return duration_.InSeconds();
81 scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
82 scoped_ptr<InverseTransformCurveAdapter> to_return(
83 new InverseTransformCurveAdapter(base_curve_,
84 initial_value_,
85 duration_));
86 return to_return.PassAs<cc::AnimationCurve>();
89 gfx::Transform InverseTransformCurveAdapter::GetValue(
90 double t) const {
91 if (t <= 0.0)
92 return initial_value_;
94 gfx::Transform base_transform = base_curve_.GetValue(t);
95 // Invert base
96 gfx::Transform to_return(gfx::Transform::kSkipInitialization);
97 bool is_invertible = base_transform.GetInverse(&to_return);
98 DCHECK(is_invertible);
100 to_return.PreconcatTransform(effective_initial_value_);
101 return to_return;
104 bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
105 const gfx::BoxF& box,
106 gfx::BoxF* bounds) const {
107 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
108 // computing bounds for TransformOperationMatrix, use that to compute
109 // the bounds we need here.
110 return false;
113 } // namespace ui