Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/input/touch_event_queue.h" | 5 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 dispatching_touch_ack_(false) { | 94 dispatching_touch_ack_(false) { |
| 95 DCHECK(client); | 95 DCHECK(client); |
| 96 } | 96 } |
| 97 | 97 |
| 98 TouchEventQueue::~TouchEventQueue() { | 98 TouchEventQueue::~TouchEventQueue() { |
| 99 if (!touch_queue_.empty()) | 99 if (!touch_queue_.empty()) |
| 100 STLDeleteElements(&touch_queue_); | 100 STLDeleteElements(&touch_queue_); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void TouchEventQueue::QueueEvent(const TouchEventWithLatencyInfo& event) { | 103 void TouchEventQueue::QueueEvent(const TouchEventWithLatencyInfo& event) { |
| 104 latest_event_ = event; | |
| 104 // If the queueing of |event| was triggered by an ack dispatch, defer | 105 // If the queueing of |event| was triggered by an ack dispatch, defer |
| 105 // processing the event until the dispatch has finished. | 106 // processing the event until the dispatch has finished. |
| 106 if (touch_queue_.empty() && !dispatching_touch_ack_) { | 107 if (touch_queue_.empty() && !dispatching_touch_ack_) { |
| 107 // There is no touch event in the queue. Forward it to the renderer | 108 // There is no touch event in the queue. Forward it to the renderer |
| 108 // immediately. | 109 // immediately. |
| 109 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); | 110 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); |
| 110 if (ShouldForwardToRenderer(event.event)) | 111 if (ShouldForwardToRenderer(event.event)) |
| 111 client_->SendTouchEventImmediately(event); | 112 client_->SendTouchEventImmediately(event); |
| 112 else | 113 else |
| 113 PopTouchEventWithAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 114 PopTouchEventWithAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 114 return; | 115 return; |
| 115 } | 116 } |
| 116 | 117 |
| 117 // If the last queued touch-event was a touch-move, and the current event is | 118 // If the last queued touch-event was a touch-move, and the current event is |
| 118 // also a touch-move, then the events can be coalesced into a single event. | 119 // also a touch-move, then the events can be coalesced into a single event. |
| 119 if (touch_queue_.size() > 1) { | 120 if (touch_queue_.size() > 1) { |
| 120 CoalescedWebTouchEvent* last_event = touch_queue_.back(); | 121 CoalescedWebTouchEvent* last_event = touch_queue_.back(); |
| 121 if (last_event->CoalesceEventIfPossible(event)) | 122 if (last_event->CoalesceEventIfPossible(event)) { |
| 123 latest_event_ = last_event->coalesced_event(); | |
| 122 return; | 124 return; |
| 125 } | |
| 123 } | 126 } |
| 124 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); | 127 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); |
| 125 } | 128 } |
| 126 | 129 |
| 127 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result) { | 130 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result) { |
| 128 DCHECK(!dispatching_touch_ack_); | 131 DCHECK(!dispatching_touch_ack_); |
| 129 if (touch_queue_.empty()) | 132 if (touch_queue_.empty()) |
| 130 return; | 133 return; |
| 131 | 134 |
| 132 // Update the ACK status for each touch point in the ACKed event. | 135 // Update the ACK status for each touch point in the ACKed event. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 157 const TouchEventWithLatencyInfo& touch = | 160 const TouchEventWithLatencyInfo& touch = |
| 158 touch_queue_.front()->coalesced_event(); | 161 touch_queue_.front()->coalesced_event(); |
| 159 if (ShouldForwardToRenderer(touch.event)) { | 162 if (ShouldForwardToRenderer(touch.event)) { |
| 160 client_->SendTouchEventImmediately(touch); | 163 client_->SendTouchEventImmediately(touch); |
| 161 break; | 164 break; |
| 162 } | 165 } |
| 163 PopTouchEventWithAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 166 PopTouchEventWithAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 164 } | 167 } |
| 165 } | 168 } |
| 166 | 169 |
| 170 void TouchEventQueue::OnGestureScrollEnd() { | |
| 171 TouchEventWithLatencyInfo end_event = GetLatestEvent(); | |
| 172 FlushQueue(); | |
| 173 end_event.event.type = WebKit::WebInputEvent::TouchEnd; | |
| 174 for (unsigned i = 0; i < end_event.event.touchesLength; ++i) | |
| 175 end_event.event.touches[i].state = WebKit::WebTouchPoint::StateReleased; | |
| 176 end_event.latency = ui::LatencyInfo(); | |
| 177 client_->SendTouchEventImmediately(end_event); | |
| 178 ClearQueue(); | |
| 179 } | |
| 180 | |
| 167 void TouchEventQueue::FlushQueue() { | 181 void TouchEventQueue::FlushQueue() { |
| 168 DCHECK(!dispatching_touch_ack_); | 182 DCHECK(!dispatching_touch_ack_); |
| 169 while (!touch_queue_.empty()) | 183 while (!touch_queue_.empty()) |
| 170 PopTouchEventWithAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 184 PopTouchEventWithAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 171 } | 185 } |
| 172 | 186 |
| 187 void TouchEventQueue::ClearQueue() { | |
| 188 if (!touch_queue_.empty()) | |
| 189 STLDeleteElements(&touch_queue_); | |
| 190 } | |
| 191 | |
| 173 size_t TouchEventQueue::GetQueueSize() const { | 192 size_t TouchEventQueue::GetQueueSize() const { |
| 174 return touch_queue_.size(); | 193 return touch_queue_.size(); |
| 175 } | 194 } |
| 176 | 195 |
| 177 const TouchEventWithLatencyInfo& TouchEventQueue::GetLatestEvent() const { | 196 const TouchEventWithLatencyInfo& TouchEventQueue::GetLatestEvent() const { |
| 178 return touch_queue_.back()->coalesced_event(); | 197 return latest_event_; |
|
sadrul
2013/08/06 19:34:19
Why is this necessary?
| |
| 179 } | 198 } |
| 180 | 199 |
| 181 void TouchEventQueue::PopTouchEventWithAck(InputEventAckState ack_result) { | 200 void TouchEventQueue::PopTouchEventWithAck(InputEventAckState ack_result) { |
| 182 if (touch_queue_.empty()) | 201 if (touch_queue_.empty()) |
| 183 return; | 202 return; |
| 184 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front()); | 203 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front()); |
| 185 touch_queue_.pop_front(); | 204 touch_queue_.pop_front(); |
| 186 | 205 |
| 187 // 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 |
| 188 // to the renderer, or touch-events being queued. | 207 // to the renderer, or touch-events being queued. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 218 // If the ACK status of a point is unknown, then the event should be | 237 // If the ACK status of a point is unknown, then the event should be |
| 219 // forwarded to the renderer. | 238 // forwarded to the renderer. |
| 220 return true; | 239 return true; |
| 221 } | 240 } |
| 222 } | 241 } |
| 223 | 242 |
| 224 return false; | 243 return false; |
| 225 } | 244 } |
| 226 | 245 |
| 227 } // namespace content | 246 } // namespace content |
| OLD | NEW |