transform_animation_curve_adapter.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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 7namespace ui { 8 9TransformAnimationCurveAdapter::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_); 20} 21 22TransformAnimationCurveAdapter::~TransformAnimationCurveAdapter() { 23} 24 25double TransformAnimationCurveAdapter::Duration() const { 26 return duration_.InSecondsF(); 27} 28 29scoped_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>(); 36} 37 38gfx::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(); 45 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); 53} 54 55bool 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; 62} 63 64bool TransformAnimationCurveAdapter::AffectsScale() const { 65 return !initial_value_.IsIdentityOrTranslation() || 66 !target_value_.IsIdentityOrTranslation(); 67} 68 69bool TransformAnimationCurveAdapter::IsTranslation() const { 70 return initial_value_.IsIdentityOrTranslation() && 71 target_value_.IsIdentityOrTranslation(); 72} 73 74bool TransformAnimationCurveAdapter::MaximumScale(float* max_scale) const { 75 return false; 76} 77 78InverseTransformCurveAdapter::InverseTransformCurveAdapter( 79 TransformAnimationCurveAdapter base_curve, 80 gfx::Transform initial_value, 81 base::TimeDelta duration) 82 : base_curve_(base_curve), 83 initial_value_(initial_value), 84 duration_(duration) { 85 effective_initial_value_ = base_curve_.GetValue(0.0) * initial_value_; 86} 87 88InverseTransformCurveAdapter::~InverseTransformCurveAdapter() { 89} 90 91double InverseTransformCurveAdapter::Duration() const { 92 return duration_.InSeconds(); 93} 94 95scoped_ptr<cc::AnimationCurve> InverseTransformCurveAdapter::Clone() const { 96 scoped_ptr<InverseTransformCurveAdapter> to_return( 97 new InverseTransformCurveAdapter(base_curve_, 98 initial_value_, 99 duration_)); 100 return to_return.PassAs<cc::AnimationCurve>(); 101} 102 103gfx::Transform InverseTransformCurveAdapter::GetValue( 104 double t) const { 105 if (t <= 0.0) 106 return initial_value_; 107 108 gfx::Transform base_transform = base_curve_.GetValue(t); 109 // Invert base 110 gfx::Transform to_return(gfx::Transform::kSkipInitialization); 111 bool is_invertible = base_transform.GetInverse(&to_return); 112 DCHECK(is_invertible); 113 114 to_return.PreconcatTransform(effective_initial_value_); 115 return to_return; 116} 117 118bool InverseTransformCurveAdapter::AnimatedBoundsForBox( 119 const gfx::BoxF& box, 120 gfx::BoxF* bounds) const { 121 // TODO(ajuma): Once cc::TransformOperation::BlendedBoundsForBox supports 122 // computing bounds for TransformOperationMatrix, use that to compute 123 // the bounds we need here. 124 return false; 125} 126 127bool InverseTransformCurveAdapter::AffectsScale() const { 128 return !initial_value_.IsIdentityOrTranslation() || 129 base_curve_.AffectsScale(); 130} 131 132bool InverseTransformCurveAdapter::IsTranslation() const { 133 return initial_value_.IsIdentityOrTranslation() && 134 base_curve_.IsTranslation(); 135} 136 137bool InverseTransformCurveAdapter::MaximumScale(float* max_scale) const { 138 return false; 139} 140 141} // namespace ui 142