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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // using the disposition to determine whether a scroll update should be | 48 // using the disposition to determine whether a scroll update should be |
49 // sent. Mobile Safari's default overflow scroll behavior. | 49 // sent. Mobile Safari's default overflow scroll behavior. |
50 TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE, | 50 TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE, |
51 // Send touchmove events throughout a scroll, but throttle sending and | 51 // Send touchmove events throughout a scroll, but throttle sending and |
52 // ignore the ACK as long as scrolling remains possible. Unconsumed scroll | 52 // ignore the ACK as long as scrolling remains possible. Unconsumed scroll |
53 // events return touchmove events to being dispatched synchronously. | 53 // events return touchmove events to being dispatched synchronously. |
54 TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE, | 54 TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE, |
55 TOUCH_SCROLLING_MODE_DEFAULT = TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE | 55 TOUCH_SCROLLING_MODE_DEFAULT = TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE |
56 }; | 56 }; |
57 | 57 |
58 struct CONTENT_EXPORT Config { | 58 // The |client| must outlive the TouchEventQueue. If |
59 Config(); | 59 // |touchmove_suppression_length_dips| <= 0, touch move suppression is |
60 | 60 // disabled. |
61 // Determines the bounds of the (square) touchmove slop suppression region. | 61 TouchEventQueue(TouchEventQueueClient* client, |
62 // Defaults to 0 (disabled). | 62 TouchScrollingMode mode, |
63 double touchmove_slop_suppression_length_dips; | 63 double touchmove_suppression_length_dips); |
64 | |
65 // Determines the type of touch scrolling. | |
66 // Defaults to TouchEventQueue:::TOUCH_SCROLLING_MODE_DEFAULT. | |
67 TouchEventQueue::TouchScrollingMode touch_scrolling_mode; | |
68 | |
69 // Controls whether touch ack timeouts will trigger touch cancellation. | |
70 // Defaults to 200ms. | |
71 base::TimeDelta touch_ack_timeout_delay; | |
72 | |
73 // Whether the platform supports touch ack timeout behavior. | |
74 // Defaults to false (disabled). | |
75 bool touch_ack_timeout_supported; | |
76 }; | |
77 | |
78 // The |client| must outlive the TouchEventQueue. | |
79 TouchEventQueue(TouchEventQueueClient* client, const Config& config); | |
80 | |
81 ~TouchEventQueue(); | 64 ~TouchEventQueue(); |
82 | 65 |
83 // 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 |
84 // 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 |
85 // 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 |
86 // 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). |
87 void QueueEvent(const TouchEventWithLatencyInfo& event); | 70 void QueueEvent(const TouchEventWithLatencyInfo& event); |
88 | 71 |
89 // Notifies the queue that a touch-event has been processed by the renderer. | 72 // Notifies the queue that a touch-event has been processed by the renderer. |
90 // At this point, the queue may send one or more gesture events and/or | 73 // At this point, the queue may send one or more gesture events and/or |
(...skipping 14 matching lines...) Expand all Loading... |
105 // Notifies the queue whether the renderer has at least one touch handler. | 88 // Notifies the queue whether the renderer has at least one touch handler. |
106 void OnHasTouchEventHandlers(bool has_handlers); | 89 void OnHasTouchEventHandlers(bool has_handlers); |
107 | 90 |
108 // Returns whether the currently pending touch event (waiting ACK) is for | 91 // Returns whether the currently pending touch event (waiting ACK) is for |
109 // a touch start event. | 92 // a touch start event. |
110 bool IsPendingAckTouchStart() const; | 93 bool IsPendingAckTouchStart() const; |
111 | 94 |
112 // Sets whether a delayed touch ack will cancel and flush the current | 95 // Sets whether a delayed touch ack will cancel and flush the current |
113 // touch sequence. Note that, if the timeout was previously disabled, enabling | 96 // touch sequence. Note that, if the timeout was previously disabled, enabling |
114 // it will take effect only for the following touch sequence. | 97 // it will take effect only for the following touch sequence. |
115 void SetAckTimeoutEnabled(bool enabled); | 98 void SetAckTimeoutEnabled(bool enabled, base::TimeDelta ack_timeout_delay); |
116 | 99 |
117 bool empty() const WARN_UNUSED_RESULT { | 100 bool empty() const WARN_UNUSED_RESULT { |
118 return touch_queue_.empty(); | 101 return touch_queue_.empty(); |
119 } | 102 } |
120 | 103 |
121 size_t size() const { | 104 size_t size() const { |
122 return touch_queue_.size(); | 105 return touch_queue_.size(); |
123 } | 106 } |
124 | 107 |
125 bool ack_timeout_enabled() const { | 108 bool ack_timeout_enabled() const { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 enum TouchFilteringState { | 193 enum TouchFilteringState { |
211 FORWARD_ALL_TOUCHES, // Don't filter at all - the default. | 194 FORWARD_ALL_TOUCHES, // Don't filter at all - the default. |
212 FORWARD_TOUCHES_UNTIL_TIMEOUT, // Don't filter unless we get an ACK timeout. | 195 FORWARD_TOUCHES_UNTIL_TIMEOUT, // Don't filter unless we get an ACK timeout. |
213 DROP_TOUCHES_IN_SEQUENCE, // Filter all events until a new touch | 196 DROP_TOUCHES_IN_SEQUENCE, // Filter all events until a new touch |
214 // sequence is received. | 197 // sequence is received. |
215 DROP_ALL_TOUCHES, // Filter all events, e.g., no touch handler. | 198 DROP_ALL_TOUCHES, // Filter all events, e.g., no touch handler. |
216 TOUCH_FILTERING_STATE_DEFAULT = FORWARD_ALL_TOUCHES, | 199 TOUCH_FILTERING_STATE_DEFAULT = FORWARD_ALL_TOUCHES, |
217 }; | 200 }; |
218 TouchFilteringState touch_filtering_state_; | 201 TouchFilteringState touch_filtering_state_; |
219 | 202 |
220 // Optional handler for timed-out touch event acks. | 203 // Optional handler for timed-out touch event acks, disabled by default. |
221 bool ack_timeout_enabled_; | 204 bool ack_timeout_enabled_; |
222 scoped_ptr<TouchTimeoutHandler> timeout_handler_; | 205 scoped_ptr<TouchTimeoutHandler> timeout_handler_; |
223 | 206 |
224 // Suppression of TouchMove's within a slop region when a sequence has not yet | 207 // Suppression of TouchMove's within a slop region when a sequence has not yet |
225 // been preventDefaulted. | 208 // been preventDefaulted. |
226 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 209 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
227 | 210 |
228 // Whether touch events should remain buffered and dispatched asynchronously | 211 // Whether touch events should remain buffered and dispatched asynchronously |
229 // while a scroll sequence is active. In this mode, touchmove's are throttled | 212 // while a scroll sequence is active. In this mode, touchmove's are throttled |
230 // and ack'ed immediately, but remain buffered in |pending_async_touchmove_| | 213 // and ack'ed immediately, but remain buffered in |pending_async_touch_move_| |
231 // until a sufficient time period has elapsed since the last sent touch event. | 214 // until a sufficient time period has elapsed since the last sent touch event. |
232 // For details see the design doc at http://goo.gl/lVyJAa. | 215 // For details see the design doc at http://goo.gl/lVyJAa. |
233 bool send_touch_events_async_; | 216 bool send_touch_events_async_; |
234 bool needs_async_touchmove_for_outer_slop_region_; | 217 bool needs_async_touch_move_for_outer_slop_region_; |
235 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; | 218 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touch_move_; |
236 double last_sent_touch_timestamp_sec_; | 219 double last_sent_touch_timestamp_sec_; |
237 | 220 |
238 // How touch events are handled during scrolling. For now this is a global | 221 // How touch events are handled during scrolling. For now this is a global |
239 // setting for experimentation, but we may evolve it into an app-controlled | 222 // setting for experimentation, but we may evolve it into an app-controlled |
240 // mode. | 223 // mode. |
241 const TouchScrollingMode touch_scrolling_mode_; | 224 const TouchScrollingMode touch_scrolling_mode_; |
242 | 225 |
243 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 226 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
244 }; | 227 }; |
245 | 228 |
246 } // namespace content | 229 } // namespace content |
247 | 230 |
248 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 231 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |