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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 case PENDING_ACK_NONE: | 100 case PENDING_ACK_NONE: |
101 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 101 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
102 enabled_for_current_sequence_ = false; | 102 enabled_for_current_sequence_ = false; |
103 timeout_monitor_.Stop(); | 103 timeout_monitor_.Stop(); |
104 return false; | 104 return false; |
105 case PENDING_ACK_ORIGINAL_EVENT: | 105 case PENDING_ACK_ORIGINAL_EVENT: |
106 if (AckedTimeoutEventRequiresCancel(ack_result)) { | 106 if (AckedTimeoutEventRequiresCancel(ack_result)) { |
107 SetPendingAckState(PENDING_ACK_CANCEL_EVENT); | 107 SetPendingAckState(PENDING_ACK_CANCEL_EVENT); |
108 TouchEventWithLatencyInfo cancel_event = | 108 TouchEventWithLatencyInfo cancel_event = |
109 ObtainCancelEventForTouchEvent(timeout_event_); | 109 ObtainCancelEventForTouchEvent(timeout_event_); |
110 touch_queue_->SendTouchEventImmediately(cancel_event); | 110 touch_queue_->SendTouchEventImmediately(&cancel_event); |
111 } else { | 111 } else { |
112 SetPendingAckState(PENDING_ACK_NONE); | 112 SetPendingAckState(PENDING_ACK_NONE); |
113 touch_queue_->UpdateTouchConsumerStates(timeout_event_.event, | 113 touch_queue_->UpdateTouchConsumerStates(timeout_event_.event, |
114 ack_result); | 114 ack_result); |
115 } | 115 } |
116 return true; | 116 return true; |
117 case PENDING_ACK_CANCEL_EVENT: | 117 case PENDING_ACK_CANCEL_EVENT: |
118 SetPendingAckState(PENDING_ACK_NONE); | 118 SetPendingAckState(PENDING_ACK_NONE); |
119 return true; | 119 return true; |
120 } | 120 } |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 if (pending_async_touchmove_->CanCoalesceWith(touch)) { | 518 if (pending_async_touchmove_->CanCoalesceWith(touch)) { |
519 pending_async_touchmove_->CoalesceWith(touch); | 519 pending_async_touchmove_->CoalesceWith(touch); |
520 pending_async_touchmove_->event.cancelable = !send_touch_events_async_; | 520 pending_async_touchmove_->event.cancelable = !send_touch_events_async_; |
521 touch = *pending_async_touchmove_; | 521 touch = *pending_async_touchmove_; |
522 pending_async_touchmove_.reset(); | 522 pending_async_touchmove_.reset(); |
523 } else { | 523 } else { |
524 scoped_ptr<TouchEventWithLatencyInfo> async_move = | 524 scoped_ptr<TouchEventWithLatencyInfo> async_move = |
525 pending_async_touchmove_.Pass(); | 525 pending_async_touchmove_.Pass(); |
526 async_move->event.cancelable = false; | 526 async_move->event.cancelable = false; |
527 touch_queue_.push_front(new CoalescedWebTouchEvent(*async_move, true)); | 527 touch_queue_.push_front(new CoalescedWebTouchEvent(*async_move, true)); |
528 SendTouchEventImmediately(*async_move); | 528 SendTouchEventImmediately(async_move.get()); |
529 return; | 529 return; |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 // Note: Marking touchstart events as not-cancelable prevents them from | 533 // Note: Marking touchstart events as not-cancelable prevents them from |
534 // blocking subsequent gestures, but it may not be the best long term solution | 534 // blocking subsequent gestures, but it may not be the best long term solution |
535 // for tracking touch point dispatch. | 535 // for tracking touch point dispatch. |
536 if (send_touch_events_async_) | 536 if (send_touch_events_async_) |
537 touch.event.cancelable = false; | 537 touch.event.cancelable = false; |
538 | 538 |
539 // A synchronous ack will reset |dispatching_touch_|, in which case | 539 // A synchronous ack will reset |dispatching_touch_|, in which case |
540 // the touch timeout should not be started. | 540 // the touch timeout should not be started. |
541 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true); | 541 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true); |
542 SendTouchEventImmediately(touch); | 542 SendTouchEventImmediately(&touch); |
543 if (dispatching_touch_ && timeout_handler_) | 543 if (dispatching_touch_ && timeout_handler_) |
544 timeout_handler_->StartIfNecessary(touch); | 544 timeout_handler_->StartIfNecessary(touch); |
545 } | 545 } |
546 | 546 |
547 void TouchEventQueue::OnGestureScrollEvent( | 547 void TouchEventQueue::OnGestureScrollEvent( |
548 const GestureEventWithLatencyInfo& gesture_event) { | 548 const GestureEventWithLatencyInfo& gesture_event) { |
549 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { | 549 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { |
550 if (!touch_consumer_states_.is_empty() && | 550 if (!touch_consumer_states_.is_empty() && |
551 !drop_remaining_touches_in_sequence_) { | 551 !drop_remaining_touches_in_sequence_) { |
552 DCHECK(!touchmove_slop_suppressor_->suppressing_touchmoves()) | 552 DCHECK(!touchmove_slop_suppressor_->suppressing_touchmoves()) |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } | 696 } |
697 | 697 |
698 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { | 698 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { |
699 DCHECK(!touch_queue_.empty()); | 699 DCHECK(!touch_queue_.empty()); |
700 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); | 700 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); |
701 touch_queue_.pop_front(); | 701 touch_queue_.pop_front(); |
702 return event.Pass(); | 702 return event.Pass(); |
703 } | 703 } |
704 | 704 |
705 void TouchEventQueue::SendTouchEventImmediately( | 705 void TouchEventQueue::SendTouchEventImmediately( |
706 const TouchEventWithLatencyInfo& touch) { | 706 TouchEventWithLatencyInfo* touch) { |
707 if (needs_async_touchmove_for_outer_slop_region_) { | 707 if (needs_async_touchmove_for_outer_slop_region_) { |
708 // Any event other than a touchmove (e.g., touchcancel or secondary | 708 // Any event other than a touchmove (e.g., touchcancel or secondary |
709 // touchstart) after a scroll has started will interrupt the need to send a | 709 // touchstart) after a scroll has started will interrupt the need to send a |
710 // an outer slop-region exceeding touchmove. | 710 // an outer slop-region exceeding touchmove. |
711 if (touch.event.type != WebInputEvent::TouchMove || | 711 if (touch->event.type != WebInputEvent::TouchMove || |
712 OutsideApplicationSlopRegion(touch.event, | 712 OutsideApplicationSlopRegion(touch->event, |
713 touch_sequence_start_position_)) | 713 touch_sequence_start_position_)) |
714 needs_async_touchmove_for_outer_slop_region_ = false; | 714 needs_async_touchmove_for_outer_slop_region_ = false; |
715 } | 715 } |
716 | 716 |
717 client_->SendTouchEventImmediately(touch); | 717 // For touchmove events, compare touch points position from current event |
| 718 // to last sent event and update touch points state. |
| 719 if (touch->event.type == WebInputEvent::TouchMove) { |
| 720 CHECK(last_sent_touchevent_); |
| 721 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) { |
| 722 const WebTouchPoint& last_touch_point = |
| 723 last_sent_touchevent_->touches[i]; |
| 724 // Touches with same id may not have same index in Touches array. |
| 725 for (unsigned int j = 0; j < touch->event.touchesLength; ++j) { |
| 726 const WebTouchPoint& current_touchmove_point = touch->event.touches[j]; |
| 727 if (current_touchmove_point.id != last_touch_point.id) |
| 728 continue; |
| 729 |
| 730 if (current_touchmove_point.position == last_touch_point.position) |
| 731 touch->event.touches[j].state = WebTouchPoint::StateStationary; |
| 732 |
| 733 break; |
| 734 } |
| 735 } |
| 736 } |
| 737 |
| 738 if (last_sent_touchevent_) |
| 739 *last_sent_touchevent_ = touch->event; |
| 740 else |
| 741 last_sent_touchevent_.reset(new WebTouchEvent(touch->event)); |
| 742 |
| 743 client_->SendTouchEventImmediately(*touch); |
718 } | 744 } |
719 | 745 |
720 TouchEventQueue::PreFilterResult | 746 TouchEventQueue::PreFilterResult |
721 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { | 747 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { |
722 if (timeout_handler_ && timeout_handler_->FilterEvent(event)) | 748 if (timeout_handler_ && timeout_handler_->FilterEvent(event)) |
723 return ACK_WITH_NO_CONSUMER_EXISTS; | 749 return ACK_WITH_NO_CONSUMER_EXISTS; |
724 | 750 |
725 if (touchmove_slop_suppressor_->FilterEvent(event)) | 751 if (touchmove_slop_suppressor_->FilterEvent(event)) |
726 return ACK_WITH_NOT_CONSUMED; | 752 return ACK_WITH_NOT_CONSUMED; |
727 | 753 |
728 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { | 754 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { |
729 touch_consumer_states_.clear(); | 755 touch_consumer_states_.clear(); |
730 send_touch_events_async_ = false; | 756 send_touch_events_async_ = false; |
731 pending_async_touchmove_.reset(); | 757 pending_async_touchmove_.reset(); |
| 758 last_sent_touchevent_.reset(); |
| 759 |
732 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position); | 760 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position); |
733 drop_remaining_touches_in_sequence_ = false; | 761 drop_remaining_touches_in_sequence_ = false; |
734 if (!has_handlers_) { | 762 if (!has_handlers_) { |
735 drop_remaining_touches_in_sequence_ = true; | 763 drop_remaining_touches_in_sequence_ = true; |
736 return ACK_WITH_NO_CONSUMER_EXISTS; | 764 return ACK_WITH_NO_CONSUMER_EXISTS; |
737 } | 765 } |
738 } | 766 } |
739 | 767 |
740 if (drop_remaining_touches_in_sequence_ && | 768 if (drop_remaining_touches_in_sequence_ && |
741 event.type != WebInputEvent::TouchCancel) { | 769 event.type != WebInputEvent::TouchCancel) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 if (ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) | 805 if (ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) |
778 touch_consumer_states_.mark_bit(point.id); | 806 touch_consumer_states_.mark_bit(point.id); |
779 else | 807 else |
780 touch_consumer_states_.clear_bit(point.id); | 808 touch_consumer_states_.clear_bit(point.id); |
781 } | 809 } |
782 } | 810 } |
783 } | 811 } |
784 } | 812 } |
785 | 813 |
786 } // namespace content | 814 } // namespace content |
OLD | NEW |