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

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

Issue 1780953003: Change the non-blocking event queue to the main thread event queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_regression_5
Patch Set: Fix up issues from patch set 2 Created 4 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/input/main_thread_event_queue.h"
6
7 namespace content {
8
9 MainThreadEventQueue::MainThreadEventQueue(int routing_id,
10 MainThreadEventQueueClient* client)
11 : routing_id_(routing_id), client_(client) {}
12
13 MainThreadEventQueue::~MainThreadEventQueue() {}
14
15 bool MainThreadEventQueue::HandleEvent(
16 const blink::WebInputEvent* event,
17 const ui::LatencyInfo& latency,
18 InputEventDispatchType original_dispatch_type,
19 InputEventAckState ack_result) {
20 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING ||
21 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING);
22 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING ||
23 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
24
25 bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING ||
26 ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING;
27
28 InputEventDispatchType dispatch_type =
29 non_blocking ? DISPATCH_TYPE_NON_BLOCKING_NOTIFY_MAIN
30 : DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN;
31
32 if (event->type == blink::WebInputEvent::MouseWheel) {
33 if (wheel_events_.state() == WebInputEventQueueState::ITEM_PENDING) {
34 wheel_events_.Queue(PendingMouseWheelEvent(
35 *static_cast<const blink::WebMouseWheelEvent*>(event), latency,
36 dispatch_type));
37 } else {
38 if (non_blocking) {
39 wheel_events_.set_state(WebInputEventQueueState::ITEM_PENDING);
40 client_->SendEventToMainThread(routing_id_, event, latency,
41 dispatch_type);
42 } else {
43 // If there is nothing in the event queue and the event is
44 // blocking we can avoid having the main thread call us
tdresser 2016/03/16 15:34:47 Just to be a bit more explicit: "we can avoid hav
dtapuska 2016/03/17 13:32:36 Done.
45 // back when it handled the event as an optimization.
46 client_->SendEventToMainThread(routing_id_, event, latency,
47 original_dispatch_type);
48 }
49 }
50 } else if (blink::WebInputEvent::isTouchEventType(event->type)) {
51 if (touch_events_.state() == WebInputEventQueueState::ITEM_PENDING) {
52 touch_events_.Queue(
53 PendingTouchEvent(*static_cast<const blink::WebTouchEvent*>(event),
54 latency, dispatch_type));
55 } else {
56 if (non_blocking) {
57 touch_events_.set_state(WebInputEventQueueState::ITEM_PENDING);
58 client_->SendEventToMainThread(routing_id_, event, latency,
59 dispatch_type);
60 } else {
61 // If there is nothing in the event queue and the event is
62 // blocking we can avoid having the main thread call us
63 // back when it handled the event as an optimization.
64 client_->SendEventToMainThread(routing_id_, event, latency,
65 original_dispatch_type);
66 }
67 }
68 } else {
69 client_->SendEventToMainThread(routing_id_, event, latency,
70 original_dispatch_type);
71 }
72
73 // send an ack when we are non-blocking.
74 return non_blocking;
75 }
76
77 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type) {
78 if (type == blink::WebInputEvent::MouseWheel) {
79 if (!wheel_events_.empty()) {
80 scoped_ptr<PendingMouseWheelEvent> event = wheel_events_.Pop();
81 client_->SendEventToMainThread(routing_id_, &event->event, event->latency,
82 event->type);
83 } else {
84 wheel_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
85 }
86 } else if (blink::WebInputEvent::isTouchEventType(type)) {
87 if (!touch_events_.empty()) {
88 scoped_ptr<PendingTouchEvent> event = touch_events_.Pop();
89 client_->SendEventToMainThread(routing_id_, &event->event, event->latency,
90 event->type);
91 } else {
92 touch_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
93 }
94 } else {
95 NOTREACHED() << "Invalid passive event type";
96 }
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698