| OLD | NEW |
| 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 #include "content/renderer/input/main_thread_event_queue.h" | 5 #include "content/renderer/input/main_thread_event_queue.h" |
| 6 | 6 |
| 7 #include "content/common/input/event_with_latency_info.h" | 7 #include "content/common/input/event_with_latency_info.h" |
| 8 #include "content/common/input_messages.h" | 8 #include "content/common/input_messages.h" |
| 9 #include "content/renderer/render_thread_impl.h" | |
| 10 | 9 |
| 11 namespace content { | 10 namespace content { |
| 12 | 11 |
| 13 EventWithDispatchType::EventWithDispatchType( | 12 EventWithDispatchType::EventWithDispatchType( |
| 14 ui::ScopedWebInputEvent event, | 13 ui::ScopedWebInputEvent event, |
| 15 const ui::LatencyInfo& latency, | 14 const ui::LatencyInfo& latency, |
| 16 InputEventDispatchType dispatch_type) | 15 InputEventDispatchType dispatch_type) |
| 17 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency), | 16 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency), |
| 18 dispatch_type_(dispatch_type) {} | 17 dispatch_type_(dispatch_type) {} |
| 19 | 18 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 // We should only have blocking touch events that need coalescing. | 31 // We should only have blocking touch events that need coalescing. |
| 33 eventsToAck_.push_back( | 32 eventsToAck_.push_back( |
| 34 ui::WebInputEventTraits::GetUniqueTouchEventId(other.event())); | 33 ui::WebInputEventTraits::GetUniqueTouchEventId(other.event())); |
| 35 } | 34 } |
| 36 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other); | 35 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other); |
| 37 } | 36 } |
| 38 | 37 |
| 39 MainThreadEventQueue::MainThreadEventQueue( | 38 MainThreadEventQueue::MainThreadEventQueue( |
| 40 int routing_id, | 39 int routing_id, |
| 41 MainThreadEventQueueClient* client, | 40 MainThreadEventQueueClient* client, |
| 42 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) | 41 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| 42 blink::scheduler::RendererScheduler* renderer_scheduler) |
| 43 : routing_id_(routing_id), | 43 : routing_id_(routing_id), |
| 44 client_(client), | 44 client_(client), |
| 45 is_flinging_(false), | 45 is_flinging_(false), |
| 46 last_touch_start_forced_nonblocking_due_to_fling_(false), | 46 last_touch_start_forced_nonblocking_due_to_fling_(false), |
| 47 enable_fling_passive_listener_flag_(base::FeatureList::IsEnabled( | 47 enable_fling_passive_listener_flag_(base::FeatureList::IsEnabled( |
| 48 features::kPassiveEventListenersDueToFling)), | 48 features::kPassiveEventListenersDueToFling)), |
| 49 main_task_runner_(main_task_runner) {} | 49 main_task_runner_(main_task_runner), |
| 50 renderer_scheduler_(renderer_scheduler) {} |
| 50 | 51 |
| 51 MainThreadEventQueue::~MainThreadEventQueue() {} | 52 MainThreadEventQueue::~MainThreadEventQueue() {} |
| 52 | 53 |
| 53 bool MainThreadEventQueue::HandleEvent( | 54 bool MainThreadEventQueue::HandleEvent( |
| 54 ui::ScopedWebInputEvent event, | 55 ui::ScopedWebInputEvent event, |
| 55 const ui::LatencyInfo& latency, | 56 const ui::LatencyInfo& latency, |
| 56 InputEventDispatchType original_dispatch_type, | 57 InputEventDispatchType original_dispatch_type, |
| 57 InputEventAckState ack_result) { | 58 InputEventAckState ack_result) { |
| 58 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || | 59 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || |
| 59 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); | 60 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 in_flight_event_->latencyInfo(), | 128 in_flight_event_->latencyInfo(), |
| 128 dispatch_type); | 129 dispatch_type); |
| 129 } | 130 } |
| 130 | 131 |
| 131 in_flight_event_.reset(); | 132 in_flight_event_.reset(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type, | 135 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type, |
| 135 InputEventAckState ack_result) { | 136 InputEventAckState ack_result) { |
| 136 if (in_flight_event_) { | 137 if (in_flight_event_) { |
| 137 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); | |
| 138 // Send acks for blocking touch events. | 138 // Send acks for blocking touch events. |
| 139 for (const auto id : in_flight_event_->eventsToAck()) { | 139 for (const auto id : in_flight_event_->eventsToAck()) { |
| 140 client_->SendInputEventAck(routing_id_, type, ack_result, id); | 140 client_->SendInputEventAck(routing_id_, type, ack_result, id); |
| 141 if (render_thread_impl) { | 141 if (renderer_scheduler_) { |
| 142 render_thread_impl->GetRendererScheduler() | 142 renderer_scheduler_->DidHandleInputEventOnMainThread( |
| 143 ->DidHandleInputEventOnMainThread(in_flight_event_->event()); | 143 in_flight_event_->event()); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 void MainThreadEventQueue::SendEventNotificationToMainThread() { | 149 void MainThreadEventQueue::SendEventNotificationToMainThread() { |
| 150 main_task_runner_->PostTask( | 150 main_task_runner_->PostTask( |
| 151 FROM_HERE, base::Bind(&MainThreadEventQueue::PopEventOnMainThread, | 151 FROM_HERE, base::Bind(&MainThreadEventQueue::PopEventOnMainThread, |
| 152 this)); | 152 this)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void MainThreadEventQueue::QueueEvent( | 155 void MainThreadEventQueue::QueueEvent( |
| 156 std::unique_ptr<EventWithDispatchType> event) { | 156 std::unique_ptr<EventWithDispatchType> event) { |
| 157 bool send_notification = false; | 157 bool send_notification = false; |
| 158 { | 158 { |
| 159 base::AutoLock lock(event_queue_lock_); | 159 base::AutoLock lock(event_queue_lock_); |
| 160 size_t size_before = events_.size(); | 160 size_t size_before = events_.size(); |
| 161 events_.Queue(std::move(event)); | 161 events_.Queue(std::move(event)); |
| 162 send_notification = events_.size() != size_before; | 162 send_notification = events_.size() != size_before; |
| 163 } | 163 } |
| 164 if (send_notification) | 164 if (send_notification) |
| 165 SendEventNotificationToMainThread(); | 165 SendEventNotificationToMainThread(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace content | 168 } // namespace content |
| OLD | NEW |