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 30 matching lines...) Expand all Loading... | |
41 // TODO(rbyers): Remove this once we're confident that touch move absorption | 41 // TODO(rbyers): Remove this once we're confident that touch move absorption |
42 // is OK. http://crbug.com/350430 | 42 // is OK. http://crbug.com/350430 |
43 enum TouchScrollingMode { | 43 enum TouchScrollingMode { |
44 // Send a touchcancel on scroll start and no further touch events for the | 44 // Send a touchcancel on scroll start and no further touch events for the |
45 // duration of the scroll. Chrome Android's traditional behavior. | 45 // duration of the scroll. Chrome Android's traditional behavior. |
46 TOUCH_SCROLLING_MODE_TOUCHCANCEL, | 46 TOUCH_SCROLLING_MODE_TOUCHCANCEL, |
47 // Send touchmove events throughout a scroll, blocking on each ACK and | 47 // Send touchmove events throughout a scroll, blocking on each ACK and |
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 | |
52 // ignore the ACK as long as scrolling remains possible. Unconsumed scroll | |
53 // events return touchmove events to being dispatched synchronously. | |
54 TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE, | |
51 // Like sync, except that consumed scroll events cause subsequent touchmove | 55 // Like sync, except that consumed scroll events cause subsequent touchmove |
52 // events to be suppressed. Unconsumed scroll events return touchmove | 56 // events to be suppressed. Unconsumed scroll events return touchmove |
53 // events to being dispatched synchronously (so scrolling may be hijacked | 57 // events to being dispatched synchronously (so scrolling may be hijacked |
54 // when a scroll limit is reached, and later resumed). http://goo.gl/RShsdN | 58 // when a scroll limit is reached, and later resumed). http://goo.gl/RShsdN |
55 TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE, | 59 TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE, |
aelias_OOO_until_Jul13
2014/04/22 01:56:39
Can we delete this mode as part of this patch? Th
Rick Byers
2014/04/22 14:52:59
Replacing ABSORB with ASYNC is OK with me (async j
jdduke (slow)
2014/04/23 19:57:41
Done.
| |
56 TOUCH_SCROLLING_MODE_DEFAULT = TOUCH_SCROLLING_MODE_TOUCHCANCEL | 60 TOUCH_SCROLLING_MODE_DEFAULT = TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE |
57 }; | 61 }; |
58 | 62 |
59 // The |client| must outlive the TouchEventQueue. If | 63 // The |client| must outlive the TouchEventQueue. If |
60 // |touchmove_suppression_length_dips| <= 0, touch move suppression is | 64 // |touchmove_suppression_length_dips| <= 0, touch move suppression is |
61 // disabled. | 65 // disabled. |
62 TouchEventQueue(TouchEventQueueClient* client, | 66 TouchEventQueue(TouchEventQueueClient* client, |
63 TouchScrollingMode mode, | 67 TouchScrollingMode mode, |
64 double touchmove_suppression_length_dips); | 68 double touchmove_suppression_length_dips); |
65 ~TouchEventQueue(); | 69 ~TouchEventQueue(); |
66 | 70 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 friend class TouchEventQueueTest; | 125 friend class TouchEventQueueTest; |
122 | 126 |
123 bool HasTimeoutEvent() const; | 127 bool HasTimeoutEvent() const; |
124 bool IsTimeoutRunningForTesting() const; | 128 bool IsTimeoutRunningForTesting() const; |
125 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; | 129 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; |
126 | 130 |
127 // Empties the queue of touch events. This may result in any number of gesture | 131 // Empties the queue of touch events. This may result in any number of gesture |
128 // events being sent to the renderer. | 132 // events being sent to the renderer. |
129 void FlushQueue(); | 133 void FlushQueue(); |
130 | 134 |
131 // Walks the queue, checking each event for |ShouldForwardToRenderer()|. | 135 // Walks the queue, checking each event with |FilterBeforeFowarding()|. |
132 // If true, forwards the touch event and stops processing further events. | 136 // If allowed, forwards the touch event and stops processing further events. |
133 // If false, acks the event with |INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS|. | 137 // Otherwise, acks the event with |INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS|. |
134 void TryForwardNextEventToRenderer(); | 138 void TryForwardNextEventToRenderer(); |
135 | 139 |
136 // Pops the touch-event from the top of the queue and sends it to the | 140 // Forwards the event at the head of the queue to the renderer. |
137 // TouchEventQueueClient. This reduces the size of the queue by one. | 141 void ForwardNextEventToRenderer(); |
142 | |
143 // Pops the touch-event from the head of the queue and acks it to the client. | |
144 void PopTouchEventToClient(InputEventAckState ack_result); | |
145 | |
146 // Pops the touch-event from the head of the queue and acks it to the client, | |
147 // updating the event with |renderer_latency_info|. | |
138 void PopTouchEventToClient(InputEventAckState ack_result, | 148 void PopTouchEventToClient(InputEventAckState ack_result, |
139 const ui::LatencyInfo& renderer_latency_info); | 149 const ui::LatencyInfo& renderer_latency_info); |
140 | 150 |
151 // Ack all coalesced events in |acked_event| to the client with |ack_result|. | |
152 void AckTouchEventToClient(InputEventAckState ack_result, | |
153 const CoalescedWebTouchEvent& acked_event); | |
154 | |
155 // Safely pop the head of the queue. | |
156 scoped_ptr<CoalescedWebTouchEvent> PopTouchEvent(); | |
157 | |
141 enum PreFilterResult { | 158 enum PreFilterResult { |
142 ACK_WITH_NO_CONSUMER_EXISTS, | 159 ACK_WITH_NO_CONSUMER_EXISTS, |
143 ACK_WITH_NOT_CONSUMED, | 160 ACK_WITH_NOT_CONSUMED, |
144 FORWARD_TO_RENDERER, | 161 FORWARD_TO_RENDERER, |
145 }; | 162 }; |
146 // Filter touches prior to forwarding to the renderer, e.g., if the renderer | 163 // Filter touches prior to forwarding to the renderer, e.g., if the renderer |
147 // has no touch handler. | 164 // has no touch handler. |
148 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); | 165 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); |
149 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); | |
150 void UpdateTouchAckStates(const blink::WebTouchEvent& event, | 166 void UpdateTouchAckStates(const blink::WebTouchEvent& event, |
151 InputEventAckState ack_result); | 167 InputEventAckState ack_result); |
152 | 168 |
153 | 169 |
154 // Handles touch event forwarding and ack'ed event dispatch. | 170 // Handles touch event forwarding and ack'ed event dispatch. |
155 TouchEventQueueClient* client_; | 171 TouchEventQueueClient* client_; |
156 | 172 |
157 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; | 173 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; |
158 TouchQueue touch_queue_; | 174 TouchQueue touch_queue_; |
159 | 175 |
160 // Maintain the ACK status for each touch point. | 176 // Maintain the ACK status for each touch point. |
161 typedef std::map<int, InputEventAckState> TouchPointAckStates; | 177 typedef std::map<int, InputEventAckState> TouchPointAckStates; |
162 TouchPointAckStates touch_ack_states_; | 178 TouchPointAckStates touch_ack_states_; |
163 | 179 |
164 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | 180 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. |
165 // If not NULL, |dispatching_touch_ack_| is the touch event of which the ack | 181 // If not NULL, |dispatching_touch_ack_| is the touch event of which the ack |
166 // is being dispatched. | 182 // is being dispatched. |
167 CoalescedWebTouchEvent* dispatching_touch_ack_; | 183 const CoalescedWebTouchEvent* dispatching_touch_ack_; |
168 | 184 |
169 // Used to prevent touch timeout scheduling if we receive a synchronous | 185 // Used to prevent touch timeout scheduling if we receive a synchronous |
170 // ack after forwarding a touch event to the client. | 186 // ack after forwarding a touch event to the client. |
171 bool dispatching_touch_; | 187 bool dispatching_touch_; |
172 | 188 |
173 enum TouchFilteringState { | 189 enum TouchFilteringState { |
174 FORWARD_ALL_TOUCHES, // Don't filter at all - the default. | 190 FORWARD_ALL_TOUCHES, // Don't filter at all - the default. |
175 FORWARD_TOUCHES_UNTIL_TIMEOUT, // Don't filter unless we get an ACK timeout. | 191 FORWARD_TOUCHES_UNTIL_TIMEOUT, // Don't filter unless we get an ACK timeout. |
176 DROP_TOUCHES_IN_SEQUENCE, // Filter all events until a new touch | 192 DROP_TOUCHES_IN_SEQUENCE, // Filter all events until a new touch |
177 // sequence is received. | 193 // sequence is received. |
(...skipping 10 matching lines...) Expand all Loading... | |
188 // been preventDefaulted. | 204 // been preventDefaulted. |
189 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 205 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
190 | 206 |
191 // Whether touchmove events should be dropped due to the | 207 // Whether touchmove events should be dropped due to the |
192 // TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE mode. Note that we can't use | 208 // TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE mode. Note that we can't use |
193 // touch_filtering_state_ for this (without adding a few new states and | 209 // touch_filtering_state_ for this (without adding a few new states and |
194 // complicating the code significantly) because it can occur with and without | 210 // complicating the code significantly) because it can occur with and without |
195 // timeout, and shouldn't cause touchend to be dropped. | 211 // timeout, and shouldn't cause touchend to be dropped. |
196 bool absorbing_touch_moves_; | 212 bool absorbing_touch_moves_; |
197 | 213 |
214 // Whether touchmove's should remain buffered and dispatched asynchronously | |
215 // while a scroll sequence is active. In this mode, touchmove's are | |
216 // ack'ed immediately but remain buffered in |pending_async_touch_move_| until | |
217 // a sufficient time period has elapsed since the last sent touch event. | |
218 bool async_touch_moves_; | |
aelias_OOO_until_Jul13
2014/04/22 01:56:39
Instead of these bools, can we keep the enum value
Rick Byers
2014/04/22 14:52:59
We can remove this bool completely when we collaps
jdduke (slow)
2014/04/23 19:57:41
Done.
| |
219 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touch_move_; | |
220 double last_sent_touch_timestamp_; | |
aelias_OOO_until_Jul13
2014/04/22 01:56:39
Please specify "ms" or "sec" in the variable name.
jdduke (slow)
2014/04/23 19:57:41
Done.
| |
221 | |
198 // How touch events are handled during scrolling. For now this is a global | 222 // How touch events are handled during scrolling. For now this is a global |
199 // setting for experimentation, but we may evolve it into an app-controlled | 223 // setting for experimentation, but we may evolve it into an app-controlled |
200 // mode. | 224 // mode. |
201 const TouchScrollingMode touch_scrolling_mode_; | 225 const TouchScrollingMode touch_scrolling_mode_; |
202 | 226 |
203 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 227 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
204 }; | 228 }; |
205 | 229 |
206 } // namespace content | 230 } // namespace content |
207 | 231 |
208 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 232 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |