| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_GESTURE_EVENT_QUEUE_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "content/browser/renderer_host/input/tap_suppression_controller.h" |
| 14 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle
r.h" |
| 15 #include "content/browser/renderer_host/input/touchscreen_tap_suppression_contro
ller.h" |
| 13 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 14 #include "content/port/browser/event_with_latency_info.h" | 17 #include "content/port/browser/event_with_latency_info.h" |
| 15 #include "content/port/common/input_event_ack_state.h" | 18 #include "content/port/common/input_event_ack_state.h" |
| 16 #include "third_party/WebKit/public/web/WebInputEvent.h" | 19 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 17 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
| 18 | 21 |
| 19 namespace content { | 22 namespace content { |
| 20 class GestureEventQueueTest; | 23 class GestureEventQueueTest; |
| 21 class InputRouter; | 24 class InputRouter; |
| 22 class MockRenderWidgetHost; | 25 class MockRenderWidgetHost; |
| 23 class TouchpadTapSuppressionController; | |
| 24 class TouchpadTapSuppressionControllerClient; | |
| 25 class TouchscreenTapSuppressionController; | |
| 26 | 26 |
| 27 // Interface with which the GestureEventQueue can forward gesture events, and | 27 // Interface with which the GestureEventQueue can forward gesture events, and |
| 28 // dispatch gesture event responses. | 28 // dispatch gesture event responses. |
| 29 class CONTENT_EXPORT GestureEventQueueClient { | 29 class CONTENT_EXPORT GestureEventQueueClient { |
| 30 public: | 30 public: |
| 31 virtual ~GestureEventQueueClient() {} | 31 virtual ~GestureEventQueueClient() {} |
| 32 | 32 |
| 33 virtual void SendGestureEventImmediately( | 33 virtual void SendGestureEventImmediately( |
| 34 const GestureEventWithLatencyInfo& event) = 0; | 34 const GestureEventWithLatencyInfo& event) = 0; |
| 35 | 35 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 // as possible and therefore maximize the chance that the event stream can be | 54 // as possible and therefore maximize the chance that the event stream can be |
| 55 // handled entirely by the compositor thread. | 55 // handled entirely by the compositor thread. |
| 56 // Events in the queue are forwarded to the renderer one by one; i.e., each | 56 // Events in the queue are forwarded to the renderer one by one; i.e., each |
| 57 // event is sent after receiving the ACK for previous one. The only exception is | 57 // event is sent after receiving the ACK for previous one. The only exception is |
| 58 // that if a GestureScrollUpdate is followed by a GesturePinchUpdate, they are | 58 // that if a GestureScrollUpdate is followed by a GesturePinchUpdate, they are |
| 59 // sent together. | 59 // sent together. |
| 60 // TODO(rjkroege): Possibly refactor into a filter chain: | 60 // TODO(rjkroege): Possibly refactor into a filter chain: |
| 61 // http://crbug.com/148443. | 61 // http://crbug.com/148443. |
| 62 class CONTENT_EXPORT GestureEventQueue { | 62 class CONTENT_EXPORT GestureEventQueue { |
| 63 public: | 63 public: |
| 64 struct CONTENT_EXPORT Config { |
| 65 Config(); |
| 66 |
| 67 // Controls touchpad-related tap suppression, disabled by default. |
| 68 TapSuppressionController::Config touchpad_tap_suppression_config; |
| 69 |
| 70 // Controls touchscreen-related tap suppression, disabled by default. |
| 71 TapSuppressionController::Config touchscreen_tap_suppression_config; |
| 72 |
| 73 // Determines whether non-scroll gesture events are "debounced" during an |
| 74 // active scroll sequence, suppressing brief scroll interruptions. |
| 75 // Disabled by default. |
| 76 base::TimeDelta debounce_interval; |
| 77 bool enable_debounce_during_scroll; |
| 78 }; |
| 79 |
| 64 // Both |client| and |touchpad_client| must outlive the GestureEventQueue. | 80 // Both |client| and |touchpad_client| must outlive the GestureEventQueue. |
| 65 GestureEventQueue(GestureEventQueueClient* client, | 81 GestureEventQueue(GestureEventQueueClient* client, |
| 66 TouchpadTapSuppressionControllerClient* touchpad_client); | 82 TouchpadTapSuppressionControllerClient* touchpad_client, |
| 83 const Config& config); |
| 67 ~GestureEventQueue(); | 84 ~GestureEventQueue(); |
| 68 | 85 |
| 69 // Returns |true| if the caller should immediately forward the provided | 86 // Returns |true| if the caller should immediately forward the provided |
| 70 // |GestureEventWithLatencyInfo| argument to the renderer. | 87 // |GestureEventWithLatencyInfo| argument to the renderer. |
| 71 // If this function returns false, then the event may be queued and forwared | 88 // If this function returns false, then the event may be queued and forwared |
| 72 // at a later point. | 89 // at a later point. |
| 73 bool ShouldForward(const GestureEventWithLatencyInfo&); | 90 bool ShouldForward(const GestureEventWithLatencyInfo&); |
| 74 | 91 |
| 75 // Indicates that the caller has received an acknowledgement from the renderer | 92 // Indicates that the caller has received an acknowledgement from the renderer |
| 76 // with state |ack_result| and event |type|. May send events if the queue is | 93 // with state |ack_result| and event |type|. May send events if the queue is |
| (...skipping 12 matching lines...) Expand all Loading... |
| 89 void ForwardGestureEvent(const GestureEventWithLatencyInfo& gesture_event); | 106 void ForwardGestureEvent(const GestureEventWithLatencyInfo& gesture_event); |
| 90 | 107 |
| 91 // Whether the queue is expecting a gesture event ack. | 108 // Whether the queue is expecting a gesture event ack. |
| 92 bool ExpectingGestureAck() const; | 109 bool ExpectingGestureAck() const; |
| 93 | 110 |
| 94 bool empty() const { | 111 bool empty() const { |
| 95 return coalesced_gesture_events_.empty() && | 112 return coalesced_gesture_events_.empty() && |
| 96 debouncing_deferral_queue_.empty(); | 113 debouncing_deferral_queue_.empty(); |
| 97 } | 114 } |
| 98 | 115 |
| 99 void set_debounce_enabled_for_testing(bool enabled) { | 116 void set_debounce_enabled_for_testing(bool enabled) { |
| 100 debounce_enabled_ = enabled; | 117 debounce_enabled_ = enabled; |
| 101 } | 118 } |
| 102 | 119 |
| 103 void set_debounce_interval_time_ms_for_testing(int interval_time_ms) { | 120 void set_debounce_interval_time_ms_for_testing(int interval_time_ms) { |
| 104 debounce_interval_time_ms_ = interval_time_ms; | 121 debounce_interval_ = base::TimeDelta::FromMilliseconds(interval_time_ms); |
| 105 } | 122 } |
| 106 | 123 |
| 107 private: | 124 private: |
| 108 friend class GestureEventQueueTest; | 125 friend class GestureEventQueueTest; |
| 109 friend class MockRenderWidgetHost; | 126 friend class MockRenderWidgetHost; |
| 110 | 127 |
| 111 // TODO(mohsen): There are a bunch of ShouldForward.../ShouldDiscard... | 128 // TODO(mohsen): There are a bunch of ShouldForward.../ShouldDiscard... |
| 112 // methods that are getting confusing. This should be somehow fixed. Maybe | 129 // methods that are getting confusing. This should be somehow fixed. Maybe |
| 113 // while refactoring GEQ: http://crbug.com/148443. | 130 // while refactoring GEQ: http://crbug.com/148443. |
| 114 | 131 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 198 |
| 182 // True if two related gesture events were sent before without waiting | 199 // True if two related gesture events were sent before without waiting |
| 183 // for an ACK, so the next gesture ACK should be ignored. | 200 // for an ACK, so the next gesture ACK should be ignored. |
| 184 bool ignore_next_ack_; | 201 bool ignore_next_ack_; |
| 185 | 202 |
| 186 // An object tracking the state of touchpad on the delivery of mouse events to | 203 // An object tracking the state of touchpad on the delivery of mouse events to |
| 187 // the renderer to filter mouse immediately after a touchpad fling canceling | 204 // the renderer to filter mouse immediately after a touchpad fling canceling |
| 188 // tap. | 205 // tap. |
| 189 // TODO(mohsen): Move touchpad tap suppression out of GestureEventQueue since | 206 // TODO(mohsen): Move touchpad tap suppression out of GestureEventQueue since |
| 190 // GEQ is meant to only be used for touchscreen gesture events. | 207 // GEQ is meant to only be used for touchscreen gesture events. |
| 191 scoped_ptr<TouchpadTapSuppressionController> | 208 TouchpadTapSuppressionController touchpad_tap_suppression_controller_; |
| 192 touchpad_tap_suppression_controller_; | |
| 193 | 209 |
| 194 // An object tracking the state of touchscreen on the delivery of gesture tap | 210 // An object tracking the state of touchscreen on the delivery of gesture tap |
| 195 // events to the renderer to filter taps immediately after a touchscreen fling | 211 // events to the renderer to filter taps immediately after a touchscreen fling |
| 196 // canceling tap. | 212 // canceling tap. |
| 197 scoped_ptr<TouchscreenTapSuppressionController> | 213 TouchscreenTapSuppressionController touchscreen_tap_suppression_controller_; |
| 198 touchscreen_tap_suppression_controller_; | |
| 199 | 214 |
| 200 typedef std::deque<GestureEventWithLatencyInfo> GestureQueue; | 215 typedef std::deque<GestureEventWithLatencyInfo> GestureQueue; |
| 201 | 216 |
| 202 // Queue of coalesced gesture events not yet sent to the renderer. If | 217 // Queue of coalesced gesture events not yet sent to the renderer. If |
| 203 // |ignore_next_ack_| is false, then the event at the front of the queue has | 218 // |ignore_next_ack_| is false, then the event at the front of the queue has |
| 204 // been sent and is awaiting an ACK, and all other events have yet to be sent. | 219 // been sent and is awaiting an ACK, and all other events have yet to be sent. |
| 205 // If |ignore_next_ack_| is true, then the two events at the front of the | 220 // If |ignore_next_ack_| is true, then the two events at the front of the |
| 206 // queue have been sent, and the second is awaiting an ACK. All other events | 221 // queue have been sent, and the second is awaiting an ACK. All other events |
| 207 // have yet to be sent. | 222 // have yet to be sent. |
| 208 GestureQueue coalesced_gesture_events_; | 223 GestureQueue coalesced_gesture_events_; |
| 209 | 224 |
| 210 // Timer to release a previously deferred gesture event. | 225 // Timer to release a previously deferred gesture event. |
| 211 base::OneShotTimer<GestureEventQueue> debounce_deferring_timer_; | 226 base::OneShotTimer<GestureEventQueue> debounce_deferring_timer_; |
| 212 | 227 |
| 213 // Queue of events that have been deferred for debounce. | 228 // Queue of events that have been deferred for debounce. |
| 214 GestureQueue debouncing_deferral_queue_; | 229 GestureQueue debouncing_deferral_queue_; |
| 215 | 230 |
| 216 // Time window in which to debounce scroll/fling ends. | 231 // Time window in which to debounce scroll/fling ends. |
| 217 // TODO(rjkroege): Make this dynamically configurable. | 232 base::TimeDelta debounce_interval_; |
| 218 int debounce_interval_time_ms_; | |
| 219 | 233 |
| 220 // Whether scroll-ending events should be deferred when a scroll is active. | 234 // Whether scroll-ending events should be deferred when a scroll is active. |
| 221 // Defaults to true. | 235 // Defaults to true. |
| 222 bool debounce_enabled_; | 236 bool debounce_enabled_; |
| 223 | 237 |
| 224 DISALLOW_COPY_AND_ASSIGN(GestureEventQueue); | 238 DISALLOW_COPY_AND_ASSIGN(GestureEventQueue); |
| 225 }; | 239 }; |
| 226 | 240 |
| 227 } // namespace content | 241 } // namespace content |
| 228 | 242 |
| 229 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_ | 243 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_ |
| OLD | NEW |