android scroller: Stop fling earlier.

If the fling update is close to the final state, then stop the fling. The
threshold for this used to be 1e-5f, but change it to 1e-1f, since there
won't be any visual changes for subsequent fling-update steps.

BUG=none
R=jdduke@chromium.org

Review URL: https://codereview.chromium.org/606093002

Cr-Commit-Position: refs/heads/master@{#297198}
parent 9291444d
......@@ -25,6 +25,10 @@ const float kInflexion = 0.35f;
const float kEpsilon = 1e-5f;
// Fling scroll is stopped when the scroll position is |kThresholdForFlingEnd|
// pixels or closer from the end.
const float kThresholdForFlingEnd = 0.1;
bool ApproxEquals(float a, float b) {
return std::abs(a - b) < kEpsilon;
}
......@@ -324,9 +328,10 @@ bool Scroller::ComputeScrollOffset(base::TimeTicks time) {
curr_y_ = start_y_ + distance_coef * delta_y_;
curr_y_ = Clamped(curr_y_, min_y_, max_y_);
if (ApproxEquals(curr_x_, final_x_) && ApproxEquals(curr_y_, final_y_)) {
float diff_x = std::abs(curr_x_ - final_x_);
float diff_y = std::abs(curr_y_ - final_y_);
if (diff_x < kThresholdForFlingEnd && diff_y < kThresholdForFlingEnd)
finished_ = true;
}
} break;
}
......
......@@ -14,8 +14,8 @@ const float kDefaultStartX = 7.f;
const float kDefaultStartY = 25.f;
const float kDefaultDeltaX = -20.f;
const float kDefaultDeltaY = 73.f;
const float kDefaultVelocityX = -35.f;
const float kDefaultVelocityY = 22.f;
const float kDefaultVelocityX = -350.f;
const float kDefaultVelocityY = 220.f;
const float kEpsilon = 1e-3f;
Scroller::Config DefaultConfig() {
......
......@@ -25,6 +25,7 @@
],
'all_sources': [
'<@(_common_sources)',
'android/scroller_unittest.cc',
'animation/animation_container_unittest.cc',
'animation/animation_unittest.cc',
'animation/multi_animation_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment