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

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, 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 "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); 35 std::deque<uint32_t> eventsToAck_;
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 }; 36 };
48 37
49 using PendingMouseWheelEvent =
50 EventWithDispatchType<MouseWheelEventWithLatencyInfo,
51 blink::WebMouseWheelEvent>;
52
53 using PendingTouchEvent =
54 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>;
55
56 class CONTENT_EXPORT MainThreadEventQueueClient { 38 class CONTENT_EXPORT MainThreadEventQueueClient {
57 public: 39 public:
58 // Send an |event| that was previously queued (possibly 40 // Send an |event| that was previously queued (possibly
59 // coalesced with another event) to the |routing_id|'s 41 // coalesced with another event) to the |routing_id|'s
60 // channel. Implementors must implement this callback. 42 // channel. Implementors must implement this callback.
61 virtual void SendEventToMainThread(int routing_id, 43 virtual void SendEventToMainThread(int routing_id,
62 const blink::WebInputEvent* event, 44 const blink::WebInputEvent* event,
63 const ui::LatencyInfo& latency, 45 const ui::LatencyInfo& latency,
64 InputEventDispatchType dispatch_type) = 0; 46 InputEventDispatchType dispatch_type) = 0;
65 47
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // in flight. 103 // in flight.
122 void EventHandled(blink::WebInputEvent::Type type, 104 void EventHandled(blink::WebInputEvent::Type type,
123 InputEventAckState ack_result); 105 InputEventAckState ack_result);
124 106
125 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } 107 void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; }
126 108
127 private: 109 private:
128 friend class MainThreadEventQueueTest; 110 friend class MainThreadEventQueueTest;
129 int routing_id_; 111 int routing_id_;
130 MainThreadEventQueueClient* client_; 112 MainThreadEventQueueClient* client_;
131 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; 113 WebInputEventQueue<EventWithDispatchType> events_;
132 WebInputEventQueue<PendingTouchEvent> touch_events_; 114 std::unique_ptr<EventWithDispatchType> in_flight_event_;
133 bool is_flinging_; 115 bool is_flinging_;
134 116 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 117
140 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); 118 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
141 }; 119 };
142 120
143 } // namespace content 121 } // namespace content
144 122
145 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ 123 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698