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

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

Issue 2663493003: Move the TouchEventQueue to be completely virtual. (Closed)
Patch Set: Created 3 years, 10 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <deque> 11 #include <deque>
12 #include <list> 12 #include <list>
13 #include <memory> 13 #include <memory>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "content/browser/renderer_host/event_with_latency_info.h" 17 #include "content/browser/renderer_host/event_with_latency_info.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/common/input/input_event_ack_state.h" 19 #include "content/common/input/input_event_ack_state.h"
20 #include "third_party/WebKit/public/platform/WebInputEvent.h" 20 #include "third_party/WebKit/public/platform/WebInputEvent.h"
21 #include "ui/gfx/geometry/point_f.h" 21 #include "ui/gfx/geometry/point_f.h"
tdresser 2017/01/27 15:11:57 We don't need PointF anymore.
22 22
23 namespace content { 23 namespace content {
24 24
25 class CoalescedWebTouchEvent;
26
27 // Interface with which TouchEventQueue can forward touch events, and dispatch 25 // Interface with which TouchEventQueue can forward touch events, and dispatch
28 // touch event responses. 26 // touch event responses.
29 class CONTENT_EXPORT TouchEventQueueClient { 27 class CONTENT_EXPORT TouchEventQueueClient {
30 public: 28 public:
31 virtual ~TouchEventQueueClient() {} 29 virtual ~TouchEventQueueClient() {}
32 30
33 virtual void SendTouchEventImmediately( 31 virtual void SendTouchEventImmediately(
34 const TouchEventWithLatencyInfo& event) = 0; 32 const TouchEventWithLatencyInfo& event) = 0;
35 33
36 virtual void OnTouchEventAck( 34 virtual void OnTouchEventAck(
(...skipping 19 matching lines...) Expand all
56 base::TimeDelta mobile_touch_ack_timeout_delay; 54 base::TimeDelta mobile_touch_ack_timeout_delay;
57 55
58 // Whether the platform supports touch ack timeout behavior. 56 // Whether the platform supports touch ack timeout behavior.
59 // Defaults to false (disabled). 57 // Defaults to false (disabled).
60 bool touch_ack_timeout_supported; 58 bool touch_ack_timeout_supported;
61 }; 59 };
62 60
63 // The |client| must outlive the TouchEventQueue. 61 // The |client| must outlive the TouchEventQueue.
64 TouchEventQueue(TouchEventQueueClient* client, const Config& config); 62 TouchEventQueue(TouchEventQueueClient* client, const Config& config);
65 63
66 ~TouchEventQueue(); 64 virtual ~TouchEventQueue();
67 65
68 // Adds an event to the queue. The event may be coalesced with previously 66 // Adds an event to the queue. The event may be coalesced with previously
69 // queued events (e.g. consecutive touch-move events can be coalesced into a 67 // queued events (e.g. consecutive touch-move events can be coalesced into a
70 // single touch-move event). The event may also be immediately forwarded to 68 // single touch-move event). The event may also be immediately forwarded to
71 // the renderer (e.g. when there are no other queued touch event). 69 // the renderer (e.g. when there are no other queued touch event).
72 void QueueEvent(const TouchEventWithLatencyInfo& event); 70 virtual void QueueEvent(const TouchEventWithLatencyInfo& event) = 0;
73 71
74 // Insert a TouchScrollStarted event in the queue ahead of all not-in-flight 72 // Insert a TouchScrollStarted event in the queue ahead of all not-in-flight
75 // events. 73 // events.
76 void PrependTouchScrollNotification(); 74 virtual void PrependTouchScrollNotification() = 0;
77 75
78 // Notifies the queue that a touch-event has been processed by the renderer. 76 // Notifies the queue that a touch-event has been processed by the renderer.
79 // At this point, if the ack is for async touchmove, remove the uncancelable 77 // At this point, if the ack is for async touchmove, remove the uncancelable
80 // touchmove from the front of the queue and decide if it should dispatch the 78 // touchmove from the front of the queue and decide if it should dispatch the
81 // next pending async touch move event, otherwise the queue may send one or 79 // next pending async touch move event, otherwise the queue may send one or
82 // more gesture events and/or additional queued touch-events to the renderer. 80 // more gesture events and/or additional queued touch-events to the renderer.
83 void ProcessTouchAck(InputEventAckState ack_result, 81 virtual void ProcessTouchAck(InputEventAckState ack_result,
84 const ui::LatencyInfo& latency_info, 82 const ui::LatencyInfo& latency_info,
85 const uint32_t unique_touch_event_id); 83 const uint32_t unique_touch_event_id) = 0;
86 84
87 // When GestureScrollBegin is received, we send a touch cancel to renderer, 85 // When GestureScrollBegin is received, we send a touch cancel to renderer,
88 // route all the following touch events directly to client, and ignore the 86 // route all the following touch events directly to client, and ignore the
89 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, 87 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received,
90 // resume the normal flow of sending touch events to the renderer. 88 // resume the normal flow of sending touch events to the renderer.
91 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); 89 virtual void OnGestureScrollEvent(
90 const GestureEventWithLatencyInfo& gesture_event) = 0;
92 91
93 void OnGestureEventAck( 92 virtual void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
94 const GestureEventWithLatencyInfo& event, 93 InputEventAckState ack_result) = 0;
95 InputEventAckState ack_result);
96 94
97 // Notifies the queue whether the renderer has at least one touch handler. 95 // Notifies the queue whether the renderer has at least one touch handler.
98 void OnHasTouchEventHandlers(bool has_handlers); 96 virtual void OnHasTouchEventHandlers(bool has_handlers) = 0;
99 97
100 // Returns whether the currently pending touch event (waiting ACK) is for 98 // Returns whether the currently pending touch event (waiting ACK) is for
101 // a touch start event. 99 // a touch start event.
102 bool IsPendingAckTouchStart() const; 100 virtual bool IsPendingAckTouchStart() const = 0;
103 101
104 // Sets whether a delayed touch ack will cancel and flush the current 102 // Sets whether a delayed touch ack will cancel and flush the current
105 // touch sequence. Note that, if the timeout was previously disabled, enabling 103 // touch sequence. Note that, if the timeout was previously disabled, enabling
106 // it will take effect only for the following touch sequence. 104 // it will take effect only for the following touch sequence.
107 void SetAckTimeoutEnabled(bool enabled); 105 virtual void SetAckTimeoutEnabled(bool enabled) = 0;
108 106
109 // Sets whether the current site has a mobile friendly viewport. This 107 // Sets whether the current site has a mobile friendly viewport. This
110 // determines which ack timeout delay will be used for *future* touch events. 108 // determines which ack timeout delay will be used for *future* touch events.
111 // The default assumption is that the site is *not* mobile-optimized. 109 // The default assumption is that the site is *not* mobile-optimized.
112 void SetIsMobileOptimizedSite(bool mobile_optimized_site); 110 virtual void SetIsMobileOptimizedSite(bool mobile_optimized_site) = 0;
113 111
114 // Whether ack timeout behavior is supported and enabled for the current site. 112 // Whether ack timeout behavior is supported and enabled for the current site.
115 bool IsAckTimeoutEnabled() const; 113 virtual bool IsAckTimeoutEnabled() const = 0;
116 114
117 bool empty() const WARN_UNUSED_RESULT { 115 virtual bool Empty() const WARN_UNUSED_RESULT = 0;
118 return touch_queue_.empty();
119 }
120 116
121 size_t size() const { 117 protected:
122 return touch_queue_.size();
123 }
124
125 bool has_handlers() const { return has_handlers_; }
126
127 size_t uncancelable_touch_moves_pending_ack_count() const {
128 return ack_pending_async_touchmove_ids_.size();
129 }
130
131 private:
132 class TouchTimeoutHandler;
133 class TouchMoveSlopSuppressor;
134 friend class TouchTimeoutHandler;
135 friend class TouchEventQueueTest;
136
137 bool HasPendingAsyncTouchMoveForTesting() const;
138 bool IsTimeoutRunningForTesting() const;
139 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const;
140
141 // Empties the queue of touch events. This may result in any number of gesture
142 // events being sent to the renderer.
143 void FlushQueue();
144
145 // Walks the queue, checking each event with |FilterBeforeForwarding()|.
146 // If allowed, forwards the touch event and stops processing further events.
147 // Otherwise, acks the event with |INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS|.
148 void TryForwardNextEventToRenderer();
149
150 // Forwards the event at the head of the queue to the renderer.
151 void ForwardNextEventToRenderer();
152
153 // Pops the touch-event from the head of the queue and acks it to the client.
154 void PopTouchEventToClient(InputEventAckState ack_result);
155
156 // Pops the touch-event from the top of the queue and acks it to the client,
157 // updating the event with |renderer_latency_info|.
158 void PopTouchEventToClient(InputEventAckState ack_result,
159 const ui::LatencyInfo& renderer_latency_info);
160
161 // Ack all coalesced events at the head of the queue to the client with
162 // |ack_result|, updating the acked events with |optional_latency_info| if it
163 // exists, and popping the head of the queue.
164 void AckTouchEventToClient(InputEventAckState ack_result,
165 const ui::LatencyInfo* optional_latency_info);
166
167 // Dispatch |touch| to the client. Before dispatching, updates pointer
168 // states in touchmove events for pointers that have not changed position.
169 void SendTouchEventImmediately(TouchEventWithLatencyInfo* touch);
170
171 enum PreFilterResult {
172 ACK_WITH_NO_CONSUMER_EXISTS,
173 ACK_WITH_NOT_CONSUMED,
174 FORWARD_TO_RENDERER,
175 };
176 // Filter touches prior to forwarding to the renderer, e.g., if the renderer
177 // has no touch handler.
178 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event);
179 void ForwardToRenderer(const TouchEventWithLatencyInfo& event);
180 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event,
181 InputEventAckState ack_result);
182 void FlushPendingAsyncTouchmove();
183
184 // Handles touch event forwarding and ack'ed event dispatch. 118 // Handles touch event forwarding and ack'ed event dispatch.
185 TouchEventQueueClient* client_; 119 TouchEventQueueClient* client_;
tdresser 2017/01/27 15:11:57 Let's just duplicate this in both subclasses, so w
dtapuska 2017/01/27 15:57:39 Done.
186 120
187 std::list<std::unique_ptr<CoalescedWebTouchEvent>> touch_queue_; 121 private:
188
189 // Position of the first touch in the most recent sequence forwarded to the
190 // client.
191 gfx::PointF touch_sequence_start_position_;
192
193 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|.
194 // True within the scope of |AckTouchEventToClient()|.
195 bool dispatching_touch_ack_;
196
197 // Used to prevent touch timeout scheduling and increase the count for async
198 // touchmove if we receive a synchronous ack after forwarding a touch event
199 // to the client.
200 bool dispatching_touch_;
201
202 // Whether the renderer has at least one touch handler.
203 bool has_handlers_;
204
205 // Whether any pointer in the touch sequence reported having a consumer.
206 bool has_handler_for_current_sequence_;
207
208 // Whether to allow any remaining touches for the current sequence. Note that
209 // this is a stricter condition than an empty |touch_consumer_states_|, as it
210 // also prevents forwarding of touchstart events for new pointers in the
211 // current sequence. This is only used when the event is synthetically
212 // cancelled after a touch timeout.
213 bool drop_remaining_touches_in_sequence_;
214
215 // Optional handler for timed-out touch event acks.
216 std::unique_ptr<TouchTimeoutHandler> timeout_handler_;
217
218 // Suppression of TouchMove's within a slop region when a sequence has not yet
219 // been preventDefaulted.
220 std::unique_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_;
221
222 // Whether touch events should remain buffered and dispatched asynchronously
223 // while a scroll sequence is active. In this mode, touchmove's are throttled
224 // and ack'ed immediately, but remain buffered in |pending_async_touchmove_|
225 // until a sufficient time period has elapsed since the last sent touch event.
226 // For details see the design doc at http://goo.gl/lVyJAa.
227 bool send_touch_events_async_;
228 std::unique_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_;
229
230 // For uncancelable touch moves, not only we send a fake ack, but also a real
231 // ack from render, which we use to decide when to send the next async
232 // touchmove. This can help avoid the touch event queue keep growing when
233 // render handles touchmove slow. We use a queue
234 // ack_pending_async_touchmove_ids to store the recent dispatched
235 // uncancelable touchmoves which are still waiting for their acks back from
236 // render. We do not put them back to the front the touch_event_queue any
237 // more.
238 std::deque<uint32_t> ack_pending_async_touchmove_ids_;
239
240 double last_sent_touch_timestamp_sec_;
241
242 // Event is saved to compare pointer positions for new touchmove events.
243 std::unique_ptr<blink::WebTouchEvent> last_sent_touchevent_;
244
245 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); 122 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue);
246 }; 123 };
247 124
248 } // namespace content 125 } // namespace content
249 126
250 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ 127 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698