| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/passthrough_touch_event_queue.h" | 5 #include "content/browser/renderer_host/input/passthrough_touch_event_queue.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 void TearDown() override { queue_.reset(); } | 58 void TearDown() override { queue_.reset(); } |
| 59 | 59 |
| 60 // TouchEventQueueClient | 60 // TouchEventQueueClient |
| 61 void SendTouchEventImmediately( | 61 void SendTouchEventImmediately( |
| 62 const TouchEventWithLatencyInfo& event) override { | 62 const TouchEventWithLatencyInfo& event) override { |
| 63 sent_events_.push_back(event.event); | 63 sent_events_.push_back(event.event); |
| 64 sent_events_ids_.push_back(event.event.unique_touch_event_id); | 64 sent_events_ids_.push_back(event.event.unique_touch_event_id); |
| 65 if (sync_ack_result_) { | 65 if (sync_ack_result_) { |
| 66 auto sync_ack_result = std::move(sync_ack_result_); | 66 auto sync_ack_result = std::move(sync_ack_result_); |
| 67 SendTouchEventAck(*sync_ack_result); | 67 SendTouchEventAckWithID(*sync_ack_result, |
| 68 event.event.unique_touch_event_id); |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 | 71 |
| 71 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, | 72 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, |
| 72 InputEventAckState ack_result) override { | 73 InputEventAckState ack_result) override { |
| 73 ++acked_event_count_; | 74 ++acked_event_count_; |
| 74 last_acked_event_ = event.event; | |
| 75 last_acked_event_state_ = ack_result; | |
| 76 if (followup_touch_event_) { | 75 if (followup_touch_event_) { |
| 77 std::unique_ptr<WebTouchEvent> followup_touch_event = | 76 std::unique_ptr<WebTouchEvent> followup_touch_event = |
| 78 std::move(followup_touch_event_); | 77 std::move(followup_touch_event_); |
| 79 SendTouchEvent(*followup_touch_event); | 78 SendTouchEvent(*followup_touch_event); |
| 80 } | 79 } |
| 81 if (followup_gesture_event_) { | 80 if (followup_gesture_event_) { |
| 82 std::unique_ptr<WebGestureEvent> followup_gesture_event = | 81 std::unique_ptr<WebGestureEvent> followup_gesture_event = |
| 83 std::move(followup_gesture_event_); | 82 std::move(followup_gesture_event_); |
| 84 queue_->OnGestureScrollEvent(GestureEventWithLatencyInfo( | 83 queue_->OnGestureScrollEvent(GestureEventWithLatencyInfo( |
| 85 *followup_gesture_event, ui::LatencyInfo())); | 84 *followup_gesture_event, ui::LatencyInfo())); |
| 86 } | 85 } |
| 86 last_acked_event_ = event.event; |
| 87 last_acked_event_state_ = ack_result; |
| 87 } | 88 } |
| 88 | 89 |
| 89 void OnFilteringTouchEvent(const blink::WebTouchEvent& touch_event) override { | 90 void OnFilteringTouchEvent(const blink::WebTouchEvent& touch_event) override { |
| 90 } | 91 } |
| 91 | 92 |
| 92 protected: | 93 protected: |
| 93 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { | 94 void SetUpForTouchMoveSlopTesting(double slop_length_dips) { |
| 94 slop_length_dips_ = slop_length_dips; | 95 slop_length_dips_ = slop_length_dips; |
| 95 } | 96 } |
| 96 | 97 |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 750 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 750 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 751 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 751 | 752 |
| 752 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | 753 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 753 CancelTouchPoint(0); | 754 CancelTouchPoint(0); |
| 754 EXPECT_EQ(0U, queued_event_count()); | 755 EXPECT_EQ(0U, queued_event_count()); |
| 755 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 756 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 756 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 757 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 757 } | 758 } |
| 758 | 759 |
| 760 // Tests that touch-events acks are in order even with synchronous acks. |
| 761 TEST_F(PassthroughTouchEventQueueTest, SynchronousAcksInOrder) { |
| 762 // TouchStart |
| 763 PressTouchPoint(1, 1); |
| 764 EXPECT_EQ(1U, queued_event_count()); |
| 765 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 766 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 767 |
| 768 // TouchMove |
| 769 MoveTouchPoint(0, 2, 3); |
| 770 EXPECT_EQ(2U, queued_event_count()); |
| 771 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 772 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 773 |
| 774 // Ack the TouchMove |
| 775 SendTouchEventAckLast(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 776 EXPECT_EQ(2U, queued_event_count()); |
| 777 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 778 EXPECT_EQ(0U, GetAndResetAckedEventCount()); |
| 779 |
| 780 // Create a touch event that will be queued synchronously by a touch ack. |
| 781 WebTouchEvent followup_event( |
| 782 WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers, |
| 783 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 784 followup_event.touches_length = 1; |
| 785 followup_event.touches[0].id = 0; |
| 786 followup_event.unique_touch_event_id = 100; |
| 787 followup_event.touches[0].state = WebTouchPoint::kStateMoved; |
| 788 SetFollowupEvent(followup_event); |
| 789 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 790 |
| 791 // Ack the touch start, should release the |follow_up| event (and its ack). |
| 792 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 793 |
| 794 EXPECT_EQ(0U, queued_event_count()); |
| 795 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 796 EXPECT_EQ(3U, GetAndResetAckedEventCount()); |
| 797 EXPECT_EQ(100U, acked_event().unique_touch_event_id); |
| 798 } |
| 799 |
| 759 // Tests that followup events triggered by an immediate ack from | 800 // Tests that followup events triggered by an immediate ack from |
| 760 // TouchEventQueue::QueueEvent() are properly handled. | 801 // TouchEventQueue::QueueEvent() are properly handled. |
| 761 TEST_F(PassthroughTouchEventQueueTest, ImmediateAckWithFollowupEvents) { | 802 TEST_F(PassthroughTouchEventQueueTest, ImmediateAckWithFollowupEvents) { |
| 762 // Create a touch event that will be queued synchronously by a touch ack. | 803 // Create a touch event that will be queued synchronously by a touch ack. |
| 763 WebTouchEvent followup_event( | 804 WebTouchEvent followup_event( |
| 764 WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers, | 805 WebInputEvent::kTouchStart, WebInputEvent::kNoModifiers, |
| 765 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); | 806 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 766 followup_event.touches_length = 1; | 807 followup_event.touches_length = 1; |
| 767 followup_event.touches[0].id = 1; | 808 followup_event.touches[0].id = 1; |
| 768 followup_event.touches[0].state = WebTouchPoint::kStatePressed; | 809 followup_event.touches[0].state = WebTouchPoint::kStatePressed; |
| 769 SetFollowupEvent(followup_event); | 810 SetFollowupEvent(followup_event); |
| 770 | 811 |
| 771 // Now, enqueue a stationary touch that will not be forwarded. This should be | 812 // Now, enqueue a stationary touch that will not be forwarded. This should be |
| 772 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should | 813 // immediately ack'ed with "NO_CONSUMER_EXISTS". The followup event should |
| 773 // then be enqueued and immediately sent to the renderer. | 814 // then be enqueued and immediately sent to the renderer. |
| 774 WebTouchEvent stationary_event( | 815 WebTouchEvent stationary_event( |
| 775 WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers, | 816 WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers, |
| 776 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); | 817 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); |
| 777 ; | |
| 778 stationary_event.touches_length = 1; | 818 stationary_event.touches_length = 1; |
| 779 stationary_event.touches[0].id = 1; | 819 stationary_event.touches[0].id = 1; |
| 780 stationary_event.touches[0].state = WebTouchPoint::kStateStationary; | 820 stationary_event.touches[0].state = WebTouchPoint::kStateStationary; |
| 781 SendTouchEvent(stationary_event); | 821 SendTouchEvent(stationary_event); |
| 782 | 822 |
| 783 EXPECT_EQ(1U, queued_event_count()); | 823 EXPECT_EQ(1U, queued_event_count()); |
| 784 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 824 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 785 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 825 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 786 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 826 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 787 EXPECT_EQ(WebInputEvent::kTouchMove, acked_event().GetType()); | 827 EXPECT_EQ(WebInputEvent::kTouchMove, acked_event().GetType()); |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 EXPECT_EQ(WebInputEvent::kTouchMove, sent_event().GetType()); | 1765 EXPECT_EQ(WebInputEvent::kTouchMove, sent_event().GetType()); |
| 1726 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); | 1766 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); |
| 1727 | 1767 |
| 1728 ReleaseTouchPoint(0); | 1768 ReleaseTouchPoint(0); |
| 1729 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1769 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1730 EXPECT_EQ(WebInputEvent::kTouchEnd, sent_event().GetType()); | 1770 EXPECT_EQ(WebInputEvent::kTouchEnd, sent_event().GetType()); |
| 1731 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); | 1771 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); |
| 1732 } | 1772 } |
| 1733 | 1773 |
| 1734 } // namespace content | 1774 } // namespace content |
| OLD | NEW |