| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 case InputMsg_HandleInputEvent::ID: | 114 case InputMsg_HandleInputEvent::ID: |
| 115 NOTREACHED() << "WebInputEvents should never be sent via SendInput."; | 115 NOTREACHED() << "WebInputEvents should never be sent via SendInput."; |
| 116 return false; | 116 return false; |
| 117 default: | 117 default: |
| 118 return Send(message.release()); | 118 return Send(message.release()); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 void InputRouterImpl::SendMouseEvent( | 122 void InputRouterImpl::SendMouseEvent( |
| 123 const MouseEventWithLatencyInfo& mouse_event) { | 123 const MouseEventWithLatencyInfo& mouse_event) { |
| 124 if (mouse_event.event.type == WebInputEvent::MouseDown && | 124 if (mouse_event.event.type() == WebInputEvent::MouseDown && |
| 125 gesture_event_queue_.GetTouchpadTapSuppressionController()-> | 125 gesture_event_queue_.GetTouchpadTapSuppressionController() |
| 126 ShouldDeferMouseDown(mouse_event)) | 126 ->ShouldDeferMouseDown(mouse_event)) |
| 127 return; | 127 return; |
| 128 if (mouse_event.event.type == WebInputEvent::MouseUp && | 128 if (mouse_event.event.type() == WebInputEvent::MouseUp && |
| 129 gesture_event_queue_.GetTouchpadTapSuppressionController()-> | 129 gesture_event_queue_.GetTouchpadTapSuppressionController() |
| 130 ShouldSuppressMouseUp()) | 130 ->ShouldSuppressMouseUp()) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 SendMouseEventImmediately(mouse_event); | 133 SendMouseEventImmediately(mouse_event); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void InputRouterImpl::SendWheelEvent( | 136 void InputRouterImpl::SendWheelEvent( |
| 137 const MouseWheelEventWithLatencyInfo& wheel_event) { | 137 const MouseWheelEventWithLatencyInfo& wheel_event) { |
| 138 wheel_event_queue_.QueueEvent(wheel_event); | 138 wheel_event_queue_.QueueEvent(wheel_event); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void InputRouterImpl::SendKeyboardEvent( | 141 void InputRouterImpl::SendKeyboardEvent( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 input_stream_validator_.Validate(original_gesture_event.event); | 157 input_stream_validator_.Validate(original_gesture_event.event); |
| 158 | 158 |
| 159 GestureEventWithLatencyInfo gesture_event(original_gesture_event); | 159 GestureEventWithLatencyInfo gesture_event(original_gesture_event); |
| 160 | 160 |
| 161 if (touch_action_filter_.FilterGestureEvent(&gesture_event.event)) | 161 if (touch_action_filter_.FilterGestureEvent(&gesture_event.event)) |
| 162 return; | 162 return; |
| 163 | 163 |
| 164 wheel_event_queue_.OnGestureScrollEvent(gesture_event); | 164 wheel_event_queue_.OnGestureScrollEvent(gesture_event); |
| 165 | 165 |
| 166 if (gesture_event.event.sourceDevice == blink::WebGestureDeviceTouchscreen) { | 166 if (gesture_event.event.sourceDevice == blink::WebGestureDeviceTouchscreen) { |
| 167 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { | 167 if (gesture_event.event.type() == |
| 168 blink::WebInputEvent::GestureScrollBegin) { |
| 168 touch_scroll_started_sent_ = false; | 169 touch_scroll_started_sent_ = false; |
| 169 } else if(!touch_scroll_started_sent_ | 170 } else if (!touch_scroll_started_sent_ && |
| 170 && gesture_event.event.type == | 171 gesture_event.event.type() == |
| 171 blink::WebInputEvent::GestureScrollUpdate) { | 172 blink::WebInputEvent::GestureScrollUpdate) { |
| 172 // A touch scroll hasn't really started until the first | 173 // A touch scroll hasn't really started until the first |
| 173 // GestureScrollUpdate event. Eg. if the page consumes all touchmoves | 174 // GestureScrollUpdate event. Eg. if the page consumes all touchmoves |
| 174 // then no scrolling really ever occurs (even though we still send | 175 // then no scrolling really ever occurs (even though we still send |
| 175 // GestureScrollBegin). | 176 // GestureScrollBegin). |
| 176 touch_event_queue_.PrependTouchScrollNotification(); | 177 touch_event_queue_.PrependTouchScrollNotification(); |
| 177 touch_scroll_started_sent_ = true; | 178 touch_scroll_started_sent_ = true; |
| 178 } | 179 } |
| 179 touch_event_queue_.OnGestureScrollEvent(gesture_event); | 180 touch_event_queue_.OnGestureScrollEvent(gesture_event); |
| 180 } | 181 } |
| 181 | 182 |
| 182 gesture_event_queue_.QueueEvent(gesture_event); | 183 gesture_event_queue_.QueueEvent(gesture_event); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void InputRouterImpl::SendTouchEvent( | 186 void InputRouterImpl::SendTouchEvent( |
| 186 const TouchEventWithLatencyInfo& touch_event) { | 187 const TouchEventWithLatencyInfo& touch_event) { |
| 187 input_stream_validator_.Validate(touch_event.event); | 188 input_stream_validator_.Validate(touch_event.event); |
| 188 touch_event_queue_.QueueEvent(touch_event); | 189 touch_event_queue_.QueueEvent(touch_event); |
| 189 } | 190 } |
| 190 | 191 |
| 191 // Forwards MouseEvent without passing it through | 192 // Forwards MouseEvent without passing it through |
| 192 // TouchpadTapSuppressionController. | 193 // TouchpadTapSuppressionController. |
| 193 void InputRouterImpl::SendMouseEventImmediately( | 194 void InputRouterImpl::SendMouseEventImmediately( |
| 194 const MouseEventWithLatencyInfo& mouse_event) { | 195 const MouseEventWithLatencyInfo& mouse_event) { |
| 195 if (mouse_event.event.type == blink::WebInputEvent::MouseMove) | 196 if (mouse_event.event.type() == blink::WebInputEvent::MouseMove) |
| 196 mouse_move_queue_.push_back(mouse_event); | 197 mouse_move_queue_.push_back(mouse_event); |
| 197 | 198 |
| 198 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); | 199 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); |
| 199 } | 200 } |
| 200 | 201 |
| 201 void InputRouterImpl::SendTouchEventImmediately( | 202 void InputRouterImpl::SendTouchEventImmediately( |
| 202 const TouchEventWithLatencyInfo& touch_event) { | 203 const TouchEventWithLatencyInfo& touch_event) { |
| 203 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) { | 204 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) { |
| 204 touch_action_filter_.ResetTouchAction(); | 205 touch_action_filter_.ResetTouchAction(); |
| 205 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling | 206 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 344 } |
| 344 | 345 |
| 345 bool InputRouterImpl::Send(IPC::Message* message) { | 346 bool InputRouterImpl::Send(IPC::Message* message) { |
| 346 return sender_->Send(message); | 347 return sender_->Send(message); |
| 347 } | 348 } |
| 348 | 349 |
| 349 void InputRouterImpl::FilterAndSendWebInputEvent( | 350 void InputRouterImpl::FilterAndSendWebInputEvent( |
| 350 const WebInputEvent& input_event, | 351 const WebInputEvent& input_event, |
| 351 const ui::LatencyInfo& latency_info) { | 352 const ui::LatencyInfo& latency_info) { |
| 352 TRACE_EVENT1("input", "InputRouterImpl::FilterAndSendWebInputEvent", "type", | 353 TRACE_EVENT1("input", "InputRouterImpl::FilterAndSendWebInputEvent", "type", |
| 353 WebInputEvent::GetName(input_event.type)); | 354 WebInputEvent::GetName(input_event.type())); |
| 354 TRACE_EVENT_WITH_FLOW2("input,benchmark,devtools.timeline", | 355 TRACE_EVENT_WITH_FLOW2("input,benchmark,devtools.timeline", |
| 355 "LatencyInfo.Flow", | 356 "LatencyInfo.Flow", |
| 356 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), | 357 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), |
| 357 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | 358 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
| 358 "step", "SendInputEventUI", | 359 "step", "SendInputEventUI", |
| 359 "frameTreeNodeId", frame_tree_node_id_); | 360 "frameTreeNodeId", frame_tree_node_id_); |
| 360 | 361 |
| 361 OfferToHandlers(input_event, latency_info); | 362 OfferToHandlers(input_event, latency_info); |
| 362 } | 363 } |
| 363 | 364 |
| 364 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event, | 365 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event, |
| 365 const ui::LatencyInfo& latency_info) { | 366 const ui::LatencyInfo& latency_info) { |
| 366 output_stream_validator_.Validate(input_event); | 367 output_stream_validator_.Validate(input_event); |
| 367 | 368 |
| 368 if (OfferToClient(input_event, latency_info)) | 369 if (OfferToClient(input_event, latency_info)) |
| 369 return; | 370 return; |
| 370 | 371 |
| 371 bool should_block = WebInputEventTraits::ShouldBlockEventStream(input_event); | 372 bool should_block = WebInputEventTraits::ShouldBlockEventStream(input_event); |
| 372 OfferToRenderer(input_event, latency_info, | 373 OfferToRenderer(input_event, latency_info, |
| 373 should_block | 374 should_block |
| 374 ? InputEventDispatchType::DISPATCH_TYPE_BLOCKING | 375 ? InputEventDispatchType::DISPATCH_TYPE_BLOCKING |
| 375 : InputEventDispatchType::DISPATCH_TYPE_NON_BLOCKING); | 376 : InputEventDispatchType::DISPATCH_TYPE_NON_BLOCKING); |
| 376 | 377 |
| 377 // Generate a synthetic ack if the event was sent so it doesn't block. | 378 // Generate a synthetic ack if the event was sent so it doesn't block. |
| 378 if (!should_block) { | 379 if (!should_block) { |
| 379 ProcessInputEventAck( | 380 ProcessInputEventAck( |
| 380 input_event.type, INPUT_EVENT_ACK_STATE_IGNORED, latency_info, | 381 input_event.type(), INPUT_EVENT_ACK_STATE_IGNORED, latency_info, |
| 381 WebInputEventTraits::GetUniqueTouchEventId(input_event), | 382 WebInputEventTraits::GetUniqueTouchEventId(input_event), |
| 382 IGNORING_DISPOSITION); | 383 IGNORING_DISPOSITION); |
| 383 } | 384 } |
| 384 } | 385 } |
| 385 | 386 |
| 386 bool InputRouterImpl::OfferToClient(const WebInputEvent& input_event, | 387 bool InputRouterImpl::OfferToClient(const WebInputEvent& input_event, |
| 387 const ui::LatencyInfo& latency_info) { | 388 const ui::LatencyInfo& latency_info) { |
| 388 bool consumed = false; | 389 bool consumed = false; |
| 389 | 390 |
| 390 InputEventAckState filter_ack = | 391 InputEventAckState filter_ack = |
| 391 client_->FilterInputEvent(input_event, latency_info); | 392 client_->FilterInputEvent(input_event, latency_info); |
| 392 switch (filter_ack) { | 393 switch (filter_ack) { |
| 393 case INPUT_EVENT_ACK_STATE_CONSUMED: | 394 case INPUT_EVENT_ACK_STATE_CONSUMED: |
| 394 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: | 395 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: |
| 395 // Send the ACK and early exit. | 396 // Send the ACK and early exit. |
| 396 ProcessInputEventAck( | 397 ProcessInputEventAck( |
| 397 input_event.type, filter_ack, latency_info, | 398 input_event.type(), filter_ack, latency_info, |
| 398 WebInputEventTraits::GetUniqueTouchEventId(input_event), CLIENT); | 399 WebInputEventTraits::GetUniqueTouchEventId(input_event), CLIENT); |
| 399 // WARNING: |this| may be deleted at this point. | 400 // WARNING: |this| may be deleted at this point. |
| 400 consumed = true; | 401 consumed = true; |
| 401 break; | 402 break; |
| 402 case INPUT_EVENT_ACK_STATE_UNKNOWN: | 403 case INPUT_EVENT_ACK_STATE_UNKNOWN: |
| 403 // Simply drop the event. | 404 // Simply drop the event. |
| 404 consumed = true; | 405 consumed = true; |
| 405 break; | 406 break; |
| 406 default: | 407 default: |
| 407 break; | 408 break; |
| 408 } | 409 } |
| 409 | 410 |
| 410 return consumed; | 411 return consumed; |
| 411 } | 412 } |
| 412 | 413 |
| 413 bool InputRouterImpl::OfferToRenderer(const WebInputEvent& input_event, | 414 bool InputRouterImpl::OfferToRenderer(const WebInputEvent& input_event, |
| 414 const ui::LatencyInfo& latency_info, | 415 const ui::LatencyInfo& latency_info, |
| 415 InputEventDispatchType dispatch_type) { | 416 InputEventDispatchType dispatch_type) { |
| 416 DCHECK(input_event.type != blink::WebInputEvent::GestureFlingStart || | 417 DCHECK(input_event.type() != blink::WebInputEvent::GestureFlingStart || |
| 417 static_cast<const blink::WebGestureEvent&>(input_event) | 418 static_cast<const blink::WebGestureEvent&>(input_event) |
| 418 .data.flingStart.velocityX != 0.0 || | 419 .data.flingStart.velocityX != 0.0 || |
| 419 static_cast<const blink::WebGestureEvent&>(input_event) | 420 static_cast<const blink::WebGestureEvent&>(input_event) |
| 420 .data.flingStart.velocityY != 0.0); | 421 .data.flingStart.velocityY != 0.0); |
| 421 | 422 |
| 422 // This conversion is temporary. WebInputEvent should be generated | 423 // This conversion is temporary. WebInputEvent should be generated |
| 423 // directly from ui::Event with the viewport coordinates. See | 424 // directly from ui::Event with the viewport coordinates. See |
| 424 // crbug.com/563730. | 425 // crbug.com/563730. |
| 425 std::unique_ptr<blink::WebInputEvent> event_in_viewport = | 426 std::unique_ptr<blink::WebInputEvent> event_in_viewport = |
| 426 ui::ScaleWebInputEvent(input_event, device_scale_factor_); | 427 ui::ScaleWebInputEvent(input_event, device_scale_factor_); |
| 427 const WebInputEvent* event_to_send = | 428 const WebInputEvent* event_to_send = |
| 428 event_in_viewport ? event_in_viewport.get() : &input_event; | 429 event_in_viewport ? event_in_viewport.get() : &input_event; |
| 429 | 430 |
| 430 if (Send(new InputMsg_HandleInputEvent(routing_id(), event_to_send, | 431 if (Send(new InputMsg_HandleInputEvent(routing_id(), event_to_send, |
| 431 latency_info, dispatch_type))) { | 432 latency_info, dispatch_type))) { |
| 432 // Ack messages for ignored ack event types should never be sent by the | 433 // Ack messages for ignored ack event types should never be sent by the |
| 433 // renderer. Consequently, such event types should not affect event time | 434 // renderer. Consequently, such event types should not affect event time |
| 434 // or in-flight event count metrics. | 435 // or in-flight event count metrics. |
| 435 if (dispatch_type == InputEventDispatchType::DISPATCH_TYPE_BLOCKING) | 436 if (dispatch_type == InputEventDispatchType::DISPATCH_TYPE_BLOCKING) |
| 436 client_->IncrementInFlightEventCount(input_event.type); | 437 client_->IncrementInFlightEventCount(input_event.type()); |
| 437 return true; | 438 return true; |
| 438 } | 439 } |
| 439 return false; | 440 return false; |
| 440 } | 441 } |
| 441 | 442 |
| 442 void InputRouterImpl::OnInputEventAck(const InputEventAck& ack) { | 443 void InputRouterImpl::OnInputEventAck(const InputEventAck& ack) { |
| 443 client_->DecrementInFlightEventCount(ack.source); | 444 client_->DecrementInFlightEventCount(ack.source); |
| 444 | 445 |
| 445 if (ack.overscroll) { | 446 if (ack.overscroll) { |
| 446 DCHECK(ack.type == WebInputEvent::MouseWheel || | 447 DCHECK(ack.type == WebInputEvent::MouseWheel || |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 } | 546 } |
| 546 | 547 |
| 547 SignalFlushedIfNecessary(); | 548 SignalFlushedIfNecessary(); |
| 548 } | 549 } |
| 549 | 550 |
| 550 void InputRouterImpl::ProcessKeyboardAck(blink::WebInputEvent::Type type, | 551 void InputRouterImpl::ProcessKeyboardAck(blink::WebInputEvent::Type type, |
| 551 InputEventAckState ack_result, | 552 InputEventAckState ack_result, |
| 552 const ui::LatencyInfo& latency) { | 553 const ui::LatencyInfo& latency) { |
| 553 if (key_queue_.empty()) { | 554 if (key_queue_.empty()) { |
| 554 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_ACK); | 555 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_ACK); |
| 555 } else if (key_queue_.front().event.type != type) { | 556 } else if (key_queue_.front().event.type() != type) { |
| 556 // Something must be wrong. Clear the |key_queue_| and char event | 557 // Something must be wrong. Clear the |key_queue_| and char event |
| 557 // suppression so that we can resume from the error. | 558 // suppression so that we can resume from the error. |
| 558 key_queue_.clear(); | 559 key_queue_.clear(); |
| 559 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_EVENT_TYPE); | 560 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_EVENT_TYPE); |
| 560 } else { | 561 } else { |
| 561 NativeWebKeyboardEventWithLatencyInfo front_item = key_queue_.front(); | 562 NativeWebKeyboardEventWithLatencyInfo front_item = key_queue_.front(); |
| 562 front_item.latency.AddNewLatencyFrom(latency); | 563 front_item.latency.AddNewLatencyFrom(latency); |
| 563 key_queue_.pop_front(); | 564 key_queue_.pop_front(); |
| 564 | 565 |
| 565 ack_handler_->OnKeyboardEventAck(front_item, ack_result); | 566 ack_handler_->OnKeyboardEventAck(front_item, ack_result); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 | 630 |
| 630 flush_requested_ = false; | 631 flush_requested_ = false; |
| 631 client_->DidFlush(); | 632 client_->DidFlush(); |
| 632 } | 633 } |
| 633 | 634 |
| 634 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { | 635 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { |
| 635 frame_tree_node_id_ = frameTreeNodeId; | 636 frame_tree_node_id_ = frameTreeNodeId; |
| 636 } | 637 } |
| 637 | 638 |
| 638 } // namespace content | 639 } // namespace content |
| OLD | NEW |