| 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 #include "content/browser/renderer_host/input/gesture_event_queue.h" | 5 #include "content/browser/renderer_host/input/gesture_event_queue.h" |
| 6 | 6 |
| 7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
| 8 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle
r.h" | 8 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle
r.h" |
| 9 #include "content/browser/renderer_host/input/touchscreen_tap_suppression_contro
ller.h" | 9 #include "content/browser/renderer_host/input/touchscreen_tap_suppression_contro
ller.h" |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 GestureEventQueue::Config::Config() { | 57 GestureEventQueue::Config::Config() { |
| 58 } | 58 } |
| 59 | 59 |
| 60 GestureEventQueue::GestureEventQueue( | 60 GestureEventQueue::GestureEventQueue( |
| 61 GestureEventQueueClient* client, | 61 GestureEventQueueClient* client, |
| 62 TouchpadTapSuppressionControllerClient* touchpad_client, | 62 TouchpadTapSuppressionControllerClient* touchpad_client, |
| 63 const Config& config) | 63 const Config& config) |
| 64 : client_(client), | 64 : client_(client), |
| 65 fling_in_progress_(false), | 65 active_fling_count_(0), |
| 66 scrolling_in_progress_(false), | 66 scrolling_in_progress_(false), |
| 67 ignore_next_ack_(false), | 67 ignore_next_ack_(false), |
| 68 touchpad_tap_suppression_controller_( | 68 touchpad_tap_suppression_controller_( |
| 69 touchpad_client, | 69 touchpad_client, |
| 70 config.touchpad_tap_suppression_config), | 70 config.touchpad_tap_suppression_config), |
| 71 touchscreen_tap_suppression_controller_( | 71 touchscreen_tap_suppression_controller_( |
| 72 this, | 72 this, |
| 73 config.touchscreen_tap_suppression_config), | 73 config.touchscreen_tap_suppression_config), |
| 74 debounce_interval_(config.debounce_interval) { | 74 debounce_interval_(config.debounce_interval) { |
| 75 DCHECK(client); | 75 DCHECK(client); |
| 76 DCHECK(touchpad_client); | 76 DCHECK(touchpad_client); |
| 77 } | 77 } |
| 78 | 78 |
| 79 GestureEventQueue::~GestureEventQueue() { } | 79 GestureEventQueue::~GestureEventQueue() { } |
| 80 | 80 |
| 81 void GestureEventQueue::QueueEvent( | 81 void GestureEventQueue::QueueEvent( |
| 82 const GestureEventWithLatencyInfo& gesture_event) { | 82 const GestureEventWithLatencyInfo& gesture_event) { |
| 83 TRACE_EVENT0("input", "GestureEventQueue::QueueEvent"); | 83 TRACE_EVENT0("input", "GestureEventQueue::QueueEvent"); |
| 84 if (!ShouldForwardForBounceReduction(gesture_event) || | 84 if (!ShouldForwardForBounceReduction(gesture_event) || |
| 85 !ShouldForwardForGFCFiltering(gesture_event) || | 85 !ShouldForwardForGFCFiltering(gesture_event) || |
| 86 !ShouldForwardForTapSuppression(gesture_event)) { | 86 !ShouldForwardForTapSuppression(gesture_event)) { |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 | 89 |
| 90 QueueAndForwardIfNecessary(gesture_event); | 90 QueueAndForwardIfNecessary(gesture_event); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool GestureEventQueue::ShouldDiscardFlingCancelEvent( | 93 bool GestureEventQueue::ShouldDiscardFlingCancelEvent( |
| 94 const GestureEventWithLatencyInfo& gesture_event) const { | 94 const GestureEventWithLatencyInfo& gesture_event) const { |
| 95 if (coalesced_gesture_events_.empty() && fling_in_progress_) | |
| 96 return false; | |
| 97 GestureQueue::const_reverse_iterator it = | 95 GestureQueue::const_reverse_iterator it = |
| 98 coalesced_gesture_events_.rbegin(); | 96 coalesced_gesture_events_.rbegin(); |
| 99 while (it != coalesced_gesture_events_.rend()) { | 97 while (it != coalesced_gesture_events_.rend()) { |
| 100 if (it->event.type == WebInputEvent::GestureFlingStart) | 98 if (it->event.type == WebInputEvent::GestureFlingStart) |
| 101 return false; | 99 return false; |
| 102 if (it->event.type == WebInputEvent::GestureFlingCancel) | 100 if (it->event.type == WebInputEvent::GestureFlingCancel) |
| 103 return true; | 101 return true; |
| 104 it++; | 102 it++; |
| 105 } | 103 } |
| 106 return true; | 104 // If there are no fling-affecting events in the queue, and there's still an |
| 105 // active fling in the renderer, the cancel event should not be dropped. |
| 106 return !active_fling_count_; |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool GestureEventQueue::ShouldForwardForBounceReduction( | 109 bool GestureEventQueue::ShouldForwardForBounceReduction( |
| 110 const GestureEventWithLatencyInfo& gesture_event) { | 110 const GestureEventWithLatencyInfo& gesture_event) { |
| 111 if (debounce_interval_ <= base::TimeDelta()) | 111 if (debounce_interval_ <= base::TimeDelta()) |
| 112 return true; | 112 return true; |
| 113 switch (gesture_event.event.type) { | 113 switch (gesture_event.event.type) { |
| 114 case WebInputEvent::GestureScrollUpdate: | 114 case WebInputEvent::GestureScrollUpdate: |
| 115 if (!scrolling_in_progress_) { | 115 if (!scrolling_in_progress_) { |
| 116 debounce_deferring_timer_.Start( | 116 debounce_deferring_timer_.Start( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 168 } |
| 169 return true; | 169 return true; |
| 170 default: | 170 default: |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 void GestureEventQueue::QueueAndForwardIfNecessary( | 175 void GestureEventQueue::QueueAndForwardIfNecessary( |
| 176 const GestureEventWithLatencyInfo& gesture_event) { | 176 const GestureEventWithLatencyInfo& gesture_event) { |
| 177 switch (gesture_event.event.type) { | 177 switch (gesture_event.event.type) { |
| 178 case WebInputEvent::GestureFlingCancel: | |
| 179 fling_in_progress_ = false; | |
| 180 break; | |
| 181 case WebInputEvent::GestureFlingStart: | |
| 182 fling_in_progress_ = true; | |
| 183 break; | |
| 184 case WebInputEvent::GesturePinchUpdate: | 178 case WebInputEvent::GesturePinchUpdate: |
| 185 case WebInputEvent::GestureScrollUpdate: | 179 case WebInputEvent::GestureScrollUpdate: |
| 186 QueueScrollOrPinchAndForwardIfNecessary(gesture_event); | 180 QueueScrollOrPinchAndForwardIfNecessary(gesture_event); |
| 187 return; | 181 return; |
| 188 default: | 182 default: |
| 189 break; | 183 break; |
| 190 } | 184 } |
| 191 | 185 |
| 192 coalesced_gesture_events_.push_back(gesture_event); | 186 coalesced_gesture_events_.push_back(gesture_event); |
| 193 if (coalesced_gesture_events_.size() == 1) | 187 if (coalesced_gesture_events_.size() == 1) |
| 194 client_->SendGestureEventImmediately(gesture_event); | 188 client_->SendGestureEventImmediately(gesture_event); |
| 195 } | 189 } |
| 196 | 190 |
| 197 void GestureEventQueue::ProcessGestureAck(InputEventAckState ack_result, | 191 void GestureEventQueue::ProcessGestureAck(InputEventAckState ack_result, |
| 198 WebInputEvent::Type type, | 192 WebInputEvent::Type type, |
| 199 const ui::LatencyInfo& latency) { | 193 const ui::LatencyInfo& latency) { |
| 200 TRACE_EVENT0("input", "GestureEventQueue::ProcessGestureAck"); | 194 TRACE_EVENT0("input", "GestureEventQueue::ProcessGestureAck"); |
| 201 | 195 |
| 202 if (coalesced_gesture_events_.empty()) { | 196 if (coalesced_gesture_events_.empty()) { |
| 203 DLOG(ERROR) << "Received unexpected ACK for event type " << type; | 197 DLOG(ERROR) << "Received unexpected ACK for event type " << type; |
| 204 return; | 198 return; |
| 205 } | 199 } |
| 206 | 200 |
| 201 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED && |
| 202 type == blink::WebInputEvent::GestureFlingStart) { |
| 203 ++active_fling_count_; |
| 204 } |
| 205 |
| 207 // It's possible that the ack for the second event in an in-flight, coalesced | 206 // It's possible that the ack for the second event in an in-flight, coalesced |
| 208 // Gesture{Scroll,Pinch}Update pair is received prior to the first event ack. | 207 // Gesture{Scroll,Pinch}Update pair is received prior to the first event ack. |
| 209 // TODO(jdduke): Unify GSU/GPU pairs into a single event, crbug.com/359115. | 208 // TODO(jdduke): Unify GSU/GPU pairs into a single event, crbug.com/359115. |
| 210 size_t event_index = 0; | 209 size_t event_index = 0; |
| 211 if (ignore_next_ack_ && | 210 if (ignore_next_ack_ && |
| 212 coalesced_gesture_events_.size() > 1 && | 211 coalesced_gesture_events_.size() > 1 && |
| 213 coalesced_gesture_events_[0].event.type != type && | 212 coalesced_gesture_events_[0].event.type != type && |
| 214 coalesced_gesture_events_[1].event.type == type) { | 213 coalesced_gesture_events_[1].event.type == type) { |
| 215 event_index = 1; | 214 event_index = 1; |
| 216 } | 215 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 client_->SendGestureEventImmediately(first_gesture_event); | 261 client_->SendGestureEventImmediately(first_gesture_event); |
| 263 if (second_gesture_event.event.type != WebInputEvent::Undefined) | 262 if (second_gesture_event.event.type != WebInputEvent::Undefined) |
| 264 client_->SendGestureEventImmediately(second_gesture_event); | 263 client_->SendGestureEventImmediately(second_gesture_event); |
| 265 } | 264 } |
| 266 | 265 |
| 267 TouchpadTapSuppressionController* | 266 TouchpadTapSuppressionController* |
| 268 GestureEventQueue::GetTouchpadTapSuppressionController() { | 267 GestureEventQueue::GetTouchpadTapSuppressionController() { |
| 269 return &touchpad_tap_suppression_controller_; | 268 return &touchpad_tap_suppression_controller_; |
| 270 } | 269 } |
| 271 | 270 |
| 272 void GestureEventQueue::FlingHasBeenHalted() { | 271 void GestureEventQueue::DidStopFlinging() { |
| 273 fling_in_progress_ = false; | 272 DCHECK_GE(active_fling_count_, 0); |
| 273 --active_fling_count_; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void GestureEventQueue::ForwardGestureEvent( | 276 void GestureEventQueue::ForwardGestureEvent( |
| 277 const GestureEventWithLatencyInfo& gesture_event) { | 277 const GestureEventWithLatencyInfo& gesture_event) { |
| 278 QueueAndForwardIfNecessary(gesture_event); | 278 QueueAndForwardIfNecessary(gesture_event); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void GestureEventQueue::SendScrollEndingEventsNow() { | 281 void GestureEventQueue::SendScrollEndingEventsNow() { |
| 282 scrolling_in_progress_ = false; | 282 scrolling_in_progress_ = false; |
| 283 if (debouncing_deferral_queue_.empty()) | 283 if (debouncing_deferral_queue_.empty()) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 return 0; | 389 return 0; |
| 390 | 390 |
| 391 if (!ignore_next_ack_) | 391 if (!ignore_next_ack_) |
| 392 return 1; | 392 return 1; |
| 393 | 393 |
| 394 DCHECK_GT(coalesced_gesture_events_.size(), 1U); | 394 DCHECK_GT(coalesced_gesture_events_.size(), 1U); |
| 395 return 2; | 395 return 2; |
| 396 } | 396 } |
| 397 | 397 |
| 398 } // namespace content | 398 } // namespace content |
| OLD | NEW |