Chromium Code Reviews| 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 bc88da4299a9c44c39fcfbe8f0915741a2f56ed3..f16c71002dded3e2b04c3c5466879967cfdf0f9d 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_.size()) |
|
piman
2012/10/06 06:18:57
nit: ! .empty() instead of .size()
|
| + 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 |
| @@ -1613,21 +1620,45 @@ void RenderWidgetHostImpl::OnMsgBeginSmoothScroll( |
| std::make_pair(gesture_id, |
| view_->CreateSmoothScrollGesture( |
| scroll_down, scroll_far))); |
| + |
| + // If an input ack is pending, then hold off ticking the gesture |
| + // until we get an input ack. |
| + if (in_process_event_types_.size()) |
|
piman
2012/10/06 06:18:57
nit: ! .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_.size() == 0) { |
|
piman
2012/10/06 06:18:57
nit: 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); |
|
piman
2012/10/06 06:18:57
nit: line continuations at +4
|
| + base::TimeDelta time_until_next_ideal_interval = |
| + (last_smooth_scroll_gestures_tick_time_ + preferred_interval) - |
|
piman
2012/10/06 06:18:57
+4
|
| + 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; |
| @@ -1651,6 +1682,19 @@ void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() { |
| Send(new ViewMsg_SmoothScrollCompleted(routing_id_, id)); |
| } |
| + |
| + // No need to ost the next tick if an input is in flight. |
| + if (in_process_event_types_.size() != 0) |
|
piman
2012/10/06 06:18:57
!.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() { |