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

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: Ignored ack mismatch. 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.
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
512
494 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result, 513 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result,
495 const LatencyInfo& latency_info, 514 const LatencyInfo& latency_info,
496 const uint32_t unique_touch_event_id) { 515 const uint32_t unique_touch_event_id) {
497 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck"); 516 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck");
498 517
499 // We receive an ack for async touchmove from render. 518 // We receive an ack for async touchmove from render.
500 if (!ack_pending_async_touchmove_ids_.empty() && 519 if (!ack_pending_async_touchmove_ids_.empty() &&
501 ack_pending_async_touchmove_ids_.front() == unique_touch_event_id) { 520 ack_pending_async_touchmove_ids_.front() == unique_touch_event_id) {
502 // Remove the first touchmove from the ack_pending_async_touchmove queue. 521 // Remove the first touchmove from the ack_pending_async_touchmove queue.
503 ack_pending_async_touchmove_ids_.pop_front(); 522 ack_pending_async_touchmove_ids_.pop_front();
(...skipping 14 matching lines...) Expand all
518 dispatching_touch_ = false; 537 dispatching_touch_ = false;
519 538
520 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result)) 539 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result))
521 return; 540 return;
522 541
523 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result); 542 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result);
524 543
525 if (touch_queue_.empty()) 544 if (touch_queue_.empty())
526 return; 545 return;
527 546
528 DCHECK_EQ(touch_queue_.front()->coalesced_event().event.uniqueTouchEventId, 547 // We don't care about the ordering of the acks vs the ordering of the
529 unique_touch_event_id); 548 // dispatched events because we can receive the ack for event B before the ack
549 // for event A even though A was sent before B. This can happen, for example,
550 // when A is acked from renderer but B isn't, so the ack for B is synthesized
551 // "locally" in InputRouter.
tdresser 2016/04/11 14:43:37 This should never happen. Does this still happen n
mustaq 2016/04/11 16:03:12 Yes, this can happen even when we avoid reentry to
530 552
531 PopTouchEventToClient(ack_result, latency_info); 553 PopTouchEventToClient(ack_result, latency_info);
532 TryForwardNextEventToRenderer(); 554 TryForwardNextEventToRenderer();
533 } 555 }
534 556
535 void TouchEventQueue::TryForwardNextEventToRenderer() { 557 void TouchEventQueue::TryForwardNextEventToRenderer() {
536 DCHECK(!dispatching_touch_ack_); 558 DCHECK(!dispatching_touch_ack_);
537 // If there are queued touch events, then try to forward them to the renderer 559 // 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. 560 // immediately, or ACK the events back to the client if appropriate.
539 while (!touch_queue_.empty()) { 561 while (!touch_queue_.empty()) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 void TouchEventQueue::FlushQueue() { 734 void TouchEventQueue::FlushQueue() {
713 DCHECK(!dispatching_touch_ack_); 735 DCHECK(!dispatching_touch_ack_);
714 DCHECK(!dispatching_touch_); 736 DCHECK(!dispatching_touch_);
715 pending_async_touchmove_.reset(); 737 pending_async_touchmove_.reset();
716 drop_remaining_touches_in_sequence_ = true; 738 drop_remaining_touches_in_sequence_ = true;
717 while (!touch_queue_.empty()) 739 while (!touch_queue_.empty())
718 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 740 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
719 } 741 }
720 742
721 void TouchEventQueue::PopTouchEventToClient(InputEventAckState ack_result) { 743 void TouchEventQueue::PopTouchEventToClient(InputEventAckState ack_result) {
722 AckTouchEventToClient(ack_result, PopTouchEvent(), nullptr); 744 AckTouchEventToClient(ack_result, nullptr);
723 } 745 }
724 746
725 void TouchEventQueue::PopTouchEventToClient( 747 void TouchEventQueue::PopTouchEventToClient(
726 InputEventAckState ack_result, 748 InputEventAckState ack_result,
727 const LatencyInfo& renderer_latency_info) { 749 const LatencyInfo& renderer_latency_info) {
728 AckTouchEventToClient(ack_result, PopTouchEvent(), &renderer_latency_info); 750 AckTouchEventToClient(ack_result, &renderer_latency_info);
729 } 751 }
730 752
731 void TouchEventQueue::AckTouchEventToClient( 753 void TouchEventQueue::AckTouchEventToClient(
732 InputEventAckState ack_result, 754 InputEventAckState ack_result,
733 scoped_ptr<CoalescedWebTouchEvent> acked_event,
734 const ui::LatencyInfo* optional_latency_info) { 755 const ui::LatencyInfo* optional_latency_info) {
756 DCHECK(!dispatching_touch_ack_);
757 DCHECK(!touch_queue_.empty());
758 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front());
735 DCHECK(acked_event); 759 DCHECK(acked_event);
736 DCHECK(!dispatching_touch_ack_); 760
737 UpdateTouchConsumerStates(acked_event->coalesced_event().event, ack_result); 761 UpdateTouchConsumerStates(acked_event->coalesced_event().event, ack_result);
738 762
739 // Note that acking the touch-event may result in multiple gestures being sent 763 // Note that acking the touch-event may result in multiple gestures being sent
740 // to the renderer, or touch-events being queued. 764 // to the renderer, or touch-events being queued.
741 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true); 765 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true);
742 acked_event->DispatchAckToClient(ack_result, optional_latency_info, client_);
743 }
744 766
745 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { 767 // Skip ack for TouchScrollStarted since it was synthesized within the queue.
746 DCHECK(!touch_queue_.empty()); 768 if (acked_event->coalesced_event().event.type !=
747 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); 769 WebInputEvent::TouchScrollStarted) {
770 acked_event->DispatchAckToClient(ack_result, optional_latency_info,
771 client_);
772 }
773
748 touch_queue_.pop_front(); 774 touch_queue_.pop_front();
749 return event;
750 } 775 }
751 776
752 void TouchEventQueue::SendTouchEventImmediately( 777 void TouchEventQueue::SendTouchEventImmediately(
753 TouchEventWithLatencyInfo* touch) { 778 TouchEventWithLatencyInfo* touch) {
779 // crbug.com(600773): Hack to avoid cyclic reentry to this method.
tdresser 2016/04/11 14:43:37 Let's format the bug as a url.
mustaq 2016/04/11 16:03:12 Done.
780 if (dispatching_touch_)
781 return;
782
754 // For touchmove events, compare touch points position from current event 783 // For touchmove events, compare touch points position from current event
755 // to last sent event and update touch points state. 784 // to last sent event and update touch points state.
756 if (touch->event.type == WebInputEvent::TouchMove) { 785 if (touch->event.type == WebInputEvent::TouchMove) {
757 CHECK(last_sent_touchevent_); 786 CHECK(last_sent_touchevent_);
758 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) { 787 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) {
759 const WebTouchPoint& last_touch_point = 788 const WebTouchPoint& last_touch_point =
760 last_sent_touchevent_->touches[i]; 789 last_sent_touchevent_->touches[i];
761 // Touches with same id may not have same index in Touches array. 790 // Touches with same id may not have same index in Touches array.
762 for (unsigned int j = 0; j < touch->event.touchesLength; ++j) { 791 for (unsigned int j = 0; j < touch->event.touchesLength; ++j) {
763 const WebTouchPoint& current_touchmove_point = touch->event.touches[j]; 792 const WebTouchPoint& current_touchmove_point = touch->event.touches[j];
764 if (current_touchmove_point.id != last_touch_point.id) 793 if (current_touchmove_point.id != last_touch_point.id)
765 continue; 794 continue;
766 795
767 if (!HasPointChanged(last_touch_point, current_touchmove_point)) 796 if (!HasPointChanged(last_touch_point, current_touchmove_point))
768 touch->event.touches[j].state = WebTouchPoint::StateStationary; 797 touch->event.touches[j].state = WebTouchPoint::StateStationary;
769 798
770 break; 799 break;
771 } 800 }
772 } 801 }
773 } 802 }
774 803
775 if (last_sent_touchevent_) 804 if (touch->event.type != WebInputEvent::TouchScrollStarted) {
776 *last_sent_touchevent_ = touch->event; 805 if (last_sent_touchevent_)
777 else 806 *last_sent_touchevent_ = touch->event;
778 last_sent_touchevent_.reset(new WebTouchEvent(touch->event)); 807 else
808 last_sent_touchevent_.reset(new WebTouchEvent(touch->event));
809 }
779 810
780 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true); 811 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true);
781 812
782 client_->SendTouchEventImmediately(*touch); 813 client_->SendTouchEventImmediately(*touch);
783 814
784 // A synchronous ack will reset |dispatching_touch_|, in which case the touch 815 // 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. 816 // timeout should not be started and the count also should not be increased.
786 if (dispatching_touch_) { 817 if (dispatching_touch_) {
787 if (touch->event.type == WebInputEvent::TouchMove && 818 if (touch->event.type == WebInputEvent::TouchMove &&
788 !touch->event.cancelable) { 819 !touch->event.cancelable) {
789 // When we send out a uncancelable touch move, we increase the count and 820 // 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 821 // 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 822 // and wait for the ack from render. Also we will remove it from the front
792 // of the queue. 823 // of the queue.
793 ack_pending_async_touchmove_ids_.push_back( 824 ack_pending_async_touchmove_ids_.push_back(
794 touch->event.uniqueTouchEventId); 825 touch->event.uniqueTouchEventId);
795 dispatching_touch_ = false; 826 dispatching_touch_ = false;
796 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED); 827 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED);
797 TryForwardNextEventToRenderer(); 828 TryForwardNextEventToRenderer();
798 return; 829 return;
799 } 830 }
800 831
801 if (timeout_handler_) 832 if (timeout_handler_)
802 timeout_handler_->StartIfNecessary(*touch); 833 timeout_handler_->StartIfNecessary(*touch);
803 } 834 }
804 } 835 }
805 836
806 TouchEventQueue::PreFilterResult 837 TouchEventQueue::PreFilterResult
807 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { 838 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) {
839 if (event.type == WebInputEvent::TouchScrollStarted)
840 return FORWARD_TO_RENDERER;
841
808 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { 842 if (WebTouchEventTraits::IsTouchSequenceStart(event)) {
809 has_handler_for_current_sequence_ = false; 843 has_handler_for_current_sequence_ = false;
810 send_touch_events_async_ = false; 844 send_touch_events_async_ = false;
811 pending_async_touchmove_.reset(); 845 pending_async_touchmove_.reset();
812 last_sent_touchevent_.reset(); 846 last_sent_touchevent_.reset();
813 847
814 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position); 848 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position);
815 drop_remaining_touches_in_sequence_ = false; 849 drop_remaining_touches_in_sequence_ = false;
816 if (!has_handlers_) { 850 if (!has_handlers_) {
817 drop_remaining_touches_in_sequence_ = true; 851 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) 914 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED)
881 send_touch_events_async_ = false; 915 send_touch_events_async_ = false;
882 has_handler_for_current_sequence_ |= 916 has_handler_for_current_sequence_ |=
883 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 917 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
884 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { 918 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) {
885 has_handler_for_current_sequence_ = false; 919 has_handler_for_current_sequence_ = false;
886 } 920 }
887 } 921 }
888 922
889 } // namespace content 923 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698