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

Side by Side Diff: content/renderer/input/main_thread_event_queue.h

Issue 2170913002: Generalize the main thread event queue into a common event queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 5 #ifndef CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
6 #define CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 6 #define CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include "base/memory/ref_counted.h"
tdresser 2016/07/22 19:13:41 Not used (yet).
dtapuska 2016/07/22 20:14:08 Done.
9 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
10 #include "content/common/input/event_with_latency_info.h" 11 #include "content/common/input/event_with_latency_info.h"
11 #include "content/common/input/input_event_ack_state.h" 12 #include "content/common/input/input_event_ack_state.h"
12 #include "content/common/input/input_event_dispatch_type.h" 13 #include "content/common/input/input_event_dispatch_type.h"
13 #include "content/common/input/web_input_event_queue.h" 14 #include "content/common/input/web_input_event_queue.h"
14 #include "content/common/input/web_input_event_traits.h" 15 #include "content/common/input/web_input_event_traits.h"
15 #include "third_party/WebKit/public/web/WebInputEvent.h" 16 #include "third_party/WebKit/public/web/WebInputEvent.h"
16 #include "ui/events/latency_info.h" 17 #include "ui/events/latency_info.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 template <typename BaseClass, typename BaseType> 21 class EventWithDispatchType : public ScopedWebInputEventWithLatencyInfo {
21 class EventWithDispatchType : public BaseClass {
22 public: 22 public:
23 EventWithDispatchType(const BaseType& e, 23 EventWithDispatchType(const blink::WebInputEvent& event,
24 const ui::LatencyInfo& l, 24 const ui::LatencyInfo& latency,
25 InputEventDispatchType t) 25 InputEventDispatchType dispatch_type);
26 : BaseClass(e, l), type(t) {} 26 ~EventWithDispatchType();
27 bool CanCoalesceWith(const EventWithDispatchType& other) const
28 WARN_UNUSED_RESULT;
29 void CoalesceWith(const EventWithDispatchType& other);
27 30
28 InputEventDispatchType type; 31 const std::deque<uint32_t>& eventsToAck() const { return eventsToAck_; }
29 std::deque<uint32_t> eventsToAck; 32 InputEventDispatchType dispatchType() const { return dispatch_type_; }
30 33
31 bool CanCoalesceWith(const EventWithDispatchType& other) const 34 private:
32 WARN_UNUSED_RESULT { 35 InputEventDispatchType dispatch_type_;
33 return other.type == type && BaseClass::CanCoalesceWith(other); 36 std::deque<uint32_t> eventsToAck_;
tdresser 2016/07/22 19:13:41 Indicate that this is touch specific.
dtapuska 2016/07/22 20:14:08 I think that is a specialization just in the insta
tdresser 2016/07/25 14:01:40 I guess that's reasonable. Maybe add a comment ind
34 }
35
36 void CoalesceWith(const EventWithDispatchType& other) {
37 // If we are blocking and are coalescing touch, make sure to keep
38 // the touch ids that need to be acked.
39 if (type == DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN) {
40 // We should only have blocking touch events that need coalescing.
41 DCHECK(blink::WebInputEvent::isTouchEventType(other.event.type));
42 eventsToAck.push_back(
43 WebInputEventTraits::GetUniqueTouchEventId(other.event));
44 }
45 BaseClass::CoalesceWith(other);
46 }
47 }; 37 };
48 38
49 using PendingMouseWheelEvent =
50 EventWithDispatchType<MouseWheelEventWithLatencyInfo,
51 blink::WebMouseWheelEvent>;
52
53 using PendingTouchEvent =
54 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>;
55
56 class CONTENT_EXPORT MainThreadEventQueueClient { 39 class CONTENT_EXPORT MainThreadEventQueueClient {
57 public: 40 public:
58 // Send an |event| that was previously queued (possibly 41 // Send an |event| that was previously queued (possibly
59 // coalesced with another event) to the |routing_id|'s 42 // coalesced with another event) to the |routing_id|'s
60 // channel. Implementors must implement this callback. 43 // channel. Implementors must implement this callback.
61 virtual void SendEventToMainThread(int routing_id, 44 virtual void SendEventToMainThread(int routing_id,
62 const blink::WebInputEvent* event, 45 const blink::WebInputEvent* event,
63 const ui::LatencyInfo& latency, 46 const ui::LatencyInfo& latency,
64 InputEventDispatchType dispatch_type) = 0; 47 InputEventDispatchType dispatch_type) = 0;
65 48
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // in flight. 104 // in flight.
122 void EventHandled(blink::WebInputEvent::Type type, 105 void EventHandled(blink::WebInputEvent::Type type,
123 InputEventAckState ack_result); 106 InputEventAckState ack_result);
124 107
125 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } 108 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; }
126 109
127 private: 110 private:
128 friend class MainThreadEventQueueTest; 111 friend class MainThreadEventQueueTest;
129 int routing_id_; 112 int routing_id_;
130 MainThreadEventQueueClient* client_; 113 MainThreadEventQueueClient* client_;
131 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; 114 WebInputEventQueue<EventWithDispatchType> events_;
132 WebInputEventQueue<PendingTouchEvent> touch_events_; 115 std::unique_ptr<EventWithDispatchType> in_flight_event_;
133 bool is_flinging_; 116 bool is_flinging_;
134 117 bool sent_notification_to_main_;
135 // TODO(dtapuska): These can be removed when the queues are dequeued
136 // on the main thread. See crbug.com/624021
137 std::unique_ptr<PendingMouseWheelEvent> in_flight_wheel_event_;
138 std::unique_ptr<PendingTouchEvent> in_flight_touch_event_;
139 118
140 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); 119 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
141 }; 120 };
142 121
143 } // namespace content 122 } // namespace content
144 123
145 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 124 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698