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

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: 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(const blink::WebInputEvent* event,
16 const ui::LatencyInfo& latency,
17 InputEventAckState ack_result) {
18 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING ||
19 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
20
21 bool non_blocking = ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING;
22
23 InputEventDispatchType type = non_blocking
24 ? DISPATCH_TYPE_NON_BLOCKING_NOTIFY_MAIN
25 : DISPATCH_TYPE_NORMAL_NOTIFY_MAIN;
26 if (event->type == blink::WebInputEvent::MouseWheel) {
27 if (wheel_events_.state() == WebInputEventQueueState::ITEM_PENDING) {
28 wheel_events_.Queue(PendingMouseWheelEvent(
29 *static_cast<const blink::WebMouseWheelEvent*>(event), latency,
30 type));
31 } else {
32 // If there is nothing in the event queue and the event is
33 // blocking we can avoid having the main thread call us
34 // back when it handled the event as an optimization.
35 if (non_blocking) {
36 wheel_events_.set_state(WebInputEventQueueState::ITEM_PENDING);
37 client_->SendEventToMainThread(routing_id_, event, latency, type);
38 } else {
39 client_->SendEventToMainThread(routing_id_, event, latency,
40 DISPATCH_TYPE_NORMAL);
41 }
42 }
43 } else if (blink::WebInputEvent::isTouchEventType(event->type)) {
44
45 if (touch_events_.state() == WebInputEventQueueState::ITEM_PENDING) {
46 touch_events_.Queue(PendingTouchEvent(
47 *static_cast<const blink::WebTouchEvent*>(event), latency, type));
48 } else {
49 // If there is nothing in the event queue and the event is
50 // blocking we can avoid having the main thread call us
51 // back when it handled the event as an optimization.
52 if (non_blocking) {
53 touch_events_.set_state(WebInputEventQueueState::ITEM_PENDING);
54 client_->SendEventToMainThread(routing_id_, event, latency, type);
55 } else {
56 client_->SendEventToMainThread(routing_id_, event, latency,
57 DISPATCH_TYPE_NORMAL);
58 }
59 }
60 } else {
61 client_->SendEventToMainThread(routing_id_, event, latency,
62 DISPATCH_TYPE_NORMAL);
63 }
64
65 // send an ack when we are non-blocking.
66 return non_blocking;
67 }
68
69 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type) {
70 if (type == blink::WebInputEvent::MouseWheel) {
71 if (!wheel_events_.empty()) {
72 scoped_ptr<PendingMouseWheelEvent> event = wheel_events_.Pop();
73 client_->SendEventToMainThread(routing_id_, &event->event, event->latency,
74 event->type);
75 } else {
76 wheel_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
77 }
78 } else if (blink::WebInputEvent::isTouchEventType(type)) {
79 if (!touch_events_.empty()) {
80 scoped_ptr<PendingTouchEvent> event = touch_events_.Pop();
81 client_->SendEventToMainThread(routing_id_, &event->event, event->latency,
82 event->type);
83 } else {
84 touch_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
85 }
86 } else {
87 NOTREACHED() << "Invalid passive event type";
88 }
89 }
90
91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698