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

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: Fix nits Created 4 years, 4 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 "content/common/content_export.h" 9 #include "content/common/content_export.h"
10 #include "content/common/input/event_with_latency_info.h" 10 #include "content/common/input/event_with_latency_info.h"
11 #include "content/common/input/input_event_ack_state.h" 11 #include "content/common/input/input_event_ack_state.h"
12 #include "content/common/input/input_event_dispatch_type.h" 12 #include "content/common/input/input_event_dispatch_type.h"
13 #include "content/common/input/web_input_event_queue.h" 13 #include "content/common/input/web_input_event_queue.h"
14 #include "content/common/input/web_input_event_traits.h" 14 #include "content/common/input/web_input_event_traits.h"
15 #include "third_party/WebKit/public/web/WebInputEvent.h" 15 #include "third_party/WebKit/public/web/WebInputEvent.h"
16 #include "ui/events/latency_info.h" 16 #include "ui/events/latency_info.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 template <typename BaseClass, typename BaseType> 20 class EventWithDispatchType : public ScopedWebInputEventWithLatencyInfo {
21 class EventWithDispatchType : public BaseClass {
22 public: 21 public:
23 EventWithDispatchType(const BaseType& e, 22 EventWithDispatchType(const blink::WebInputEvent& event,
24 const ui::LatencyInfo& l, 23 const ui::LatencyInfo& latency,
25 InputEventDispatchType t) 24 InputEventDispatchType dispatch_type);
26 : BaseClass(e, l), type(t) {} 25 ~EventWithDispatchType();
26 bool CanCoalesceWith(const EventWithDispatchType& other) const
27 WARN_UNUSED_RESULT;
28 void CoalesceWith(const EventWithDispatchType& other);
27 29
28 InputEventDispatchType type; 30 const std::deque<uint32_t>& eventsToAck() const { return eventsToAck_; }
29 std::deque<uint32_t> eventsToAck; 31 InputEventDispatchType dispatchType() const { return dispatch_type_; }
30 32
31 bool CanCoalesceWith(const EventWithDispatchType& other) const 33 private:
32 WARN_UNUSED_RESULT { 34 InputEventDispatchType dispatch_type_;
33 return other.type == type && BaseClass::CanCoalesceWith(other);
34 }
35 35
36 void CoalesceWith(const EventWithDispatchType& other) { 36 // |eventsToAck_| contains the unique touch event id to be acked. If
37 // If we are blocking and are coalescing touch, make sure to keep 37 // the events are TouchEvents the value will be 0. More importantly for
38 // the touch ids that need to be acked. 38 // those cases the deque ends up containing how many additional ACKs
39 if (type == DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN) { 39 // need to be sent.
40 // We should only have blocking touch events that need coalescing. 40 std::deque<uint32_t> eventsToAck_;
41 DCHECK(blink::WebInputEvent::isTouchEventType(other.event.type));
42 eventsToAck.push_back(
43 WebInputEventTraits::GetUniqueTouchEventId(other.event));
44 }
45 BaseClass::CoalesceWith(other);
46 }
47 }; 41 };
48 42
49 using PendingMouseWheelEvent =
50 EventWithDispatchType<MouseWheelEventWithLatencyInfo,
51 blink::WebMouseWheelEvent>;
52
53 using PendingTouchEvent =
54 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>;
55
56 class CONTENT_EXPORT MainThreadEventQueueClient { 43 class CONTENT_EXPORT MainThreadEventQueueClient {
57 public: 44 public:
58 // Send an |event| that was previously queued (possibly 45 // Send an |event| that was previously queued (possibly
59 // coalesced with another event) to the |routing_id|'s 46 // coalesced with another event) to the |routing_id|'s
60 // channel. Implementors must implement this callback. 47 // channel. Implementors must implement this callback.
61 virtual void SendEventToMainThread(int routing_id, 48 virtual void SendEventToMainThread(int routing_id,
62 const blink::WebInputEvent* event, 49 const blink::WebInputEvent* event,
63 const ui::LatencyInfo& latency, 50 const ui::LatencyInfo& latency,
64 InputEventDispatchType dispatch_type) = 0; 51 InputEventDispatchType dispatch_type) = 0;
65 52
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // in flight. 108 // in flight.
122 void EventHandled(blink::WebInputEvent::Type type, 109 void EventHandled(blink::WebInputEvent::Type type,
123 InputEventAckState ack_result); 110 InputEventAckState ack_result);
124 111
125 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } 112 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; }
126 113
127 private: 114 private:
128 friend class MainThreadEventQueueTest; 115 friend class MainThreadEventQueueTest;
129 int routing_id_; 116 int routing_id_;
130 MainThreadEventQueueClient* client_; 117 MainThreadEventQueueClient* client_;
131 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; 118 WebInputEventQueue<EventWithDispatchType> events_;
132 WebInputEventQueue<PendingTouchEvent> touch_events_; 119 std::unique_ptr<EventWithDispatchType> in_flight_event_;
133 bool is_flinging_; 120 bool is_flinging_;
134 121 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 122
140 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); 123 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
141 }; 124 };
142 125
143 } // namespace content 126 } // namespace content
144 127
145 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 128 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
OLDNEW
« no previous file with comments | « content/common/input/web_input_event_queue.h ('k') | content/renderer/input/main_thread_event_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698