Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: content/browser/renderer_host/input/touch_event_queue.cc

Issue 26923002: Consolidate WebInputEvent coalescing logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and review Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_.CanCoalesceWith(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);
42 coalesced_event_.CoalesceWith(event_with_latency);
48 events_.push_back(event_with_latency); 43 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; 44 return true;
65 } 45 }
66 46
67 return false; 47 return false;
68 } 48 }
69 49
70 const TouchEventWithLatencyInfo& coalesced_event() const { 50 const TouchEventWithLatencyInfo& coalesced_event() const {
71 return coalesced_event_; 51 return coalesced_event_;
72 } 52 }
73 53
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // If the ACK status of a point is unknown, then the event should be 255 // If the ACK status of a point is unknown, then the event should be
276 // forwarded to the renderer. 256 // forwarded to the renderer.
277 return true; 257 return true;
278 } 258 }
279 } 259 }
280 260
281 return false; 261 return false;
282 } 262 }
283 263
284 } // namespace content 264 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698