Chromium Code Reviews| Index: content/browser/renderer_host/touch_event_queue.cc |
| diff --git a/content/browser/renderer_host/touch_event_queue.cc b/content/browser/renderer_host/touch_event_queue.cc |
| index d66727daa30ba8d06490380bc669dcbcadcb80d3..560a43b72c8fe7983fcf6ec0136a7f905c92162c 100644 |
| --- a/content/browser/renderer_host/touch_event_queue.cc |
| +++ b/content/browser/renderer_host/touch_event_queue.cc |
| @@ -26,12 +26,27 @@ void TouchEventQueue::QueueEvent(const WebKit::WebTouchEvent& event) { |
| return; |
| } |
| - // TODO(sad): Coalesce with |touch_queue_.back()| if appropriate. |
| - // http://crbug.com/110231 |
| - touch_queue_.push_back(event); |
| + if (!CoalesceIfPossible(event)) |
| + touch_queue_.push_back(event); |
|
aelias_OOO_until_Jul13
2012/10/17 01:52:57
Can we just move the coalescing logic into QueueEv
sadrul
2012/10/17 02:18:00
Good idea. Done.
|
| } |
| void TouchEventQueue::ProcessTouchAck(bool processed) { |
| + PopTouchEventToView(processed); |
| + // If there's a queued touch-event, then forward it to the renderer now. |
| + if (!touch_queue_.empty()) |
| + render_widget_host_->ForwardTouchEventImmediately(touch_queue_.front()); |
| +} |
| + |
| +void TouchEventQueue::FlushQueue() { |
| + while (!touch_queue_.empty()) |
| + PopTouchEventToView(false); |
| +} |
| + |
| +void TouchEventQueue::Reset() { |
| + touch_queue_.clear(); |
| +} |
| + |
| +void TouchEventQueue::PopTouchEventToView(bool processed) { |
| CHECK(!touch_queue_.empty()); |
| WebKit::WebTouchEvent acked_event = touch_queue_.front(); |
| touch_queue_.pop_front(); |
| @@ -41,10 +56,29 @@ void TouchEventQueue::ProcessTouchAck(bool processed) { |
| RenderWidgetHostViewPort* view = RenderWidgetHostViewPort::FromRWHV( |
| render_widget_host_->GetView()); |
| view->ProcessAckedTouchEvent(acked_event, processed); |
| +} |
| - // If there's a queued touch-event, then forward it to the renderer now. |
| - if (!touch_queue_.empty()) |
| - render_widget_host_->ForwardTouchEventImmediately(touch_queue_.front()); |
| +bool TouchEventQueue::CoalesceIfPossible(const WebKit::WebTouchEvent& event) { |
| + if (empty()) |
| + return false; |
| + |
| + // Allow coalescing only touch-move events, and only if they have the same |
| + // number of touches and the same modifiers. |
| + WebKit::WebTouchEvent& last_event = touch_queue_.back(); |
| + if (event.type != WebKit::WebInputEvent::TouchMove || |
| + last_event.type != WebKit::WebInputEvent::TouchMove) |
| + return false; |
| + |
| + if (event.modifiers != last_event.modifiers) |
| + return false; |
| + if (event.touchesLength != last_event.touchesLength) |
| + return false; |
| + |
| + // The WebTouchPoints include absolute position information. So it is |
| + // sufficient to simply replace the previous event with the new event. |
| + touch_queue_.pop_back(); |
| + touch_queue_.push_back(event); |
| + return true; |
| } |
| } // namespace content |