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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT), | 342 touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT), |
343 ack_timeout_enabled_(config.touch_ack_timeout_supported), | 343 ack_timeout_enabled_(config.touch_ack_timeout_supported), |
344 touchmove_slop_suppressor_(new TouchMoveSlopSuppressor( | 344 touchmove_slop_suppressor_(new TouchMoveSlopSuppressor( |
345 config.touchmove_slop_suppression_length_dips + | 345 config.touchmove_slop_suppression_length_dips + |
346 (config.touchmove_slop_suppression_region_includes_boundary | 346 (config.touchmove_slop_suppression_region_includes_boundary |
347 ? kSlopEpsilon | 347 ? kSlopEpsilon |
348 : -kSlopEpsilon))), | 348 : -kSlopEpsilon))), |
349 send_touch_events_async_(false), | 349 send_touch_events_async_(false), |
350 needs_async_touchmove_for_outer_slop_region_(false), | 350 needs_async_touchmove_for_outer_slop_region_(false), |
351 last_sent_touch_timestamp_sec_(0), | 351 last_sent_touch_timestamp_sec_(0), |
352 touch_scrolling_mode_(config.touch_scrolling_mode) { | 352 touch_scrolling_mode_(config.touch_scrolling_mode), |
| 353 seen_scroll_update_this_sequence_(false) { |
353 DCHECK(client); | 354 DCHECK(client); |
354 if (ack_timeout_enabled_) { | 355 if (ack_timeout_enabled_) { |
355 timeout_handler_.reset( | 356 timeout_handler_.reset( |
356 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); | 357 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); |
357 } | 358 } |
358 } | 359 } |
359 | 360 |
360 TouchEventQueue::~TouchEventQueue() { | 361 TouchEventQueue::~TouchEventQueue() { |
361 if (!touch_queue_.empty()) | 362 if (!touch_queue_.empty()) |
362 STLDeleteElements(&touch_queue_); | 363 STLDeleteElements(&touch_queue_); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 if (dispatching_touch_ && | 528 if (dispatching_touch_ && |
528 touch_filtering_state_ == FORWARD_TOUCHES_UNTIL_TIMEOUT && | 529 touch_filtering_state_ == FORWARD_TOUCHES_UNTIL_TIMEOUT && |
529 ShouldTouchTriggerTimeout(touch.event)) { | 530 ShouldTouchTriggerTimeout(touch.event)) { |
530 DCHECK(timeout_handler_); | 531 DCHECK(timeout_handler_); |
531 timeout_handler_->Start(touch); | 532 timeout_handler_->Start(touch); |
532 } | 533 } |
533 } | 534 } |
534 | 535 |
535 void TouchEventQueue::OnGestureScrollEvent( | 536 void TouchEventQueue::OnGestureScrollEvent( |
536 const GestureEventWithLatencyInfo& gesture_event) { | 537 const GestureEventWithLatencyInfo& gesture_event) { |
537 if (gesture_event.event.type != blink::WebInputEvent::GestureScrollBegin) | 538 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { |
538 return; | 539 seen_scroll_update_this_sequence_ = false; |
539 | 540 |
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 | |
546 if (touch_scrolling_mode_ == TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE) { | |
547 if (touch_filtering_state_ != DROP_ALL_TOUCHES && | 541 if (touch_filtering_state_ != DROP_ALL_TOUCHES && |
548 touch_filtering_state_ != DROP_TOUCHES_IN_SEQUENCE) { | 542 touch_filtering_state_ != DROP_TOUCHES_IN_SEQUENCE) { |
| 543 DCHECK(!touchmove_slop_suppressor_->suppressing_touchmoves()) |
| 544 << "The renderer should be offered a touchmove before scrolling " |
| 545 "begins"; |
| 546 } |
| 547 |
| 548 if (touch_scrolling_mode_ == TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE && |
| 549 touch_filtering_state_ != DROP_ALL_TOUCHES && |
| 550 touch_filtering_state_ != DROP_TOUCHES_IN_SEQUENCE && |
| 551 (touch_ack_states_.empty() || |
| 552 AllTouchAckStatesHaveState( |
| 553 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS))) { |
549 // If no touch points have a consumer, prevent all subsequent touch events | 554 // If no touch points have a consumer, prevent all subsequent touch events |
550 // received during the scroll from reaching the renderer. This ensures | 555 // received during the scroll from reaching the renderer. This ensures |
551 // that the first touchstart the renderer sees in any given sequence can | 556 // that the first touchstart the renderer sees in any given sequence can |
552 // always be preventDefault'ed (cancelable == true). | 557 // always be preventDefault'ed (cancelable == true). |
553 // TODO(jdduke): Revisit if touchstarts during scroll are made cancelable. | 558 // TODO(jdduke): Revisit if touchstarts during scroll are made cancelable. |
554 if (touch_ack_states_.empty() || | 559 touch_filtering_state_ = DROP_TOUCHES_IN_SEQUENCE; |
555 AllTouchAckStatesHaveState( | |
556 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS)) { | |
557 touch_filtering_state_ = DROP_TOUCHES_IN_SEQUENCE; | |
558 return; | |
559 } | |
560 } | 560 } |
| 561 return; |
| 562 } |
561 | 563 |
| 564 if (gesture_event.event.type != blink::WebInputEvent::GestureScrollUpdate || |
| 565 seen_scroll_update_this_sequence_) |
| 566 return; |
| 567 |
| 568 if (touch_scrolling_mode_ == TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE) { |
562 pending_async_touchmove_.reset(); | 569 pending_async_touchmove_.reset(); |
563 send_touch_events_async_ = true; | 570 send_touch_events_async_ = true; |
564 needs_async_touchmove_for_outer_slop_region_ = true; | 571 needs_async_touchmove_for_outer_slop_region_ = true; |
565 return; | 572 return; |
566 } | 573 } |
567 | 574 |
568 if (touch_scrolling_mode_ != TOUCH_SCROLLING_MODE_TOUCHCANCEL) | 575 if (touch_scrolling_mode_ != TOUCH_SCROLLING_MODE_TOUCHCANCEL) |
569 return; | 576 return; |
570 | 577 |
571 // We assume that scroll events are generated synchronously from | 578 // We assume that scroll events are generated synchronously from |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 iter != end; | 820 iter != end; |
814 ++iter) { | 821 ++iter) { |
815 if (iter->second != ack_state) | 822 if (iter->second != ack_state) |
816 return false; | 823 return false; |
817 } | 824 } |
818 | 825 |
819 return true; | 826 return true; |
820 } | 827 } |
821 | 828 |
822 } // namespace content | 829 } // namespace content |
OLD | NEW |