forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform_animation_curve_adapter.cc
111 lines (93 loc) · 3.64 KB
/
transform_animation_curve_adapter.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/compositor/transform_animation_curve_adapter.h"
namespace ui {
TransformAnimationCurveAdapter::TransformAnimationCurveAdapter(
Tween::Type tween_type,
gfx::Transform initial_value,
gfx::Transform target_value,
base::TimeDelta duration)
: tween_type_(tween_type),
initial_value_(initial_value),
target_value_(target_value),
duration_(duration) {
gfx::DecomposeTransform(&decomposed_initial_value_, initial_value_);
gfx::DecomposeTransform(&decomposed_target_value_, target_value_);
}
TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
}
double TransformAnimationCurveAdapter::Duration() const {
return duration_.InSecondsF();
}
scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() const {
scoped_ptr<TransformAnimationCurveAdapter> to_return(
new TransformAnimationCurveAdapter(tween_type_,
initial_value_,
target_value_,
duration_));
return to_return.PassAs<cc::AnimationCurve>();
}
gfx::Transform TransformAnimationCurveAdapter::GetValue(
double t) const {
if (t >= duration_.InSecondsF())
return target_value_;
if (t <= 0.0)
return initial_value_;
double progress = t / duration_.InSecondsF();
gfx::DecomposedTransform to_return;
gfx::BlendDecomposedTransforms(&to_return,
decomposed_target_value_,
decomposed_initial_value_,
Tween::CalculateValue(tween_type_, progress));
return gfx::ComposeTransform(to_return);
}
bool TransformAnimationCurveAdapter::AnimatedBoundsForBox(
const gfx::BoxF& box,
gfx::BoxF* bounds) const {
// TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
// computing bounds for TransformOperationMatrix, use that to compute
// the bounds we need here.
return false;
}
InverseTransformCurveAdapter::InverseTransformCurveAdapter(
TransformAnimationCurveAdapter base_curve,
gfx::Transform initial_value,
base::TimeDelta duration)
: base_curve_(base_curve),
initial_value_(initial_value),
duration_(duration) {
effective_initial_value_ = base_curve_.GetValue(0.0) * initial_value_;
}
InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
}
double InverseTransformCurveAdapter::Duration() const {
return duration_.InSeconds();
}
scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
scoped_ptr<InverseTransformCurveAdapter> to_return(
new InverseTransformCurveAdapter(base_curve_,
initial_value_,
duration_));
return to_return.PassAs<cc::AnimationCurve>();
}
gfx::Transform InverseTransformCurveAdapter::GetValue(
double t) const {
if (t <= 0.0)
return initial_value_;
gfx::Transform base_transform = base_curve_.GetValue(t);
// Invert base
gfx::Transform to_return(gfx::Transform::kSkipInitialization);
DCHECK(base_transform.GetInverse(&to_return));
to_return.PreconcatTransform(effective_initial_value_);
return to_return;
}
bool InverseTransformCurveAdapter::AnimatedBoundsForBox(
const gfx::BoxF& box,
gfx::BoxF* bounds) const {
// TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports
// computing bounds for TransformOperationMatrix, use that to compute
// the bounds we need here.
return false;
}
} // namespace ui