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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 const TouchEventWithLatencyInfo& coalesced_event() const { | 68 const TouchEventWithLatencyInfo& coalesced_event() const { |
| 69 return coalesced_event_; | 69 return coalesced_event_; |
| 70 } | 70 } |
| 71 | 71 |
| 72 WebTouchEventWithLatencyList::const_iterator begin() const { | 72 WebTouchEventWithLatencyList::iterator begin() { |
| 73 return events_.begin(); | 73 return events_.begin(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 WebTouchEventWithLatencyList::const_iterator end() const { | 76 WebTouchEventWithLatencyList::iterator end() { |
| 77 return events_.end(); | 77 return events_.end(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 size_t size() const { return events_.size(); } | 80 size_t size() const { return events_.size(); } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 // This is the event that is forwarded to the renderer. | 83 // This is the event that is forwarded to the renderer. |
| 84 TouchEventWithLatencyInfo coalesced_event_; | 84 TouchEventWithLatencyInfo coalesced_event_; |
| 85 | 85 |
| 86 // This is the list of the original events that were coalesced. | 86 // This is the list of the original events that were coalesced. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 116 // also a touch-move, then the events can be coalesced into a single event. | 116 // also a touch-move, then the events can be coalesced into a single event. |
| 117 if (touch_queue_.size() > 1) { | 117 if (touch_queue_.size() > 1) { |
| 118 CoalescedWebTouchEvent* last_event = touch_queue_.back(); | 118 CoalescedWebTouchEvent* last_event = touch_queue_.back(); |
| 119 if (last_event->CoalesceEventIfPossible(event)) | 119 if (last_event->CoalesceEventIfPossible(event)) |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); | 122 touch_queue_.push_back(new CoalescedWebTouchEvent(event)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result, | 125 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result, |
| 126 const ui::LatencyInfo& latency_info) { | 126 ui::LatencyInfo* latency_info) { |
|
jdduke (slow)
2013/10/04 02:22:19
It looks like you can keep this a const ref, same
Yufeng Shen (Slow to review)
2013/10/04 18:03:03
Done.
| |
| 127 DCHECK(!dispatching_touch_ack_); | 127 DCHECK(!dispatching_touch_ack_); |
| 128 if (touch_queue_.empty()) | 128 if (touch_queue_.empty()) |
| 129 return; | 129 return; |
| 130 | 130 |
| 131 // Update the ACK status for each touch point in the ACKed event. | 131 // Update the ACK status for each touch point in the ACKed event. |
| 132 const WebKit::WebTouchEvent& event = | 132 const WebKit::WebTouchEvent& event = |
| 133 touch_queue_.front()->coalesced_event().event; | 133 touch_queue_.front()->coalesced_event().event; |
| 134 if (event.type == WebKit::WebInputEvent::TouchEnd || | 134 if (event.type == WebKit::WebInputEvent::TouchEnd || |
| 135 event.type == WebKit::WebInputEvent::TouchCancel) { | 135 event.type == WebKit::WebInputEvent::TouchCancel) { |
| 136 // The points have been released. Erase the ACK states. | 136 // The points have been released. Erase the ACK states. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 155 void TouchEventQueue::TryForwardNextEventToRenderer() { | 155 void TouchEventQueue::TryForwardNextEventToRenderer() { |
| 156 // If there are queued touch events, then try to forward them to the renderer | 156 // If there are queued touch events, then try to forward them to the renderer |
| 157 // immediately, or ACK the events back to the client if appropriate. | 157 // immediately, or ACK the events back to the client if appropriate. |
| 158 while (!touch_queue_.empty()) { | 158 while (!touch_queue_.empty()) { |
| 159 const TouchEventWithLatencyInfo& touch = | 159 const TouchEventWithLatencyInfo& touch = |
| 160 touch_queue_.front()->coalesced_event(); | 160 touch_queue_.front()->coalesced_event(); |
| 161 if (ShouldForwardToRenderer(touch.event)) { | 161 if (ShouldForwardToRenderer(touch.event)) { |
| 162 client_->SendTouchEventImmediately(touch); | 162 client_->SendTouchEventImmediately(touch); |
| 163 break; | 163 break; |
| 164 } | 164 } |
| 165 ui::LatencyInfo latency; | |
| 165 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, | 166 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
| 166 ui::LatencyInfo()); | 167 &latency); |
| 167 } | 168 } |
| 168 } | 169 } |
| 169 | 170 |
| 170 void TouchEventQueue::FlushQueue() { | 171 void TouchEventQueue::FlushQueue() { |
| 171 DCHECK(!dispatching_touch_ack_); | 172 DCHECK(!dispatching_touch_ack_); |
| 173 ui::LatencyInfo latency; | |
| 172 while (!touch_queue_.empty()) | 174 while (!touch_queue_.empty()) |
| 173 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, | 175 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, |
| 174 ui::LatencyInfo()); | 176 &latency); |
| 175 } | 177 } |
| 176 | 178 |
| 177 size_t TouchEventQueue::GetQueueSize() const { | 179 size_t TouchEventQueue::GetQueueSize() const { |
| 178 return touch_queue_.size(); | 180 return touch_queue_.size(); |
| 179 } | 181 } |
| 180 | 182 |
| 181 const TouchEventWithLatencyInfo& TouchEventQueue::GetLatestEvent() const { | 183 const TouchEventWithLatencyInfo& TouchEventQueue::GetLatestEvent() const { |
| 182 return touch_queue_.back()->coalesced_event(); | 184 return touch_queue_.back()->coalesced_event(); |
| 183 } | 185 } |
| 184 | 186 |
| 185 void TouchEventQueue::PopTouchEventToClient( | 187 void TouchEventQueue::PopTouchEventToClient( |
| 186 InputEventAckState ack_result, | 188 InputEventAckState ack_result, |
| 187 const ui::LatencyInfo& renderer_latency_info) { | 189 ui::LatencyInfo* renderer_latency_info) { |
| 188 if (touch_queue_.empty()) | 190 if (touch_queue_.empty()) |
|
jdduke (slow)
2013/10/04 02:22:19
You're adding renderer_latency_info to latency bel
Yufeng Shen (Slow to review)
2013/10/04 18:03:03
Done.
| |
| 189 return; | 191 return; |
| 190 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front()); | 192 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front()); |
| 191 touch_queue_.pop_front(); | 193 touch_queue_.pop_front(); |
| 192 | 194 |
| 193 // Note that acking the touch-event may result in multiple gestures being sent | 195 // Note that acking the touch-event may result in multiple gestures being sent |
| 194 // to the renderer, or touch-events being queued. | 196 // to the renderer, or touch-events being queued. |
| 195 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true); | 197 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true); |
| 196 | 198 |
| 197 base::TimeTicks now = base::TimeTicks::HighResNow(); | 199 for (WebTouchEventWithLatencyList::iterator iter = acked_event->begin(), |
| 198 for (WebTouchEventWithLatencyList::const_iterator iter = acked_event->begin(), | |
| 199 end = acked_event->end(); | 200 end = acked_event->end(); |
| 200 iter != end; ++iter) { | 201 iter != end; ++iter) { |
| 201 ui::LatencyInfo* latency = const_cast<ui::LatencyInfo*>(&(iter->latency)); | 202 ui::LatencyInfo* latency = &(iter->latency); |
| 202 latency->AddNewLatencyFrom(renderer_latency_info); | 203 latency->AddNewLatencyFrom(*renderer_latency_info); |
| 203 latency->AddLatencyNumberWithTimestamp( | 204 client_->OnTouchEventAck(iter->event, ack_result, latency); |
| 204 ui::INPUT_EVENT_LATENCY_ACKED_COMPONENT, 0, 0, now, 1); | |
| 205 client_->OnTouchEventAck((*iter), ack_result); | |
| 206 } | 205 } |
| 207 } | 206 } |
| 208 | 207 |
| 209 bool TouchEventQueue::ShouldForwardToRenderer( | 208 bool TouchEventQueue::ShouldForwardToRenderer( |
| 210 const WebKit::WebTouchEvent& event) const { | 209 const WebKit::WebTouchEvent& event) const { |
| 211 // Touch press events should always be forwarded to the renderer. | 210 // Touch press events should always be forwarded to the renderer. |
| 212 if (event.type == WebKit::WebInputEvent::TouchStart) | 211 if (event.type == WebKit::WebInputEvent::TouchStart) |
| 213 return true; | 212 return true; |
| 214 | 213 |
| 215 if (event.type == WebKit::WebInputEvent::TouchMove && | 214 if (event.type == WebKit::WebInputEvent::TouchMove && |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 230 // If the ACK status of a point is unknown, then the event should be | 229 // If the ACK status of a point is unknown, then the event should be |
| 231 // forwarded to the renderer. | 230 // forwarded to the renderer. |
| 232 return true; | 231 return true; |
| 233 } | 232 } |
| 234 } | 233 } |
| 235 | 234 |
| 236 return false; | 235 return false; |
| 237 } | 236 } |
| 238 | 237 |
| 239 } // namespace content | 238 } // namespace content |
| OLD | NEW |