Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/gfx/android/scroller.cc

Issue 606093002: android scroller: Stop fling earlier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/android/scroller_unittest.cc » ('j') | ui/gfx/gfx_tests.gyp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/gfx/android/scroller.h" 5 #include "ui/gfx/android/scroller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 10
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 t, &distance_coef, &velocity_coef); 317 t, &distance_coef, &velocity_coef);
318 318
319 curr_velocity_ = velocity_coef * distance_ * duration_seconds_reciprocal_; 319 curr_velocity_ = velocity_coef * distance_ * duration_seconds_reciprocal_;
320 320
321 curr_x_ = start_x_ + distance_coef * delta_x_; 321 curr_x_ = start_x_ + distance_coef * delta_x_;
322 curr_x_ = Clamped(curr_x_, min_x_, max_x_); 322 curr_x_ = Clamped(curr_x_, min_x_, max_x_);
323 323
324 curr_y_ = start_y_ + distance_coef * delta_y_; 324 curr_y_ = start_y_ + distance_coef * delta_y_;
325 curr_y_ = Clamped(curr_y_, min_y_, max_y_); 325 curr_y_ = Clamped(curr_y_, min_y_, max_y_);
326 326
327 if (ApproxEquals(curr_x_, final_x_) && ApproxEquals(curr_y_, final_y_)) { 327 float diff_x = std::abs(curr_x_ - final_x_);
328 float diff_y = std::abs(curr_y_ - final_y_);
329 const float kThresholdForFlingEnd = 0.1;
jdduke (slow) 2014/09/26 22:19:53 Nit: Might as well stick this at the top with the
sadrul 2014/09/29 17:23:56 Done.
330 if (diff_x < kThresholdForFlingEnd && diff_y < kThresholdForFlingEnd)
328 finished_ = true; 331 finished_ = true;
329 }
330 } break; 332 } break;
331 } 333 }
332 334
333 return true; 335 return true;
334 } 336 }
335 337
336 void Scroller::ExtendDuration(base::TimeDelta extend) { 338 void Scroller::ExtendDuration(base::TimeDelta extend) {
337 base::TimeDelta passed = GetTimePassed(); 339 base::TimeDelta passed = GetTimePassed();
338 duration_ = passed + extend; 340 duration_ = passed + extend;
339 duration_seconds_reciprocal_ = 1.0 / duration_.InSecondsF(); 341 duration_seconds_reciprocal_ = 1.0 / duration_.InSecondsF();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 432 }
431 433
432 double Scroller::GetSplineFlingDistance(float velocity) const { 434 double Scroller::GetSplineFlingDistance(float velocity) const {
433 const double l = GetSplineDeceleration(velocity); 435 const double l = GetSplineDeceleration(velocity);
434 const double decel_minus_one = kDecelerationRate - 1.0; 436 const double decel_minus_one = kDecelerationRate - 1.0;
435 return fling_friction_ * tuning_coeff_ * 437 return fling_friction_ * tuning_coeff_ *
436 std::exp(kDecelerationRate / decel_minus_one * l); 438 std::exp(kDecelerationRate / decel_minus_one * l);
437 } 439 }
438 440
439 } // namespace gfx 441 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/android/scroller_unittest.cc » ('j') | ui/gfx/gfx_tests.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698