| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/renderer_host/input/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 InputAckHandler* ack_handler, | 72 InputAckHandler* ack_handler, |
| 73 int routing_id, | 73 int routing_id, |
| 74 const Config& config) | 74 const Config& config) |
| 75 : sender_(sender), | 75 : sender_(sender), |
| 76 client_(client), | 76 client_(client), |
| 77 ack_handler_(ack_handler), | 77 ack_handler_(ack_handler), |
| 78 routing_id_(routing_id), | 78 routing_id_(routing_id), |
| 79 frame_tree_node_id_(-1), | 79 frame_tree_node_id_(-1), |
| 80 select_message_pending_(false), | 80 select_message_pending_(false), |
| 81 move_caret_pending_(false), | 81 move_caret_pending_(false), |
| 82 mouse_move_pending_(false), | |
| 83 current_ack_source_(ACK_SOURCE_NONE), | 82 current_ack_source_(ACK_SOURCE_NONE), |
| 84 flush_requested_(false), | 83 flush_requested_(false), |
| 85 active_renderer_fling_count_(0), | 84 active_renderer_fling_count_(0), |
| 86 touch_scroll_started_sent_(false), | 85 touch_scroll_started_sent_(false), |
| 87 wheel_event_queue_(this, kDefaultWheelScrollTransactionMs), | 86 wheel_event_queue_(this, kDefaultWheelScrollTransactionMs), |
| 88 touch_event_queue_(this, config.touch_config), | 87 touch_event_queue_(this, config.touch_config), |
| 89 gesture_event_queue_(this, this, config.gesture_config), | 88 gesture_event_queue_(this, this, config.gesture_config), |
| 90 device_scale_factor_(1.f) { | 89 device_scale_factor_(1.f) { |
| 91 DCHECK(sender); | 90 DCHECK(sender); |
| 92 DCHECK(client); | 91 DCHECK(client); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 void InputRouterImpl::SendTouchEvent( | 180 void InputRouterImpl::SendTouchEvent( |
| 182 const TouchEventWithLatencyInfo& touch_event) { | 181 const TouchEventWithLatencyInfo& touch_event) { |
| 183 input_stream_validator_.Validate(touch_event.event); | 182 input_stream_validator_.Validate(touch_event.event); |
| 184 touch_event_queue_.QueueEvent(touch_event); | 183 touch_event_queue_.QueueEvent(touch_event); |
| 185 } | 184 } |
| 186 | 185 |
| 187 // Forwards MouseEvent without passing it through | 186 // Forwards MouseEvent without passing it through |
| 188 // TouchpadTapSuppressionController. | 187 // TouchpadTapSuppressionController. |
| 189 void InputRouterImpl::SendMouseEventImmediately( | 188 void InputRouterImpl::SendMouseEventImmediately( |
| 190 const MouseEventWithLatencyInfo& mouse_event) { | 189 const MouseEventWithLatencyInfo& mouse_event) { |
| 191 // Avoid spamming the renderer with mouse move events. It is important | 190 if (mouse_event.event.type == blink::WebInputEvent::MouseMove) |
| 192 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our | 191 mouse_move_queue_.push_back(mouse_event); |
| 193 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way | |
| 194 // more WM_MOUSEMOVE events than we wish to send to the renderer. | |
| 195 if (mouse_event.event.type == WebInputEvent::MouseMove) { | |
| 196 if (mouse_move_pending_) { | |
| 197 if (!next_mouse_move_) | |
| 198 next_mouse_move_.reset(new MouseEventWithLatencyInfo(mouse_event)); | |
| 199 else | |
| 200 next_mouse_move_->CoalesceWith(mouse_event); | |
| 201 return; | |
| 202 } | |
| 203 mouse_move_pending_ = true; | |
| 204 current_mouse_move_ = mouse_event; | |
| 205 } | |
| 206 | 192 |
| 207 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); | 193 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); |
| 208 } | 194 } |
| 209 | 195 |
| 210 void InputRouterImpl::SendTouchEventImmediately( | 196 void InputRouterImpl::SendTouchEventImmediately( |
| 211 const TouchEventWithLatencyInfo& touch_event) { | 197 const TouchEventWithLatencyInfo& touch_event) { |
| 212 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) { | 198 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) { |
| 213 touch_action_filter_.ResetTouchAction(); | 199 touch_action_filter_.ResetTouchAction(); |
| 214 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling | 200 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling |
| 215 // the timeout here will not take effect until the *following* touch | 201 // the timeout here will not take effect until the *following* touch |
| (...skipping 20 matching lines...) Expand all Loading... |
| 236 touch_event_queue_.SetIsMobileOptimizedSite(is_mobile_optimized); | 222 touch_event_queue_.SetIsMobileOptimizedSite(is_mobile_optimized); |
| 237 } | 223 } |
| 238 | 224 |
| 239 void InputRouterImpl::RequestNotificationWhenFlushed() { | 225 void InputRouterImpl::RequestNotificationWhenFlushed() { |
| 240 flush_requested_ = true; | 226 flush_requested_ = true; |
| 241 SignalFlushedIfNecessary(); | 227 SignalFlushedIfNecessary(); |
| 242 } | 228 } |
| 243 | 229 |
| 244 bool InputRouterImpl::HasPendingEvents() const { | 230 bool InputRouterImpl::HasPendingEvents() const { |
| 245 return !touch_event_queue_.empty() || !gesture_event_queue_.empty() || | 231 return !touch_event_queue_.empty() || !gesture_event_queue_.empty() || |
| 246 !key_queue_.empty() || mouse_move_pending_ || | 232 !key_queue_.empty() || !mouse_move_queue_.empty() || |
| 247 wheel_event_queue_.has_pending() || select_message_pending_ || | 233 wheel_event_queue_.has_pending() || select_message_pending_ || |
| 248 move_caret_pending_ || active_renderer_fling_count_ > 0; | 234 move_caret_pending_ || active_renderer_fling_count_ > 0; |
| 249 } | 235 } |
| 250 | 236 |
| 251 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { | 237 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 252 device_scale_factor_ = device_scale_factor; | 238 device_scale_factor_ = device_scale_factor; |
| 253 } | 239 } |
| 254 | 240 |
| 255 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { | 241 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { |
| 256 bool handled = true; | 242 bool handled = true; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 "InputRouterImpl::FilterAndSendWebInputEvent", | 349 "InputRouterImpl::FilterAndSendWebInputEvent", |
| 364 "type", | 350 "type", |
| 365 WebInputEventTraits::GetName(input_event.type)); | 351 WebInputEventTraits::GetName(input_event.type)); |
| 366 TRACE_EVENT_WITH_FLOW2("input,benchmark,devtools.timeline", | 352 TRACE_EVENT_WITH_FLOW2("input,benchmark,devtools.timeline", |
| 367 "LatencyInfo.Flow", | 353 "LatencyInfo.Flow", |
| 368 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), | 354 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), |
| 369 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | 355 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
| 370 "step", "SendInputEventUI", | 356 "step", "SendInputEventUI", |
| 371 "frameTreeNodeId", frame_tree_node_id_); | 357 "frameTreeNodeId", frame_tree_node_id_); |
| 372 | 358 |
| 373 // Any input event cancels a pending mouse move event. | |
| 374 next_mouse_move_.reset(); | |
| 375 | |
| 376 OfferToHandlers(input_event, latency_info); | 359 OfferToHandlers(input_event, latency_info); |
| 377 } | 360 } |
| 378 | 361 |
| 379 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event, | 362 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event, |
| 380 const ui::LatencyInfo& latency_info) { | 363 const ui::LatencyInfo& latency_info) { |
| 381 output_stream_validator_.Validate(input_event); | 364 output_stream_validator_.Validate(input_event); |
| 382 | 365 |
| 383 if (OfferToClient(input_event, latency_info)) | 366 if (OfferToClient(input_event, latency_info)) |
| 384 return; | 367 return; |
| 385 | 368 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 401 bool InputRouterImpl::OfferToClient(const WebInputEvent& input_event, | 384 bool InputRouterImpl::OfferToClient(const WebInputEvent& input_event, |
| 402 const ui::LatencyInfo& latency_info) { | 385 const ui::LatencyInfo& latency_info) { |
| 403 bool consumed = false; | 386 bool consumed = false; |
| 404 | 387 |
| 405 InputEventAckState filter_ack = | 388 InputEventAckState filter_ack = |
| 406 client_->FilterInputEvent(input_event, latency_info); | 389 client_->FilterInputEvent(input_event, latency_info); |
| 407 switch (filter_ack) { | 390 switch (filter_ack) { |
| 408 case INPUT_EVENT_ACK_STATE_CONSUMED: | 391 case INPUT_EVENT_ACK_STATE_CONSUMED: |
| 409 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: | 392 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: |
| 410 // Send the ACK and early exit. | 393 // Send the ACK and early exit. |
| 411 next_mouse_move_.reset(); | |
| 412 ProcessInputEventAck( | 394 ProcessInputEventAck( |
| 413 input_event.type, filter_ack, latency_info, | 395 input_event.type, filter_ack, latency_info, |
| 414 WebInputEventTraits::GetUniqueTouchEventId(input_event), CLIENT); | 396 WebInputEventTraits::GetUniqueTouchEventId(input_event), CLIENT); |
| 415 // WARNING: |this| may be deleted at this point. | 397 // WARNING: |this| may be deleted at this point. |
| 416 consumed = true; | 398 consumed = true; |
| 417 break; | 399 break; |
| 418 case INPUT_EVENT_ACK_STATE_UNKNOWN: | 400 case INPUT_EVENT_ACK_STATE_UNKNOWN: |
| 419 // Simply drop the event. | 401 // Simply drop the event. |
| 420 consumed = true; | 402 consumed = true; |
| 421 break; | 403 break; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 // TODO(jdduke): crbug.com/274029 - Make ack-triggered shutdown async. | 572 // TODO(jdduke): crbug.com/274029 - Make ack-triggered shutdown async. |
| 591 } | 573 } |
| 592 } | 574 } |
| 593 | 575 |
| 594 void InputRouterImpl::ProcessMouseAck(blink::WebInputEvent::Type type, | 576 void InputRouterImpl::ProcessMouseAck(blink::WebInputEvent::Type type, |
| 595 InputEventAckState ack_result, | 577 InputEventAckState ack_result, |
| 596 const ui::LatencyInfo& latency) { | 578 const ui::LatencyInfo& latency) { |
| 597 if (type != WebInputEvent::MouseMove) | 579 if (type != WebInputEvent::MouseMove) |
| 598 return; | 580 return; |
| 599 | 581 |
| 600 current_mouse_move_.latency.AddNewLatencyFrom(latency); | 582 if (mouse_move_queue_.empty()) { |
| 601 ack_handler_->OnMouseEventAck(current_mouse_move_, ack_result); | 583 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_ACK); |
| 602 | 584 } else { |
| 603 DCHECK(mouse_move_pending_); | 585 MouseEventWithLatencyInfo front_item = mouse_move_queue_.front(); |
| 604 mouse_move_pending_ = false; | 586 front_item.latency.AddNewLatencyFrom(latency); |
| 605 | 587 mouse_move_queue_.pop_front(); |
| 606 if (next_mouse_move_) { | 588 ack_handler_->OnMouseEventAck(front_item, ack_result); |
| 607 DCHECK(next_mouse_move_->event.type == WebInputEvent::MouseMove); | |
| 608 std::unique_ptr<MouseEventWithLatencyInfo> next_mouse_move = | |
| 609 std::move(next_mouse_move_); | |
| 610 SendMouseEvent(*next_mouse_move); | |
| 611 } | 589 } |
| 612 } | 590 } |
| 613 | 591 |
| 614 void InputRouterImpl::ProcessWheelAck(InputEventAckState ack_result, | 592 void InputRouterImpl::ProcessWheelAck(InputEventAckState ack_result, |
| 615 const ui::LatencyInfo& latency) { | 593 const ui::LatencyInfo& latency) { |
| 616 wheel_event_queue_.ProcessMouseWheelAck(ack_result, latency); | 594 wheel_event_queue_.ProcessMouseWheelAck(ack_result, latency); |
| 617 } | 595 } |
| 618 | 596 |
| 619 void InputRouterImpl::ProcessGestureAck(WebInputEvent::Type type, | 597 void InputRouterImpl::ProcessGestureAck(WebInputEvent::Type type, |
| 620 InputEventAckState ack_result, | 598 InputEventAckState ack_result, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 632 |
| 655 flush_requested_ = false; | 633 flush_requested_ = false; |
| 656 client_->DidFlush(); | 634 client_->DidFlush(); |
| 657 } | 635 } |
| 658 | 636 |
| 659 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { | 637 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { |
| 660 frame_tree_node_id_ = frameTreeNodeId; | 638 frame_tree_node_id_ = frameTreeNodeId; |
| 661 } | 639 } |
| 662 | 640 |
| 663 } // namespace content | 641 } // namespace content |
| OLD | NEW |