Chromium Code Reviews| Index: content/renderer/input/main_thread_event_queue.cc |
| diff --git a/content/renderer/input/main_thread_event_queue.cc b/content/renderer/input/main_thread_event_queue.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7dc1b573f14ca65474c2c0455169dfd54bfec0c0 |
| --- /dev/null |
| +++ b/content/renderer/input/main_thread_event_queue.cc |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/input/main_thread_event_queue.h" |
| + |
| +namespace content { |
| + |
| +MainThreadEventQueue::MainThreadEventQueue(int routing_id, |
| + MainThreadEventQueueClient* client) |
| + : routing_id_(routing_id), client_(client) {} |
| + |
| +MainThreadEventQueue::~MainThreadEventQueue() {} |
| + |
| +bool MainThreadEventQueue::HandleEvent( |
| + const blink::WebInputEvent* event, |
| + const ui::LatencyInfo& latency, |
| + InputEventDispatchType original_dispatch_type, |
| + InputEventAckState ack_result) { |
| + DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || |
| + original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); |
| + DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING || |
| + ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| + |
| + bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING || |
| + ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING; |
| + |
| + InputEventDispatchType dispatch_type = |
| + non_blocking ? DISPATCH_TYPE_NON_BLOCKING_NOTIFY_MAIN |
| + : DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN; |
| + |
| + if (event->type == blink::WebInputEvent::MouseWheel) { |
| + if (wheel_events_.state() == WebInputEventQueueState::ITEM_PENDING) { |
| + wheel_events_.Queue(PendingMouseWheelEvent( |
| + *static_cast<const blink::WebMouseWheelEvent*>(event), latency, |
| + dispatch_type)); |
| + } else { |
| + // If there is nothing in the event queue and the event is |
| + // blocking we can avoid having the main thread call us |
| + // back when it handled the event as an optimization. |
|
tdresser
2016/03/15 13:41:21
I'm a bit confused here. The comment says "if the
dtapuska
2016/03/15 19:46:04
Done.
|
| + if (non_blocking) { |
| + wheel_events_.set_state(WebInputEventQueueState::ITEM_PENDING); |
| + client_->SendEventToMainThread(routing_id_, event, latency, |
| + dispatch_type); |
| + } else { |
| + client_->SendEventToMainThread(routing_id_, event, latency, |
| + original_dispatch_type); |
| + } |
| + } |
| + } else if (blink::WebInputEvent::isTouchEventType(event->type)) { |
| + if (touch_events_.state() == WebInputEventQueueState::ITEM_PENDING) { |
| + touch_events_.Queue( |
| + PendingTouchEvent(*static_cast<const blink::WebTouchEvent*>(event), |
| + latency, dispatch_type)); |
| + } else { |
| + // If there is nothing in the event queue and the event is |
| + // blocking we can avoid having the main thread call us |
| + // back when it handled the event as an optimization. |
| + if (non_blocking) { |
| + touch_events_.set_state(WebInputEventQueueState::ITEM_PENDING); |
| + client_->SendEventToMainThread(routing_id_, event, latency, |
| + dispatch_type); |
| + } else { |
| + client_->SendEventToMainThread(routing_id_, event, latency, |
| + original_dispatch_type); |
| + } |
| + } |
| + } else { |
| + client_->SendEventToMainThread(routing_id_, event, latency, |
| + original_dispatch_type); |
| + } |
| + |
| + // send an ack when we are non-blocking. |
| + return non_blocking; |
| +} |
| + |
| +void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type) { |
| + if (type == blink::WebInputEvent::MouseWheel) { |
| + if (!wheel_events_.empty()) { |
| + scoped_ptr<PendingMouseWheelEvent> event = wheel_events_.Pop(); |
| + client_->SendEventToMainThread(routing_id_, &event->event, event->latency, |
| + event->type); |
| + } else { |
| + wheel_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING); |
| + } |
| + } else if (blink::WebInputEvent::isTouchEventType(type)) { |
| + if (!touch_events_.empty()) { |
| + scoped_ptr<PendingTouchEvent> event = touch_events_.Pop(); |
| + client_->SendEventToMainThread(routing_id_, &event->event, event->latency, |
| + event->type); |
| + } else { |
| + touch_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING); |
| + } |
| + } else { |
| + NOTREACHED() << "Invalid passive event type"; |
| + } |
| +} |
| + |
| +} // namespace content |