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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/android/scroller.cc
diff --git a/ui/events/android/scroller.cc b/ui/events/android/scroller.cc
index 1375f3f02f520de6267abd84ffdebed26422d939..bb82624b2206b2a484a6bc5928e03c0f6671c071 100644
--- a/ui/events/android/scroller.cc
+++ b/ui/events/android/scroller.cc
@@ -208,6 +208,25 @@ bool Scroller::ComputeScrollOffset(base::TimeTicks time,
return true;
}
+void Scroller::ComputeTotalScrollOffset(gfx::Vector2dF& offset) {
+ offset.set_x(final_x_);
+ offset.set_y(final_y_);
+}
+
+bool Scroller::ResetCurveBySnappedOffset(const gfx::Vector2dF& offset) {
+ final_x_ = offset.x();
+ final_y_ = offset.y();
+ distance_ = std::sqrt(final_x_ * final_x_ + final_y_ * final_y_);
+
+ velocity_ = GetSplineVelocityFromDistance(distance_);
+ duration_ = GetSplineFlingDuration(velocity_);
+ if (duration_.ToInternalValue() <= 0)
+ return false;
+ duration_seconds_reciprocal_ = 1.0 / duration_.InSecondsF();
+ RecomputeDeltas();
+ return true;
+}
+
void Scroller::StartScroll(float start_x,
float start_y,
float dx,
@@ -294,6 +313,8 @@ void Scroller::Fling(float start_x,
final_y_ = start_y + total_distance * coeff_y;
final_y_ = Clamped(final_y_, min_y_, max_y_);
+ // LOG(ERROR) << final_x_ << ".." << final_y_;
+
RecomputeDeltas();
}
@@ -474,4 +495,16 @@ double Scroller::GetSplineFlingDistance(float velocity) const {
std::exp(kDecelerationRate / decel_minus_one * l);
}
+double Scroller::GetSplineVelocityFromDeceleration(float deceleration) const {
+ return std::exp(deceleration) * (fling_friction_ * tuning_coeff_) /
+ kInflexion;
+}
+
+double Scroller::GetSplineVelocityFromDistance(float distance) const {
+ double decel_minus_one = kDecelerationRate - 1.0;
+ double deceleration = std::log(distance / (fling_friction_ * tuning_coeff_)) /
+ (kDecelerationRate / decel_minus_one);
+ return GetSplineVelocityFromDeceleration(deceleration);
+}
+
} // namespace ui
« 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