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

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: Fixed touch_event_stream_validator 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;
tdresser 2016/04/01 14:50:24 The WebTouchEventConstructor zeroes these fields,
mustaq 2016/04/01 18:31:04 Removed the length. But left the id as-is to empha
500
501 // Leave the head of the queue untouched since it is an in-flight event.
502 auto it = touch_queue_.begin();
503 if (it != touch_queue_.end())
504 ++it;
505 touch_queue_.insert(it, new CoalescedWebTouchEvent(touch, false));
506 }
507
508
494 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result, 509 void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result,
495 const LatencyInfo& latency_info, 510 const LatencyInfo& latency_info,
496 const uint32_t unique_touch_event_id) { 511 const uint32_t unique_touch_event_id) {
497 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck"); 512 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck");
498 513
499 // We receive an ack for async touchmove from render. 514 // We receive an ack for async touchmove from render.
500 if (!ack_pending_async_touchmove_ids_.empty() && 515 if (!ack_pending_async_touchmove_ids_.empty() &&
501 ack_pending_async_touchmove_ids_.front() == unique_touch_event_id) { 516 ack_pending_async_touchmove_ids_.front() == unique_touch_event_id) {
502 // Remove the first touchmove from the ack_pending_async_touchmove queue. 517 // Remove the first touchmove from the ack_pending_async_touchmove queue.
503 ack_pending_async_touchmove_ids_.pop_front(); 518 ack_pending_async_touchmove_ids_.pop_front();
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 void TouchEventQueue::FlushQueue() { 727 void TouchEventQueue::FlushQueue() {
713 DCHECK(!dispatching_touch_ack_); 728 DCHECK(!dispatching_touch_ack_);
714 DCHECK(!dispatching_touch_); 729 DCHECK(!dispatching_touch_);
715 pending_async_touchmove_.reset(); 730 pending_async_touchmove_.reset();
716 drop_remaining_touches_in_sequence_ = true; 731 drop_remaining_touches_in_sequence_ = true;
717 while (!touch_queue_.empty()) 732 while (!touch_queue_.empty())
718 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); 733 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
719 } 734 }
720 735
721 void TouchEventQueue::PopTouchEventToClient(InputEventAckState ack_result) { 736 void TouchEventQueue::PopTouchEventToClient(InputEventAckState ack_result) {
722 AckTouchEventToClient(ack_result, PopTouchEvent(), nullptr); 737 AckTouchEventToClient(ack_result, nullptr);
723 } 738 }
724 739
725 void TouchEventQueue::PopTouchEventToClient( 740 void TouchEventQueue::PopTouchEventToClient(
726 InputEventAckState ack_result, 741 InputEventAckState ack_result,
727 const LatencyInfo& renderer_latency_info) { 742 const LatencyInfo& renderer_latency_info) {
728 AckTouchEventToClient(ack_result, PopTouchEvent(), &renderer_latency_info); 743 AckTouchEventToClient(ack_result, &renderer_latency_info);
729 } 744 }
730 745
731 void TouchEventQueue::AckTouchEventToClient( 746 void TouchEventQueue::AckTouchEventToClient(
732 InputEventAckState ack_result, 747 InputEventAckState ack_result,
733 scoped_ptr<CoalescedWebTouchEvent> acked_event,
734 const ui::LatencyInfo* optional_latency_info) { 748 const ui::LatencyInfo* optional_latency_info) {
749 DCHECK(!dispatching_touch_ack_);
750 DCHECK(!touch_queue_.empty());
751 scoped_ptr<CoalescedWebTouchEvent> acked_event(touch_queue_.front());
735 DCHECK(acked_event); 752 DCHECK(acked_event);
736 DCHECK(!dispatching_touch_ack_); 753
737 UpdateTouchConsumerStates(acked_event->coalesced_event().event, ack_result); 754 UpdateTouchConsumerStates(acked_event->coalesced_event().event, ack_result);
738 755
739 // Note that acking the touch-event may result in multiple gestures being sent 756 // Note that acking the touch-event may result in multiple gestures being sent
740 // to the renderer, or touch-events being queued. 757 // to the renderer, or touch-events being queued.
741 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true); 758 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true);
742 acked_event->DispatchAckToClient(ack_result, optional_latency_info, client_);
743 }
744 759
745 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { 760 // Skip ack for TouchScrollStarted since it was synthesized within the queue.
746 DCHECK(!touch_queue_.empty()); 761 if (acked_event->coalesced_event().event.type !=
747 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); 762 WebInputEvent::TouchScrollStarted)
763 acked_event->DispatchAckToClient(ack_result, optional_latency_info,
764 client_);
765
748 touch_queue_.pop_front(); 766 touch_queue_.pop_front();
749 return event;
750 } 767 }
751 768
752 void TouchEventQueue::SendTouchEventImmediately( 769 void TouchEventQueue::SendTouchEventImmediately(
753 TouchEventWithLatencyInfo* touch) { 770 TouchEventWithLatencyInfo* touch) {
754 // For touchmove events, compare touch points position from current event 771 // For touchmove events, compare touch points position from current event
755 // to last sent event and update touch points state. 772 // to last sent event and update touch points state.
756 if (touch->event.type == WebInputEvent::TouchMove) { 773 if (touch->event.type == WebInputEvent::TouchMove) {
757 CHECK(last_sent_touchevent_); 774 CHECK(last_sent_touchevent_);
758 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) { 775 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) {
759 const WebTouchPoint& last_touch_point = 776 const WebTouchPoint& last_touch_point =
760 last_sent_touchevent_->touches[i]; 777 last_sent_touchevent_->touches[i];
761 // Touches with same id may not have same index in Touches array. 778 // Touches with same id may not have same index in Touches array.
762 for (unsigned int j = 0; j < touch->event.touchesLength; ++j) { 779 for (unsigned int j = 0; j < touch->event.touchesLength; ++j) {
763 const WebTouchPoint& current_touchmove_point = touch->event.touches[j]; 780 const WebTouchPoint& current_touchmove_point = touch->event.touches[j];
764 if (current_touchmove_point.id != last_touch_point.id) 781 if (current_touchmove_point.id != last_touch_point.id)
765 continue; 782 continue;
766 783
767 if (!HasPointChanged(last_touch_point, current_touchmove_point)) 784 if (!HasPointChanged(last_touch_point, current_touchmove_point))
768 touch->event.touches[j].state = WebTouchPoint::StateStationary; 785 touch->event.touches[j].state = WebTouchPoint::StateStationary;
769 786
770 break; 787 break;
771 } 788 }
772 } 789 }
773 } 790 }
774 791
775 if (last_sent_touchevent_) 792 if (touch->event.type != WebInputEvent::TouchScrollStarted) {
776 *last_sent_touchevent_ = touch->event; 793 if (last_sent_touchevent_)
777 else 794 *last_sent_touchevent_ = touch->event;
778 last_sent_touchevent_.reset(new WebTouchEvent(touch->event)); 795 else
796 last_sent_touchevent_.reset(new WebTouchEvent(touch->event));
797 }
779 798
780 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true); 799 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true);
781 800
782 client_->SendTouchEventImmediately(*touch); 801 client_->SendTouchEventImmediately(*touch);
783 802
784 // A synchronous ack will reset |dispatching_touch_|, in which case the touch 803 // 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. 804 // timeout should not be started and the count also should not be increased.
786 if (dispatching_touch_) { 805 if (dispatching_touch_) {
787 if (touch->event.type == WebInputEvent::TouchMove && 806 if (touch->event.type == WebInputEvent::TouchMove &&
788 !touch->event.cancelable) { 807 !touch->event.cancelable) {
789 // When we send out a uncancelable touch move, we increase the count and 808 // 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 809 // 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 810 // and wait for the ack from render. Also we will remove it from the front
792 // of the queue. 811 // of the queue.
793 ack_pending_async_touchmove_ids_.push_back( 812 ack_pending_async_touchmove_ids_.push_back(
794 touch->event.uniqueTouchEventId); 813 touch->event.uniqueTouchEventId);
795 dispatching_touch_ = false; 814 dispatching_touch_ = false;
796 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED); 815 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED);
797 TryForwardNextEventToRenderer(); 816 TryForwardNextEventToRenderer();
798 return; 817 return;
799 } 818 }
800 819
801 if (timeout_handler_) 820 if (timeout_handler_)
802 timeout_handler_->StartIfNecessary(*touch); 821 timeout_handler_->StartIfNecessary(*touch);
803 } 822 }
804 } 823 }
805 824
806 TouchEventQueue::PreFilterResult 825 TouchEventQueue::PreFilterResult
807 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { 826 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) {
827 if (event.type == WebInputEvent::TouchScrollStarted)
828 return FORWARD_TO_RENDERER;
829
808 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { 830 if (WebTouchEventTraits::IsTouchSequenceStart(event)) {
809 has_handler_for_current_sequence_ = false; 831 has_handler_for_current_sequence_ = false;
810 send_touch_events_async_ = false; 832 send_touch_events_async_ = false;
811 pending_async_touchmove_.reset(); 833 pending_async_touchmove_.reset();
812 last_sent_touchevent_.reset(); 834 last_sent_touchevent_.reset();
813 835
814 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position); 836 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position);
815 drop_remaining_touches_in_sequence_ = false; 837 drop_remaining_touches_in_sequence_ = false;
816 if (!has_handlers_) { 838 if (!has_handlers_) {
817 drop_remaining_touches_in_sequence_ = true; 839 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) 902 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED)
881 send_touch_events_async_ = false; 903 send_touch_events_async_ = false;
882 has_handler_for_current_sequence_ |= 904 has_handler_for_current_sequence_ |=
883 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 905 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
884 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { 906 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) {
885 has_handler_for_current_sequence_ = false; 907 has_handler_for_current_sequence_ = false;
886 } 908 }
887 } 909 }
888 910
889 } // namespace content 911 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698