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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "content/browser/renderer_host/event_with_latency_info.h" | 13 #include "content/browser/renderer_host/event_with_latency_info.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/common/input/input_event_ack_state.h" | 15 #include "content/common/input/input_event_ack_state.h" |
16 #include "third_party/WebKit/public/web/WebInputEvent.h" | 16 #include "third_party/WebKit/public/web/WebInputEvent.h" |
17 #include "ui/events/gesture_detection/bitset_32.h" | |
17 #include "ui/gfx/geometry/point_f.h" | 18 #include "ui/gfx/geometry/point_f.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 class CoalescedWebTouchEvent; | 22 class CoalescedWebTouchEvent; |
22 | 23 |
23 // Interface with which TouchEventQueue can forward touch events, and dispatch | 24 // Interface with which TouchEventQueue can forward touch events, and dispatch |
24 // touch event responses. | 25 // touch event responses. |
25 class CONTENT_EXPORT TouchEventQueueClient { | 26 class CONTENT_EXPORT TouchEventQueueClient { |
26 public: | 27 public: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 108 |
108 // Returns whether the currently pending touch event (waiting ACK) is for | 109 // Returns whether the currently pending touch event (waiting ACK) is for |
109 // a touch start event. | 110 // a touch start event. |
110 bool IsPendingAckTouchStart() const; | 111 bool IsPendingAckTouchStart() const; |
111 | 112 |
112 // Sets whether a delayed touch ack will cancel and flush the current | 113 // Sets whether a delayed touch ack will cancel and flush the current |
113 // touch sequence. Note that, if the timeout was previously disabled, enabling | 114 // touch sequence. Note that, if the timeout was previously disabled, enabling |
114 // it will take effect only for the following touch sequence. | 115 // it will take effect only for the following touch sequence. |
115 void SetAckTimeoutEnabled(bool enabled); | 116 void SetAckTimeoutEnabled(bool enabled); |
116 | 117 |
118 bool IsAckTimeoutEnabled() const; | |
119 | |
120 bool IsForwardingTouches(); | |
121 | |
117 bool empty() const WARN_UNUSED_RESULT { | 122 bool empty() const WARN_UNUSED_RESULT { |
118 return touch_queue_.empty(); | 123 return touch_queue_.empty(); |
119 } | 124 } |
120 | 125 |
121 size_t size() const { | 126 size_t size() const { |
122 return touch_queue_.size(); | 127 return touch_queue_.size(); |
123 } | 128 } |
124 | 129 |
125 bool ack_timeout_enabled() const { | 130 bool has_handlers() const { return has_handlers_; } |
126 return ack_timeout_enabled_; | |
127 } | |
128 | |
129 bool has_handlers() const { | |
130 return touch_filtering_state_ != DROP_ALL_TOUCHES; | |
131 } | |
132 | 131 |
133 private: | 132 private: |
134 class TouchTimeoutHandler; | 133 class TouchTimeoutHandler; |
135 class TouchMoveSlopSuppressor; | 134 class TouchMoveSlopSuppressor; |
136 friend class TouchTimeoutHandler; | 135 friend class TouchTimeoutHandler; |
137 friend class TouchEventQueueTest; | 136 friend class TouchEventQueueTest; |
138 | 137 |
139 bool HasPendingAsyncTouchMoveForTesting() const; | 138 bool HasPendingAsyncTouchMoveForTesting() const; |
140 bool IsTimeoutRunningForTesting() const; | 139 bool IsTimeoutRunningForTesting() const; |
141 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; | 140 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; |
(...skipping 30 matching lines...) Expand all Loading... | |
172 | 171 |
173 enum PreFilterResult { | 172 enum PreFilterResult { |
174 ACK_WITH_NO_CONSUMER_EXISTS, | 173 ACK_WITH_NO_CONSUMER_EXISTS, |
175 ACK_WITH_NOT_CONSUMED, | 174 ACK_WITH_NOT_CONSUMED, |
176 FORWARD_TO_RENDERER, | 175 FORWARD_TO_RENDERER, |
177 }; | 176 }; |
178 // Filter touches prior to forwarding to the renderer, e.g., if the renderer | 177 // Filter touches prior to forwarding to the renderer, e.g., if the renderer |
179 // has no touch handler. | 178 // has no touch handler. |
180 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); | 179 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); |
181 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); | 180 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); |
182 void UpdateTouchAckStates(const blink::WebTouchEvent& event, | 181 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, |
183 InputEventAckState ack_result); | 182 InputEventAckState ack_result); |
184 bool AllTouchAckStatesHaveState(InputEventAckState ack_state) const; | |
185 | |
186 | 183 |
187 // Handles touch event forwarding and ack'ed event dispatch. | 184 // Handles touch event forwarding and ack'ed event dispatch. |
188 TouchEventQueueClient* client_; | 185 TouchEventQueueClient* client_; |
189 | 186 |
190 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; | 187 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; |
191 TouchQueue touch_queue_; | 188 TouchQueue touch_queue_; |
192 | 189 |
193 // Maintain the ACK status for each touch point. | 190 // Maps whether each active pointer has a consumer (i.e., a touch point has a |
194 typedef std::map<int, InputEventAckState> TouchPointAckStates; | 191 // valid consumer iff |touch_consumer_states[pointer.id]| is true.). |
195 TouchPointAckStates touch_ack_states_; | 192 ui::BitSet32 touch_consumer_states_; |
Rick Byers
2014/09/19 17:54:07
I wonder if we could simplify this further by keep
jdduke (slow)
2014/09/22 16:30:14
Hmm, interesting, that is a tempting simplificatio
| |
196 | 193 |
197 // Position of the first touch in the most recent sequence forwarded to the | 194 // Position of the first touch in the most recent sequence forwarded to the |
198 // client. | 195 // client. |
199 gfx::PointF touch_sequence_start_position_; | 196 gfx::PointF touch_sequence_start_position_; |
200 | 197 |
201 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | 198 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. |
202 // If not NULL, |dispatching_touch_ack_| is the touch event of which the ack | 199 // If not NULL, |dispatching_touch_ack_| is the touch event of which the ack |
203 // is being dispatched. | 200 // is being dispatched. |
204 const CoalescedWebTouchEvent* dispatching_touch_ack_; | 201 const CoalescedWebTouchEvent* dispatching_touch_ack_; |
205 | 202 |
206 // Used to prevent touch timeout scheduling if we receive a synchronous | 203 // Used to prevent touch timeout scheduling if we receive a synchronous |
207 // ack after forwarding a touch event to the client. | 204 // ack after forwarding a touch event to the client. |
208 bool dispatching_touch_; | 205 bool dispatching_touch_; |
209 | 206 |
210 enum TouchFilteringState { | 207 // Whether the renderer has at least one touch handler. |
211 FORWARD_ALL_TOUCHES, // Don't filter at all - the default. | 208 bool has_handlers_; |
212 FORWARD_TOUCHES_UNTIL_TIMEOUT, // Don't filter unless we get an ACK timeout. | 209 |
213 DROP_TOUCHES_IN_SEQUENCE, // Filter all events until a new touch | 210 // Whether to allow any remaining touches for the current sequence. Note that |
214 // sequence is received. | 211 // this is a stricter condition than an empty |touch_consumer_states|, as it |
215 DROP_ALL_TOUCHES, // Filter all events, e.g., no touch handler. | 212 // also prevents forwarding of touchstart events for new pointers in the |
216 TOUCH_FILTERING_STATE_DEFAULT = FORWARD_ALL_TOUCHES, | 213 // current sequence. This is only used when the event is synthetically |
217 }; | 214 // cancelled after a touch timeout, or after a scroll event when the |
218 TouchFilteringState touch_filtering_state_; | 215 // mode is TOUCH_SCROLLING_MODE_TOUCHCANCEL. |
216 bool drop_remaining_touches_in_sequence_; | |
219 | 217 |
220 // Optional handler for timed-out touch event acks. | 218 // Optional handler for timed-out touch event acks. |
221 bool ack_timeout_enabled_; | |
222 scoped_ptr<TouchTimeoutHandler> timeout_handler_; | 219 scoped_ptr<TouchTimeoutHandler> timeout_handler_; |
223 | 220 |
224 // Suppression of TouchMove's within a slop region when a sequence has not yet | 221 // Suppression of TouchMove's within a slop region when a sequence has not yet |
225 // been preventDefaulted. | 222 // been preventDefaulted. |
226 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 223 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
227 | 224 |
228 // Whether touch events should remain buffered and dispatched asynchronously | 225 // Whether touch events should remain buffered and dispatched asynchronously |
229 // while a scroll sequence is active. In this mode, touchmove's are throttled | 226 // 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_| | 227 // and ack'ed immediately, but remain buffered in |pending_async_touchmove_| |
231 // until a sufficient time period has elapsed since the last sent touch event. | 228 // 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. | 229 // For details see the design doc at http://goo.gl/lVyJAa. |
233 bool send_touch_events_async_; | 230 bool send_touch_events_async_; |
234 bool needs_async_touchmove_for_outer_slop_region_; | 231 bool needs_async_touchmove_for_outer_slop_region_; |
235 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; | 232 scoped_ptr<TouchEventWithLatencyInfo> pending_async_touchmove_; |
236 double last_sent_touch_timestamp_sec_; | 233 double last_sent_touch_timestamp_sec_; |
237 | 234 |
238 // How touch events are handled during scrolling. For now this is a global | 235 // 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 | 236 // setting for experimentation, but we may evolve it into an app-controlled |
240 // mode. | 237 // mode. |
241 const TouchScrollingMode touch_scrolling_mode_; | 238 const TouchScrollingMode touch_scrolling_mode_; |
242 | 239 |
243 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 240 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
244 }; | 241 }; |
245 | 242 |
246 } // namespace content | 243 } // namespace content |
247 | 244 |
248 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 245 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |