| 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 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 typedef std::vector<TouchEventWithLatencyInfo> WebTouchEventWithLatencyList; | 13 typedef std::vector<TouchEventWithLatencyInfo> WebTouchEventWithLatencyList; |
| 14 | 14 |
| 15 // This class represents a single coalesced touch event. However, it also keeps | 15 // This class represents a single coalesced touch event. However, it also keeps |
| 16 // track of all the original touch-events that were coalesced into a single | 16 // track of all the original touch-events that were coalesced into a single |
| 17 // event. The coalesced event is forwarded to the renderer, while the original | 17 // event. The coalesced event is forwarded to the renderer, while the original |
| 18 // touch-events are sent to the Client (on ACK for the coalesced event) so that | 18 // touch-events are sent to the Client (on ACK for the coalesced event) so that |
| 19 // the Client receives the event with their original timestamp. | 19 // the Client receives the event with their original timestamp. |
| 20 class CoalescedWebTouchEvent { | 20 class CoalescedWebTouchEvent { |
| 21 public: | 21 public: |
| 22 explicit CoalescedWebTouchEvent(const TouchEventWithLatencyInfo& event) | 22 explicit CoalescedWebTouchEvent(const TouchEventWithLatencyInfo& event) |
| 23 : coalesced_event_(event), | 23 : coalesced_event_(event) { |
| 24 ignore_ack_(false) { | |
| 25 events_.push_back(event); | 24 events_.push_back(event); |
| 26 TRACE_EVENT_ASYNC_BEGIN0( | 25 TRACE_EVENT_ASYNC_BEGIN0( |
| 27 "input", "TouchEventQueue::QueueEvent", this); | 26 "input", "TouchEventQueue::QueueEvent", this); |
| 28 } | 27 } |
| 29 | 28 |
| 30 ~CoalescedWebTouchEvent() { | 29 ~CoalescedWebTouchEvent() { |
| 31 TRACE_EVENT_ASYNC_END0( | 30 TRACE_EVENT_ASYNC_END0( |
| 32 "input", "TouchEventQueue::QueueEvent", this); | 31 "input", "TouchEventQueue::QueueEvent", this); |
| 33 } | 32 } |
| 34 | 33 |
| 35 // Coalesces the event with the existing event if possible. Returns whether | 34 // Coalesces the event with the existing event if possible. Returns whether |
| 36 // the event was coalesced. | 35 // the event was coalesced. |
| 37 bool CoalesceEventIfPossible( | 36 bool CoalesceEventIfPossible( |
| 38 const TouchEventWithLatencyInfo& event_with_latency) { | 37 const TouchEventWithLatencyInfo& event_with_latency) { |
| 39 if (coalesced_event_.event.type == WebKit::WebInputEvent::TouchMove && | 38 if (!ignore_ack_ && |
| 40 event_with_latency.event.type == WebKit::WebInputEvent::TouchMove && | 39 coalesced_event_.TryCoalesceWith(event_with_latency)) { |
| 41 coalesced_event_.event.modifiers == | |
| 42 event_with_latency.event.modifiers && | |
| 43 coalesced_event_.event.touchesLength == | |
| 44 event_with_latency.event.touchesLength && | |
| 45 !ignore_ack_) { | |
| 46 TRACE_EVENT_INSTANT0( | 40 TRACE_EVENT_INSTANT0( |
| 47 "input", "TouchEventQueue::MoveCoalesced", TRACE_EVENT_SCOPE_THREAD); | 41 "input", "TouchEventQueue::MoveCoalesced", TRACE_EVENT_SCOPE_THREAD); |
| 48 events_.push_back(event_with_latency); | 42 events_.push_back(event_with_latency); |
| 49 // The WebTouchPoints include absolute position information. So it is | |
| 50 // sufficient to simply replace the previous event with the new event. | |
| 51 // However, it is necessary to make sure that all the points have the | |
| 52 // correct state, i.e. the touch-points that moved in the last event, but | |
| 53 // didn't change in the current event, will have Stationary state. It is | |
| 54 // necessary to change them back to Moved state. | |
| 55 const WebKit::WebTouchEvent last_event = coalesced_event_.event; | |
| 56 const ui::LatencyInfo last_latency = coalesced_event_.latency; | |
| 57 coalesced_event_ = event_with_latency; | |
| 58 coalesced_event_.latency.MergeWith(last_latency); | |
| 59 for (unsigned i = 0; i < last_event.touchesLength; ++i) { | |
| 60 if (last_event.touches[i].state == WebKit::WebTouchPoint::StateMoved) | |
| 61 coalesced_event_.event.touches[i].state = | |
| 62 WebKit::WebTouchPoint::StateMoved; | |
| 63 } | |
| 64 return true; | 43 return true; |
| 65 } | 44 } |
| 66 | 45 |
| 67 return false; | 46 return false; |
| 68 } | 47 } |
| 69 | 48 |
| 70 const TouchEventWithLatencyInfo& coalesced_event() const { | 49 const TouchEventWithLatencyInfo& coalesced_event() const { |
| 71 return coalesced_event_; | 50 return coalesced_event_; |
| 72 } | 51 } |
| 73 | 52 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // If the ACK status of a point is unknown, then the event should be | 258 // If the ACK status of a point is unknown, then the event should be |
| 280 // forwarded to the renderer. | 259 // forwarded to the renderer. |
| 281 return true; | 260 return true; |
| 282 } | 261 } |
| 283 } | 262 } |
| 284 | 263 |
| 285 return false; | 264 return false; |
| 286 } | 265 } |
| 287 | 266 |
| 288 } // namespace content | 267 } // namespace content |
| OLD | NEW |