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 // Zero by default (disabled). |
| 76 base::TimeDelta debounce_interval; |
| 77 }; |
| 78 |
64 // Both |client| and |touchpad_client| must outlive the GestureEventQueue. | 79 // Both |client| and |touchpad_client| must outlive the GestureEventQueue. |
65 GestureEventQueue(GestureEventQueueClient* client, | 80 GestureEventQueue(GestureEventQueueClient* client, |
66 TouchpadTapSuppressionControllerClient* touchpad_client); | 81 TouchpadTapSuppressionControllerClient* touchpad_client, |
| 82 const Config& config); |
67 ~GestureEventQueue(); | 83 ~GestureEventQueue(); |
68 | 84 |
69 // Returns |true| if the caller should immediately forward the provided | 85 // Returns |true| if the caller should immediately forward the provided |
70 // |GestureEventWithLatencyInfo| argument to the renderer. | 86 // |GestureEventWithLatencyInfo| argument to the renderer. |
71 // If this function returns false, then the event may be queued and forwared | 87 // If this function returns false, then the event may be queued and forwared |
72 // at a later point. | 88 // at a later point. |
73 bool ShouldForward(const GestureEventWithLatencyInfo&); | 89 bool ShouldForward(const GestureEventWithLatencyInfo&); |
74 | 90 |
75 // Indicates that the caller has received an acknowledgement from the renderer | 91 // 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 | 92 // 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); | 105 void ForwardGestureEvent(const GestureEventWithLatencyInfo& gesture_event); |
90 | 106 |
91 // Whether the queue is expecting a gesture event ack. | 107 // Whether the queue is expecting a gesture event ack. |
92 bool ExpectingGestureAck() const; | 108 bool ExpectingGestureAck() const; |
93 | 109 |
94 bool empty() const { | 110 bool empty() const { |
95 return coalesced_gesture_events_.empty() && | 111 return coalesced_gesture_events_.empty() && |
96 debouncing_deferral_queue_.empty(); | 112 debouncing_deferral_queue_.empty(); |
97 } | 113 } |
98 | 114 |
99 void set_debounce_enabled_for_testing(bool enabled) { | 115 void set_debounce_interval_time_ms_for_testing(int interval_ms) { |
100 debounce_enabled_ = enabled; | 116 debounce_interval_ = base::TimeDelta::FromMilliseconds(interval_ms); |
101 } | |
102 | |
103 void set_debounce_interval_time_ms_for_testing(int interval_time_ms) { | |
104 debounce_interval_time_ms_ = interval_time_ms; | |
105 } | 117 } |
106 | 118 |
107 private: | 119 private: |
108 friend class GestureEventQueueTest; | 120 friend class GestureEventQueueTest; |
109 friend class MockRenderWidgetHost; | 121 friend class MockRenderWidgetHost; |
110 | 122 |
111 // TODO(mohsen): There are a bunch of ShouldForward.../ShouldDiscard... | 123 // TODO(mohsen): There are a bunch of ShouldForward.../ShouldDiscard... |
112 // methods that are getting confusing. This should be somehow fixed. Maybe | 124 // methods that are getting confusing. This should be somehow fixed. Maybe |
113 // while refactoring GEQ: http://crbug.com/148443. | 125 // while refactoring GEQ: http://crbug.com/148443. |
114 | 126 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 193 |
182 // True if two related gesture events were sent before without waiting | 194 // True if two related gesture events were sent before without waiting |
183 // for an ACK, so the next gesture ACK should be ignored. | 195 // for an ACK, so the next gesture ACK should be ignored. |
184 bool ignore_next_ack_; | 196 bool ignore_next_ack_; |
185 | 197 |
186 // An object tracking the state of touchpad on the delivery of mouse events to | 198 // 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 | 199 // the renderer to filter mouse immediately after a touchpad fling canceling |
188 // tap. | 200 // tap. |
189 // TODO(mohsen): Move touchpad tap suppression out of GestureEventQueue since | 201 // TODO(mohsen): Move touchpad tap suppression out of GestureEventQueue since |
190 // GEQ is meant to only be used for touchscreen gesture events. | 202 // GEQ is meant to only be used for touchscreen gesture events. |
191 scoped_ptr<TouchpadTapSuppressionController> | 203 TouchpadTapSuppressionController touchpad_tap_suppression_controller_; |
192 touchpad_tap_suppression_controller_; | |
193 | 204 |
194 // An object tracking the state of touchscreen on the delivery of gesture tap | 205 // 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 | 206 // events to the renderer to filter taps immediately after a touchscreen fling |
196 // canceling tap. | 207 // canceling tap. |
197 scoped_ptr<TouchscreenTapSuppressionController> | 208 TouchscreenTapSuppressionController touchscreen_tap_suppression_controller_; |
198 touchscreen_tap_suppression_controller_; | |
199 | 209 |
200 typedef std::deque<GestureEventWithLatencyInfo> GestureQueue; | 210 typedef std::deque<GestureEventWithLatencyInfo> GestureQueue; |
201 | 211 |
202 // Queue of coalesced gesture events not yet sent to the renderer. If | 212 // 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 | 213 // |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. | 214 // 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 | 215 // 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 | 216 // queue have been sent, and the second is awaiting an ACK. All other events |
207 // have yet to be sent. | 217 // have yet to be sent. |
208 GestureQueue coalesced_gesture_events_; | 218 GestureQueue coalesced_gesture_events_; |
209 | 219 |
210 // Timer to release a previously deferred gesture event. | 220 // Timer to release a previously deferred gesture event. |
211 base::OneShotTimer<GestureEventQueue> debounce_deferring_timer_; | 221 base::OneShotTimer<GestureEventQueue> debounce_deferring_timer_; |
212 | 222 |
213 // Queue of events that have been deferred for debounce. | 223 // Queue of events that have been deferred for debounce. |
214 GestureQueue debouncing_deferral_queue_; | 224 GestureQueue debouncing_deferral_queue_; |
215 | 225 |
216 // Time window in which to debounce scroll/fling ends. | 226 // Time window in which to debounce scroll/fling ends. Note that an interval |
217 // TODO(rjkroege): Make this dynamically configurable. | 227 // of zero effectively disables debouncing. |
218 int debounce_interval_time_ms_; | 228 base::TimeDelta debounce_interval_; |
219 | |
220 // Whether scroll-ending events should be deferred when a scroll is active. | |
221 // Defaults to true. | |
222 bool debounce_enabled_; | |
223 | 229 |
224 DISALLOW_COPY_AND_ASSIGN(GestureEventQueue); | 230 DISALLOW_COPY_AND_ASSIGN(GestureEventQueue); |
225 }; | 231 }; |
226 | 232 |
227 } // namespace content | 233 } // namespace content |
228 | 234 |
229 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_ | 235 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_ |
OLD | NEW |