Chromium Code Reviews| 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_TOUCH_EVENT_QUEUE_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_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 <map> | 13 #include <map> |
| 13 | 14 |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "content/browser/renderer_host/event_with_latency_info.h" | 17 #include "content/browser/renderer_host/event_with_latency_info.h" |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "content/common/input/input_event_ack_state.h" | 19 #include "content/common/input/input_event_ack_state.h" |
| 19 #include "third_party/WebKit/public/web/WebInputEvent.h" | 20 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 20 #include "ui/gfx/geometry/point_f.h" | 21 #include "ui/gfx/geometry/point_f.h" |
| 21 | 22 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 TouchEventQueue(TouchEventQueueClient* client, const Config& config); | 64 TouchEventQueue(TouchEventQueueClient* client, const Config& config); |
| 64 | 65 |
| 65 ~TouchEventQueue(); | 66 ~TouchEventQueue(); |
| 66 | 67 |
| 67 // Adds an event to the queue. The event may be coalesced with previously | 68 // Adds an event to the queue. The event may be coalesced with previously |
| 68 // queued events (e.g. consecutive touch-move events can be coalesced into a | 69 // queued events (e.g. consecutive touch-move events can be coalesced into a |
| 69 // single touch-move event). The event may also be immediately forwarded to | 70 // single touch-move event). The event may also be immediately forwarded to |
| 70 // the renderer (e.g. when there are no other queued touch event). | 71 // the renderer (e.g. when there are no other queued touch event). |
| 71 void QueueEvent(const TouchEventWithLatencyInfo& event); | 72 void QueueEvent(const TouchEventWithLatencyInfo& event); |
| 72 | 73 |
| 74 // Adds a TouchScrollStarted event to the front of the queue. | |
|
tdresser
2016/03/30 19:19:01
This comment is a bit misleading, as it's often pl
mustaq
2016/03/30 20:21:05
It is better? Or you want to see something like "1
| |
| 75 void PrependTouchScrollNotification(); | |
| 76 | |
| 73 // Notifies the queue that a touch-event has been processed by the renderer. | 77 // Notifies the queue that a touch-event has been processed by the renderer. |
| 74 // At this point, if the ack is for async touchmove, remove the uncancelable | 78 // At this point, if the ack is for async touchmove, remove the uncancelable |
| 75 // touchmove from the front of the queue and decide if it should dispatch the | 79 // touchmove from the front of the queue and decide if it should dispatch the |
| 76 // next pending async touch move event, otherwise the queue may send one or | 80 // next pending async touch move event, otherwise the queue may send one or |
| 77 // more gesture events and/or additional queued touch-events to the renderer. | 81 // more gesture events and/or additional queued touch-events to the renderer. |
| 78 void ProcessTouchAck(InputEventAckState ack_result, | 82 void ProcessTouchAck(InputEventAckState ack_result, |
| 79 const ui::LatencyInfo& latency_info, | 83 const ui::LatencyInfo& latency_info, |
| 80 const uint32_t unique_touch_event_id); | 84 const uint32_t unique_touch_event_id); |
| 81 | 85 |
| 82 // When GestureScrollBegin is received, we send a touch cancel to renderer, | 86 // When GestureScrollBegin is received, we send a touch cancel to renderer, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 102 void SetAckTimeoutEnabled(bool enabled); | 106 void SetAckTimeoutEnabled(bool enabled); |
| 103 | 107 |
| 104 // Sets whether the current site has a mobile friendly viewport. This | 108 // Sets whether the current site has a mobile friendly viewport. This |
| 105 // determines which ack timeout delay will be used for *future* touch events. | 109 // determines which ack timeout delay will be used for *future* touch events. |
| 106 // The default assumption is that the site is *not* mobile-optimized. | 110 // The default assumption is that the site is *not* mobile-optimized. |
| 107 void SetIsMobileOptimizedSite(bool mobile_optimized_site); | 111 void SetIsMobileOptimizedSite(bool mobile_optimized_site); |
| 108 | 112 |
| 109 // Whether ack timeout behavior is supported and enabled for the current site. | 113 // Whether ack timeout behavior is supported and enabled for the current site. |
| 110 bool IsAckTimeoutEnabled() const; | 114 bool IsAckTimeoutEnabled() const; |
| 111 | 115 |
| 112 bool IsForwardingTouches(); | |
| 113 | |
| 114 bool empty() const WARN_UNUSED_RESULT { | 116 bool empty() const WARN_UNUSED_RESULT { |
| 115 return touch_queue_.empty(); | 117 return touch_queue_.empty(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 size_t size() const { | 120 size_t size() const { |
| 119 return touch_queue_.size(); | 121 return touch_queue_.size(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 bool has_handlers() const { return has_handlers_; } | 124 bool has_handlers() const { return has_handlers_; } |
| 123 | 125 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 148 void ForwardNextEventToRenderer(); | 150 void ForwardNextEventToRenderer(); |
| 149 | 151 |
| 150 // Pops the touch-event from the head of the queue and acks it to the client. | 152 // Pops the touch-event from the head of the queue and acks it to the client. |
| 151 void PopTouchEventToClient(InputEventAckState ack_result); | 153 void PopTouchEventToClient(InputEventAckState ack_result); |
| 152 | 154 |
| 153 // Pops the touch-event from the top of the queue and acks it to the client, | 155 // Pops the touch-event from the top of the queue and acks it to the client, |
| 154 // updating the event with |renderer_latency_info|. | 156 // updating the event with |renderer_latency_info|. |
| 155 void PopTouchEventToClient(InputEventAckState ack_result, | 157 void PopTouchEventToClient(InputEventAckState ack_result, |
| 156 const ui::LatencyInfo& renderer_latency_info); | 158 const ui::LatencyInfo& renderer_latency_info); |
| 157 | 159 |
| 158 // Ack all coalesced events in |acked_event| to the client with |ack_result|, | 160 // Ack all coalesced events at the head of the queue to the client with |
| 159 // updating the acked events with |optional_latency_info| if it exists. | 161 // |ack_result|, updating the acked events with |optional_latency_info| if it |
| 162 // exists, and popping the head of the queue. | |
| 160 void AckTouchEventToClient(InputEventAckState ack_result, | 163 void AckTouchEventToClient(InputEventAckState ack_result, |
| 161 scoped_ptr<CoalescedWebTouchEvent> acked_event, | |
| 162 const ui::LatencyInfo* optional_latency_info); | 164 const ui::LatencyInfo* optional_latency_info); |
| 163 | 165 |
| 164 // Safely pop the head of the queue. | |
| 165 scoped_ptr<CoalescedWebTouchEvent> PopTouchEvent(); | |
| 166 | |
| 167 // Dispatch |touch| to the client. Before dispatching, updates pointer | 166 // Dispatch |touch| to the client. Before dispatching, updates pointer |
| 168 // states in touchmove events for pointers that have not changed position. | 167 // states in touchmove events for pointers that have not changed position. |
| 169 void SendTouchEventImmediately(TouchEventWithLatencyInfo* touch); | 168 void SendTouchEventImmediately(TouchEventWithLatencyInfo* touch); |
| 170 | 169 |
| 171 enum PreFilterResult { | 170 enum PreFilterResult { |
| 172 ACK_WITH_NO_CONSUMER_EXISTS, | 171 ACK_WITH_NO_CONSUMER_EXISTS, |
| 173 ACK_WITH_NOT_CONSUMED, | 172 ACK_WITH_NOT_CONSUMED, |
| 174 FORWARD_TO_RENDERER, | 173 FORWARD_TO_RENDERER, |
| 175 }; | 174 }; |
| 176 // Filter touches prior to forwarding to the renderer, e.g., if the renderer | 175 // Filter touches prior to forwarding to the renderer, e.g., if the renderer |
| 177 // has no touch handler. | 176 // has no touch handler. |
| 178 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); | 177 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); |
| 179 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); | 178 void ForwardToRenderer(const TouchEventWithLatencyInfo& event); |
| 180 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, | 179 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, |
| 181 InputEventAckState ack_result); | 180 InputEventAckState ack_result); |
| 182 void FlushPendingAsyncTouchmove(); | 181 void FlushPendingAsyncTouchmove(); |
| 183 | 182 |
| 184 // Handles touch event forwarding and ack'ed event dispatch. | 183 // Handles touch event forwarding and ack'ed event dispatch. |
| 185 TouchEventQueueClient* client_; | 184 TouchEventQueueClient* client_; |
| 186 | 185 |
| 187 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; | 186 typedef std::list<CoalescedWebTouchEvent*> TouchQueue; |
| 188 TouchQueue touch_queue_; | 187 TouchQueue touch_queue_; |
| 189 | 188 |
| 190 // Position of the first touch in the most recent sequence forwarded to the | 189 // Position of the first touch in the most recent sequence forwarded to the |
| 191 // client. | 190 // client. |
| 192 gfx::PointF touch_sequence_start_position_; | 191 gfx::PointF touch_sequence_start_position_; |
| 193 | 192 |
| 194 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. | 193 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. |
| 195 // True within the scope of |AckTouchEventToClient()|. | 194 // True within the scope of |AckTouchEventToClient()|. |
| 196 bool dispatching_touch_ack_; | 195 bool dispatching_touch_ack_; |
| 197 | 196 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 | 241 |
| 243 // Event is saved to compare pointer positions for new touchmove events. | 242 // Event is saved to compare pointer positions for new touchmove events. |
| 244 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; | 243 scoped_ptr<blink::WebTouchEvent> last_sent_touchevent_; |
| 245 | 244 |
| 246 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); | 245 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); |
| 247 }; | 246 }; |
| 248 | 247 |
| 249 } // namespace content | 248 } // namespace content |
| 250 | 249 |
| 251 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ | 250 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ |
| OLD | NEW |