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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 int routing_id, | 77 int routing_id, |
78 const Config& config) | 78 const Config& config) |
79 : sender_(sender), | 79 : sender_(sender), |
80 client_(client), | 80 client_(client), |
81 ack_handler_(ack_handler), | 81 ack_handler_(ack_handler), |
82 routing_id_(routing_id), | 82 routing_id_(routing_id), |
83 frame_tree_node_id_(-1), | 83 frame_tree_node_id_(-1), |
84 select_message_pending_(false), | 84 select_message_pending_(false), |
85 move_caret_pending_(false), | 85 move_caret_pending_(false), |
86 current_ack_source_(ACK_SOURCE_NONE), | 86 current_ack_source_(ACK_SOURCE_NONE), |
87 flush_requested_(false), | |
88 active_renderer_fling_count_(0), | 87 active_renderer_fling_count_(0), |
89 touch_scroll_started_sent_(false), | 88 touch_scroll_started_sent_(false), |
90 wheel_event_queue_(this, | 89 wheel_event_queue_(this, |
91 base::FeatureList::IsEnabled( | 90 base::FeatureList::IsEnabled( |
92 features::kTouchpadAndWheelScrollLatching)), | 91 features::kTouchpadAndWheelScrollLatching)), |
93 gesture_event_queue_(this, this, config.gesture_config), | 92 gesture_event_queue_(this, this, config.gesture_config), |
94 device_scale_factor_(1.f), | 93 device_scale_factor_(1.f), |
95 raf_aligned_touch_enabled_( | 94 raf_aligned_touch_enabled_( |
96 base::FeatureList::IsEnabled(features::kRafAlignedTouchInputEvents)) { | 95 base::FeatureList::IsEnabled(features::kRafAlignedTouchInputEvents)) { |
97 if (raf_aligned_touch_enabled_) { | 96 if (raf_aligned_touch_enabled_) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { | 223 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { |
225 if (key_queue_.empty()) | 224 if (key_queue_.empty()) |
226 return NULL; | 225 return NULL; |
227 return &key_queue_.front().event; | 226 return &key_queue_.front().event; |
228 } | 227 } |
229 | 228 |
230 void InputRouterImpl::NotifySiteIsMobileOptimized(bool is_mobile_optimized) { | 229 void InputRouterImpl::NotifySiteIsMobileOptimized(bool is_mobile_optimized) { |
231 touch_event_queue_->SetIsMobileOptimizedSite(is_mobile_optimized); | 230 touch_event_queue_->SetIsMobileOptimizedSite(is_mobile_optimized); |
232 } | 231 } |
233 | 232 |
234 void InputRouterImpl::RequestNotificationWhenFlushed() { | |
235 flush_requested_ = true; | |
236 SignalFlushedIfNecessary(); | |
237 } | |
238 | |
239 bool InputRouterImpl::HasPendingEvents() const { | 233 bool InputRouterImpl::HasPendingEvents() const { |
240 return !touch_event_queue_->Empty() || !gesture_event_queue_.empty() || | 234 return !touch_event_queue_->Empty() || !gesture_event_queue_.empty() || |
241 !key_queue_.empty() || !mouse_move_queue_.empty() || | 235 !key_queue_.empty() || !mouse_move_queue_.empty() || |
242 wheel_event_queue_.has_pending() || select_message_pending_ || | 236 wheel_event_queue_.has_pending() || select_message_pending_ || |
243 move_caret_pending_ || active_renderer_fling_count_ > 0; | 237 move_caret_pending_ || active_renderer_fling_count_ > 0; |
244 } | 238 } |
245 | 239 |
246 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { | 240 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { |
247 device_scale_factor_ = device_scale_factor; | 241 device_scale_factor_ = device_scale_factor; |
248 } | 242 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 // kTouchActionNone should disable the touch ack timeout. | 505 // kTouchActionNone should disable the touch ack timeout. |
512 UpdateTouchAckTimeoutEnabled(); | 506 UpdateTouchAckTimeoutEnabled(); |
513 } | 507 } |
514 | 508 |
515 void InputRouterImpl::OnDidStopFlinging() { | 509 void InputRouterImpl::OnDidStopFlinging() { |
516 DCHECK_GT(active_renderer_fling_count_, 0); | 510 DCHECK_GT(active_renderer_fling_count_, 0); |
517 // Note that we're only guaranteed to get a fling end notification from the | 511 // Note that we're only guaranteed to get a fling end notification from the |
518 // renderer, not from any other consumers. Consequently, the GestureEventQueue | 512 // renderer, not from any other consumers. Consequently, the GestureEventQueue |
519 // cannot use this bookkeeping for logic like tap suppression. | 513 // cannot use this bookkeeping for logic like tap suppression. |
520 --active_renderer_fling_count_; | 514 --active_renderer_fling_count_; |
521 SignalFlushedIfNecessary(); | |
522 | 515 |
523 client_->DidStopFlinging(); | 516 client_->DidStopFlinging(); |
524 } | 517 } |
525 | 518 |
526 void InputRouterImpl::ProcessInputEventAck(WebInputEvent::Type event_type, | 519 void InputRouterImpl::ProcessInputEventAck(WebInputEvent::Type event_type, |
527 InputEventAckState ack_result, | 520 InputEventAckState ack_result, |
528 const ui::LatencyInfo& latency_info, | 521 const ui::LatencyInfo& latency_info, |
529 uint32_t unique_touch_event_id, | 522 uint32_t unique_touch_event_id, |
530 AckSource ack_source) { | 523 AckSource ack_source) { |
531 TRACE_EVENT2("input", "InputRouterImpl::ProcessInputEventAck", "type", | 524 TRACE_EVENT2("input", "InputRouterImpl::ProcessInputEventAck", "type", |
(...skipping 16 matching lines...) Expand all Loading... |
548 ProcessMouseAck(event_type, ack_result, latency_info); | 541 ProcessMouseAck(event_type, ack_result, latency_info); |
549 } else if (event_type == WebInputEvent::kMouseWheel) { | 542 } else if (event_type == WebInputEvent::kMouseWheel) { |
550 ProcessWheelAck(ack_result, latency_info); | 543 ProcessWheelAck(ack_result, latency_info); |
551 } else if (WebInputEvent::IsTouchEventType(event_type)) { | 544 } else if (WebInputEvent::IsTouchEventType(event_type)) { |
552 ProcessTouchAck(ack_result, latency_info, unique_touch_event_id); | 545 ProcessTouchAck(ack_result, latency_info, unique_touch_event_id); |
553 } else if (WebInputEvent::IsGestureEventType(event_type)) { | 546 } else if (WebInputEvent::IsGestureEventType(event_type)) { |
554 ProcessGestureAck(event_type, ack_result, latency_info); | 547 ProcessGestureAck(event_type, ack_result, latency_info); |
555 } else if (event_type != WebInputEvent::kUndefined) { | 548 } else if (event_type != WebInputEvent::kUndefined) { |
556 ack_handler_->OnUnexpectedEventAck(InputAckHandler::BAD_ACK_MESSAGE); | 549 ack_handler_->OnUnexpectedEventAck(InputAckHandler::BAD_ACK_MESSAGE); |
557 } | 550 } |
558 | |
559 SignalFlushedIfNecessary(); | |
560 } | 551 } |
561 | 552 |
562 void InputRouterImpl::ProcessKeyboardAck(blink::WebInputEvent::Type type, | 553 void InputRouterImpl::ProcessKeyboardAck(blink::WebInputEvent::Type type, |
563 InputEventAckState ack_result, | 554 InputEventAckState ack_result, |
564 const ui::LatencyInfo& latency) { | 555 const ui::LatencyInfo& latency) { |
565 if (key_queue_.empty()) { | 556 if (key_queue_.empty()) { |
566 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_ACK); | 557 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_ACK); |
567 } else if (key_queue_.front().event.GetType() != type) { | 558 } else if (key_queue_.front().event.GetType() != type) { |
568 // Something must be wrong. Clear the |key_queue_| and char event | 559 // Something must be wrong. Clear the |key_queue_| and char event |
569 // suppression so that we can resume from the error. | 560 // suppression so that we can resume from the error. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 616 |
626 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { | 617 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { |
627 // kTouchActionNone will prevent scrolling, in which case the timeout serves | 618 // kTouchActionNone will prevent scrolling, in which case the timeout serves |
628 // 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 |
629 // 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. |
630 const bool touch_ack_timeout_enabled = | 621 const bool touch_ack_timeout_enabled = |
631 touch_action_filter_.allowed_touch_action() != cc::kTouchActionNone; | 622 touch_action_filter_.allowed_touch_action() != cc::kTouchActionNone; |
632 touch_event_queue_->SetAckTimeoutEnabled(touch_ack_timeout_enabled); | 623 touch_event_queue_->SetAckTimeoutEnabled(touch_ack_timeout_enabled); |
633 } | 624 } |
634 | 625 |
635 void InputRouterImpl::SignalFlushedIfNecessary() { | |
636 if (!flush_requested_) | |
637 return; | |
638 | |
639 if (HasPendingEvents()) | |
640 return; | |
641 | |
642 flush_requested_ = false; | |
643 client_->DidFlush(); | |
644 } | |
645 | |
646 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { | 626 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { |
647 frame_tree_node_id_ = frameTreeNodeId; | 627 frame_tree_node_id_ = frameTreeNodeId; |
648 } | 628 } |
649 | 629 |
650 void InputRouterImpl::SetMovementXYForTouchPoints(blink::WebTouchEvent* event) { | 630 void InputRouterImpl::SetMovementXYForTouchPoints(blink::WebTouchEvent* event) { |
651 for (size_t i = 0; i < event->touches_length; ++i) { | 631 for (size_t i = 0; i < event->touches_length; ++i) { |
652 blink::WebTouchPoint* touch_point = &event->touches[i]; | 632 blink::WebTouchPoint* touch_point = &event->touches[i]; |
653 if (touch_point->state == blink::WebTouchPoint::kStateMoved) { | 633 if (touch_point->state == blink::WebTouchPoint::kStateMoved) { |
654 const gfx::Point& last_position = global_touch_position_[touch_point->id]; | 634 const gfx::Point& last_position = global_touch_position_[touch_point->id]; |
655 touch_point->movement_x = | 635 touch_point->movement_x = |
(...skipping 12 matching lines...) Expand all Loading... |
668 DCHECK(global_touch_position_.find(touch_point->id) == | 648 DCHECK(global_touch_position_.find(touch_point->id) == |
669 global_touch_position_.end()); | 649 global_touch_position_.end()); |
670 global_touch_position_[touch_point->id] = gfx::Point( | 650 global_touch_position_[touch_point->id] = gfx::Point( |
671 touch_point->screen_position.x, touch_point->screen_position.y); | 651 touch_point->screen_position.x, touch_point->screen_position.y); |
672 } | 652 } |
673 } | 653 } |
674 } | 654 } |
675 } | 655 } |
676 | 656 |
677 } // namespace content | 657 } // namespace content |
OLD | NEW |