Chromium Code Reviews| 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 MoveTouchPoint(0, 2, 3); | |
| 769 EXPECT_EQ(2U, queued_event_count()); | |
| 770 EXPECT_EQ(1U, GetAndResetSentEventCount()); | |
| 771 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 772 | |
| 773 SendTouchEventAckLast(INPUT_EVENT_ACK_STATE_CONSUMED); | |
|
tdresser
2017/04/18 18:57:02
Can you comment that this will ack the touchmove,
dtapuska
2017/04/18 19:56:52
Done.
| |
| 774 EXPECT_EQ(2U, queued_event_count()); | |
| 775 EXPECT_EQ(0U, GetAndResetSentEventCount()); | |
| 776 EXPECT_EQ(0U, GetAndResetAckedEventCount()); | |
| 777 | |
| 778 // TouchMove | |
| 779 // Ack the touch start, should release two events. | |
| 780 // Create a touch event that will be queued synchronously by a touch ack. | |
| 781 // Note, this will be triggered by all subsequent touch acks. | |
|
tdresser
2017/04/18 18:57:02
I don't quite understand "this will be triggered b
dtapuska
2017/04/18 19:56:52
Done.
| |
| 782 WebTouchEvent followup_event( | |
| 783 WebInputEvent::kTouchMove, WebInputEvent::kNoModifiers, | |
| 784 ui::EventTimeStampToSeconds(ui::EventTimeForNow())); | |
| 785 followup_event.touches_length = 1; | |
| 786 followup_event.touches[0].id = 0; | |
| 787 followup_event.unique_touch_event_id = 100; | |
| 788 followup_event.touches[0].state = WebTouchPoint::kStateMoved; | |
| 789 SetFollowupEvent(followup_event); | |
| 790 | |
| 791 SetSyncAckResult(INPUT_EVENT_ACK_STATE_CONSUMED); | |
| 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 ; | 818 ; |
|
tdresser
2017/04/18 18:57:03
While you're here, can you remove this extra ; ?
dtapuska
2017/04/18 19:56:52
Done.
| |
| 778 stationary_event.touches_length = 1; | 819 stationary_event.touches_length = 1; |
| 779 stationary_event.touches[0].id = 1; | 820 stationary_event.touches[0].id = 1; |
| 780 stationary_event.touches[0].state = WebTouchPoint::kStateStationary; | 821 stationary_event.touches[0].state = WebTouchPoint::kStateStationary; |
| 781 SendTouchEvent(stationary_event); | 822 SendTouchEvent(stationary_event); |
| 782 | 823 |
| 783 EXPECT_EQ(1U, queued_event_count()); | 824 EXPECT_EQ(1U, queued_event_count()); |
| 784 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 825 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 785 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 826 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 786 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); | 827 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 787 EXPECT_EQ(WebInputEvent::kTouchMove, acked_event().GetType()); | 828 EXPECT_EQ(WebInputEvent::kTouchMove, acked_event().GetType()); |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1719 EXPECT_EQ(WebInputEvent::kTouchMove, sent_event().GetType()); | 1760 EXPECT_EQ(WebInputEvent::kTouchMove, sent_event().GetType()); |
| 1720 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); | 1761 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); |
| 1721 | 1762 |
| 1722 ReleaseTouchPoint(0); | 1763 ReleaseTouchPoint(0); |
| 1723 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 1764 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1724 EXPECT_EQ(WebInputEvent::kTouchEnd, sent_event().GetType()); | 1765 EXPECT_EQ(WebInputEvent::kTouchEnd, sent_event().GetType()); |
| 1725 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); | 1766 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); |
| 1726 } | 1767 } |
| 1727 | 1768 |
| 1728 } // namespace content | 1769 } // namespace content |
| OLD | NEW |