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