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 |
| index 243bc4fe9508b0386899b6c22929c0e8ebfda206..b40555967c9b71d82dd145c01915e3689d52d775 100644 |
| --- a/content/renderer/input/main_thread_event_queue.cc |
| +++ b/content/renderer/input/main_thread_event_queue.cc |
| @@ -3,12 +3,20 @@ |
| // found in the LICENSE file. |
| #include "content/renderer/input/main_thread_event_queue.h" |
| +#include "content/common/input_messages.h" |
| namespace content { |
| -MainThreadEventQueue::MainThreadEventQueue(int routing_id, |
| - MainThreadEventQueueClient* client) |
| - : routing_id_(routing_id), client_(client), is_flinging_(false) {} |
| +MainThreadEventQueue::MainThreadEventQueue( |
| + int routing_id, |
| + MainThreadEventQueueClient* client, |
| + const base::Callback<void(const IPC::Message&)>& main_listener, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) |
| + : routing_id_(routing_id), |
| + client_(client), |
| + is_flinging_(false), |
| + main_task_runner_(main_task_runner), |
| + main_listener_(main_listener) {} |
| MainThreadEventQueue::~MainThreadEventQueue() {} |
| @@ -41,24 +49,7 @@ bool MainThreadEventQueue::HandleEvent( |
| modified_dispatch_type_event.event.dispatchType = |
| blink::WebInputEvent::ListenersNonBlockingPassive; |
| } |
| - |
| - if (wheel_events_.state() == WebInputEventQueueState::ITEM_PENDING) { |
| - wheel_events_.Queue(modified_dispatch_type_event); |
| - } else { |
| - if (non_blocking) { |
| - wheel_events_.set_state(WebInputEventQueueState::ITEM_PENDING); |
| - client_->SendEventToMainThread(routing_id_, |
| - &modified_dispatch_type_event.event, |
| - latency, dispatch_type); |
| - } else { |
| - // If there is nothing in the event queue and the event is |
| - // blocking pass the |original_dispatch_type| to avoid |
| - // having the main thread call us back as an optimization. |
| - client_->SendEventToMainThread(routing_id_, |
| - &modified_dispatch_type_event.event, |
| - latency, original_dispatch_type); |
| - } |
| - } |
| + QueueWheelEvent(modified_dispatch_type_event); |
| } else if (blink::WebInputEvent::isTouchEventType(event->type)) { |
| PendingTouchEvent modified_dispatch_type_event = |
| PendingTouchEvent(*static_cast<const blink::WebTouchEvent*>(event), |
| @@ -72,52 +63,150 @@ bool MainThreadEventQueue::HandleEvent( |
| blink::WebInputEvent::ListenersNonBlockingPassive; |
| } |
| - if (touch_events_.state() == WebInputEventQueueState::ITEM_PENDING) { |
| - touch_events_.Queue(modified_dispatch_type_event); |
| - } else { |
| - if (non_blocking) { |
| - touch_events_.set_state(WebInputEventQueueState::ITEM_PENDING); |
| - client_->SendEventToMainThread(routing_id_, |
| - &modified_dispatch_type_event.event, |
| - latency, dispatch_type); |
| - } else { |
| - // If there is nothing in the event queue and the event is |
| - // blocking pass the |original_dispatch_type| to avoid |
| - // having the main thread call us back as an optimization. |
| - client_->SendEventToMainThread(routing_id_, |
| - &modified_dispatch_type_event.event, |
| - latency, original_dispatch_type); |
| - } |
| - } |
| + QueueTouchEvent(modified_dispatch_type_event); |
| + } else if (blink::WebInputEvent::isMouseEventType(event->type)) { |
| + PendingMouseEvent modified_dispatch_type_event = |
| + PendingMouseEvent(*static_cast<const blink::WebMouseEvent*>(event), |
| + latency, dispatch_type); |
| + QueueMouseEvent(modified_dispatch_type_event); |
| } else { |
| - client_->SendEventToMainThread(routing_id_, event, latency, |
| - original_dispatch_type); |
| + SendEventToMainThread(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()) { |
| - std::unique_ptr<PendingMouseWheelEvent> event = wheel_events_.Pop(); |
| - client_->SendEventToMainThread(routing_id_, &event->event, event->latency, |
| +void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type) {} |
|
tdresser
2016/05/30 14:05:32
So we'd get rid of this completely?
dtapuska
2016/06/01 18:22:53
Yes
|
| + |
| +void MainThreadEventQueue::SendEventToMainThread( |
| + const blink::WebInputEvent* event, |
| + const ui::LatencyInfo& latency, |
| + InputEventDispatchType dispatch_type) { |
| + IPC::Message new_msg = |
| + InputMsg_HandleInputEvent(routing_id_, event, latency, dispatch_type); |
| + |
| + main_task_runner_->PostTask(FROM_HERE, base::Bind(main_listener_, new_msg)); |
| +} |
| + |
| +void MainThreadEventQueue::PopWheelEventOnMainThread() { |
| + std::unique_ptr<PendingMouseWheelEvent> event; |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + if (!wheel_events_.empty()) |
|
tdresser
2016/05/30 14:05:32
Should this case ever occur?
dtapuska
2016/06/01 18:22:54
No it shouldn't can add dcheck
|
| + event = wheel_events_.Pop(); |
| + } |
| + |
| + if (event) { |
|
tdresser
2016/05/30 14:05:32
Should this ever not be true?
dtapuska
2016/06/01 18:22:53
No it shouldn't
|
| + client_->HandleEventOnMainThread(routing_id_, &event->event, event->latency, |
| event->type); |
| - } else { |
| - wheel_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING); |
| + } |
| + |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + if (!wheel_events_.empty()) { |
| + SendWheelEventNotificationToMainThread(); |
| } |
| - } else if (blink::WebInputEvent::isTouchEventType(type)) { |
| + } |
| +} |
| + |
| +void MainThreadEventQueue::PopTouchEventOnMainThread() { |
| + std::unique_ptr<PendingTouchEvent> event; |
| + size_t size; |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + if (!touch_events_.empty()) |
| + event = touch_events_.Pop(); |
| + size = touch_events_.size(); |
| + } |
| + |
| + LOG(ERROR) << size; |
| + if (event) { |
| + client_->HandleEventOnMainThread(routing_id_, &event->event, event->latency, |
| + event->type); |
| + } |
| + |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| if (!touch_events_.empty()) { |
| - std::unique_ptr<PendingTouchEvent> event = touch_events_.Pop(); |
| - client_->SendEventToMainThread(routing_id_, &event->event, event->latency, |
| + SendTouchEventNotificationToMainThread(); |
| + } |
| + } |
| +} |
| + |
| +void MainThreadEventQueue::PopMouseEventOnMainThread() { |
| + std::unique_ptr<PendingMouseEvent> event; |
| + size_t size; |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + if (!mouse_events_.empty()) |
| + event = mouse_events_.Pop(); |
| + size = mouse_events_.size(); |
| + } |
| + |
| + if (event) { |
| + client_->HandleEventOnMainThread(routing_id_, &event->event, event->latency, |
| event->type); |
| - } else { |
| - touch_events_.set_state(WebInputEventQueueState::ITEM_NOT_PENDING); |
| + } |
| + |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + if (!mouse_events_.empty()) { |
| + SendMouseEventNotificationToMainThread(); |
| } |
| - } else { |
| - NOTREACHED() << "Invalid passive event type"; |
| } |
| } |
| +void MainThreadEventQueue::SendWheelEventNotificationToMainThread() { |
| + main_task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&MainThreadEventQueue::PopWheelEventOnMainThread, |
| + base::Unretained(this))); |
| +} |
| + |
| +void MainThreadEventQueue::SendTouchEventNotificationToMainThread() { |
| + main_task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&MainThreadEventQueue::PopTouchEventOnMainThread, |
| + base::Unretained(this))); |
| +} |
| + |
| +void MainThreadEventQueue::SendMouseEventNotificationToMainThread() { |
| + main_task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&MainThreadEventQueue::PopMouseEventOnMainThread, |
| + base::Unretained(this))); |
| +} |
| + |
| +void MainThreadEventQueue::QueueWheelEvent( |
| + const PendingMouseWheelEvent& event) { |
| + size_t pending; |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + pending = wheel_events_.size(); |
| + wheel_events_.Queue(event); |
| + } |
| + if (pending == 0) |
| + SendWheelEventNotificationToMainThread(); |
| +} |
| + |
| +void MainThreadEventQueue::QueueTouchEvent(const PendingTouchEvent& event) { |
| + size_t pending; |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + pending = touch_events_.size(); |
| + touch_events_.Queue(event); |
| + } |
| + if (pending == 0) |
| + SendTouchEventNotificationToMainThread(); |
| +} |
| + |
| +void MainThreadEventQueue::QueueMouseEvent(const PendingMouseEvent& event) { |
| + size_t pending; |
| + { |
| + base::AutoLock lock(event_queue_mutex_); |
| + pending = mouse_events_.size(); |
| + mouse_events_.Queue(event); |
| + } |
| + if (pending == 0) |
| + SendMouseEventNotificationToMainThread(); |
| +} |
| + |
| } // namespace content |