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

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

Issue 48973005: Move TouchEvent timeout code to the TouchEventQueue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle no consumer Created 7 years 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_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 <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 10
(...skipping 20 matching lines...) Expand all
31 const TouchEventWithLatencyInfo& event, 31 const TouchEventWithLatencyInfo& event,
32 InputEventAckState ack_result) = 0; 32 InputEventAckState ack_result) = 0;
33 }; 33 };
34 34
35 // A queue for throttling and coalescing touch-events. 35 // A queue for throttling and coalescing touch-events.
36 class CONTENT_EXPORT TouchEventQueue { 36 class CONTENT_EXPORT TouchEventQueue {
37 public: 37 public:
38 38
39 // The |client| must outlive the TouchEventQueue. 39 // The |client| must outlive the TouchEventQueue.
40 explicit TouchEventQueue(TouchEventQueueClient* client); 40 explicit TouchEventQueue(TouchEventQueueClient* client);
41 virtual ~TouchEventQueue(); 41 ~TouchEventQueue();
42 42
43 // Adds an event to the queue. The event may be coalesced with previously 43 // Adds an event to the queue. The event may be coalesced with previously
44 // queued events (e.g. consecutive touch-move events can be coalesced into a 44 // queued events (e.g. consecutive touch-move events can be coalesced into a
45 // single touch-move event). The event may also be immediately forwarded to 45 // single touch-move event). The event may also be immediately forwarded to
46 // the renderer (e.g. when there are no other queued touch event). 46 // the renderer (e.g. when there are no other queued touch event).
47 void QueueEvent(const TouchEventWithLatencyInfo& event); 47 void QueueEvent(const TouchEventWithLatencyInfo& event);
48 48
49 // Notifies the queue that a touch-event has been processed by the renderer. 49 // Notifies the queue that a touch-event has been processed by the renderer.
50 // At this point, the queue may send one or more gesture events and/or 50 // At this point, the queue may send one or more gesture events and/or
51 // additional queued touch-events to the renderer. 51 // additional queued touch-events to the renderer.
52 void ProcessTouchAck(InputEventAckState ack_result, 52 void ProcessTouchAck(InputEventAckState ack_result,
53 const ui::LatencyInfo& latency_info); 53 const ui::LatencyInfo& latency_info);
54 54
55 // When GestureScrollBegin is received, we send a touch cancel to renderer, 55 // When GestureScrollBegin is received, we send a touch cancel to renderer,
56 // 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
57 // ack for the touch cancel. When GestureScrollEnd/GestureFlingStart is 57 // ack for the touch cancel. When Gesture{ScrollEnd,FlingStart} is received,
58 // received, we resume the normal flow of sending touch events to renderer. 58 // resume the normal flow of sending touch events to the renderer.
59 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event); 59 void OnGestureScrollEvent(const GestureEventWithLatencyInfo& gesture_event);
60 60
61 // Empties the queue of touch events. This may result in any number of gesture 61 // Empties the queue of touch events. This may result in any number of gesture
62 // events being sent to the renderer. 62 // events being sent to the renderer.
63 void FlushQueue(); 63 void FlushQueue();
64 64
65 // Returns whether the event-queue is empty. 65 // Toggle whether a delayed touch ack will cancel and flush the current
sadrul 2013/12/06 07:35:18 s/Toggle/Sets/
jdduke (slow) 2013/12/06 17:17:20 Done.
66 // touch sequence.
67 void SetAckTimeoutEnabled(bool enabled, size_t ack_timeout_delay_ms);
68
66 bool empty() const WARN_UNUSED_RESULT { 69 bool empty() const WARN_UNUSED_RESULT {
67 return touch_queue_.empty(); 70 return touch_queue_.empty();
68 } 71 }
69 72
70 bool no_touch_to_renderer() const { 73 size_t size() const {
71 return no_touch_to_renderer_; 74 return touch_queue_.size();
75 }
76
77 bool ack_timeout_enabled() const {
78 return ack_timeout_enabled_;
72 } 79 }
73 80
74 private: 81 private:
82 class TouchTimeoutHandler;
83 friend class TouchTimeoutHandler;
75 friend class TouchEventQueueTest; 84 friend class TouchEventQueueTest;
76 85
77 size_t GetQueueSize() const; 86 bool HasTimeoutEvent() const;
78 const TouchEventWithLatencyInfo& GetLatestEvent() const; 87 bool IsTimeoutRunningForTesting() const;
88 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const;
79 89
80 // Walks the queue, checking each event for |ShouldForwardToRenderer()|. 90 // Walks the queue, checking each event for |ShouldForwardToRenderer()|.
81 // If true, forwards the touch event and stops processing further events. 91 // If true, forwards the touch event and stops processing further events.
82 // If false, acks the event with |INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS|. 92 // If false, acks the event with |INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS|.
83 void TryForwardNextEventToRenderer(); 93 void TryForwardNextEventToRenderer();
84 94
85 // Pops the touch-event from the top of the queue and sends it to the 95 // Pops the touch-event from the top of the queue and sends it to the
86 // TouchEventQueueClient. This reduces the size of the queue by one. 96 // TouchEventQueueClient. This reduces the size of the queue by one.
87 void PopTouchEventToClient(InputEventAckState ack_result, 97 void PopTouchEventToClient(InputEventAckState ack_result,
88 const ui::LatencyInfo& renderer_latency_info); 98 const ui::LatencyInfo& renderer_latency_info);
89 99
90 bool ShouldForwardToRenderer(const blink::WebTouchEvent& event) const; 100 bool ShouldForwardToRenderer(const blink::WebTouchEvent& event) const;
101 void ForwardToRenderer(const TouchEventWithLatencyInfo& event);
102 void UpdateTouchAckStates(const blink::WebTouchEvent& event,
103 InputEventAckState ack_result);
104
91 105
92 // Handles touch event forwarding and ack'ed event dispatch. 106 // Handles touch event forwarding and ack'ed event dispatch.
93 TouchEventQueueClient* client_; 107 TouchEventQueueClient* client_;
94 108
95 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue; 109 typedef std::deque<CoalescedWebTouchEvent*> TouchQueue;
96 TouchQueue touch_queue_; 110 TouchQueue touch_queue_;
97 111
98 // Maintain the ACK status for each touch point. 112 // Maintain the ACK status for each touch point.
99 typedef std::map<int, InputEventAckState> TouchPointAckStates; 113 typedef std::map<int, InputEventAckState> TouchPointAckStates;
100 TouchPointAckStates touch_ack_states_; 114 TouchPointAckStates touch_ack_states_;
101 115
102 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|. 116 // Used to defer touch forwarding when ack dispatch triggers |QueueEvent()|.
103 // If not NULL, |dispatching_touch_ack_| is the touch event of which the ack 117 // If not NULL, |dispatching_touch_ack_| is the touch event of which the ack
104 // is being dispatched. 118 // is being dispatched.
105 CoalescedWebTouchEvent* dispatching_touch_ack_; 119 CoalescedWebTouchEvent* dispatching_touch_ack_;
106 120
107 // Don't send touch events to renderer. This is enabled when the page 121 // Used to prevent touch timeout scheduling if we receive a synchronous
108 // is scrolling. This behaviour is currently enabled only on aura behind 122 // ack after forwarding a touch event to the client.
109 // a flag. 123 bool dispatching_touch_;
124
125 // Don't send touch events to the renderer while scrolling.
110 bool no_touch_to_renderer_; 126 bool no_touch_to_renderer_;
111 127
128 // Whether an event in the current TouchStart sequence was consumed by the
129 // renderer. The touch timeout will never be activated when this is true.
130 bool renderer_is_consuming_gesture_;
sadrul 2013/12/06 07:35:18 renderer_is_consuming_touch_?
jdduke (slow) 2013/12/06 17:17:20 Hmm, I'd like it to be specific about this particu
131
132 // Optional handler for timed-out touch event acks, disabled by default.
133 bool ack_timeout_enabled_;
134 scoped_ptr<TouchTimeoutHandler> timeout_handler_;
135
112 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); 136 DISALLOW_COPY_AND_ASSIGN(TouchEventQueue);
113 }; 137 };
114 138
115 } // namespace content 139 } // namespace content
116 140
117 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_ 141 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698