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

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

Issue 11013043: beginSmoothScroll should send wheel ticks at constant velocity. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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_impl.cc
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index 62fd6edbc99ef68534bfecfeb75d4304dbe6059d..0b6ab8e26ab85920eae3b54e22e12813719f11bd 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -147,6 +147,7 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
allow_privileged_mouse_lock_(false),
has_touch_handler_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ tick_active_smooth_scroll_gestures_task_posted_(false),
gesture_event_filter_(new GestureEventFilter(this)) {
CHECK(delegate_);
if (routing_id_ == MSG_ROUTING_NONE) {
@@ -1592,6 +1593,12 @@ void RenderWidgetHostImpl::OnMsgInputEventAck(WebInputEvent::Type event_type,
ProcessGestureAck(processed, type);
}
+ // If an input ack is pending, then hold off ticking the gesture
+ // until we get an input ack.
+ if (in_process_event_types_.size() == 0 &&
+ !active_smooth_scroll_gestures_.empty())
+ TickActiveSmoothScrollGesture();
+
// This is used only for testing, and the other end does not use the
// source object. On linux, specifying
// Source<RenderWidgetHost> results in a very strange
@@ -1615,21 +1622,45 @@ void RenderWidgetHostImpl::OnMsgBeginSmoothScroll(
view_->CreateSmoothScrollGesture(
scroll_down, scroll_far, mouse_event_x,
mouse_event_y)));
+
+ // If an input ack is pending, then hold off ticking the gesture
+ // until we get an input ack.
+ if (!in_process_event_types_.empty())
+ return;
+ if (tick_active_smooth_scroll_gestures_task_posted_)
+ return;
TickActiveSmoothScrollGesture();
}
void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() {
- if (active_smooth_scroll_gestures_.size() == 0)
+ TRACE_EVENT0("input", "RenderWidgetHostImpl::TickActiveSmoothScrollGesture");
+ tick_active_smooth_scroll_gestures_task_posted_ = false;
+ if (active_smooth_scroll_gestures_.empty()) {
+ TRACE_EVENT_INSTANT0("input", "EarlyOut_NoActiveScrollGesture");
return;
+ }
- TimeTicks now = TimeTicks::HighResNow();
+ base::TimeTicks now = TimeTicks::HighResNow();
+ base::TimeDelta preferred_interval =
+ base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs);
+ base::TimeDelta time_until_next_ideal_interval =
+ (last_smooth_scroll_gestures_tick_time_ + preferred_interval) -
+ now;
+ if (time_until_next_ideal_interval.InMilliseconds() > 0) {
+ TRACE_EVENT_INSTANT1(
+ "input", "EarlyOut_TickedTooRecently",
+ "delay", time_until_next_ideal_interval.InMilliseconds());
+ // Post a task.
+ tick_active_smooth_scroll_gestures_task_posted_ = true;
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture,
+ weak_factory_.GetWeakPtr()),
+ time_until_next_ideal_interval);
+ return;
+ }
- // Post the next tick right away so it is regular.
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture,
- weak_factory_.GetWeakPtr()),
- base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs));
+ last_smooth_scroll_gestures_tick_time_ = now;
// Separate ticking of gestures from sending their completion messages.
std::vector<int> ids_that_are_done;
@@ -1653,6 +1684,19 @@ void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() {
Send(new ViewMsg_SmoothScrollCompleted(routing_id_, id));
}
+
+ // No need to post the next tick if an input is in flight.
+ if (!in_process_event_types_.empty())
+ return;
+
+ TRACE_EVENT_INSTANT1("input", "PostTickTask",
+ "delay", preferred_interval.InMilliseconds());
+ tick_active_smooth_scroll_gestures_task_posted_ = true;
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture,
+ weak_factory_.GetWeakPtr()),
+ preferred_interval);
}
void RenderWidgetHostImpl::OnMsgSelectRangeAck() {
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_view_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698