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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 10 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 TouchEventQueue::TouchEventQueue(RenderWidgetHostImpl* host) | 92 TouchEventQueue::TouchEventQueue(RenderWidgetHostImpl* host) |
| 93 : render_widget_host_(host) { | 93 : render_widget_host_(host) { |
| 94 } | 94 } |
| 95 | 95 |
| 96 TouchEventQueue::~TouchEventQueue() { | 96 TouchEventQueue::~TouchEventQueue() { |
| 97 if (!touch_queue_.empty()) | 97 if (!touch_queue_.empty()) |
| 98 STLDeleteElements(&touch_queue_); | 98 STLDeleteElements(&touch_queue_); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void TouchEventQueue::QueueEvent(const TouchEventWithLatencyInfo& event) { | 101 void TouchEventQueue::QueueEvent(const TouchEventWithLatencyInfo& event) { |
| 102 latest_event_ = event; | |
| 102 if (touch_queue_.empty()) { | 103 if (touch_queue_.empty()) { |
| 103 // There is no touch event in the queue. Forward it to the renderer | 104 // There is no touch event in the queue. Forward it to the renderer |
| 104 // immediately. | 105 // immediately. |
| 105 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); | 106 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); |
| 106 if (ShouldForwardToRenderer(event.event)) | 107 if (ShouldForwardToRenderer(event.event)) |
| 107 render_widget_host_->ForwardTouchEventImmediately(event); | 108 render_widget_host_->ForwardTouchEventImmediately(event); |
| 108 else | 109 else |
| 109 PopTouchEventToView(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 110 PopTouchEventToView(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 110 return; | 111 return; |
| 111 } | 112 } |
| 112 | 113 |
| 113 // If the last queued touch-event was a touch-move, and the current event is | 114 // If the last queued touch-event was a touch-move, and the current event is |
| 114 // also a touch-move, then the events can be coalesced into a single event. | 115 // also a touch-move, then the events can be coalesced into a single event. |
| 115 if (touch_queue_.size() > 1) { | 116 if (touch_queue_.size() > 1) { |
| 116 CoalescedWebTouchEvent* last_event = touch_queue_.back(); | 117 CoalescedWebTouchEvent* last_event = touch_queue_.back(); |
| 117 if (last_event->CoalesceEventIfPossible(event)) | 118 if (last_event->CoalesceEventIfPossible(event)) { |
| 119 latest_event_ = last_event->coalesced_event(); | |
| 118 return; | 120 return; |
| 121 } | |
| 119 } | 122 } |
| 120 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); | 123 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); |
| 121 } | 124 } |
| 122 | 125 |
| 123 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result) { | 126 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result) { |
| 124 if (touch_queue_.empty()) | 127 if (touch_queue_.empty()) |
| 125 return; | 128 return; |
| 126 | 129 |
| 130 // If scroll update is in progress, we should have cleared the touch | |
| 131 // event queue. | |
| 132 DCHECK(!render_widget_host_->is_scroll_update_in_progress()); | |
| 133 | |
| 127 // Update the ACK status for each touch point in the ACKed event. | 134 // Update the ACK status for each touch point in the ACKed event. |
| 128 const WebKit::WebTouchEvent& event = | 135 const WebKit::WebTouchEvent& event = |
| 129 touch_queue_.front()->coalesced_event().event; | 136 touch_queue_.front()->coalesced_event().event; |
| 130 if (event.type == WebKit::WebInputEvent::TouchEnd || | 137 if (event.type == WebKit::WebInputEvent::TouchEnd || |
| 131 event.type == WebKit::WebInputEvent::TouchCancel) { | 138 event.type == WebKit::WebInputEvent::TouchCancel) { |
| 132 // The points have been released. Erase the ACK states. | 139 // The points have been released. Erase the ACK states. |
| 133 for (unsigned i = 0; i < event.touchesLength; ++i) { | 140 for (unsigned i = 0; i < event.touchesLength; ++i) { |
| 134 const WebKit::WebTouchPoint& point = event.touches[i]; | 141 const WebKit::WebTouchPoint& point = event.touches[i]; |
| 135 if (point.state == WebKit::WebTouchPoint::StateReleased || | 142 if (point.state == WebKit::WebTouchPoint::StateReleased || |
| 136 point.state == WebKit::WebTouchPoint::StateCancelled) | 143 point.state == WebKit::WebTouchPoint::StateCancelled) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 152 const TouchEventWithLatencyInfo& touch = | 159 const TouchEventWithLatencyInfo& touch = |
| 153 touch_queue_.front()->coalesced_event(); | 160 touch_queue_.front()->coalesced_event(); |
| 154 if (ShouldForwardToRenderer(touch.event)) { | 161 if (ShouldForwardToRenderer(touch.event)) { |
| 155 render_widget_host_->ForwardTouchEventImmediately(touch); | 162 render_widget_host_->ForwardTouchEventImmediately(touch); |
| 156 break; | 163 break; |
| 157 } | 164 } |
| 158 PopTouchEventToView(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 165 PopTouchEventToView(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 159 } | 166 } |
| 160 } | 167 } |
| 161 | 168 |
| 169 void TouchEventQueue::OnGestureScrollStart() { | |
| 170 TouchEventWithLatencyInfo cancel_event = GetLatestEvent(); | |
| 171 FlushQueue(); | |
| 172 cancel_event.event.type = WebKit::WebInputEvent::TouchCancel; | |
| 173 for (size_t i = 0; i < cancel_event.event.touchesLength; i++) | |
| 174 cancel_event.event.touches[i].state = WebKit::WebTouchPoint::StateCancelled; | |
| 175 render_widget_host_->ForwardTouchEventImmediately(cancel_event); | |
| 176 // We only want to send the touch cancel to the renderer, but don't want | |
| 177 // it gets processed in view. So clear the touch event queue here and the | |
| 178 // ack for the cancel event will just be ignored. | |
| 179 Reset(); | |
| 180 } | |
| 181 | |
| 162 void TouchEventQueue::FlushQueue() { | 182 void TouchEventQueue::FlushQueue() { |
| 163 while (!touch_queue_.empty()) | 183 while (!touch_queue_.empty()) |
| 164 PopTouchEventToView(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 184 PopTouchEventToView(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 165 } | 185 } |
| 166 | 186 |
| 167 void TouchEventQueue::Reset() { | 187 void TouchEventQueue::Reset() { |
| 168 if (!touch_queue_.empty()) | 188 if (!touch_queue_.empty()) |
| 169 STLDeleteElements(&touch_queue_); | 189 STLDeleteElements(&touch_queue_); |
| 170 } | 190 } |
| 171 | 191 |
| 172 size_t TouchEventQueue::GetQueueSize() const { | 192 size_t TouchEventQueue::GetQueueSize() const { |
| 173 return touch_queue_.size(); | 193 return touch_queue_.size(); |
| 174 } | 194 } |
| 175 | 195 |
| 176 const TouchEventWithLatencyInfo& TouchEventQueue::GetLatestEvent() const { | 196 const TouchEventWithLatencyInfo& TouchEventQueue::GetLatestEvent() const { |
| 177 return touch_queue_.back()->coalesced_event(); | 197 return latest_event_; |
|
sadrul
2013/06/20 08:51:27
When is touch_queue_ empty here?
Yufeng Shen (Slow to review)
2013/06/20 17:56:45
The PopTouchEventToView() below first pops the tou
| |
| 178 } | 198 } |
| 179 | 199 |
| 180 void TouchEventQueue::PopTouchEventToView(InputEventAckState ack_result) { | 200 void TouchEventQueue::PopTouchEventToView(InputEventAckState ack_result) { |
| 181 if (touch_queue_.empty()) | 201 if (touch_queue_.empty()) |
| 182 return; | 202 return; |
| 183 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front()); | 203 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front()); |
| 184 touch_queue_.pop_front(); | 204 touch_queue_.pop_front(); |
| 185 | 205 |
| 186 // Note that acking the touch-event may result in multiple gestures being sent | 206 // Note that acking the touch-event may result in multiple gestures being sent |
| 187 // to the renderer. | 207 // to the renderer. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 214 // If the ACK status of a point is unknown, then the event should be | 234 // If the ACK status of a point is unknown, then the event should be |
| 215 // forwarded to the renderer. | 235 // forwarded to the renderer. |
| 216 return true; | 236 return true; |
| 217 } | 237 } |
| 218 } | 238 } |
| 219 | 239 |
| 220 return false; | 240 return false; |
| 221 } | 241 } |
| 222 | 242 |
| 223 } // namespace content | 243 } // namespace content |
| OLD | NEW |