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..362aa1ed5483b275648b7e5773e7a797f3066a4b 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,20 @@ ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( |
ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} |
+void ScrollOffsetAnimationCurve::SetInitialValue(gfx::Vector2dF initial_value) { |
+ initial_value_ = initial_value; |
+ |
+ // The duration of a scroll animation depends on the size of the scroll. |
+ // The exact relationship between the size and the duration isn't specified |
+ // by the CSSOM View smooth scroll spec and is instead left up to user agents |
+ // to decide. The calculation performed here will very likely be further |
+ // tweaked before the smooth scroll API ships. |
+ 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; |
+} |
+ |
gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(double t) const { |
if (t <= 0) |
return initial_value_; |
@@ -53,8 +72,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>(); |
} |