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(); | |
jdduke (slow)
2015/05/08 21:30:49
I think we can remove this function.
lanwei
2015/05/11 19:27:56
Done.
| |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 ACK_WITH_NO_CONSUMER_EXISTS, | 162 ACK_WITH_NO_CONSUMER_EXISTS, |
150 ACK_WITH_NOT_CONSUMED, | 163 ACK_WITH_NOT_CONSUMED, |
151 FORWARD_TO_RENDERER, | 164 FORWARD_TO_RENDERER, |
152 }; | 165 }; |
153 // Filter touches prior to forwarding to the renderer, e.g., if the renderer | 166 // Filter touches prior to forwarding to the renderer, e.g., if the renderer |
154 // has no touch handler. | 167 // has no touch handler. |
155 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); | 168 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); |
156 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); | 169 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); |
157 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, | 170 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, |
158 InputEventAckState ack_result); | 171 InputEventAckState ack_result); |
172 void FlushPendingAsyncTouchmove(); | |
159 | 173 |
160 // Handles touch event forwarding and ack'ed event dispatch. | 174 // Handles touch event forwarding and ack'ed event dispatch. |
161 TouchEventQueueClient* client_; | 175 TouchEventQueueClient* client_; |
162 | 176 |
163 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; | 177 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; |
164 TouchQueue touch_queue_; | 178 TouchQueue touch_queue_; |
165 | 179 |
166 // Position of the first touch in the most recent sequence forwarded to the | 180 // Position of the first touch in the most recent sequence forwarded to the |
167 // client. | 181 // client. |
168 gfx::PointF touch_sequence_start_position_; | 182 gfx::PointF touch_sequence_start_position_; |
169 | 183 |
170 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | 184 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. |
171 // True within the scope of |AckTouchEventToClient()|. | 185 // True within the scope of |AckTouchEventToClient()|. |
172 bool dispatching_touch_ack_; | 186 bool dispatching_touch_ack_; |
173 | 187 |
174 // Used to prevent touch timeout scheduling if we receive a synchronous | 188 // Used to prevent touch timeout scheduling and increase the count for async |
175 // ack after forwarding a touch event to the client. | 189 // touchmove if we receive a synchronous ack after forwarding a touch event |
190 // to the client. | |
176 bool dispatching_touch_; | 191 bool dispatching_touch_; |
177 | 192 |
178 // Whether the renderer has at least one touch handler. | 193 // Whether the renderer has at least one touch handler. |
179 bool has_handlers_; | 194 bool has_handlers_; |
180 | 195 |
181 // Whether any pointer in the touch sequence reported having a consumer. | 196 // Whether any pointer in the touch sequence reported having a consumer. |
182 bool has_handler_for_current_sequence_; | 197 bool has_handler_for_current_sequence_; |
183 | 198 |
184 // Whether to allow any remaining touches for the current sequence. Note that | 199 // 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 | 200 // 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 | 201 // also prevents forwarding of touchstart events for new pointers in the |
187 // current sequence. This is only used when the event is synthetically | 202 // current sequence. This is only used when the event is synthetically |
188 // cancelled after a touch timeout. | 203 // cancelled after a touch timeout. |
189 bool drop_remaining_touches_in_sequence_; | 204 bool drop_remaining_touches_in_sequence_; |
190 | 205 |
191 // Optional handler for timed-out touch event acks. | 206 // Optional handler for timed-out touch event acks. |
192 scoped_ptr<TouchTimeoutHandler> timeout_handler_; | 207 scoped_ptr<TouchTimeoutHandler> timeout_handler_; |
193 | 208 |
194 // Suppression of TouchMove's within a slop region when a sequence has not yet | 209 // Suppression of TouchMove's within a slop region when a sequence has not yet |
195 // been preventDefaulted. | 210 // been preventDefaulted. |
196 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 211 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
197 | 212 |
198 // Whether touch events should remain buffered and dispatched asynchronously | 213 // Whether touch events should remain buffered and dispatched asynchronously |
199 // while a scroll sequence is active. In this mode, touchmove's are throttled | 214 // 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_| | 215 // 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. | 216 // 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. | 217 // For details see the design doc at http://goo.gl/lVyJAa. |
203 bool send_touch_events_async_; | 218 bool send_touch_events_async_; |
204 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; | 219 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; |
220 | |
221 // For uncancelable touch moves, not only we send a fake ack, but also a real | |
222 // ack from render, which we use to decide when to send the next async | |
223 // touchmove. This can help avoid the touch event queue keep growing when | |
224 // render handles touchmove slow. We use a queue ack_pending_async_touchmove_ | |
225 // to store the recent dispatched uncancelable touchmoves which are still | |
226 // waiting for their acks back from render. We do not put them back to the | |
227 // front the touch_event_queue any more. | |
228 std::deque<uint32> ack_pending_async_touchmove_; | |
229 | |
205 double last_sent_touch_timestamp_sec_; | 230 double last_sent_touch_timestamp_sec_; |
206 | 231 |
207 // Event is saved to compare pointer positions for new touchmove events. | 232 // Event is saved to compare pointer positions for new touchmove events. |
208 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; | 233 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; |
209 | 234 |
210 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 235 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
211 }; | 236 }; |
212 | 237 |
213 } // namespace content | 238 } // namespace content |
214 | 239 |
215 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 240 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |