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

Unified Diff: content/browser/renderer_host/render_widget_host_view_base.cc

Issue 11013043: beginSmoothScroll should send wheel ticks at constant velocity. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try Created 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_base.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_base.cc b/content/browser/renderer_host/render_widget_host_view_base.cc
index f7662385b6565b16fbc14ea7212692da10bee85d..9a7265cf8a2b5df108f4453c543a575f79acaf93 100644
--- a/content/browser/renderer_host/render_widget_host_view_base.cc
+++ b/content/browser/renderer_host/render_widget_host_view_base.cc
@@ -42,6 +42,8 @@ static const int64 kDurationOfNearScrollGestureMs = 150;
// How long a smooth scroll gesture should run when it is a far scroll.
static const int64 kDurationOfFarScrollGestureMs = 500;
+static const int64 kWheelTicksPerSecond = 1500;
+
// static
RenderWidgetHostViewPort* RenderWidgetHostViewPort::FromRWHV(
RenderWidgetHostView* rwhv) {
@@ -417,6 +419,7 @@ class BasicMouseWheelSmoothScrollGesture
public:
BasicMouseWheelSmoothScrollGesture(bool scroll_down, bool scroll_far)
: start_time_(base::TimeTicks::HighResNow()),
+ last_forward_time_(start_time_),
scroll_down_(scroll_down),
scroll_far_(scroll_far) { }
@@ -431,11 +434,23 @@ class BasicMouseWheelSmoothScrollGesture
if (now - start_time_ > base::TimeDelta::FromMilliseconds(duration_in_ms))
return false;
+ // Figure out how many wheel ticks to send.
+ double seconds_since_last_tick = (now - last_forward_time_).InSecondsF();
+ int num_wheel_ticks = static_cast<int>(
+ seconds_since_last_tick * kWheelTicksPerSecond);
+ if (!num_wheel_ticks) {
+ TRACE_EVENT_INSTANT1("input", "NoMovement",
+ "seconds_since_last_tick", seconds_since_last_tick);
+ return true;
+ }
+
+ last_forward_time_ = now;
+
WebKit::WebMouseWheelEvent event;
event.type = WebKit::WebInputEvent::MouseWheel;
// TODO(nduca): Figure out plausible value.
event.deltaY = scroll_down_ ? -10 : 10;
- event.wheelTicksY = scroll_down_ ? 1 : -1;
+ event.wheelTicksY = (scroll_down_ ? 1 : -1) * num_wheel_ticks;
event.modifiers = 0;
// TODO(nduca): Figure out plausible x and y values.
@@ -452,6 +467,7 @@ class BasicMouseWheelSmoothScrollGesture
private:
virtual ~BasicMouseWheelSmoothScrollGesture() { }
base::TimeTicks start_time_;
+ base::TimeTicks last_forward_time_;
bool scroll_down_;
bool scroll_far_;
};

Powered by Google App Engine
This is Rietveld 408576698