Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/browser/renderer_host/input/touch_event_queue.cc

Issue 1800143002: Notify Blink about start of gesture scroll through a queued event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 10 matching lines...) Expand all
21 using ui::LatencyInfo; 21 using ui::LatencyInfo;
22 22
23 namespace content { 23 namespace content {
24 namespace { 24 namespace {
25 25
26 // Time interval at which touchmove events will be forwarded to the client while 26 // Time interval at which touchmove events will be forwarded to the client while
27 // scrolling is active and possible. 27 // scrolling is active and possible.
28 const double kAsyncTouchMoveIntervalSec = .2; 28 const double kAsyncTouchMoveIntervalSec = .2;
29 29
30 // A sanity check on touches received to ensure that touch movement outside 30 // A sanity check on touches received to ensure that touch movement outside
31 // the platform slop region will cause scrolling, as indicated by the event's 31 // the platform slop region will cause scrolling.
32 // |causesScrollingIfUncanceled| bit.
33 const double kMaxConceivablePlatformSlopRegionLengthDipsSquared = 60. * 60.; 32 const double kMaxConceivablePlatformSlopRegionLengthDipsSquared = 60. * 60.;
34 33
35 TouchEventWithLatencyInfo ObtainCancelEventForTouchEvent( 34 TouchEventWithLatencyInfo ObtainCancelEventForTouchEvent(
36 const TouchEventWithLatencyInfo& event_to_cancel) { 35 const TouchEventWithLatencyInfo& event_to_cancel) {
37 TouchEventWithLatencyInfo event = event_to_cancel; 36 TouchEventWithLatencyInfo event = event_to_cancel;
38 WebTouchEventTraits::ResetTypeAndTouchStates( 37 WebTouchEventTraits::ResetTypeAndTouchStates(
39 WebInputEvent::TouchCancel, 38 WebInputEvent::TouchCancel,
40 // TODO(rbyers): Shouldn't we use a fresh timestamp? 39 // TODO(rbyers): Shouldn't we use a fresh timestamp?
41 event.event.timeStampSeconds, 40 event.event.timeStampSeconds,
42 &event.event); 41 &event.event);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 // If the last queued touch-event was a touch-move, and the current event is 483 // If the last queued touch-event was a touch-move, and the current event is
485 // also a touch-move, then the events can be coalesced into a single event. 484 // also a touch-move, then the events can be coalesced into a single event.
486 if (touch_queue_.size() > 1) { 485 if (touch_queue_.size() > 1) {
487 CoalescedWebTouchEvent* last_event = touch_queue_.back(); 486 CoalescedWebTouchEvent* last_event = touch_queue_.back();
488 if (last_event->CoalesceEventIfPossible(event)) 487 if (last_event->CoalesceEventIfPossible(event))
489 return; 488 return;
490 } 489 }
491 touch_queue_.push_back(new CoalescedWebTouchEvent(event, false)); 490 touch_queue_.push_back(new CoalescedWebTouchEvent(event, false));
492 } 491 }
493 492
493 void TouchEventQueue::PrependTouchScrollNotification() {
494 TRACE_EVENT0("input", "TouchEventQueue::PrependTouchScrollNotification");
495
496 TouchEventWithLatencyInfo touch;
497 touch.event.type = WebInputEvent::TouchScrollStarted;
498 touch.event.uniqueTouchEventId = 0;
499 touch.event.touchesLength = 0;
500
501 // Leave the head of the queue untouched since it is an in-flight event. The
502 // queue should have an in-flight event at this moment because this method is
503 // triggered by InputRouterImpl::SendGestureEvent, which is triggered by
504 // TouchEventQueue::AckTouchEventToClient, which has just received an ack for
505 // the in-flight event.
tdresser 2016/04/11 18:19:38 Should we DCHECK this here?
mustaq 2016/04/11 18:40:41 Didn't add a DCHECK here because I am not 100% sur
506 auto it = touch_queue_.begin();
507 if (it != touch_queue_.end())
508 ++it;
509 touch_queue_.insert(it, new CoalescedWebTouchEvent(touch, false));
510 }
511
494 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result, 512 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result,
495 const LatencyInfo& latency_info, 513 const LatencyInfo& latency_info,
496 const uint32_t unique_touch_event_id) { 514 const uint32_t unique_touch_event_id) {
497 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck"); 515 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck");
498 516
499 // We receive an ack for async touchmove from render. 517 // We receive an ack for async touchmove from render.
500 if (!ack_pending_async_touchmove_ids_.empty() && 518 if (!ack_pending_async_touchmove_ids_.empty() &&
501 ack_pending_async_touchmove_ids_.front() == unique_touch_event_id) { 519 ack_pending_async_touchmove_ids_.front() == unique_touch_event_id) {
502 // Remove the first touchmove from the ack_pending_async_touchmove queue. 520 // Remove the first touchmove from the ack_pending_async_touchmove queue.
503 ack_pending_async_touchmove_ids_.pop_front(); 521 ack_pending_async_touchmove_ids_.pop_front();
(...skipping 14 matching lines...) Expand all
518 dispatching_touch_ = false; 536 dispatching_touch_ = false;
519 537
520 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result)) 538 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result))
521 return; 539 return;
522 540
523 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result); 541 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result);
524 542
525 if (touch_queue_.empty()) 543 if (touch_queue_.empty())
526 return; 544 return;
527 545
528 DCHECK_EQ(touch_queue_.front()->coalesced_event().event.uniqueTouchEventId, 546 // We don't care about the ordering of the acks vs the ordering of the
529 unique_touch_event_id); 547 // dispatched events because we can receive the ack for event B before the ack
548 // for event A even though A was sent before B. This seems to be happening
549 // when, for example, A is acked from renderer but B isn't, so the ack for B
550 // is synthesized "locally" in InputRouter.
551 //
552 // TODO(crbug.com/600773): Bring the id checks back when dispatch triggering
553 // is sane.
530 554
531 PopTouchEventToClient(ack_result, latency_info); 555 PopTouchEventToClient(ack_result, latency_info);
532 TryForwardNextEventToRenderer(); 556 TryForwardNextEventToRenderer();
533 } 557 }
534 558
535 void TouchEventQueue::TryForwardNextEventToRenderer() { 559 void TouchEventQueue::TryForwardNextEventToRenderer() {
536 DCHECK(!dispatching_touch_ack_); 560 DCHECK(!dispatching_touch_ack_);
537 // If there are queued touch events, then try to forward them to the renderer 561 // If there are queued touch events, then try to forward them to the renderer
538 // immediately, or ACK the events back to the client if appropriate. 562 // immediately, or ACK the events back to the client if appropriate.
539 while (!touch_queue_.empty()) { 563 while (!touch_queue_.empty()) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 void TouchEventQueue::FlushQueue() { 736 void TouchEventQueue::FlushQueue() {
713 DCHECK(!dispatching_touch_ack_); 737 DCHECK(!dispatching_touch_ack_);
714 DCHECK(!dispatching_touch_); 738 DCHECK(!dispatching_touch_);
715 pending_async_touchmove_.reset(); 739 pending_async_touchmove_.reset();
716 drop_remaining_touches_in_sequence_ = true; 740 drop_remaining_touches_in_sequence_ = true;
717 while (!touch_queue_.empty()) 741 while (!touch_queue_.empty())
718 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 742 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
719 } 743 }
720 744
721 void TouchEventQueue::PopTouchEventToClient(InputEventAckState ack_result) { 745 void TouchEventQueue::PopTouchEventToClient(InputEventAckState ack_result) {
722 AckTouchEventToClient(ack_result, PopTouchEvent(), nullptr); 746 AckTouchEventToClient(ack_result, nullptr);
723 } 747 }
724 748
725 void TouchEventQueue::PopTouchEventToClient( 749 void TouchEventQueue::PopTouchEventToClient(
726 InputEventAckState ack_result, 750 InputEventAckState ack_result,
727 const LatencyInfo& renderer_latency_info) { 751 const LatencyInfo& renderer_latency_info) {
728 AckTouchEventToClient(ack_result, PopTouchEvent(), &renderer_latency_info); 752 AckTouchEventToClient(ack_result, &renderer_latency_info);
729 } 753 }
730 754
731 void TouchEventQueue::AckTouchEventToClient( 755 void TouchEventQueue::AckTouchEventToClient(
732 InputEventAckState ack_result, 756 InputEventAckState ack_result,
733 std::unique_ptr<CoalescedWebTouchEvent> acked_event,
734 const ui::LatencyInfo* optional_latency_info) { 757 const ui::LatencyInfo* optional_latency_info) {
758 DCHECK(!dispatching_touch_ack_);
759 DCHECK(!touch_queue_.empty());
760 std::unique_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front());
735 DCHECK(acked_event); 761 DCHECK(acked_event);
736 DCHECK(!dispatching_touch_ack_); 762
737 UpdateTouchConsumerStates(acked_event->coalesced_event().event, ack_result); 763 UpdateTouchConsumerStates(acked_event->coalesced_event().event, ack_result);
738 764
739 // Note that acking the touch-event may result in multiple gestures being sent 765 // Note that acking the touch-event may result in multiple gestures being sent
740 // to the renderer, or touch-events being queued. 766 // to the renderer, or touch-events being queued.
741 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true); 767 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true);
742 acked_event->DispatchAckToClient(ack_result, optional_latency_info, client_);
743 }
744 768
745 std::unique_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { 769 // Skip ack for TouchScrollStarted since it was synthesized within the queue.
746 DCHECK(!touch_queue_.empty()); 770 if (acked_event->coalesced_event().event.type !=
747 std::unique_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); 771 WebInputEvent::TouchScrollStarted) {
772 acked_event->DispatchAckToClient(ack_result, optional_latency_info,
773 client_);
774 }
775
748 touch_queue_.pop_front(); 776 touch_queue_.pop_front();
749 return event;
750 } 777 }
751 778
752 void TouchEventQueue::SendTouchEventImmediately( 779 void TouchEventQueue::SendTouchEventImmediately(
753 TouchEventWithLatencyInfo* touch) { 780 TouchEventWithLatencyInfo* touch) {
781 // TODO(crbug.com/600773): Hack to avoid cyclic reentry to this method.
782 if (dispatching_touch_)
783 return;
784
754 // For touchmove events, compare touch points position from current event 785 // For touchmove events, compare touch points position from current event
755 // to last sent event and update touch points state. 786 // to last sent event and update touch points state.
756 if (touch->event.type == WebInputEvent::TouchMove) { 787 if (touch->event.type == WebInputEvent::TouchMove) {
757 CHECK(last_sent_touchevent_); 788 CHECK(last_sent_touchevent_);
758 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) { 789 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) {
759 const WebTouchPoint& last_touch_point = 790 const WebTouchPoint& last_touch_point =
760 last_sent_touchevent_->touches[i]; 791 last_sent_touchevent_->touches[i];
761 // Touches with same id may not have same index in Touches array. 792 // Touches with same id may not have same index in Touches array.
762 for (unsigned int j = 0; j < touch->event.touchesLength; ++j) { 793 for (unsigned int j = 0; j < touch->event.touchesLength; ++j) {
763 const WebTouchPoint& current_touchmove_point = touch->event.touches[j]; 794 const WebTouchPoint& current_touchmove_point = touch->event.touches[j];
764 if (current_touchmove_point.id != last_touch_point.id) 795 if (current_touchmove_point.id != last_touch_point.id)
765 continue; 796 continue;
766 797
767 if (!HasPointChanged(last_touch_point, current_touchmove_point)) 798 if (!HasPointChanged(last_touch_point, current_touchmove_point))
768 touch->event.touches[j].state = WebTouchPoint::StateStationary; 799 touch->event.touches[j].state = WebTouchPoint::StateStationary;
769 800
770 break; 801 break;
771 } 802 }
772 } 803 }
773 } 804 }
774 805
775 if (last_sent_touchevent_) 806 if (touch->event.type != WebInputEvent::TouchScrollStarted) {
776 *last_sent_touchevent_ = touch->event; 807 if (last_sent_touchevent_)
777 else 808 *last_sent_touchevent_ = touch->event;
778 last_sent_touchevent_.reset(new WebTouchEvent(touch->event)); 809 else
810 last_sent_touchevent_.reset(new WebTouchEvent(touch->event));
811 }
779 812
780 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true); 813 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true);
781 814
782 client_->SendTouchEventImmediately(*touch); 815 client_->SendTouchEventImmediately(*touch);
783 816
784 // A synchronous ack will reset |dispatching_touch_|, in which case the touch 817 // A synchronous ack will reset |dispatching_touch_|, in which case the touch
785 // timeout should not be started and the count also should not be increased. 818 // timeout should not be started and the count also should not be increased.
786 if (dispatching_touch_) { 819 if (dispatching_touch_) {
787 if (touch->event.type == WebInputEvent::TouchMove && 820 if (touch->event.type == WebInputEvent::TouchMove &&
788 !touch->event.cancelable) { 821 !touch->event.cancelable) {
789 // When we send out a uncancelable touch move, we increase the count and 822 // When we send out a uncancelable touch move, we increase the count and
790 // we do not process input event ack any more, we will just ack to client 823 // we do not process input event ack any more, we will just ack to client
791 // and wait for the ack from render. Also we will remove it from the front 824 // and wait for the ack from render. Also we will remove it from the front
792 // of the queue. 825 // of the queue.
793 ack_pending_async_touchmove_ids_.push_back( 826 ack_pending_async_touchmove_ids_.push_back(
794 touch->event.uniqueTouchEventId); 827 touch->event.uniqueTouchEventId);
795 dispatching_touch_ = false; 828 dispatching_touch_ = false;
796 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED); 829 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED);
797 TryForwardNextEventToRenderer(); 830 TryForwardNextEventToRenderer();
798 return; 831 return;
799 } 832 }
800 833
801 if (timeout_handler_) 834 if (timeout_handler_)
802 timeout_handler_->StartIfNecessary(*touch); 835 timeout_handler_->StartIfNecessary(*touch);
803 } 836 }
804 } 837 }
805 838
806 TouchEventQueue::PreFilterResult 839 TouchEventQueue::PreFilterResult
807 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { 840 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) {
841 if (event.type == WebInputEvent::TouchScrollStarted)
842 return FORWARD_TO_RENDERER;
843
808 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { 844 if (WebTouchEventTraits::IsTouchSequenceStart(event)) {
809 has_handler_for_current_sequence_ = false; 845 has_handler_for_current_sequence_ = false;
810 send_touch_events_async_ = false; 846 send_touch_events_async_ = false;
811 pending_async_touchmove_.reset(); 847 pending_async_touchmove_.reset();
812 last_sent_touchevent_.reset(); 848 last_sent_touchevent_.reset();
813 849
814 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position); 850 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position);
815 drop_remaining_touches_in_sequence_ = false; 851 drop_remaining_touches_in_sequence_ = false;
816 if (!has_handlers_) { 852 if (!has_handlers_) {
817 drop_remaining_touches_in_sequence_ = true; 853 drop_remaining_touches_in_sequence_ = true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) 916 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED)
881 send_touch_events_async_ = false; 917 send_touch_events_async_ = false;
882 has_handler_for_current_sequence_ |= 918 has_handler_for_current_sequence_ |=
883 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 919 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
884 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { 920 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) {
885 has_handler_for_current_sequence_ = false; 921 has_handler_for_current_sequence_ = false;
886 } 922 }
887 } 923 }
888 924
889 } // namespace content 925 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698