Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: ui/compositor/transform_animation_curve_adapter.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "cc/base/time_util.h"
8
9 namespace ui {
10
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_);
22 }
23
24 TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() {
25 }
26
27 base::TimeDelta TransformAnimationCurveAdapter::Duration() const {
28 return duration_;
29 }
30
31 scoped_ptr<cc::AnimationCurve> TransformAnimationCurveAdapter::Clone() const {
32 return make_scoped_ptr(new TransformAnimationCurveAdapter(
33 tween_type_, initial_value_, target_value_, duration_));
34 }
35
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_);
43
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);
51 }
52
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;
60 }
61
62 bool TransformAnimationCurveAdapter::AffectsScale() const {
63 return !initial_value_.IsIdentityOrTranslation() ||
64 !target_value_.IsIdentityOrTranslation();
65 }
66
67 bool TransformAnimationCurveAdapter::IsTranslation() const {
68 return initial_value_.IsIdentityOrTranslation() &&
69 target_value_.IsIdentityOrTranslation();
70 }
71
72 bool TransformAnimationCurveAdapter::PreservesAxisAlignment() const {
73 return (initial_value_.IsIdentity() ||
74 initial_value_.IsScaleOrTranslation()) &&
75 (target_value_.IsIdentity() || target_value_.IsScaleOrTranslation());
76 }
77
78 bool TransformAnimationCurveAdapter::MaximumTargetScale(
79 bool forward_direction,
80 float* max_scale) const {
81 return false;
82 }
83
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_;
93 }
94
95 InverseTransformCurveAdapter::~InverseTransformCurveAdapter() {
96 }
97
98 base::TimeDelta InverseTransformCurveAdapter::Duration() const {
99 return duration_;
100 }
101
102 scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const {
103 return make_scoped_ptr(
104 new InverseTransformCurveAdapter(base_curve_, initial_value_, duration_));
105 }
106
107 gfx::Transform InverseTransformCurveAdapter::GetValue(base::TimeDelta t) const {
108 if (t <= base::TimeDelta())
109 return initial_value_;
110
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);
116
117 to_return.PreconcatTransform(effective_initial_value_);
118 return to_return;
119 }
120
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;
128 }
129
130 bool InverseTransformCurveAdapter::AffectsScale() const {
131 return !initial_value_.IsIdentityOrTranslation() ||
132 base_curve_.AffectsScale();
133 }
134
135 bool InverseTransformCurveAdapter::IsTranslation() const {
136 return initial_value_.IsIdentityOrTranslation() &&
137 base_curve_.IsTranslation();
138 }
139
140 bool InverseTransformCurveAdapter::PreservesAxisAlignment() const {
141 return (initial_value_.IsIdentity() ||
142 initial_value_.IsScaleOrTranslation()) &&
143 (base_curve_.PreservesAxisAlignment());
144 }
145
146 bool InverseTransformCurveAdapter::MaximumTargetScale(bool forward_direction,
147 float* max_scale) const {
148 return false;
149 }
150
151 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/transform_animation_curve_adapter.h ('k') | ui/compositor/transform_animation_curve_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698