Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/touch_event_queue.h" | 5 #include "content/browser/renderer_host/touch_event_queue.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/render_widget_host_impl.h" | 7 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 8 #include "content/public/browser/render_widget_host_view.h" | 8 #include "content/public/browser/render_widget_host_view.h" |
| 9 #include "content/port/browser/render_widget_host_view_port.h" | 9 #include "content/port/browser/render_widget_host_view_port.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 TouchEventQueue::TouchEventQueue(RenderWidgetHostImpl* host) | 13 TouchEventQueue::TouchEventQueue(RenderWidgetHostImpl* host) |
| 14 : render_widget_host_(host) { | 14 : render_widget_host_(host) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 TouchEventQueue::~TouchEventQueue() { | 17 TouchEventQueue::~TouchEventQueue() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 void TouchEventQueue::QueueEvent(const WebKit::WebTouchEvent& event) { | 20 void TouchEventQueue::QueueEvent(const WebKit::WebTouchEvent& event) { |
| 21 if (touch_queue_.empty()) { | 21 if (touch_queue_.empty()) { |
| 22 // There is no touch event in the queue. Forward it to the renderer | 22 // There is no touch event in the queue. Forward it to the renderer |
| 23 // immediately. | 23 // immediately. |
| 24 touch_queue_.push_back(event); | 24 touch_queue_.push_back(event); |
| 25 render_widget_host_->ForwardTouchEventImmediately(event); | 25 render_widget_host_->ForwardTouchEventImmediately(event); |
| 26 return; | 26 return; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // TODO(sad): Coalesce with |touch_queue_.back()| if appropriate. | 29 if (!CoalesceIfPossible(event)) |
| 30 // http://crbug.com/110231 | 30 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.
| |
| 31 touch_queue_.push_back(event); | |
| 32 } | 31 } |
| 33 | 32 |
| 34 void TouchEventQueue::ProcessTouchAck(bool processed) { | 33 void TouchEventQueue::ProcessTouchAck(bool processed) { |
| 34 PopTouchEventToView(processed); | |
| 35 // If there's a queued touch-event, then forward it to the renderer now. | |
| 36 if (!touch_queue_.empty()) | |
| 37 render_widget_host_->ForwardTouchEventImmediately(touch_queue_.front()); | |
| 38 } | |
| 39 | |
| 40 void TouchEventQueue::FlushQueue() { | |
| 41 while (!touch_queue_.empty()) | |
| 42 PopTouchEventToView(false); | |
| 43 } | |
| 44 | |
| 45 void TouchEventQueue::Reset() { | |
| 46 touch_queue_.clear(); | |
| 47 } | |
| 48 | |
| 49 void TouchEventQueue::PopTouchEventToView(bool processed) { | |
| 35 CHECK(!touch_queue_.empty()); | 50 CHECK(!touch_queue_.empty()); |
| 36 WebKit::WebTouchEvent acked_event = touch_queue_.front(); | 51 WebKit::WebTouchEvent acked_event = touch_queue_.front(); |
| 37 touch_queue_.pop_front(); | 52 touch_queue_.pop_front(); |
| 38 | 53 |
| 39 // Note that acking the touch-event may result in multiple gestures being sent | 54 // Note that acking the touch-event may result in multiple gestures being sent |
| 40 // to the renderer. | 55 // to the renderer. |
| 41 RenderWidgetHostViewPort* view = RenderWidgetHostViewPort::FromRWHV( | 56 RenderWidgetHostViewPort* view = RenderWidgetHostViewPort::FromRWHV( |
| 42 render_widget_host_->GetView()); | 57 render_widget_host_->GetView()); |
| 43 view->ProcessAckedTouchEvent(acked_event, processed); | 58 view->ProcessAckedTouchEvent(acked_event, processed); |
| 59 } | |
| 44 | 60 |
| 45 // If there's a queued touch-event, then forward it to the renderer now. | 61 bool TouchEventQueue::CoalesceIfPossible(const WebKit::WebTouchEvent& event) { |
| 46 if (!touch_queue_.empty()) | 62 if (empty()) |
| 47 render_widget_host_->ForwardTouchEventImmediately(touch_queue_.front()); | 63 return false; |
| 64 | |
| 65 // Allow coalescing only touch-move events, and only if they have the same | |
| 66 // number of touches and the same modifiers. | |
| 67 WebKit::WebTouchEvent& last_event = touch_queue_.back(); | |
| 68 if (event.type != WebKit::WebInputEvent::TouchMove || | |
| 69 last_event.type != WebKit::WebInputEvent::TouchMove) | |
| 70 return false; | |
| 71 | |
| 72 if (event.modifiers != last_event.modifiers) | |
| 73 return false; | |
| 74 if (event.touchesLength != last_event.touchesLength) | |
| 75 return false; | |
| 76 | |
| 77 // The WebTouchPoints include absolute position information. So it is | |
| 78 // sufficient to simply replace the previous event with the new event. | |
| 79 touch_queue_.pop_back(); | |
| 80 touch_queue_.push_back(event); | |
| 81 return true; | |
| 48 } | 82 } |
| 49 | 83 |
| 50 } // namespace content | 84 } // namespace content |
| OLD | NEW |