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 #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 <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 ~TouchEventQueue(); | 55 ~TouchEventQueue(); |
56 | 56 |
57 // Adds an event to the queue. The event may be coalesced with previously | 57 // Adds an event to the queue. The event may be coalesced with previously |
58 // queued events (e.g. consecutive touch-move events can be coalesced into a | 58 // queued events (e.g. consecutive touch-move events can be coalesced into a |
59 // single touch-move event). The event may also be immediately forwarded to | 59 // single touch-move event). The event may also be immediately forwarded to |
60 // the renderer (e.g. when there are no other queued touch event). | 60 // the renderer (e.g. when there are no other queued touch event). |
61 void QueueEvent(const TouchEventWithLatencyInfo& event); | 61 void QueueEvent(const TouchEventWithLatencyInfo& event); |
62 | 62 |
63 // Notifies the queue that a touch-event has been processed by the renderer. | 63 // Notifies the queue that a touch-event has been processed by the renderer. |
64 // At this point, the queue may send one or more gesture events and/or | 64 // At this point, if the ack is for async touchmove, remove the uncancelable |
65 // additional queued touch-events to the renderer. | 65 // touchmove from the front of the queue and decide if it should dispatch the |
| 66 // next pending async touch move event, otherwise the queue may send one or |
| 67 // more gesture events and/or additional queued touch-events to the renderer. |
66 void ProcessTouchAck(InputEventAckState ack_result, | 68 void ProcessTouchAck(InputEventAckState ack_result, |
67 const ui::LatencyInfo& latency_info); | 69 const ui::LatencyInfo& latency_info, |
| 70 const uint32 unique_touch_event_id); |
| 71 |
| 72 // Notifies the queue that an uncancelable touchmove event has been received |
| 73 // by the renderer. The queue will decrease the uncancelable pending |
| 74 // touchmove ack count and decide if it should dispatch the next pending |
| 75 // async touch move event. |
| 76 void ProcessUncancelableTouchMoveAck(); |
68 | 77 |
69 // When GestureScrollBegin is received, we send a touch cancel to renderer, | 78 // When GestureScrollBegin is received, we send a touch cancel to renderer, |
70 // route all the following touch events directly to client, and ignore the | 79 // route all the following touch events directly to client, and ignore the |
71 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, | 80 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, |
72 // resume the normal flow of sending touch events to the renderer. | 81 // resume the normal flow of sending touch events to the renderer. |
73 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); | 82 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); |
74 | 83 |
75 void OnGestureEventAck( | 84 void OnGestureEventAck( |
76 const GestureEventWithLatencyInfo& event, | 85 const GestureEventWithLatencyInfo& event, |
77 InputEventAckState ack_result); | 86 InputEventAckState ack_result); |
(...skipping 17 matching lines...) Expand all Loading... |
95 bool empty() const WARN_UNUSED_RESULT { | 104 bool empty() const WARN_UNUSED_RESULT { |
96 return touch_queue_.empty(); | 105 return touch_queue_.empty(); |
97 } | 106 } |
98 | 107 |
99 size_t size() const { | 108 size_t size() const { |
100 return touch_queue_.size(); | 109 return touch_queue_.size(); |
101 } | 110 } |
102 | 111 |
103 bool has_handlers() const { return has_handlers_; } | 112 bool has_handlers() const { return has_handlers_; } |
104 | 113 |
| 114 size_t uncancelable_touch_moves_pending_ack_count() const { |
| 115 return ack_pending_async_touchmove_.size(); |
| 116 } |
| 117 |
105 private: | 118 private: |
106 class TouchTimeoutHandler; | 119 class TouchTimeoutHandler; |
107 class TouchMoveSlopSuppressor; | 120 class TouchMoveSlopSuppressor; |
108 friend class TouchTimeoutHandler; | 121 friend class TouchTimeoutHandler; |
109 friend class TouchEventQueueTest; | 122 friend class TouchEventQueueTest; |
110 | 123 |
111 bool HasPendingAsyncTouchMoveForTesting() const; | 124 bool HasPendingAsyncTouchMoveForTesting() const; |
112 bool IsTimeoutRunningForTesting() const; | 125 bool IsTimeoutRunningForTesting() const; |
113 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; | 126 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; |
114 | 127 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 TouchQueue touch_queue_; | 177 TouchQueue touch_queue_; |
165 | 178 |
166 // Position of the first touch in the most recent sequence forwarded to the | 179 // Position of the first touch in the most recent sequence forwarded to the |
167 // client. | 180 // client. |
168 gfx::PointF touch_sequence_start_position_; | 181 gfx::PointF touch_sequence_start_position_; |
169 | 182 |
170 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | 183 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. |
171 // True within the scope of |AckTouchEventToClient()|. | 184 // True within the scope of |AckTouchEventToClient()|. |
172 bool dispatching_touch_ack_; | 185 bool dispatching_touch_ack_; |
173 | 186 |
174 // Used to prevent touch timeout scheduling if we receive a synchronous | 187 // Used to prevent touch timeout scheduling and increase the count for async |
175 // ack after forwarding a touch event to the client. | 188 // touchmove if we receive a synchronous ack after forwarding a touch event |
| 189 // to the client. |
176 bool dispatching_touch_; | 190 bool dispatching_touch_; |
177 | 191 |
178 // Whether the renderer has at least one touch handler. | 192 // Whether the renderer has at least one touch handler. |
179 bool has_handlers_; | 193 bool has_handlers_; |
180 | 194 |
181 // Whether any pointer in the touch sequence reported having a consumer. | 195 // Whether any pointer in the touch sequence reported having a consumer. |
182 bool has_handler_for_current_sequence_; | 196 bool has_handler_for_current_sequence_; |
183 | 197 |
184 // Whether to allow any remaining touches for the current sequence. Note that | 198 // Whether to allow any remaining touches for the current sequence. Note that |
185 // this is a stricter condition than an empty |touch_consumer_states_|, as it | 199 // this is a stricter condition than an empty |touch_consumer_states_|, as it |
186 // also prevents forwarding of touchstart events for new pointers in the | 200 // also prevents forwarding of touchstart events for new pointers in the |
187 // current sequence. This is only used when the event is synthetically | 201 // current sequence. This is only used when the event is synthetically |
188 // cancelled after a touch timeout. | 202 // cancelled after a touch timeout. |
189 bool drop_remaining_touches_in_sequence_; | 203 bool drop_remaining_touches_in_sequence_; |
190 | 204 |
191 // Optional handler for timed-out touch event acks. | 205 // Optional handler for timed-out touch event acks. |
192 scoped_ptr<TouchTimeoutHandler> timeout_handler_; | 206 scoped_ptr<TouchTimeoutHandler> timeout_handler_; |
193 | 207 |
194 // Suppression of TouchMove's within a slop region when a sequence has not yet | 208 // Suppression of TouchMove's within a slop region when a sequence has not yet |
195 // been preventDefaulted. | 209 // been preventDefaulted. |
196 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 210 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
197 | 211 |
198 // Whether touch events should remain buffered and dispatched asynchronously | 212 // Whether touch events should remain buffered and dispatched asynchronously |
199 // while a scroll sequence is active. In this mode, touchmove's are throttled | 213 // while a scroll sequence is active. In this mode, touchmove's are throttled |
200 // and ack'ed immediately, but remain buffered in |pending_async_touchmove_| | 214 // and ack'ed immediately, but remain buffered in |pending_async_touchmove_| |
201 // until a sufficient time period has elapsed since the last sent touch event. | 215 // until a sufficient time period has elapsed since the last sent touch event. |
202 // For details see the design doc at http://goo.gl/lVyJAa. | 216 // For details see the design doc at http://goo.gl/lVyJAa. |
203 bool send_touch_events_async_; | 217 bool send_touch_events_async_; |
204 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; | 218 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; |
| 219 |
| 220 // For uncancelable touch moves, not only we send a fake ack, but also a real |
| 221 // ack from render, which we use to decide when to send the next async |
| 222 // touchmove. This can help avoid the touch event queue keep growing when |
| 223 // render handles touchmove slow. We use a queue ack_pending_async_touchmove_ |
| 224 // to store the recent dispatched uncancelable touchmoves which are still |
| 225 // waiting for their acks back from render. We do not put them back to the |
| 226 // front the touch_event_queue any more. |
| 227 std::deque<uint32> ack_pending_async_touchmove_; |
| 228 |
205 double last_sent_touch_timestamp_sec_; | 229 double last_sent_touch_timestamp_sec_; |
206 | 230 |
207 // Event is saved to compare pointer positions for new touchmove events. | 231 // Event is saved to compare pointer positions for new touchmove events. |
208 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; | 232 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; |
209 | 233 |
210 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 234 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
211 }; | 235 }; |
212 | 236 |
213 } // namespace content | 237 } // namespace content |
214 | 238 |
215 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 239 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |