| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/compositor/float_animation_curve_adapter.h" | 5 #include "ui/compositor/float_animation_curve_adapter.h" |
| 6 | 6 |
| 7 #include "cc/base/time_util.h" |
| 8 |
| 7 namespace ui { | 9 namespace ui { |
| 8 | 10 |
| 9 FloatAnimationCurveAdapter::FloatAnimationCurveAdapter( | 11 FloatAnimationCurveAdapter::FloatAnimationCurveAdapter( |
| 10 gfx::Tween::Type tween_type, | 12 gfx::Tween::Type tween_type, |
| 11 float initial_value, | 13 float initial_value, |
| 12 float target_value, | 14 float target_value, |
| 13 base::TimeDelta duration) | 15 base::TimeDelta duration) |
| 14 : tween_type_(tween_type), | 16 : tween_type_(tween_type), |
| 15 initial_value_(initial_value), | 17 initial_value_(initial_value), |
| 16 target_value_(target_value), | 18 target_value_(target_value), |
| 17 duration_(duration) { | 19 duration_(duration) { |
| 18 } | 20 } |
| 19 | 21 |
| 20 base::TimeDelta FloatAnimationCurveAdapter::Duration() const { | 22 base::TimeDelta FloatAnimationCurveAdapter::Duration() const { |
| 21 return duration_; | 23 return duration_; |
| 22 } | 24 } |
| 23 | 25 |
| 24 scoped_ptr<cc::AnimationCurve> FloatAnimationCurveAdapter::Clone() const { | 26 scoped_ptr<cc::AnimationCurve> FloatAnimationCurveAdapter::Clone() const { |
| 25 return make_scoped_ptr(new FloatAnimationCurveAdapter( | 27 return make_scoped_ptr(new FloatAnimationCurveAdapter( |
| 26 tween_type_, initial_value_, target_value_, duration_)); | 28 tween_type_, initial_value_, target_value_, duration_)); |
| 27 } | 29 } |
| 28 | 30 |
| 29 float FloatAnimationCurveAdapter::GetValue(double t) const { | 31 float FloatAnimationCurveAdapter::GetValue(base::TimeDelta t) const { |
| 30 if (t >= duration_.InSecondsF()) | 32 if (t >= duration_) |
| 31 return target_value_; | 33 return target_value_; |
| 32 if (t <= 0.0) | 34 if (t <= base::TimeDelta()) |
| 33 return initial_value_; | 35 return initial_value_; |
| 34 double progress = t / duration_.InSecondsF(); | 36 double progress = cc::TimeUtil::Divide(t, duration_); |
| 35 return gfx::Tween::FloatValueBetween( | 37 return gfx::Tween::FloatValueBetween( |
| 36 gfx::Tween::CalculateValue(tween_type_, progress), | 38 gfx::Tween::CalculateValue(tween_type_, progress), |
| 37 initial_value_, | 39 initial_value_, |
| 38 target_value_); | 40 target_value_); |
| 39 } | 41 } |
| 40 | 42 |
| 41 } // namespace ui | 43 } // namespace ui |
| OLD | NEW |