Chromium Code Reviews| Index: cc/animation/scroll_offset_animation_curve.cc |
| diff --git a/cc/animation/scroll_offset_animation_curve.cc b/cc/animation/scroll_offset_animation_curve.cc |
| index d5cfd1c2df0fe147bed0914ec59a17b295338a40..24a43cff7a4cf4720cb5c3a643921aaa8f60d193 100644 |
| --- a/cc/animation/scroll_offset_animation_curve.cc |
| +++ b/cc/animation/scroll_offset_animation_curve.cc |
| @@ -4,10 +4,15 @@ |
| #include "cc/animation/scroll_offset_animation_curve.h" |
| +#include <algorithm> |
| +#include <cmath> |
| + |
| #include "base/logging.h" |
| #include "cc/animation/timing_function.h" |
| #include "ui/gfx/animation/tween.h" |
| +const double kDurationDivisor = 60.0; |
| + |
| namespace cc { |
| scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( |
| @@ -26,6 +31,14 @@ ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( |
| ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} |
| +void ScrollOffsetAnimationCurve::SetInitialValue(gfx::Vector2dF initial_value) { |
| + initial_value_ = initial_value; |
| + float delta_x = std::abs(target_value_.x() - initial_value_.x()); |
| + float delta_y = std::abs(target_value_.y() - initial_value_.y()); |
| + float max_delta = std::max(delta_x, delta_y); |
| + duration_ = std::sqrt(max_delta)/kDurationDivisor; |
|
ajuma
2013/11/29 15:14:06
This calculation will almost certainly be tweaked
Ian Vollick
2013/11/29 15:29:29
Please add a comment here explaining that this mat
ajuma
2013/11/29 21:18:41
Done. (The reason for the sqrt is just so that the
|
| +} |
| + |
| gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(double t) const { |
| if (t <= 0) |
| return initial_value_; |
| @@ -53,8 +66,8 @@ scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { |
| static_cast<TimingFunction*>(timing_function_->Clone().release())); |
| scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = |
| Create(target_value_, timing_function.Pass()); |
| - curve_clone->set_initial_value(initial_value_); |
| - curve_clone->set_duration(duration_); |
| + curve_clone->initial_value_ = initial_value_; |
| + curve_clone->duration_ = duration_; |
| return curve_clone.PassAs<AnimationCurve>(); |
| } |