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

Side by Side Diff: content/browser/renderer_host/input/legacy_touch_event_queue.h

Issue 2663493003: Move the TouchEventQueue to be completely virtual. (Closed)
Patch Set: Fix nits Created 3 years, 10 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_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/common/content_export.h" 19 #include "content/common/content_export.h"
19 #include "content/common/input/input_event_ack_state.h" 20 #include "content/common/input/input_event_ack_state.h"
20 #include "third_party/WebKit/public/platform/WebInputEvent.h" 21 #include "third_party/WebKit/public/platform/WebInputEvent.h"
21 #include "ui/gfx/geometry/point_f.h" 22 #include "ui/gfx/geometry/point_f.h"
22 23
23 namespace content { 24 namespace content {
24 25
25 class CoalescedWebTouchEvent; 26 class CoalescedWebTouchEvent;
26 27
27 // Interface with which TouchEventQueue can forward touch events, and dispatch 28 // A queue for throttling and coalescing touch-events.
28 // touch event responses. 29 class CONTENT_EXPORT LegacyTouchEventQueue : public TouchEventQueue {
29 class CONTENT_EXPORT TouchEventQueueClient {
30 public: 30 public:
31 virtual ~TouchEventQueueClient() {} 31 // The |client| must outlive the LegacyTouchEventQueue.
32 LegacyTouchEventQueue(TouchEventQueueClient* client, const Config& config);
32 33
33 virtual void SendTouchEventImmediately( 34 ~LegacyTouchEventQueue() override;
34 const TouchEventWithLatencyInfo& event) = 0;
35
36 virtual void OnTouchEventAck(
37 const TouchEventWithLatencyInfo& event,
38 InputEventAckState ack_result) = 0;
39
40 virtual void OnFilteringTouchEvent(
41 const blink::WebTouchEvent& touch_event) = 0;
42 };
43
44 // A queue for throttling and coalescing touch-events.
45 class CONTENT_EXPORT TouchEventQueue {
46 public:
47 struct CONTENT_EXPORT Config {
48 Config();
49
50 // Touch ack timeout delay for desktop sites. If zero, timeout behavior
51 // is disabled for such sites. Defaults to 200ms.
52 base::TimeDelta desktop_touch_ack_timeout_delay;
53
54 // Touch ack timeout delay for mobile sites. If zero, timeout behavior
55 // is disabled for such sites. Defaults to 1000ms.
56 base::TimeDelta mobile_touch_ack_timeout_delay;
57
58 // Whether the platform supports touch ack timeout behavior.
59 // Defaults to false (disabled).
60 bool touch_ack_timeout_supported;
61 };
62
63 // The |client| must outlive the TouchEventQueue.
64 TouchEventQueue(TouchEventQueueClient* client, const Config& config);
65
66 ~TouchEventQueue();
67 35
68 // Adds an event to the queue. The event may be coalesced with previously 36 // Adds an event to the queue. The event may be coalesced with previously
69 // queued events (e.g. consecutive touch-move events can be coalesced into a 37 // queued events (e.g. consecutive touch-move events can be coalesced into a
70 // single touch-move event). The event may also be immediately forwarded to 38 // single touch-move event). The event may also be immediately forwarded to
71 // the renderer (e.g. when there are no other queued touch event). 39 // the renderer (e.g. when there are no other queued touch event).
72 void QueueEvent(const TouchEventWithLatencyInfo& event); 40 void QueueEvent(const TouchEventWithLatencyInfo& event) override;
73 41
74 // Insert a TouchScrollStarted event in the queue ahead of all not-in-flight 42 // Insert a TouchScrollStarted event in the queue ahead of all not-in-flight
75 // events. 43 // events.
76 void PrependTouchScrollNotification(); 44 void PrependTouchScrollNotification() override;
77 45
78 // Notifies the queue that a touch-event has been processed by the renderer. 46 // Notifies the queue that a touch-event has been processed by the renderer.
79 // At this point, if the ack is for async touchmove, remove the uncancelable 47 // At this point, if the ack is for async touchmove, remove the uncancelable
80 // touchmove from the front of the queue and decide if it should dispatch the 48 // touchmove from the front of the queue and decide if it should dispatch the
81 // next pending async touch move event, otherwise the queue may send one or 49 // next pending async touch move event, otherwise the queue may send one or
82 // more gesture events and/or additional queued touch-events to the renderer. 50 // more gesture events and/or additional queued touch-events to the renderer.
83 void ProcessTouchAck(InputEventAckState ack_result, 51 void ProcessTouchAck(InputEventAckState ack_result,
84 const ui::LatencyInfo& latency_info, 52 const ui::LatencyInfo& latency_info,
85 const uint32_t unique_touch_event_id); 53 const uint32_t unique_touch_event_id) override;
86 54
87 // When GestureScrollBegin is received, we send a touch cancel to renderer, 55 // When GestureScrollBegin is received, we send a touch cancel to renderer,
88 // route all the following touch events directly to client, and ignore the 56 // route all the following touch events directly to client, and ignore the
89 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received, 57 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received,
90 // resume the normal flow of sending touch events to the renderer. 58 // resume the normal flow of sending touch events to the renderer.
91 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); 59 void OnGestureScrollEvent(
60 const GestureEventWithLatencyInfo& gesture_event) override;
92 61
93 void OnGestureEventAck( 62 void OnGestureEventAck(const GestureEventWithLatencyInfo& event,
94 const GestureEventWithLatencyInfo& event, 63 InputEventAckState ack_result) override;
95 InputEventAckState ack_result);
96 64
97 // Notifies the queue whether the renderer has at least one touch handler. 65 // Notifies the queue whether the renderer has at least one touch handler.
98 void OnHasTouchEventHandlers(bool has_handlers); 66 void OnHasTouchEventHandlers(bool has_handlers) override;
99 67
100 // Returns whether the currently pending touch event (waiting ACK) is for 68 // Returns whether the currently pending touch event (waiting ACK) is for
101 // a touch start event. 69 // a touch start event.
102 bool IsPendingAckTouchStart() const; 70 bool IsPendingAckTouchStart() const override;
103 71
104 // Sets whether a delayed touch ack will cancel and flush the current 72 // Sets whether a delayed touch ack will cancel and flush the current
105 // touch sequence. Note that, if the timeout was previously disabled, enabling 73 // touch sequence. Note that, if the timeout was previously disabled, enabling
106 // it will take effect only for the following touch sequence. 74 // it will take effect only for the following touch sequence.
107 void SetAckTimeoutEnabled(bool enabled); 75 void SetAckTimeoutEnabled(bool enabled) override;
108 76
109 // Sets whether the current site has a mobile friendly viewport. This 77 // Sets whether the current site has a mobile friendly viewport. This
110 // determines which ack timeout delay will be used for *future* touch events. 78 // determines which ack timeout delay will be used for *future* touch events.
111 // The default assumption is that the site is *not* mobile-optimized. 79 // The default assumption is that the site is *not* mobile-optimized.
112 void SetIsMobileOptimizedSite(bool mobile_optimized_site); 80 void SetIsMobileOptimizedSite(bool mobile_optimized_site) override;
113 81
114 // Whether ack timeout behavior is supported and enabled for the current site. 82 // Whether ack timeout behavior is supported and enabled for the current site.
115 bool IsAckTimeoutEnabled() const; 83 bool IsAckTimeoutEnabled() const override;
116 84
117 bool empty() const WARN_UNUSED_RESULT { 85 bool Empty() const override;
118 return touch_queue_.empty();
119 }
120 86
121 size_t size() const { 87 bool empty() const WARN_UNUSED_RESULT { return Empty(); }
122 return touch_queue_.size(); 88
123 } 89 size_t size() const { return touch_queue_.size(); }
124 90
125 bool has_handlers() const { return has_handlers_; } 91 bool has_handlers() const { return has_handlers_; }
126 92
127 size_t uncancelable_touch_moves_pending_ack_count() const { 93 size_t uncancelable_touch_moves_pending_ack_count() const {
128 return ack_pending_async_touchmove_ids_.size(); 94 return ack_pending_async_touchmove_ids_.size();
129 } 95 }
130 96
131 private: 97 private:
132 class TouchTimeoutHandler; 98 class TouchTimeoutHandler;
133 class TouchMoveSlopSuppressor; 99 class TouchMoveSlopSuppressor;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // uncancelable touchmoves which are still waiting for their acks back from 201 // uncancelable touchmoves which are still waiting for their acks back from
236 // render. We do not put them back to the front the touch_event_queue any 202 // render. We do not put them back to the front the touch_event_queue any
237 // more. 203 // more.
238 std::deque<uint32_t> ack_pending_async_touchmove_ids_; 204 std::deque<uint32_t> ack_pending_async_touchmove_ids_;
239 205
240 double last_sent_touch_timestamp_sec_; 206 double last_sent_touch_timestamp_sec_;
241 207
242 // Event is saved to compare pointer positions for new touchmove events. 208 // Event is saved to compare pointer positions for new touchmove events.
243 std::unique_ptr<blink::WebTouchEvent> last_sent_touchevent_; 209 std::unique_ptr<blink::WebTouchEvent> last_sent_touchevent_;
244 210
245 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); 211 DISALLOW_COPY_AND_ASSIGN(LegacyTouchEventQueue);
246 }; 212 };
247 213
248 } // namespace content 214 } // namespace content
249 215
250 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ 216 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_LEGACY_TOUCH_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698