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

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

Issue 2767213003: First Implementation of Snapped Points
Patch Set: Rebase and format Created 3 years, 6 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 | « ui/events/android/scroller.h ('k') | ui/events/blink/input_handler_proxy.cc » ('j') | no next file with comments »
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/events/android/scroller.h" 5 #include "ui/events/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 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 *offset = gfx::Vector2dF(GetFinalX(), GetFinalY()); 201 *offset = gfx::Vector2dF(GetFinalX(), GetFinalY());
202 *velocity = gfx::Vector2dF(); 202 *velocity = gfx::Vector2dF();
203 return false; 203 return false;
204 } 204 }
205 205
206 *offset = gfx::Vector2dF(GetCurrX(), GetCurrY()); 206 *offset = gfx::Vector2dF(GetCurrX(), GetCurrY());
207 *velocity = gfx::Vector2dF(GetCurrVelocityX(), GetCurrVelocityY()); 207 *velocity = gfx::Vector2dF(GetCurrVelocityX(), GetCurrVelocityY());
208 return true; 208 return true;
209 } 209 }
210 210
211 void Scroller::ComputeTotalScrollOffset(gfx::Vector2dF& offset) {
212 offset.set_x(final_x_);
213 offset.set_y(final_y_);
214 }
215
216 bool Scroller::ResetCurveBySnappedOffset(const gfx::Vector2dF& offset) {
217 final_x_ = offset.x();
218 final_y_ = offset.y();
219 distance_ = std::sqrt(final_x_ * final_x_ + final_y_ * final_y_);
220
221 velocity_ = GetSplineVelocityFromDistance(distance_);
222 duration_ = GetSplineFlingDuration(velocity_);
223 if (duration_.ToInternalValue() <= 0)
224 return false;
225 duration_seconds_reciprocal_ = 1.0 / duration_.InSecondsF();
226 RecomputeDeltas();
227 return true;
228 }
229
211 void Scroller::StartScroll(float start_x, 230 void Scroller::StartScroll(float start_x,
212 float start_y, 231 float start_y,
213 float dx, 232 float dx,
214 float dy, 233 float dy,
215 base::TimeTicks start_time) { 234 base::TimeTicks start_time) {
216 StartScroll(start_x, 235 StartScroll(start_x,
217 start_y, 236 start_y,
218 dx, 237 dx,
219 dy, 238 dy,
220 start_time, 239 start_time,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 max_x_ = max_x; 306 max_x_ = max_x;
288 min_y_ = min_y; 307 min_y_ = min_y;
289 max_y_ = max_y; 308 max_y_ = max_y;
290 309
291 final_x_ = start_x + total_distance * coeff_x; 310 final_x_ = start_x + total_distance * coeff_x;
292 final_x_ = Clamped(final_x_, min_x_, max_x_); 311 final_x_ = Clamped(final_x_, min_x_, max_x_);
293 312
294 final_y_ = start_y + total_distance * coeff_y; 313 final_y_ = start_y + total_distance * coeff_y;
295 final_y_ = Clamped(final_y_, min_y_, max_y_); 314 final_y_ = Clamped(final_y_, min_y_, max_y_);
296 315
316 // LOG(ERROR) << final_x_ << ".." << final_y_;
317
297 RecomputeDeltas(); 318 RecomputeDeltas();
298 } 319 }
299 320
300 void Scroller::ExtendDuration(base::TimeDelta extend) { 321 void Scroller::ExtendDuration(base::TimeDelta extend) {
301 base::TimeDelta passed = GetTimePassed(); 322 base::TimeDelta passed = GetTimePassed();
302 duration_ = passed + extend; 323 duration_ = passed + extend;
303 duration_seconds_reciprocal_ = 1.0 / duration_.InSecondsF(); 324 duration_seconds_reciprocal_ = 1.0 / duration_.InSecondsF();
304 finished_ = false; 325 finished_ = false;
305 } 326 }
306 327
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 base::Time::kMicrosecondsPerSecond); 488 base::Time::kMicrosecondsPerSecond);
468 } 489 }
469 490
470 double Scroller::GetSplineFlingDistance(float velocity) const { 491 double Scroller::GetSplineFlingDistance(float velocity) const {
471 const double l = GetSplineDeceleration(velocity); 492 const double l = GetSplineDeceleration(velocity);
472 const double decel_minus_one = kDecelerationRate - 1.0; 493 const double decel_minus_one = kDecelerationRate - 1.0;
473 return fling_friction_ * tuning_coeff_ * 494 return fling_friction_ * tuning_coeff_ *
474 std::exp(kDecelerationRate / decel_minus_one * l); 495 std::exp(kDecelerationRate / decel_minus_one * l);
475 } 496 }
476 497
498 double Scroller::GetSplineVelocityFromDeceleration(float deceleration) const {
499 return std::exp(deceleration) * (fling_friction_ * tuning_coeff_) /
500 kInflexion;
501 }
502
503 double Scroller::GetSplineVelocityFromDistance(float distance) const {
504 double decel_minus_one = kDecelerationRate - 1.0;
505 double deceleration = std::log(distance / (fling_friction_ * tuning_coeff_)) /
506 (kDecelerationRate / decel_minus_one);
507 return GetSplineVelocityFromDeceleration(deceleration);
508 }
509
477 } // namespace ui 510 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/android/scroller.h ('k') | ui/events/blink/input_handler_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698