OLD | NEW |
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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <deque> | 11 #include <deque> |
12 #include <list> | 12 #include <list> |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "content/browser/renderer_host/event_with_latency_info.h" | 17 #include "content/browser/renderer_host/event_with_latency_info.h" |
18 #include "content/browser/renderer_host/input/touch_event_queue.h" | 18 #include "content/browser/renderer_host/input/touch_event_queue.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "content/common/input/input_event_ack_state.h" | 20 #include "content/common/input/input_event_ack_state.h" |
21 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 21 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
22 #include "ui/gfx/geometry/point_f.h" | 22 #include "ui/gfx/geometry/point_f.h" |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 class CoalescedWebTouchEvent; | 26 class CoalescedWebTouchEvent; |
| 27 class TouchTimeoutHandler; |
27 | 28 |
28 // A queue for throttling and coalescing touch-events. | 29 // A queue for throttling and coalescing touch-events. |
29 class CONTENT_EXPORT LegacyTouchEventQueue : public TouchEventQueue { | 30 class CONTENT_EXPORT LegacyTouchEventQueue : public TouchEventQueue { |
30 public: | 31 public: |
31 // The |client| must outlive the LegacyTouchEventQueue. | 32 // The |client| must outlive the LegacyTouchEventQueue. |
32 LegacyTouchEventQueue(TouchEventQueueClient* client, const Config& config); | 33 LegacyTouchEventQueue(TouchEventQueueClient* client, const Config& config); |
33 | 34 |
34 ~LegacyTouchEventQueue() override; | 35 ~LegacyTouchEventQueue() override; |
35 | 36 |
36 // Adds an event to the queue. The event may be coalesced with previously | 37 // Adds an event to the queue. The event may be coalesced with previously |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 89 |
89 size_t size() const { return touch_queue_.size(); } | 90 size_t size() const { return touch_queue_.size(); } |
90 | 91 |
91 bool has_handlers() const { return has_handlers_; } | 92 bool has_handlers() const { return has_handlers_; } |
92 | 93 |
93 size_t uncancelable_touch_moves_pending_ack_count() const { | 94 size_t uncancelable_touch_moves_pending_ack_count() const { |
94 return ack_pending_async_touchmove_ids_.size(); | 95 return ack_pending_async_touchmove_ids_.size(); |
95 } | 96 } |
96 | 97 |
97 private: | 98 private: |
98 class TouchTimeoutHandler; | |
99 friend class TouchTimeoutHandler; | |
100 friend class TouchEventQueueTest; | 99 friend class TouchEventQueueTest; |
101 | 100 |
102 bool HasPendingAsyncTouchMoveForTesting() const; | 101 bool HasPendingAsyncTouchMoveForTesting() const; |
103 bool IsTimeoutRunningForTesting() const; | 102 bool IsTimeoutRunningForTesting() const; |
104 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; | 103 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; |
105 | 104 |
106 // Empties the queue of touch events. This may result in any number of gesture | 105 // Empties the queue of touch events. This may result in any number of gesture |
107 // events being sent to the renderer. | 106 // events being sent to the renderer. |
108 void FlushQueue(); | 107 void FlushQueue() override; |
109 | 108 |
110 // Walks the queue, checking each event with |FilterBeforeForwarding()|. | 109 // Walks the queue, checking each event with |FilterBeforeForwarding()|. |
111 // If allowed, forwards the touch event and stops processing further events. | 110 // If allowed, forwards the touch event and stops processing further events. |
112 // Otherwise, acks the event with |INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS|. | 111 // Otherwise, acks the event with |INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS|. |
113 void TryForwardNextEventToRenderer(); | 112 void TryForwardNextEventToRenderer(); |
114 | 113 |
115 // Forwards the event at the head of the queue to the renderer. | 114 // Forwards the event at the head of the queue to the renderer. |
116 void ForwardNextEventToRenderer(); | 115 void ForwardNextEventToRenderer(); |
117 | 116 |
118 // Pops the touch-event from the head of the queue and acks it to the client. | 117 // Pops the touch-event from the head of the queue and acks it to the client. |
119 void PopTouchEventToClient(InputEventAckState ack_result); | 118 void PopTouchEventToClient(InputEventAckState ack_result); |
120 | 119 |
121 // Pops the touch-event from the top of the queue and acks it to the client, | 120 // Pops the touch-event from the top of the queue and acks it to the client, |
122 // updating the event with |renderer_latency_info|. | 121 // updating the event with |renderer_latency_info|. |
123 void PopTouchEventToClient(InputEventAckState ack_result, | 122 void PopTouchEventToClient(InputEventAckState ack_result, |
124 const ui::LatencyInfo& renderer_latency_info); | 123 const ui::LatencyInfo& renderer_latency_info); |
125 | 124 |
126 // Ack all coalesced events at the head of the queue to the client with | 125 // Ack all coalesced events at the head of the queue to the client with |
127 // |ack_result|, updating the acked events with |optional_latency_info| if it | 126 // |ack_result|, updating the acked events with |optional_latency_info| if it |
128 // exists, and popping the head of the queue. | 127 // exists, and popping the head of the queue. |
129 void AckTouchEventToClient(InputEventAckState ack_result, | 128 void AckTouchEventToClient(InputEventAckState ack_result, |
130 const ui::LatencyInfo* optional_latency_info); | 129 const ui::LatencyInfo* optional_latency_info); |
131 | 130 |
| 131 // Dispatch a touch cancel event for the |event_to_cancel|. |
| 132 void SendTouchCancelEventForTouchEvent( |
| 133 const TouchEventWithLatencyInfo& event_to_cancel) override; |
| 134 |
132 // Dispatch |touch| to the client. Before dispatching, updates pointer | 135 // Dispatch |touch| to the client. Before dispatching, updates pointer |
133 // states in touchmove events for pointers that have not changed position. | 136 // states in touchmove events for pointers that have not changed position. |
134 void SendTouchEventImmediately(TouchEventWithLatencyInfo* touch); | 137 void SendTouchEventImmediately(TouchEventWithLatencyInfo* touch); |
135 | 138 |
136 enum PreFilterResult { | 139 enum PreFilterResult { |
137 ACK_WITH_NO_CONSUMER_EXISTS, | 140 ACK_WITH_NO_CONSUMER_EXISTS, |
138 ACK_WITH_NOT_CONSUMED, | 141 ACK_WITH_NOT_CONSUMED, |
139 FORWARD_TO_RENDERER, | 142 FORWARD_TO_RENDERER, |
140 }; | 143 }; |
141 // Filter touches prior to forwarding to the renderer, e.g., if the renderer | 144 // Filter touches prior to forwarding to the renderer, e.g., if the renderer |
142 // has no touch handler. | 145 // has no touch handler. |
143 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); | 146 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); |
144 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); | 147 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); |
145 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, | 148 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, |
146 InputEventAckState ack_result); | 149 InputEventAckState ack_result) override; |
147 void FlushPendingAsyncTouchmove(); | 150 void FlushPendingAsyncTouchmove(); |
148 | 151 |
149 // Handles touch event forwarding and ack'ed event dispatch. | 152 // Handles touch event forwarding and ack'ed event dispatch. |
150 TouchEventQueueClient* client_; | 153 TouchEventQueueClient* client_; |
151 | 154 |
152 std::list<std::unique_ptr<CoalescedWebTouchEvent>> touch_queue_; | 155 std::list<std::unique_ptr<CoalescedWebTouchEvent>> touch_queue_; |
153 | 156 |
154 // Position of the first touch in the most recent sequence forwarded to the | |
155 // client. | |
156 gfx::PointF touch_sequence_start_position_; | |
157 | |
158 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | 157 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. |
159 // True within the scope of |AckTouchEventToClient()|. | 158 // True within the scope of |AckTouchEventToClient()|. |
160 bool dispatching_touch_ack_; | 159 bool dispatching_touch_ack_; |
161 | 160 |
162 // Used to prevent touch timeout scheduling and increase the count for async | 161 // Used to prevent touch timeout scheduling and increase the count for async |
163 // touchmove if we receive a synchronous ack after forwarding a touch event | 162 // touchmove if we receive a synchronous ack after forwarding a touch event |
164 // to the client. | 163 // to the client. |
165 bool dispatching_touch_; | 164 bool dispatching_touch_; |
166 | 165 |
167 // Whether the renderer has at least one touch handler. | 166 // Whether the renderer has at least one touch handler. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 201 |
203 // Event is saved to compare pointer positions for new touchmove events. | 202 // Event is saved to compare pointer positions for new touchmove events. |
204 std::unique_ptr<blink::WebTouchEvent> last_sent_touchevent_; | 203 std::unique_ptr<blink::WebTouchEvent> last_sent_touchevent_; |
205 | 204 |
206 DISALLOW_COPY_AND_ASSIGN(LegacyTouchEventQueue); | 205 DISALLOW_COPY_AND_ASSIGN(LegacyTouchEventQueue); |
207 }; | 206 }; |
208 | 207 |
209 } // namespace content | 208 } // namespace content |
210 | 209 |
211 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_ | 210 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |