Chromium Code Reviews| 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/immediate_input_router.h" | 5 #include "content/browser/renderer_host/input/immediate_input_router.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "content/browser/renderer_host/input/gesture_event_filter.h" | 9 #include "content/browser/renderer_host/input/gesture_event_filter.h" |
| 10 #include "content/browser/renderer_host/input/input_ack_handler.h" | |
| 10 #include "content/browser/renderer_host/input/input_router_client.h" | 11 #include "content/browser/renderer_host/input/input_router_client.h" |
| 11 #include "content/browser/renderer_host/input/touch_event_queue.h" | 12 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 12 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle r.h" | 13 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle r.h" |
| 13 #include "content/browser/renderer_host/render_process_host_impl.h" | 14 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 14 #include "content/common/content_constants_internal.h" | 15 #include "content/common/content_constants_internal.h" |
| 15 #include "content/common/edit_command.h" | 16 #include "content/common/edit_command.h" |
| 16 #include "content/common/input_messages.h" | 17 #include "content/common/input_messages.h" |
| 17 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 18 #include "content/port/common/input_event_ack_state.h" | 19 #include "content/port/common/input_event_ack_state.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: return "NO_CONSUMER_EXISTS"; | 65 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: return "NO_CONSUMER_EXISTS"; |
| 65 default: | 66 default: |
| 66 DLOG(WARNING) << "Unhandled InputEventAckState in GetEventAckName.\n"; | 67 DLOG(WARNING) << "Unhandled InputEventAckState in GetEventAckName.\n"; |
| 67 break; | 68 break; |
| 68 } | 69 } |
| 69 return ""; | 70 return ""; |
| 70 } | 71 } |
| 71 | 72 |
| 72 } // namespace | 73 } // namespace |
| 73 | 74 |
| 74 ImmediateInputRouter::ImmediateInputRouter( | 75 ImmediateInputRouter::ImmediateInputRouter(RenderProcessHost* process, |
| 75 RenderProcessHost* process, | 76 InputRouterClient* client, |
| 76 InputRouterClient* client, | 77 InputAckHandler* ack_handler, |
| 77 int routing_id) | 78 int routing_id) |
| 78 : process_(process), | 79 : process_(process), |
| 79 client_(client), | 80 client_(client), |
| 81 ack_handler_(ack_handler), | |
| 80 routing_id_(routing_id), | 82 routing_id_(routing_id), |
| 81 select_range_pending_(false), | 83 select_range_pending_(false), |
| 82 move_caret_pending_(false), | 84 move_caret_pending_(false), |
| 83 mouse_move_pending_(false), | 85 mouse_move_pending_(false), |
| 84 mouse_wheel_pending_(false), | 86 mouse_wheel_pending_(false), |
| 85 has_touch_handler_(false), | 87 has_touch_handler_(false), |
| 86 touch_event_queue_(new TouchEventQueue(this)), | 88 touch_event_queue_(new TouchEventQueue(this)), |
| 87 gesture_event_filter_(new GestureEventFilter(this)) { | 89 gesture_event_filter_(new GestureEventFilter(this)) { |
| 88 enable_no_touch_to_renderer_while_scrolling_ = | 90 enable_no_touch_to_renderer_while_scrolling_ = |
| 89 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 91 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 90 switches::kNoTouchToRendererWhileScrolling) == "1"; | 92 switches::kNoTouchToRendererWhileScrolling) == "1"; |
|
aelias_OOO_until_Jul13
2013/09/09 22:31:14
I don't understand why == "1", isn't this a boolea
jdduke (slow)
2013/09/10 19:41:16
I'd be happy to change it, but that wasn't my addi
| |
| 91 DCHECK(process); | 93 DCHECK(process); |
| 92 DCHECK(client); | 94 DCHECK(client); |
| 93 } | 95 } |
| 94 | 96 |
| 95 ImmediateInputRouter::~ImmediateInputRouter() { | 97 ImmediateInputRouter::~ImmediateInputRouter() { |
| 96 } | 98 } |
| 97 | 99 |
| 98 bool ImmediateInputRouter::SendInput(IPC::Message* message) { | 100 void ImmediateInputRouter::Flush() { |
| 101 NOTREACHED() << "ImmediateInputRouter will never request a flush."; | |
| 102 } | |
| 103 | |
| 104 bool ImmediateInputRouter::SendInput(scoped_ptr<IPC::Message> message) { | |
| 99 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart); | 105 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart); |
| 100 scoped_ptr<IPC::Message> scoped_message(message); | 106 switch (message->type()) { |
| 101 switch (scoped_message->type()) { | |
| 102 // Check for types that require an ACK. | 107 // Check for types that require an ACK. |
| 103 case InputMsg_SelectRange::ID: | 108 case InputMsg_SelectRange::ID: |
| 104 return SendSelectRange(scoped_message.release()); | 109 return SendSelectRange(message.Pass()); |
| 105 case InputMsg_MoveCaret::ID: | 110 case InputMsg_MoveCaret::ID: |
| 106 return SendMoveCaret(scoped_message.release()); | 111 return SendMoveCaret(message.Pass()); |
| 107 case InputMsg_HandleInputEvent::ID: | 112 case InputMsg_HandleInputEvent::ID: |
| 108 NOTREACHED() << "WebInputEvents should never be sent via SendInput."; | 113 NOTREACHED() << "WebInputEvents should never be sent via SendInput."; |
| 109 return false; | 114 return false; |
| 110 default: | 115 default: |
| 111 return Send(scoped_message.release()); | 116 return Send(message.release()); |
| 112 } | 117 } |
| 113 } | 118 } |
| 114 | 119 |
| 115 void ImmediateInputRouter::SendMouseEvent( | 120 void ImmediateInputRouter::SendMouseEvent( |
| 116 const MouseEventWithLatencyInfo& mouse_event) { | 121 const MouseEventWithLatencyInfo& mouse_event) { |
| 117 if (!client_->OnSendMouseEvent(mouse_event)) | 122 if (!client_->OnSendMouseEvent(mouse_event)) |
| 118 return; | 123 return; |
| 119 | 124 |
| 120 if (mouse_event.event.type == WebInputEvent::MouseDown && | 125 if (mouse_event.event.type == WebInputEvent::MouseDown && |
| 121 gesture_event_filter_->GetTouchpadTapSuppressionController()-> | 126 gesture_event_filter_->GetTouchpadTapSuppressionController()-> |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 IPC_BEGIN_MESSAGE_MAP_EX(ImmediateInputRouter, message, message_is_ok) | 297 IPC_BEGIN_MESSAGE_MAP_EX(ImmediateInputRouter, message, message_is_ok) |
| 293 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) | 298 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) |
| 294 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) | 299 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) |
| 295 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) | 300 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) |
| 296 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 301 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
| 297 OnHasTouchEventHandlers) | 302 OnHasTouchEventHandlers) |
| 298 IPC_MESSAGE_UNHANDLED(handled = false) | 303 IPC_MESSAGE_UNHANDLED(handled = false) |
| 299 IPC_END_MESSAGE_MAP() | 304 IPC_END_MESSAGE_MAP() |
| 300 | 305 |
| 301 if (!message_is_ok) | 306 if (!message_is_ok) |
| 302 client_->OnUnexpectedEventAck(true); | 307 ack_handler_->OnUnexpectedEventAck(true); |
| 303 | 308 |
| 304 return handled; | 309 return handled; |
| 305 } | 310 } |
| 306 | 311 |
| 307 void ImmediateInputRouter::OnTouchEventAck( | 312 void ImmediateInputRouter::OnTouchEventAck( |
| 308 const TouchEventWithLatencyInfo& event, | 313 const TouchEventWithLatencyInfo& event, |
| 309 InputEventAckState ack_result) { | 314 InputEventAckState ack_result) { |
| 310 client_->OnTouchEventAck(event, ack_result); | 315 ack_handler_->OnTouchEventAck(event, ack_result); |
| 311 } | 316 } |
| 312 | 317 |
| 313 bool ImmediateInputRouter::SendSelectRange(IPC::Message* message) { | 318 bool ImmediateInputRouter::SendSelectRange(scoped_ptr<IPC::Message> message) { |
| 314 DCHECK(message->type() == InputMsg_SelectRange::ID); | 319 DCHECK(message->type() == InputMsg_SelectRange::ID); |
| 315 if (select_range_pending_) { | 320 if (select_range_pending_) { |
| 316 next_selection_range_.reset(message); | 321 next_selection_range_ = message.Pass(); |
| 317 return true; | 322 return true; |
| 318 } | 323 } |
| 319 | 324 |
| 320 select_range_pending_ = true; | 325 select_range_pending_ = true; |
| 321 return Send(message); | 326 return Send(message.release()); |
| 322 } | 327 } |
| 323 | 328 |
| 324 bool ImmediateInputRouter::SendMoveCaret(IPC::Message* message) { | 329 bool ImmediateInputRouter::SendMoveCaret(scoped_ptr<IPC::Message> message) { |
| 325 DCHECK(message->type() == InputMsg_MoveCaret::ID); | 330 DCHECK(message->type() == InputMsg_MoveCaret::ID); |
| 326 if (move_caret_pending_) { | 331 if (move_caret_pending_) { |
| 327 next_move_caret_.reset(message); | 332 next_move_caret_ = message.Pass(); |
| 328 return true; | 333 return true; |
| 329 } | 334 } |
| 330 | 335 |
| 331 move_caret_pending_ = true; | 336 move_caret_pending_ = true; |
| 332 return Send(message); | 337 return Send(message.release()); |
| 333 } | 338 } |
| 334 | 339 |
| 335 bool ImmediateInputRouter::Send(IPC::Message* message) { | 340 bool ImmediateInputRouter::Send(IPC::Message* message) { |
| 336 return process_->Send(message); | 341 return process_->Send(message); |
| 337 } | 342 } |
| 338 | 343 |
| 339 void ImmediateInputRouter::SendWebInputEvent( | 344 void ImmediateInputRouter::SendWebInputEvent( |
| 340 const WebInputEvent& input_event, | 345 const WebInputEvent& input_event, |
| 341 const ui::LatencyInfo& latency_info, | 346 const ui::LatencyInfo& latency_info, |
| 342 bool is_keyboard_shortcut) { | 347 bool is_keyboard_shortcut) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 UMA_HISTOGRAM_TIMES("MPArch.IIR_InputEventDelta", delta); | 437 UMA_HISTOGRAM_TIMES("MPArch.IIR_InputEventDelta", delta); |
| 433 | 438 |
| 434 client_->DecrementInFlightEventCount(); | 439 client_->DecrementInFlightEventCount(); |
| 435 | 440 |
| 436 ProcessInputEventAck(event_type, ack_result, latency_info); | 441 ProcessInputEventAck(event_type, ack_result, latency_info); |
| 437 } | 442 } |
| 438 | 443 |
| 439 void ImmediateInputRouter::OnMsgMoveCaretAck() { | 444 void ImmediateInputRouter::OnMsgMoveCaretAck() { |
| 440 move_caret_pending_ = false; | 445 move_caret_pending_ = false; |
| 441 if (next_move_caret_) | 446 if (next_move_caret_) |
| 442 SendMoveCaret(next_move_caret_.release()); | 447 SendMoveCaret(next_move_caret_.Pass()); |
| 443 } | 448 } |
| 444 | 449 |
| 445 void ImmediateInputRouter::OnSelectRangeAck() { | 450 void ImmediateInputRouter::OnSelectRangeAck() { |
| 446 select_range_pending_ = false; | 451 select_range_pending_ = false; |
| 447 if (next_selection_range_) | 452 if (next_selection_range_) |
| 448 SendSelectRange(next_selection_range_.release()); | 453 SendSelectRange(next_selection_range_.Pass()); |
| 449 } | 454 } |
| 450 | 455 |
| 451 void ImmediateInputRouter::OnHasTouchEventHandlers(bool has_handlers) { | 456 void ImmediateInputRouter::OnHasTouchEventHandlers(bool has_handlers) { |
| 452 if (has_touch_handler_ == has_handlers) | 457 if (has_touch_handler_ == has_handlers) |
| 453 return; | 458 return; |
| 454 has_touch_handler_ = has_handlers; | 459 has_touch_handler_ = has_handlers; |
| 455 if (!has_handlers) | 460 if (!has_handlers) |
| 456 touch_event_queue_->FlushQueue(); | 461 touch_event_queue_->FlushQueue(); |
| 457 client_->OnHasTouchEventHandlers(has_handlers); | 462 client_->OnHasTouchEventHandlers(has_handlers); |
| 458 } | 463 } |
| 459 | 464 |
| 460 void ImmediateInputRouter::ProcessInputEventAck( | 465 void ImmediateInputRouter::ProcessInputEventAck( |
| 461 WebInputEvent::Type event_type, | 466 WebInputEvent::Type event_type, |
| 462 InputEventAckState ack_result, | 467 InputEventAckState ack_result, |
| 463 const ui::LatencyInfo& latency_info) { | 468 const ui::LatencyInfo& latency_info) { |
| 464 TRACE_EVENT1("input", "ImmediateInputRouter::ProcessInputEventAck", | 469 TRACE_EVENT1("input", "ImmediateInputRouter::ProcessInputEventAck", |
| 465 "ack", GetEventAckName(ack_result)); | 470 "ack", GetEventAckName(ack_result)); |
| 466 | 471 |
| 467 int type = static_cast<int>(event_type); | 472 int type = static_cast<int>(event_type); |
| 468 if (type < WebInputEvent::Undefined) { | 473 if (type < WebInputEvent::Undefined) { |
| 469 client_->OnUnexpectedEventAck(true); | 474 ack_handler_->OnUnexpectedEventAck(true); |
| 470 } else if (type == WebInputEvent::MouseMove) { | 475 } else if (type == WebInputEvent::MouseMove) { |
| 471 mouse_move_pending_ = false; | 476 mouse_move_pending_ = false; |
| 472 | 477 |
| 473 // now, we can send the next mouse move event | 478 // now, we can send the next mouse move event |
| 474 if (next_mouse_move_) { | 479 if (next_mouse_move_) { |
| 475 DCHECK(next_mouse_move_->event.type == WebInputEvent::MouseMove); | 480 DCHECK(next_mouse_move_->event.type == WebInputEvent::MouseMove); |
| 476 scoped_ptr<MouseEventWithLatencyInfo> next_mouse_move | 481 scoped_ptr<MouseEventWithLatencyInfo> next_mouse_move |
| 477 = next_mouse_move_.Pass(); | 482 = next_mouse_move_.Pass(); |
| 478 SendMouseEvent(*next_mouse_move); | 483 SendMouseEvent(*next_mouse_move); |
| 479 } | 484 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 509 LOG(ERROR) << "Got a KeyEvent back from the renderer but we " | 514 LOG(ERROR) << "Got a KeyEvent back from the renderer but we " |
| 510 << "don't seem to have sent it to the renderer!"; | 515 << "don't seem to have sent it to the renderer!"; |
| 511 } else if (key_queue_.front().type != type) { | 516 } else if (key_queue_.front().type != type) { |
| 512 LOG(ERROR) << "We seem to have a different key type sent from " | 517 LOG(ERROR) << "We seem to have a different key type sent from " |
| 513 << "the renderer. (" << key_queue_.front().type << " vs. " | 518 << "the renderer. (" << key_queue_.front().type << " vs. " |
| 514 << type << "). Ignoring event."; | 519 << type << "). Ignoring event."; |
| 515 | 520 |
| 516 // Something must be wrong. Clear the |key_queue_| and char event | 521 // Something must be wrong. Clear the |key_queue_| and char event |
| 517 // suppression so that we can resume from the error. | 522 // suppression so that we can resume from the error. |
| 518 key_queue_.clear(); | 523 key_queue_.clear(); |
| 519 client_->OnUnexpectedEventAck(false); | 524 ack_handler_->OnUnexpectedEventAck(false); |
| 520 } else { | 525 } else { |
| 521 NativeWebKeyboardEvent front_item = key_queue_.front(); | 526 NativeWebKeyboardEvent front_item = key_queue_.front(); |
| 522 key_queue_.pop_front(); | 527 key_queue_.pop_front(); |
| 523 | 528 |
| 524 client_->OnKeyboardEventAck(front_item, ack_result); | 529 ack_handler_->OnKeyboardEventAck(front_item, ack_result); |
| 525 | |
| 526 // WARNING: This ImmediateInputRouter can be deallocated at this point | 530 // WARNING: This ImmediateInputRouter can be deallocated at this point |
| 527 // (i.e. in the case of Ctrl+W, where the call to | 531 // (i.e. in the case of Ctrl+W, where the call to |
| 528 // HandleKeyboardEvent destroys this ImmediateInputRouter). | 532 // HandleKeyboardEvent destroys this ImmediateInputRouter). |
| 529 } | 533 } |
| 530 } | 534 } |
| 531 | 535 |
| 532 void ImmediateInputRouter::ProcessWheelAck(InputEventAckState ack_result) { | 536 void ImmediateInputRouter::ProcessWheelAck(InputEventAckState ack_result) { |
| 533 mouse_wheel_pending_ = false; | 537 mouse_wheel_pending_ = false; |
| 534 | 538 |
| 535 // Process the unhandled wheel event here before calling | 539 // Process the unhandled wheel event here before calling |
| 536 // ForwardWheelEventWithLatencyInfo() since it will mutate | 540 // ForwardWheelEventWithLatencyInfo() since it will mutate |
| 537 // current_wheel_event_. | 541 // current_wheel_event_. |
| 538 client_->OnWheelEventAck(current_wheel_event_.event, ack_result); | 542 ack_handler_->OnWheelEventAck(current_wheel_event_.event, ack_result); |
| 539 | 543 |
| 540 // Now send the next (coalesced) mouse wheel event. | 544 // Now send the next (coalesced) mouse wheel event. |
| 541 if (!coalesced_mouse_wheel_events_.empty()) { | 545 if (!coalesced_mouse_wheel_events_.empty()) { |
| 542 MouseWheelEventWithLatencyInfo next_wheel_event = | 546 MouseWheelEventWithLatencyInfo next_wheel_event = |
| 543 coalesced_mouse_wheel_events_.front(); | 547 coalesced_mouse_wheel_events_.front(); |
| 544 coalesced_mouse_wheel_events_.pop_front(); | 548 coalesced_mouse_wheel_events_.pop_front(); |
| 545 SendWheelEvent(next_wheel_event); | 549 SendWheelEvent(next_wheel_event); |
| 546 } | 550 } |
| 547 } | 551 } |
| 548 | 552 |
| 549 void ImmediateInputRouter::ProcessGestureAck(int type, | 553 void ImmediateInputRouter::ProcessGestureAck(int type, |
| 550 InputEventAckState ack_result) { | 554 InputEventAckState ack_result) { |
| 551 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); | 555 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); |
| 552 client_->OnGestureEventAck( | 556 ack_handler_->OnGestureEventAck( |
| 553 gesture_event_filter_->GetGestureEventAwaitingAck(), ack_result); | 557 gesture_event_filter_->GetGestureEventAwaitingAck(), ack_result); |
| 554 gesture_event_filter_->ProcessGestureAck(processed, type); | 558 gesture_event_filter_->ProcessGestureAck(processed, type); |
| 555 } | 559 } |
| 556 | 560 |
| 557 void ImmediateInputRouter::ProcessTouchAck( | 561 void ImmediateInputRouter::ProcessTouchAck( |
| 558 InputEventAckState ack_result, | 562 InputEventAckState ack_result, |
| 559 const ui::LatencyInfo& latency_info) { | 563 const ui::LatencyInfo& latency_info) { |
| 560 // |touch_event_queue_| will forward to OnTouchEventAck when appropriate. | 564 // |touch_event_queue_| will forward to OnTouchEventAck when appropriate. |
| 561 touch_event_queue_->ProcessTouchAck(ack_result, latency_info); | 565 touch_event_queue_->ProcessTouchAck(ack_result, latency_info); |
| 562 } | 566 } |
| 563 | 567 |
| 564 void ImmediateInputRouter::HandleGestureScroll( | 568 void ImmediateInputRouter::HandleGestureScroll( |
| 565 const GestureEventWithLatencyInfo& gesture_event) { | 569 const GestureEventWithLatencyInfo& gesture_event) { |
| 566 if (!enable_no_touch_to_renderer_while_scrolling_) | 570 if (!enable_no_touch_to_renderer_while_scrolling_) |
| 567 return; | 571 return; |
| 568 | 572 |
| 569 // Once scrolling is started stop forwarding touch move events to renderer. | 573 // Once scrolling is started stop forwarding touch move events to renderer. |
| 570 if (gesture_event.event.type == WebInputEvent::GestureScrollBegin) | 574 if (gesture_event.event.type == WebInputEvent::GestureScrollBegin) |
| 571 touch_event_queue_->set_no_touch_move_to_renderer(true); | 575 touch_event_queue_->set_no_touch_move_to_renderer(true); |
| 572 | 576 |
| 573 if (gesture_event.event.type == WebInputEvent::GestureScrollEnd || | 577 if (gesture_event.event.type == WebInputEvent::GestureScrollEnd || |
| 574 gesture_event.event.type == WebInputEvent::GestureFlingStart) { | 578 gesture_event.event.type == WebInputEvent::GestureFlingStart) { |
| 575 touch_event_queue_->set_no_touch_move_to_renderer(false); | 579 touch_event_queue_->set_no_touch_move_to_renderer(false); |
| 576 } | 580 } |
| 577 } | 581 } |
| 578 | 582 |
| 579 } // namespace content | 583 } // namespace content |
| OLD | NEW |