Chromium Code Reviews| 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); | |
| 68 | 71 |
| 69 // When GestureScrollBegin is received, we send a touch cancel to renderer, | 72 // When GestureScrollBegin is received, we send a touch cancel to renderer, |
| 70 // route all the following touch events directly to client, and ignore the | 73 // route all the following touch events directly to client, and ignore the |
| 71 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, | 74 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, |
| 72 // resume the normal flow of sending touch events to the renderer. | 75 // resume the normal flow of sending touch events to the renderer. |
| 73 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); | 76 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); |
| 74 | 77 |
| 75 void OnGestureEventAck( | 78 void OnGestureEventAck( |
| 76 const GestureEventWithLatencyInfo& event, | 79 const GestureEventWithLatencyInfo& event, |
| 77 InputEventAckState ack_result); | 80 InputEventAckState ack_result); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 95 bool empty() const WARN_UNUSED_RESULT { | 98 bool empty() const WARN_UNUSED_RESULT { |
| 96 return touch_queue_.empty(); | 99 return touch_queue_.empty(); |
| 97 } | 100 } |
| 98 | 101 |
| 99 size_t size() const { | 102 size_t size() const { |
| 100 return touch_queue_.size(); | 103 return touch_queue_.size(); |
| 101 } | 104 } |
| 102 | 105 |
| 103 bool has_handlers() const { return has_handlers_; } | 106 bool has_handlers() const { return has_handlers_; } |
| 104 | 107 |
| 108 size_t uncancelable_touch_moves_pending_ack_count() const { | |
| 109 return ack_pending_async_touchmove_.size(); | |
| 110 } | |
| 111 | |
| 105 private: | 112 private: |
| 106 class TouchTimeoutHandler; | 113 class TouchTimeoutHandler; |
| 107 class TouchMoveSlopSuppressor; | 114 class TouchMoveSlopSuppressor; |
| 108 friend class TouchTimeoutHandler; | 115 friend class TouchTimeoutHandler; |
| 109 friend class TouchEventQueueTest; | 116 friend class TouchEventQueueTest; |
| 110 | 117 |
| 111 bool HasPendingAsyncTouchMoveForTesting() const; | 118 bool HasPendingAsyncTouchMoveForTesting() const; |
| 112 bool IsTimeoutRunningForTesting() const; | 119 bool IsTimeoutRunningForTesting() const; |
| 113 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; | 120 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; |
| 114 | 121 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 ACK_WITH_NO_CONSUMER_EXISTS, | 156 ACK_WITH_NO_CONSUMER_EXISTS, |
| 150 ACK_WITH_NOT_CONSUMED, | 157 ACK_WITH_NOT_CONSUMED, |
| 151 FORWARD_TO_RENDERER, | 158 FORWARD_TO_RENDERER, |
| 152 }; | 159 }; |
| 153 // Filter touches prior to forwarding to the renderer, e.g., if the renderer | 160 // Filter touches prior to forwarding to the renderer, e.g., if the renderer |
| 154 // has no touch handler. | 161 // has no touch handler. |
| 155 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); | 162 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); |
| 156 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); | 163 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); |
| 157 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, | 164 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, |
| 158 InputEventAckState ack_result); | 165 InputEventAckState ack_result); |
| 166 void FlushPendingAsyncTouchmove(); | |
| 159 | 167 |
| 160 // Handles touch event forwarding and ack'ed event dispatch. | 168 // Handles touch event forwarding and ack'ed event dispatch. |
| 161 TouchEventQueueClient* client_; | 169 TouchEventQueueClient* client_; |
| 162 | 170 |
| 163 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; | 171 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; |
| 164 TouchQueue touch_queue_; | 172 TouchQueue touch_queue_; |
| 165 | 173 |
| 166 // Position of the first touch in the most recent sequence forwarded to the | 174 // Position of the first touch in the most recent sequence forwarded to the |
| 167 // client. | 175 // client. |
| 168 gfx::PointF touch_sequence_start_position_; | 176 gfx::PointF touch_sequence_start_position_; |
| 169 | 177 |
| 170 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | 178 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. |
| 171 // True within the scope of |AckTouchEventToClient()|. | 179 // True within the scope of |AckTouchEventToClient()|. |
| 172 bool dispatching_touch_ack_; | 180 bool dispatching_touch_ack_; |
| 173 | 181 |
| 174 // Used to prevent touch timeout scheduling if we receive a synchronous | 182 // Used to prevent touch timeout scheduling and increase the count for async |
| 175 // ack after forwarding a touch event to the client. | 183 // touchmove if we receive a synchronous ack after forwarding a touch event |
| 184 // to the client. | |
| 176 bool dispatching_touch_; | 185 bool dispatching_touch_; |
| 177 | 186 |
| 178 // Whether the renderer has at least one touch handler. | 187 // Whether the renderer has at least one touch handler. |
| 179 bool has_handlers_; | 188 bool has_handlers_; |
| 180 | 189 |
| 181 // Whether any pointer in the touch sequence reported having a consumer. | 190 // Whether any pointer in the touch sequence reported having a consumer. |
| 182 bool has_handler_for_current_sequence_; | 191 bool has_handler_for_current_sequence_; |
| 183 | 192 |
| 184 // Whether to allow any remaining touches for the current sequence. Note that | 193 // 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 | 194 // 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 | 195 // also prevents forwarding of touchstart events for new pointers in the |
| 187 // current sequence. This is only used when the event is synthetically | 196 // current sequence. This is only used when the event is synthetically |
| 188 // cancelled after a touch timeout. | 197 // cancelled after a touch timeout. |
| 189 bool drop_remaining_touches_in_sequence_; | 198 bool drop_remaining_touches_in_sequence_; |
| 190 | 199 |
| 191 // Optional handler for timed-out touch event acks. | 200 // Optional handler for timed-out touch event acks. |
| 192 scoped_ptr<TouchTimeoutHandler> timeout_handler_; | 201 scoped_ptr<TouchTimeoutHandler> timeout_handler_; |
| 193 | 202 |
| 194 // Suppression of TouchMove's within a slop region when a sequence has not yet | 203 // Suppression of TouchMove's within a slop region when a sequence has not yet |
| 195 // been preventDefaulted. | 204 // been preventDefaulted. |
| 196 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 205 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
| 197 | 206 |
| 198 // Whether touch events should remain buffered and dispatched asynchronously | 207 // Whether touch events should remain buffered and dispatched asynchronously |
| 199 // while a scroll sequence is active. In this mode, touchmove's are throttled | 208 // 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_| | 209 // 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. | 210 // 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. | 211 // For details see the design doc at http://goo.gl/lVyJAa. |
| 203 bool send_touch_events_async_; | 212 bool send_touch_events_async_; |
| 204 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; | 213 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; |
| 214 | |
| 215 // For uncancelable touch moves, not only we send a fake ack, but also a real | |
| 216 // ack from render, which we use to decide when to send the next async | |
| 217 // touchmove. This can help avoid the touch event queue keep growing when | |
| 218 // render handles touchmove slow. We use a queue ack_pending_async_touchmove_ | |
| 219 // to store the recent dispatched uncancelable touchmoves which are still | |
| 220 // waiting for their acks back from render. We do not put them back to the | |
| 221 // front the touch_event_queue any more. | |
| 222 std::deque<uint32> ack_pending_async_touchmove_; | |
|
jdduke (slow)
2015/05/12 16:07:11
Maybe |ack_pending_async_touchmove_ids_|?
lanwei
2015/05/13 21:01:53
Done.
| |
| 223 | |
| 205 double last_sent_touch_timestamp_sec_; | 224 double last_sent_touch_timestamp_sec_; |
| 206 | 225 |
| 207 // Event is saved to compare pointer positions for new touchmove events. | 226 // Event is saved to compare pointer positions for new touchmove events. |
| 208 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; | 227 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; |
| 209 | 228 |
| 210 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 229 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
| 211 }; | 230 }; |
| 212 | 231 |
| 213 } // namespace content | 232 } // namespace content |
| 214 | 233 |
| 215 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 234 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
| OLD | NEW |