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

Unified Diff: ui/events/gestures/fling_curve.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/gestures/fling_curve.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/gestures/fling_curve.cc
diff --git a/ui/events/gestures/fling_curve.cc b/ui/events/gestures/fling_curve.cc
index 00d29a46fd56439cf822beb806376a3c53a7377f..a2890babdc6756afaf1faeb14e8a1ac5ca7b8460 100644
--- a/ui/events/gestures/fling_curve.cc
+++ b/ui/events/gestures/fling_curve.cc
@@ -30,6 +30,24 @@ inline double GetTimeAtVelocity(double v) {
kDefaultGamma;
}
+inline double GetTimeAtPosition(double p) {
+ // TODO(sunyunjia): Set a range for the time for faster interpolation.
+ double tl = 0;
+ double tr = GetTimeAtVelocity(0);
+ p = GetPositionAtTime(tr) - p;
+ double tm = (tl + tr) / 2;
+ double pm = GetPositionAtTime(tm);
+ while (fabs(pm - p) > 0.001) {
+ if (pm < p)
+ tl = tm;
+ else
+ tr = tm;
+ tm = (tl + tr) / 2;
+ pm = GetPositionAtTime(tm);
+ }
+ return tm;
+}
+
} // namespace
namespace ui {
@@ -104,4 +122,22 @@ bool FlingCurve::ComputeScrollDeltaAtTime(base::TimeTicks current,
return still_active;
}
+void FlingCurve::ComputeTotalScrollOffset(gfx::Vector2dF& offset) {
+ float scalar_offset = GetPositionAtTime(curve_duration_) - position_offset_;
+ offset = gfx::ScaleVector2d(displacement_ratio_, scalar_offset);
+}
+
+bool FlingCurve::ResetCurveBySnappedOffset(const gfx::Vector2dF& offset) {
+ float max_offset = std::max(fabs(offset.x()), fabs(offset.y()));
+ if (max_offset > GetPositionAtTime(0)) {
+ return false;
+ }
+ displacement_ratio_ =
+ gfx::Vector2dF(offset.x() / max_offset, offset.y() / max_offset);
+
+ time_offset_ = GetTimeAtPosition(max_offset);
+ position_offset_ = GetPositionAtTime(time_offset_);
+ return true;
+}
+
} // namespace ui
« no previous file with comments | « ui/events/gestures/fling_curve.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698