| 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 #include "content/browser/renderer_host/input/touch_event_queue.h" | 5 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "content/browser/renderer_host/input/timeout_monitor.h" | 10 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 slop_suppression_length_dips), | 197 slop_suppression_length_dips), |
| 198 suppressing_touchmoves_(false) {} | 198 suppressing_touchmoves_(false) {} |
| 199 | 199 |
| 200 bool FilterEvent(const WebTouchEvent& event) { | 200 bool FilterEvent(const WebTouchEvent& event) { |
| 201 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { | 201 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { |
| 202 touch_sequence_start_position_ = | 202 touch_sequence_start_position_ = |
| 203 gfx::PointF(event.touches[0].position); | 203 gfx::PointF(event.touches[0].position); |
| 204 suppressing_touchmoves_ = slop_suppression_length_dips_squared_ != 0; | 204 suppressing_touchmoves_ = slop_suppression_length_dips_squared_ != 0; |
| 205 } | 205 } |
| 206 | 206 |
| 207 if (event.type == WebInputEvent::TouchEnd || |
| 208 event.type == WebInputEvent::TouchCancel) |
| 209 suppressing_touchmoves_ = false; |
| 210 |
| 207 if (event.type != WebInputEvent::TouchMove) | 211 if (event.type != WebInputEvent::TouchMove) |
| 208 return false; | 212 return false; |
| 209 | 213 |
| 210 if (suppressing_touchmoves_) { | 214 if (suppressing_touchmoves_) { |
| 211 // Movement with a secondary pointer should terminate suppression. | 215 // Movement with a secondary pointer should terminate suppression. |
| 212 if (event.touchesLength > 1) { | 216 if (event.touchesLength > 1) { |
| 213 suppressing_touchmoves_ = false; | 217 suppressing_touchmoves_ = false; |
| 214 } else if (event.touchesLength == 1) { | 218 } else if (event.touchesLength == 1) { |
| 215 // Movement outside of the slop region should terminate suppression. | 219 // Movement outside of the slop region should terminate suppression. |
| 216 gfx::PointF position(event.touches[0].position); | 220 gfx::PointF position(event.touches[0].position); |
| 217 if ((position - touch_sequence_start_position_).LengthSquared() > | 221 if ((position - touch_sequence_start_position_).LengthSquared() > |
| 218 slop_suppression_length_dips_squared_) | 222 slop_suppression_length_dips_squared_) |
| 219 suppressing_touchmoves_ = false; | 223 suppressing_touchmoves_ = false; |
| 220 } | 224 } |
| 221 } | 225 } |
| 222 return suppressing_touchmoves_; | 226 return suppressing_touchmoves_; |
| 223 } | 227 } |
| 224 | 228 |
| 225 void ConfirmTouchEvent(InputEventAckState ack_result) { | 229 void ConfirmTouchEvent(InputEventAckState ack_result) { |
| 226 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 230 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
| 227 suppressing_touchmoves_ = false; | 231 suppressing_touchmoves_ = false; |
| 228 } | 232 } |
| 229 | 233 |
| 234 bool suppressing_touchmoves() const { return suppressing_touchmoves_; } |
| 235 |
| 230 private: | 236 private: |
| 231 double slop_suppression_length_dips_squared_; | 237 double slop_suppression_length_dips_squared_; |
| 232 gfx::PointF touch_sequence_start_position_; | 238 gfx::PointF touch_sequence_start_position_; |
| 233 bool suppressing_touchmoves_; | 239 bool suppressing_touchmoves_; |
| 234 | 240 |
| 235 DISALLOW_COPY_AND_ASSIGN(TouchMoveSlopSuppressor); | 241 DISALLOW_COPY_AND_ASSIGN(TouchMoveSlopSuppressor); |
| 236 }; | 242 }; |
| 237 | 243 |
| 238 // This class represents a single coalesced touch event. However, it also keeps | 244 // This class represents a single coalesced touch event. However, it also keeps |
| 239 // track of all the original touch-events that were coalesced into a single | 245 // track of all the original touch-events that were coalesced into a single |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // This is the list of the original events that were coalesced, each requiring | 321 // This is the list of the original events that were coalesced, each requiring |
| 316 // future ack dispatch to the client. | 322 // future ack dispatch to the client. |
| 317 typedef std::vector<TouchEventWithLatencyInfo> WebTouchEventWithLatencyList; | 323 typedef std::vector<TouchEventWithLatencyInfo> WebTouchEventWithLatencyList; |
| 318 WebTouchEventWithLatencyList events_to_ack_; | 324 WebTouchEventWithLatencyList events_to_ack_; |
| 319 | 325 |
| 320 DISALLOW_COPY_AND_ASSIGN(CoalescedWebTouchEvent); | 326 DISALLOW_COPY_AND_ASSIGN(CoalescedWebTouchEvent); |
| 321 }; | 327 }; |
| 322 | 328 |
| 323 TouchEventQueue::Config::Config() | 329 TouchEventQueue::Config::Config() |
| 324 : touchmove_slop_suppression_length_dips(0), | 330 : touchmove_slop_suppression_length_dips(0), |
| 331 touchmove_slop_suppression_region_includes_boundary(true), |
| 325 touch_scrolling_mode(TOUCH_SCROLLING_MODE_DEFAULT), | 332 touch_scrolling_mode(TOUCH_SCROLLING_MODE_DEFAULT), |
| 326 touch_ack_timeout_delay(base::TimeDelta::FromMilliseconds(200)), | 333 touch_ack_timeout_delay(base::TimeDelta::FromMilliseconds(200)), |
| 327 touch_ack_timeout_supported(false) { | 334 touch_ack_timeout_supported(false) { |
| 328 } | 335 } |
| 329 | 336 |
| 330 TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client, | 337 TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client, |
| 331 const Config& config) | 338 const Config& config) |
| 332 : client_(client), | 339 : client_(client), |
| 333 dispatching_touch_ack_(NULL), | 340 dispatching_touch_ack_(NULL), |
| 334 dispatching_touch_(false), | 341 dispatching_touch_(false), |
| 335 touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT), | 342 touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT), |
| 336 ack_timeout_enabled_(config.touch_ack_timeout_supported), | 343 ack_timeout_enabled_(config.touch_ack_timeout_supported), |
| 337 touchmove_slop_suppressor_(new TouchMoveSlopSuppressor( | 344 touchmove_slop_suppressor_(new TouchMoveSlopSuppressor( |
| 338 config.touchmove_slop_suppression_length_dips + kSlopEpsilon)), | 345 config.touchmove_slop_suppression_length_dips + |
| 346 (config.touchmove_slop_suppression_region_includes_boundary |
| 347 ? kSlopEpsilon |
| 348 : -kSlopEpsilon))), |
| 339 send_touch_events_async_(false), | 349 send_touch_events_async_(false), |
| 340 needs_async_touchmove_for_outer_slop_region_(false), | 350 needs_async_touchmove_for_outer_slop_region_(false), |
| 341 last_sent_touch_timestamp_sec_(0), | 351 last_sent_touch_timestamp_sec_(0), |
| 342 touch_scrolling_mode_(config.touch_scrolling_mode) { | 352 touch_scrolling_mode_(config.touch_scrolling_mode) { |
| 343 DCHECK(client); | 353 DCHECK(client); |
| 344 if (ack_timeout_enabled_) { | 354 if (ack_timeout_enabled_) { |
| 345 timeout_handler_.reset( | 355 timeout_handler_.reset( |
| 346 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); | 356 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); |
| 347 } | 357 } |
| 348 } | 358 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 DCHECK(timeout_handler_); | 530 DCHECK(timeout_handler_); |
| 521 timeout_handler_->Start(touch); | 531 timeout_handler_->Start(touch); |
| 522 } | 532 } |
| 523 } | 533 } |
| 524 | 534 |
| 525 void TouchEventQueue::OnGestureScrollEvent( | 535 void TouchEventQueue::OnGestureScrollEvent( |
| 526 const GestureEventWithLatencyInfo& gesture_event) { | 536 const GestureEventWithLatencyInfo& gesture_event) { |
| 527 if (gesture_event.event.type != blink::WebInputEvent::GestureScrollBegin) | 537 if (gesture_event.event.type != blink::WebInputEvent::GestureScrollBegin) |
| 528 return; | 538 return; |
| 529 | 539 |
| 540 if (touch_filtering_state_ != DROP_ALL_TOUCHES && |
| 541 touch_filtering_state_ != DROP_TOUCHES_IN_SEQUENCE) { |
| 542 DCHECK(!touchmove_slop_suppressor_->suppressing_touchmoves()) |
| 543 << "The renderer should be offered a touchmove before scrolling begins"; |
| 544 } |
| 545 |
| 530 if (touch_scrolling_mode_ == TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE) { | 546 if (touch_scrolling_mode_ == TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE) { |
| 531 if (touch_filtering_state_ != DROP_ALL_TOUCHES && | 547 if (touch_filtering_state_ != DROP_ALL_TOUCHES && |
| 532 touch_filtering_state_ != DROP_TOUCHES_IN_SEQUENCE) { | 548 touch_filtering_state_ != DROP_TOUCHES_IN_SEQUENCE) { |
| 533 // If no touch points have a consumer, prevent all subsequent touch events | 549 // If no touch points have a consumer, prevent all subsequent touch events |
| 534 // received during the scroll from reaching the renderer. This ensures | 550 // received during the scroll from reaching the renderer. This ensures |
| 535 // that the first touchstart the renderer sees in any given sequence can | 551 // that the first touchstart the renderer sees in any given sequence can |
| 536 // always be preventDefault'ed (cancelable == true). | 552 // always be preventDefault'ed (cancelable == true). |
| 537 // TODO(jdduke): Revisit if touchstarts during scroll are made cancelable. | 553 // TODO(jdduke): Revisit if touchstarts during scroll are made cancelable. |
| 538 if (touch_ack_states_.empty() || | 554 if (touch_ack_states_.empty() || |
| 539 AllTouchAckStatesHaveState( | 555 AllTouchAckStatesHaveState( |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 iter != end; | 812 iter != end; |
| 797 ++iter) { | 813 ++iter) { |
| 798 if (iter->second != ack_state) | 814 if (iter->second != ack_state) |
| 799 return false; | 815 return false; |
| 800 } | 816 } |
| 801 | 817 |
| 802 return true; | 818 return true; |
| 803 } | 819 } |
| 804 | 820 |
| 805 } // namespace content | 821 } // namespace content |
| OLD | NEW |