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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, the queue may send one or more gesture events and/or |
65 // additional queued touch-events to the renderer. | 65 // additional queued touch-events to the renderer. |
66 void ProcessTouchAck(InputEventAckState ack_result, | 66 void ProcessTouchAck(InputEventAckState ack_result, |
67 const ui::LatencyInfo& latency_info); | 67 const ui::LatencyInfo& latency_info); |
68 | 68 |
| 69 // Notifies the queue that an uncancelable touchmove event has been received |
| 70 // by the renderer. The queue will decrease the uncancelable pending |
| 71 // touchmove ack count and decide if it should dispatch the next pending |
| 72 // async touch move event. |
| 73 void ProcessUncancelableTouchMoveAck(); |
| 74 |
69 // When GestureScrollBegin is received, we send a touch cancel to renderer, | 75 // When GestureScrollBegin is received, we send a touch cancel to renderer, |
70 // route all the following touch events directly to client, and ignore the | 76 // route all the following touch events directly to client, and ignore the |
71 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, | 77 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, |
72 // resume the normal flow of sending touch events to the renderer. | 78 // resume the normal flow of sending touch events to the renderer. |
73 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); | 79 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); |
74 | 80 |
75 void OnGestureEventAck( | 81 void OnGestureEventAck( |
76 const GestureEventWithLatencyInfo& event, | 82 const GestureEventWithLatencyInfo& event, |
77 InputEventAckState ack_result); | 83 InputEventAckState ack_result); |
78 | 84 |
(...skipping 16 matching lines...) Expand all Loading... |
95 bool empty() const WARN_UNUSED_RESULT { | 101 bool empty() const WARN_UNUSED_RESULT { |
96 return touch_queue_.empty(); | 102 return touch_queue_.empty(); |
97 } | 103 } |
98 | 104 |
99 size_t size() const { | 105 size_t size() const { |
100 return touch_queue_.size(); | 106 return touch_queue_.size(); |
101 } | 107 } |
102 | 108 |
103 bool has_handlers() const { return has_handlers_; } | 109 bool has_handlers() const { return has_handlers_; } |
104 | 110 |
| 111 size_t uncancelable_touch_moves_pending_ack_count() const { |
| 112 return ack_pending_async_touchmove_.size(); |
| 113 } |
| 114 |
105 private: | 115 private: |
106 class TouchTimeoutHandler; | 116 class TouchTimeoutHandler; |
107 class TouchMoveSlopSuppressor; | 117 class TouchMoveSlopSuppressor; |
108 friend class TouchTimeoutHandler; | 118 friend class TouchTimeoutHandler; |
109 friend class TouchEventQueueTest; | 119 friend class TouchEventQueueTest; |
110 | 120 |
111 bool HasPendingAsyncTouchMoveForTesting() const; | 121 bool HasPendingAsyncTouchMoveForTesting() const; |
112 bool IsTimeoutRunningForTesting() const; | 122 bool IsTimeoutRunningForTesting() const; |
113 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; | 123 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; |
114 | 124 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // been preventDefaulted. | 205 // been preventDefaulted. |
196 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 206 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
197 | 207 |
198 // Whether touch events should remain buffered and dispatched asynchronously | 208 // Whether touch events should remain buffered and dispatched asynchronously |
199 // while a scroll sequence is active. In this mode, touchmove's are throttled | 209 // 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_| | 210 // 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. | 211 // 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. | 212 // For details see the design doc at http://goo.gl/lVyJAa. |
203 bool send_touch_events_async_; | 213 bool send_touch_events_async_; |
204 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; | 214 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; |
| 215 |
| 216 // For uncancelable touch moves, not only we send a fake ack, but also a real |
| 217 // ack from render, which we use to decide when to send the next async |
| 218 // touchmove. This can help avoid the touch event queue keep growing when |
| 219 // render handles touchmove slow. We use a queue ack_pending_async_touchmove_ |
| 220 // to store the recent dispatched uncancelable touchmoves which are still |
| 221 // waiting for their acks back from render. We do not put them back to the |
| 222 // front the touch_event_queue any more. |
| 223 std::deque<TouchEventWithLatencyInfo> ack_pending_async_touchmove_; |
| 224 |
205 double last_sent_touch_timestamp_sec_; | 225 double last_sent_touch_timestamp_sec_; |
206 | 226 |
207 // Event is saved to compare pointer positions for new touchmove events. | 227 // Event is saved to compare pointer positions for new touchmove events. |
208 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; | 228 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; |
209 | 229 |
210 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 230 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
211 }; | 231 }; |
212 | 232 |
213 } // namespace content | 233 } // namespace content |
214 | 234 |
215 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 235 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |