| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 ~CoalescedWebTouchEvent() { | 30 ~CoalescedWebTouchEvent() { |
| 31 TRACE_EVENT_ASYNC_END0( | 31 TRACE_EVENT_ASYNC_END0( |
| 32 "input", "TouchEventQueue::QueueEvent", this); | 32 "input", "TouchEventQueue::QueueEvent", this); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Coalesces the event with the existing event if possible. Returns whether | 35 // Coalesces the event with the existing event if possible. Returns whether |
| 36 // the event was coalesced. | 36 // the event was coalesced. |
| 37 bool CoalesceEventIfPossible( | 37 bool CoalesceEventIfPossible( |
| 38 const TouchEventWithLatencyInfo& event_with_latency) { | 38 const TouchEventWithLatencyInfo& event_with_latency) { |
| 39 if (coalesced_event_.event.type == WebKit::WebInputEvent::TouchMove && | 39 if (ignore_ack_) |
| 40 event_with_latency.event.type == WebKit::WebInputEvent::TouchMove && | 40 return false; |
| 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( | |
| 47 "input", "TouchEventQueue::MoveCoalesced", TRACE_EVENT_SCOPE_THREAD); | |
| 48 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; | |
| 65 } | |
| 66 | 41 |
| 67 return false; | 42 if (!coalesced_event_.CanCoalesceWith(event_with_latency)) |
| 43 return false; |
| 44 |
| 45 TRACE_EVENT_INSTANT0( |
| 46 "input", "TouchEventQueue::MoveCoalesced", TRACE_EVENT_SCOPE_THREAD); |
| 47 coalesced_event_.CoalesceWith(event_with_latency); |
| 48 events_.push_back(event_with_latency); |
| 49 return true; |
| 68 } | 50 } |
| 69 | 51 |
| 70 const TouchEventWithLatencyInfo& coalesced_event() const { | 52 const TouchEventWithLatencyInfo& coalesced_event() const { |
| 71 return coalesced_event_; | 53 return coalesced_event_; |
| 72 } | 54 } |
| 73 | 55 |
| 74 WebTouchEventWithLatencyList::iterator begin() { | 56 WebTouchEventWithLatencyList::iterator begin() { |
| 75 return events_.begin(); | 57 return events_.begin(); |
| 76 } | 58 } |
| 77 | 59 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // If the ACK status of a point is unknown, then the event should be | 257 // If the ACK status of a point is unknown, then the event should be |
| 276 // forwarded to the renderer. | 258 // forwarded to the renderer. |
| 277 return true; | 259 return true; |
| 278 } | 260 } |
| 279 } | 261 } |
| 280 | 262 |
| 281 return false; | 263 return false; |
| 282 } | 264 } |
| 283 | 265 |
| 284 } // namespace content | 266 } // namespace content |
| OLD | NEW |