| 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 |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "content/browser/renderer_host/input/gesture_event_queue.h" | 16 #include "content/browser/renderer_host/input/gesture_event_queue.h" |
| 17 #include "content/browser/renderer_host/input/input_ack_handler.h" | 17 #include "content/browser/renderer_host/input/input_ack_handler.h" |
| 18 #include "content/browser/renderer_host/input/input_router_client.h" | 18 #include "content/browser/renderer_host/input/input_router_client.h" |
| 19 #include "content/browser/renderer_host/input/legacy_touch_event_queue.h" |
| 19 #include "content/browser/renderer_host/input/touch_event_queue.h" | 20 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 20 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle
r.h" | 21 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle
r.h" |
| 21 #include "content/common/content_constants_internal.h" | 22 #include "content/common/content_constants_internal.h" |
| 22 #include "content/common/edit_command.h" | 23 #include "content/common/edit_command.h" |
| 23 #include "content/common/input/input_event_ack_state.h" | 24 #include "content/common/input/input_event_ack_state.h" |
| 24 #include "content/common/input/touch_action.h" | 25 #include "content/common/input/touch_action.h" |
| 25 #include "content/common/input/web_touch_event_traits.h" | 26 #include "content/common/input/web_touch_event_traits.h" |
| 26 #include "content/common/input_messages.h" | 27 #include "content/common/input_messages.h" |
| 27 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
| 28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 frame_tree_node_id_(-1), | 84 frame_tree_node_id_(-1), |
| 84 select_message_pending_(false), | 85 select_message_pending_(false), |
| 85 move_caret_pending_(false), | 86 move_caret_pending_(false), |
| 86 current_ack_source_(ACK_SOURCE_NONE), | 87 current_ack_source_(ACK_SOURCE_NONE), |
| 87 flush_requested_(false), | 88 flush_requested_(false), |
| 88 active_renderer_fling_count_(0), | 89 active_renderer_fling_count_(0), |
| 89 touch_scroll_started_sent_(false), | 90 touch_scroll_started_sent_(false), |
| 90 wheel_event_queue_(this, | 91 wheel_event_queue_(this, |
| 91 base::FeatureList::IsEnabled( | 92 base::FeatureList::IsEnabled( |
| 92 features::kTouchpadAndWheelScrollLatching)), | 93 features::kTouchpadAndWheelScrollLatching)), |
| 93 touch_event_queue_(this, config.touch_config), | 94 touch_event_queue_(new LegacyTouchEventQueue(this, config.touch_config)), |
| 94 gesture_event_queue_(this, this, config.gesture_config), | 95 gesture_event_queue_(this, this, config.gesture_config), |
| 95 device_scale_factor_(1.f) { | 96 device_scale_factor_(1.f) { |
| 96 DCHECK(sender); | 97 DCHECK(sender); |
| 97 DCHECK(client); | 98 DCHECK(client); |
| 98 DCHECK(ack_handler); | 99 DCHECK(ack_handler); |
| 99 UpdateTouchAckTimeoutEnabled(); | 100 UpdateTouchAckTimeoutEnabled(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 InputRouterImpl::~InputRouterImpl() { | 103 InputRouterImpl::~InputRouterImpl() { |
| 103 } | 104 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 if (gesture_event.event.type() == | 168 if (gesture_event.event.type() == |
| 168 blink::WebInputEvent::GestureScrollBegin) { | 169 blink::WebInputEvent::GestureScrollBegin) { |
| 169 touch_scroll_started_sent_ = false; | 170 touch_scroll_started_sent_ = false; |
| 170 } else if (!touch_scroll_started_sent_ && | 171 } else if (!touch_scroll_started_sent_ && |
| 171 gesture_event.event.type() == | 172 gesture_event.event.type() == |
| 172 blink::WebInputEvent::GestureScrollUpdate) { | 173 blink::WebInputEvent::GestureScrollUpdate) { |
| 173 // A touch scroll hasn't really started until the first | 174 // A touch scroll hasn't really started until the first |
| 174 // GestureScrollUpdate event. Eg. if the page consumes all touchmoves | 175 // GestureScrollUpdate event. Eg. if the page consumes all touchmoves |
| 175 // then no scrolling really ever occurs (even though we still send | 176 // then no scrolling really ever occurs (even though we still send |
| 176 // GestureScrollBegin). | 177 // GestureScrollBegin). |
| 177 touch_event_queue_.PrependTouchScrollNotification(); | 178 touch_event_queue_->PrependTouchScrollNotification(); |
| 178 touch_scroll_started_sent_ = true; | 179 touch_scroll_started_sent_ = true; |
| 179 } | 180 } |
| 180 touch_event_queue_.OnGestureScrollEvent(gesture_event); | 181 touch_event_queue_->OnGestureScrollEvent(gesture_event); |
| 181 } | 182 } |
| 182 | 183 |
| 183 gesture_event_queue_.QueueEvent(gesture_event); | 184 gesture_event_queue_.QueueEvent(gesture_event); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void InputRouterImpl::SendTouchEvent( | 187 void InputRouterImpl::SendTouchEvent( |
| 187 const TouchEventWithLatencyInfo& touch_event) { | 188 const TouchEventWithLatencyInfo& touch_event) { |
| 188 input_stream_validator_.Validate(touch_event.event); | 189 input_stream_validator_.Validate(touch_event.event); |
| 189 touch_event_queue_.QueueEvent(touch_event); | 190 touch_event_queue_->QueueEvent(touch_event); |
| 190 } | 191 } |
| 191 | 192 |
| 192 // Forwards MouseEvent without passing it through | 193 // Forwards MouseEvent without passing it through |
| 193 // TouchpadTapSuppressionController. | 194 // TouchpadTapSuppressionController. |
| 194 void InputRouterImpl::SendMouseEventImmediately( | 195 void InputRouterImpl::SendMouseEventImmediately( |
| 195 const MouseEventWithLatencyInfo& mouse_event) { | 196 const MouseEventWithLatencyInfo& mouse_event) { |
| 196 if (mouse_event.event.type() == blink::WebInputEvent::MouseMove) | 197 if (mouse_event.event.type() == blink::WebInputEvent::MouseMove) |
| 197 mouse_move_queue_.push_back(mouse_event); | 198 mouse_move_queue_.push_back(mouse_event); |
| 198 | 199 |
| 199 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); | 200 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 218 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency); | 219 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency); |
| 219 } | 220 } |
| 220 | 221 |
| 221 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { | 222 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { |
| 222 if (key_queue_.empty()) | 223 if (key_queue_.empty()) |
| 223 return NULL; | 224 return NULL; |
| 224 return &key_queue_.front().event; | 225 return &key_queue_.front().event; |
| 225 } | 226 } |
| 226 | 227 |
| 227 void InputRouterImpl::NotifySiteIsMobileOptimized(bool is_mobile_optimized) { | 228 void InputRouterImpl::NotifySiteIsMobileOptimized(bool is_mobile_optimized) { |
| 228 touch_event_queue_.SetIsMobileOptimizedSite(is_mobile_optimized); | 229 touch_event_queue_->SetIsMobileOptimizedSite(is_mobile_optimized); |
| 229 } | 230 } |
| 230 | 231 |
| 231 void InputRouterImpl::RequestNotificationWhenFlushed() { | 232 void InputRouterImpl::RequestNotificationWhenFlushed() { |
| 232 flush_requested_ = true; | 233 flush_requested_ = true; |
| 233 SignalFlushedIfNecessary(); | 234 SignalFlushedIfNecessary(); |
| 234 } | 235 } |
| 235 | 236 |
| 236 bool InputRouterImpl::HasPendingEvents() const { | 237 bool InputRouterImpl::HasPendingEvents() const { |
| 237 return !touch_event_queue_.empty() || !gesture_event_queue_.empty() || | 238 return !touch_event_queue_->Empty() || !gesture_event_queue_.empty() || |
| 238 !key_queue_.empty() || !mouse_move_queue_.empty() || | 239 !key_queue_.empty() || !mouse_move_queue_.empty() || |
| 239 wheel_event_queue_.has_pending() || select_message_pending_ || | 240 wheel_event_queue_.has_pending() || select_message_pending_ || |
| 240 move_caret_pending_ || active_renderer_fling_count_ > 0; | 241 move_caret_pending_ || active_renderer_fling_count_ > 0; |
| 241 } | 242 } |
| 242 | 243 |
| 243 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { | 244 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 244 device_scale_factor_ = device_scale_factor; | 245 device_scale_factor_ = device_scale_factor; |
| 245 } | 246 } |
| 246 | 247 |
| 247 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { | 248 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // stream |output_stream_validator_| sees is valid, we give events which are | 285 // stream |output_stream_validator_| sees is valid, we give events which are |
| 285 // filtered out to the validator. crbug.com/589111 proposes adding an | 286 // filtered out to the validator. crbug.com/589111 proposes adding an |
| 286 // additional validator for the events which are actually sent to the | 287 // additional validator for the events which are actually sent to the |
| 287 // renderer. | 288 // renderer. |
| 288 output_stream_validator_.Validate(touch_event); | 289 output_stream_validator_.Validate(touch_event); |
| 289 } | 290 } |
| 290 | 291 |
| 291 void InputRouterImpl::OnGestureEventAck( | 292 void InputRouterImpl::OnGestureEventAck( |
| 292 const GestureEventWithLatencyInfo& event, | 293 const GestureEventWithLatencyInfo& event, |
| 293 InputEventAckState ack_result) { | 294 InputEventAckState ack_result) { |
| 294 touch_event_queue_.OnGestureEventAck(event, ack_result); | 295 touch_event_queue_->OnGestureEventAck(event, ack_result); |
| 295 ack_handler_->OnGestureEventAck(event, ack_result); | 296 ack_handler_->OnGestureEventAck(event, ack_result); |
| 296 } | 297 } |
| 297 | 298 |
| 298 void InputRouterImpl::ForwardGestureEventWithLatencyInfo( | 299 void InputRouterImpl::ForwardGestureEventWithLatencyInfo( |
| 299 const blink::WebGestureEvent& event, | 300 const blink::WebGestureEvent& event, |
| 300 const ui::LatencyInfo& latency_info) { | 301 const ui::LatencyInfo& latency_info) { |
| 301 client_->ForwardGestureEventWithLatencyInfo(event, latency_info); | 302 client_->ForwardGestureEventWithLatencyInfo(event, latency_info); |
| 302 } | 303 } |
| 303 | 304 |
| 304 void InputRouterImpl::SendMouseWheelEventImmediately( | 305 void InputRouterImpl::SendMouseWheelEventImmediately( |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 TRACE_EVENT1("input", "InputRouterImpl::OnHasTouchEventHandlers", | 480 TRACE_EVENT1("input", "InputRouterImpl::OnHasTouchEventHandlers", |
| 480 "has_handlers", has_handlers); | 481 "has_handlers", has_handlers); |
| 481 | 482 |
| 482 // Lack of a touch handler indicates that the page either has no touch-action | 483 // Lack of a touch handler indicates that the page either has no touch-action |
| 483 // modifiers or that all its touch-action modifiers are auto. Resetting the | 484 // modifiers or that all its touch-action modifiers are auto. Resetting the |
| 484 // touch-action here allows forwarding of subsequent gestures even if the | 485 // touch-action here allows forwarding of subsequent gestures even if the |
| 485 // underlying touches never reach the router. | 486 // underlying touches never reach the router. |
| 486 if (!has_handlers) | 487 if (!has_handlers) |
| 487 touch_action_filter_.ResetTouchAction(); | 488 touch_action_filter_.ResetTouchAction(); |
| 488 | 489 |
| 489 touch_event_queue_.OnHasTouchEventHandlers(has_handlers); | 490 touch_event_queue_->OnHasTouchEventHandlers(has_handlers); |
| 490 client_->OnHasTouchEventHandlers(has_handlers); | 491 client_->OnHasTouchEventHandlers(has_handlers); |
| 491 } | 492 } |
| 492 | 493 |
| 493 void InputRouterImpl::OnSetTouchAction(TouchAction touch_action) { | 494 void InputRouterImpl::OnSetTouchAction(TouchAction touch_action) { |
| 494 // Synthetic touchstart events should get filtered out in RenderWidget. | 495 // Synthetic touchstart events should get filtered out in RenderWidget. |
| 495 DCHECK(touch_event_queue_.IsPendingAckTouchStart()); | 496 DCHECK(touch_event_queue_->IsPendingAckTouchStart()); |
| 496 TRACE_EVENT1("input", "InputRouterImpl::OnSetTouchAction", | 497 TRACE_EVENT1("input", "InputRouterImpl::OnSetTouchAction", |
| 497 "action", touch_action); | 498 "action", touch_action); |
| 498 | 499 |
| 499 touch_action_filter_.OnSetTouchAction(touch_action); | 500 touch_action_filter_.OnSetTouchAction(touch_action); |
| 500 | 501 |
| 501 // TOUCH_ACTION_NONE should disable the touch ack timeout. | 502 // TOUCH_ACTION_NONE should disable the touch ack timeout. |
| 502 UpdateTouchAckTimeoutEnabled(); | 503 UpdateTouchAckTimeoutEnabled(); |
| 503 } | 504 } |
| 504 | 505 |
| 505 void InputRouterImpl::OnDidStopFlinging() { | 506 void InputRouterImpl::OnDidStopFlinging() { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 603 } |
| 603 | 604 |
| 604 // |gesture_event_queue_| will forward to OnGestureEventAck when appropriate. | 605 // |gesture_event_queue_| will forward to OnGestureEventAck when appropriate. |
| 605 gesture_event_queue_.ProcessGestureAck(ack_result, type, latency); | 606 gesture_event_queue_.ProcessGestureAck(ack_result, type, latency); |
| 606 } | 607 } |
| 607 | 608 |
| 608 void InputRouterImpl::ProcessTouchAck(InputEventAckState ack_result, | 609 void InputRouterImpl::ProcessTouchAck(InputEventAckState ack_result, |
| 609 const ui::LatencyInfo& latency, | 610 const ui::LatencyInfo& latency, |
| 610 uint32_t unique_touch_event_id) { | 611 uint32_t unique_touch_event_id) { |
| 611 // |touch_event_queue_| will forward to OnTouchEventAck when appropriate. | 612 // |touch_event_queue_| will forward to OnTouchEventAck when appropriate. |
| 612 touch_event_queue_.ProcessTouchAck(ack_result, latency, | 613 touch_event_queue_->ProcessTouchAck(ack_result, latency, |
| 613 unique_touch_event_id); | 614 unique_touch_event_id); |
| 614 } | 615 } |
| 615 | 616 |
| 616 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { | 617 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { |
| 617 // TOUCH_ACTION_NONE will prevent scrolling, in which case the timeout serves | 618 // TOUCH_ACTION_NONE will prevent scrolling, in which case the timeout serves |
| 618 // little purpose. It's also a strong signal that touch handling is critical | 619 // little purpose. It's also a strong signal that touch handling is critical |
| 619 // to page functionality, so the timeout could do more harm than good. | 620 // to page functionality, so the timeout could do more harm than good. |
| 620 const bool touch_ack_timeout_enabled = | 621 const bool touch_ack_timeout_enabled = |
| 621 touch_action_filter_.allowed_touch_action() != TOUCH_ACTION_NONE; | 622 touch_action_filter_.allowed_touch_action() != TOUCH_ACTION_NONE; |
| 622 touch_event_queue_.SetAckTimeoutEnabled(touch_ack_timeout_enabled); | 623 touch_event_queue_->SetAckTimeoutEnabled(touch_ack_timeout_enabled); |
| 623 } | 624 } |
| 624 | 625 |
| 625 void InputRouterImpl::SignalFlushedIfNecessary() { | 626 void InputRouterImpl::SignalFlushedIfNecessary() { |
| 626 if (!flush_requested_) | 627 if (!flush_requested_) |
| 627 return; | 628 return; |
| 628 | 629 |
| 629 if (HasPendingEvents()) | 630 if (HasPendingEvents()) |
| 630 return; | 631 return; |
| 631 | 632 |
| 632 flush_requested_ = false; | 633 flush_requested_ = false; |
| 633 client_->DidFlush(); | 634 client_->DidFlush(); |
| 634 } | 635 } |
| 635 | 636 |
| 636 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { | 637 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { |
| 637 frame_tree_node_id_ = frameTreeNodeId; | 638 frame_tree_node_id_ = frameTreeNodeId; |
| 638 } | 639 } |
| 639 | 640 |
| 640 } // namespace content | 641 } // namespace content |
| OLD | NEW |