| 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 18 matching lines...) Expand all Loading... |
| 29 const TouchEventWithLatencyInfo& event) = 0; | 29 const TouchEventWithLatencyInfo& event) = 0; |
| 30 | 30 |
| 31 virtual void OnTouchEventAck( | 31 virtual void OnTouchEventAck( |
| 32 const TouchEventWithLatencyInfo& event, | 32 const TouchEventWithLatencyInfo& event, |
| 33 InputEventAckState ack_result) = 0; | 33 InputEventAckState ack_result) = 0; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 // A queue for throttling and coalescing touch-events. | 36 // A queue for throttling and coalescing touch-events. |
| 37 class CONTENT_EXPORT TouchEventQueue { | 37 class CONTENT_EXPORT TouchEventQueue { |
| 38 public: | 38 public: |
| 39 // Different ways of dealing with touch events during scrolling. |
| 40 // TODO(rbyers): Remove (or otherwise update) this once results of |
| 41 // experiments are complete. http://crbug.com/328503 |
| 42 enum TouchScrollingMode { |
| 43 // Send a touchcancel on scroll start and no further touch events for the |
| 44 // duration of the scroll. Chrome Android's traditional behavior. |
| 45 TOUCH_SCROLLING_MODE_TOUCHCANCEL, |
| 46 // Send touchmove events throughout a scroll, blocking on each ACK and |
| 47 // using the disposition to determine whether a scroll update should be |
| 48 // sent. Mobile Safari's default overflow scroll behavior. |
| 49 TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE, |
| 50 // Like sync, except that consumed scroll events cause subsequent touchmove |
| 51 // events to be suppressed. Unconsumed scroll events return touchmove |
| 52 // events to being dispatched synchronously (so scrolling may be hijacked |
| 53 // when a scroll limit is reached, and later resumed). |
| 54 TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE, |
| 55 TOUCH_SCROLLING_MODE_DEFAULT = TOUCH_SCROLLING_MODE_TOUCHCANCEL |
| 56 }; |
| 39 | 57 |
| 40 // The |client| must outlive the TouchEventQueue. If | 58 // The |client| must outlive the TouchEventQueue. If |
| 41 // |touchmove_suppression_length_dips| <= 0, touch move suppression is | 59 // |touchmove_suppression_length_dips| <= 0, touch move suppression is |
| 42 // disabled. | 60 // disabled. |
| 43 TouchEventQueue(TouchEventQueueClient* client, | 61 TouchEventQueue(TouchEventQueueClient* client, |
| 62 TouchScrollingMode mode, |
| 44 double touchmove_suppression_length_dips); | 63 double touchmove_suppression_length_dips); |
| 45 ~TouchEventQueue(); | 64 ~TouchEventQueue(); |
| 46 | 65 |
| 47 // 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 |
| 48 // 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 |
| 49 // 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 |
| 50 // 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). |
| 51 void QueueEvent(const TouchEventWithLatencyInfo& event); | 70 void QueueEvent(const TouchEventWithLatencyInfo& event); |
| 52 | 71 |
| 53 // 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. |
| 54 // 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 |
| 55 // additional queued touch-events to the renderer. | 74 // additional queued touch-events to the renderer. |
| 56 void ProcessTouchAck(InputEventAckState ack_result, | 75 void ProcessTouchAck(InputEventAckState ack_result, |
| 57 const ui::LatencyInfo& latency_info); | 76 const ui::LatencyInfo& latency_info); |
| 58 | 77 |
| 59 // When GestureScrollBegin is received, we send a touch cancel to renderer, | 78 // When GestureScrollBegin is received, we send a touch cancel to renderer, |
| 60 // route all the following touch events directly to client, and ignore the | 79 // route all the following touch events directly to client, and ignore the |
| 61 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, | 80 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, |
| 62 // resume the normal flow of sending touch events to the renderer. | 81 // resume the normal flow of sending touch events to the renderer. |
| 63 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); | 82 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); |
| 64 | 83 |
| 84 void OnGestureEventAck( |
| 85 const GestureEventWithLatencyInfo& event, |
| 86 InputEventAckState ack_result); |
| 87 |
| 65 // 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. |
| 66 void OnHasTouchEventHandlers(bool has_handlers); | 89 void OnHasTouchEventHandlers(bool has_handlers); |
| 67 | 90 |
| 68 // Returns whether the currently pending touch event (waiting ACK) is for | 91 // Returns whether the currently pending touch event (waiting ACK) is for |
| 69 // a touch start event. | 92 // a touch start event. |
| 70 bool IsPendingAckTouchStart() const; | 93 bool IsPendingAckTouchStart() const; |
| 71 | 94 |
| 72 // 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 |
| 73 // touch sequence. | 96 // touch sequence. |
| 74 void SetAckTimeoutEnabled(bool enabled, size_t ack_timeout_delay_ms); | 97 void SetAckTimeoutEnabled(bool enabled, size_t ack_timeout_delay_ms); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 TouchFilteringState touch_filtering_state_; | 179 TouchFilteringState touch_filtering_state_; |
| 157 | 180 |
| 158 // Optional handler for timed-out touch event acks, disabled by default. | 181 // Optional handler for timed-out touch event acks, disabled by default. |
| 159 bool ack_timeout_enabled_; | 182 bool ack_timeout_enabled_; |
| 160 scoped_ptr<TouchTimeoutHandler> timeout_handler_; | 183 scoped_ptr<TouchTimeoutHandler> timeout_handler_; |
| 161 | 184 |
| 162 // Suppression of TouchMove's within a slop region when a sequence has not yet | 185 // Suppression of TouchMove's within a slop region when a sequence has not yet |
| 163 // been preventDefaulted. | 186 // been preventDefaulted. |
| 164 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; | 187 scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; |
| 165 | 188 |
| 189 // How touch events are handled during scrolling. For now this is a global |
| 190 // setting for experimentation, but we may evolve it into an app-controlled |
| 191 // mode. |
| 192 const TouchScrollingMode touch_scrolling_mode_; |
| 193 |
| 194 // Whether touchmove events should be dropped due to the |
| 195 // TOUCH_SCROLLING_MODE_ABSORB_TOUCHMOVE mode. Note that we can't use |
| 196 // touch_filtering_state_ for this (without adding a few new states and |
| 197 // complicating the code significantly) because it can occur with and without |
| 198 // timeout, and shouldn't cause touchend to be dropped. |
| 199 bool absorbing_touch_moves_; |
| 200 |
| 166 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 201 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
| 167 }; | 202 }; |
| 168 | 203 |
| 169 } // namespace content | 204 } // namespace content |
| 170 | 205 |
| 171 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 206 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
| OLD | NEW |