Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1124)

Side by Side Diff: content/browser/renderer_host/input/input_router_impl.cc

Issue 1003023002: Signal input flush when all flings have terminated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 client_(client), 69 client_(client),
70 ack_handler_(ack_handler), 70 ack_handler_(ack_handler),
71 routing_id_(routing_id), 71 routing_id_(routing_id),
72 select_message_pending_(false), 72 select_message_pending_(false),
73 move_caret_pending_(false), 73 move_caret_pending_(false),
74 mouse_move_pending_(false), 74 mouse_move_pending_(false),
75 mouse_wheel_pending_(false), 75 mouse_wheel_pending_(false),
76 current_view_flags_(0), 76 current_view_flags_(0),
77 current_ack_source_(ACK_SOURCE_NONE), 77 current_ack_source_(ACK_SOURCE_NONE),
78 flush_requested_(false), 78 flush_requested_(false),
79 active_fling_count_(0),
79 touch_event_queue_(this, config.touch_config), 80 touch_event_queue_(this, config.touch_config),
80 gesture_event_queue_(this, this, config.gesture_config) { 81 gesture_event_queue_(this, this, config.gesture_config) {
81 DCHECK(sender); 82 DCHECK(sender);
82 DCHECK(client); 83 DCHECK(client);
83 DCHECK(ack_handler); 84 DCHECK(ack_handler);
84 UpdateTouchAckTimeoutEnabled(); 85 UpdateTouchAckTimeoutEnabled();
85 } 86 }
86 87
87 InputRouterImpl::~InputRouterImpl() { 88 InputRouterImpl::~InputRouterImpl() {
88 STLDeleteElements(&pending_select_messages_); 89 STLDeleteElements(&pending_select_messages_);
89 } 90 }
90 91
91 void InputRouterImpl::Flush() {
92 flush_requested_ = true;
93 SignalFlushedIfNecessary();
94 }
95
96 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) { 92 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) {
97 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart); 93 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart);
98 switch (message->type()) { 94 switch (message->type()) {
99 // Check for types that require an ACK. 95 // Check for types that require an ACK.
100 case InputMsg_SelectRange::ID: 96 case InputMsg_SelectRange::ID:
101 case InputMsg_MoveRangeSelectionExtent::ID: 97 case InputMsg_MoveRangeSelectionExtent::ID:
102 return SendSelectMessage(message.Pass()); 98 return SendSelectMessage(message.Pass());
103 case InputMsg_MoveCaret::ID: 99 case InputMsg_MoveCaret::ID:
104 return SendMoveCaret(message.Pass()); 100 return SendMoveCaret(message.Pass());
105 case InputMsg_HandleInputEvent::ID: 101 case InputMsg_HandleInputEvent::ID:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 return &key_queue_.front(); 233 return &key_queue_.front();
238 } 234 }
239 235
240 void InputRouterImpl::OnViewUpdated(int view_flags) { 236 void InputRouterImpl::OnViewUpdated(int view_flags) {
241 current_view_flags_ = view_flags; 237 current_view_flags_ = view_flags;
242 238
243 // A fixed page scale or mobile viewport should disable the touch ack timeout. 239 // A fixed page scale or mobile viewport should disable the touch ack timeout.
244 UpdateTouchAckTimeoutEnabled(); 240 UpdateTouchAckTimeoutEnabled();
245 } 241 }
246 242
243 void InputRouterImpl::RequestNotificationWhenFlushed() {
244 flush_requested_ = true;
245 SignalFlushedIfNecessary();
246 }
247
248 bool InputRouterImpl::HasPendingEvents() const {
249 return !touch_event_queue_.empty() ||
250 !gesture_event_queue_.empty() ||
251 !key_queue_.empty() ||
252 mouse_move_pending_ ||
253 mouse_wheel_pending_ ||
254 select_message_pending_ ||
255 move_caret_pending_ ||
256 active_fling_count_ > 0;
257 }
258
247 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { 259 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) {
248 bool handled = true; 260 bool handled = true;
249 IPC_BEGIN_MESSAGE_MAP(InputRouterImpl, message) 261 IPC_BEGIN_MESSAGE_MAP(InputRouterImpl, message)
250 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) 262 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck)
251 IPC_MESSAGE_HANDLER(InputHostMsg_DidOverscroll, OnDidOverscroll) 263 IPC_MESSAGE_HANDLER(InputHostMsg_DidOverscroll, OnDidOverscroll)
252 IPC_MESSAGE_HANDLER(InputHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) 264 IPC_MESSAGE_HANDLER(InputHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck)
253 IPC_MESSAGE_HANDLER(InputHostMsg_SelectRange_ACK, OnSelectMessageAck) 265 IPC_MESSAGE_HANDLER(InputHostMsg_SelectRange_ACK, OnSelectMessageAck)
254 IPC_MESSAGE_HANDLER(InputHostMsg_MoveRangeSelectionExtent_ACK, 266 IPC_MESSAGE_HANDLER(InputHostMsg_MoveRangeSelectionExtent_ACK,
255 OnSelectMessageAck) 267 OnSelectMessageAck)
256 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, 268 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
257 OnHasTouchEventHandlers) 269 OnHasTouchEventHandlers)
258 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction, 270 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction,
259 OnSetTouchAction) 271 OnSetTouchAction)
272 IPC_MESSAGE_HANDLER(InputHostMsg_DidStopFlinging, OnFlingingStopped)
260 IPC_MESSAGE_UNHANDLED(handled = false) 273 IPC_MESSAGE_UNHANDLED(handled = false)
261 IPC_END_MESSAGE_MAP() 274 IPC_END_MESSAGE_MAP()
262 275
263 return handled; 276 return handled;
264 } 277 }
265 278
266 void InputRouterImpl::OnTouchEventAck(const TouchEventWithLatencyInfo& event, 279 void InputRouterImpl::OnTouchEventAck(const TouchEventWithLatencyInfo& event,
267 InputEventAckState ack_result) { 280 InputEventAckState ack_result) {
268 // Touchstart events sent to the renderer indicate a new touch sequence, but 281 // Touchstart events sent to the renderer indicate a new touch sequence, but
269 // in some cases we may filter out sending the touchstart - catch those here. 282 // in some cases we may filter out sending the touchstart - catch those here.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 DCHECK(touch_event_queue_.IsPendingAckTouchStart()); 491 DCHECK(touch_event_queue_.IsPendingAckTouchStart());
479 TRACE_EVENT1("input", "InputRouterImpl::OnSetTouchAction", 492 TRACE_EVENT1("input", "InputRouterImpl::OnSetTouchAction",
480 "action", touch_action); 493 "action", touch_action);
481 494
482 touch_action_filter_.OnSetTouchAction(touch_action); 495 touch_action_filter_.OnSetTouchAction(touch_action);
483 496
484 // TOUCH_ACTION_NONE should disable the touch ack timeout. 497 // TOUCH_ACTION_NONE should disable the touch ack timeout.
485 UpdateTouchAckTimeoutEnabled(); 498 UpdateTouchAckTimeoutEnabled();
486 } 499 }
487 500
501 void InputRouterImpl::OnFlingingStopped() {
502 DCHECK_GT(active_fling_count_, 0);
503 --active_fling_count_;
504 SignalFlushedIfNecessary();
505 client_->DidStopFlinging();
506 }
507
488 void InputRouterImpl::ProcessInputEventAck( 508 void InputRouterImpl::ProcessInputEventAck(
489 WebInputEvent::Type event_type, 509 WebInputEvent::Type event_type,
490 InputEventAckState ack_result, 510 InputEventAckState ack_result,
491 const ui::LatencyInfo& latency_info, 511 const ui::LatencyInfo& latency_info,
492 AckSource ack_source) { 512 AckSource ack_source) {
493 TRACE_EVENT2("input", "InputRouterImpl::ProcessInputEventAck", 513 TRACE_EVENT2("input", "InputRouterImpl::ProcessInputEventAck",
494 "type", WebInputEventTraits::GetName(event_type), 514 "type", WebInputEventTraits::GetName(event_type),
495 "ack", GetEventAckName(ack_result)); 515 "ack", GetEventAckName(ack_result));
496 516
497 // Note: The keyboard ack must be treated carefully, as it may result in 517 // Note: The keyboard ack must be treated carefully, as it may result in
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 MouseWheelEventWithLatencyInfo next_wheel_event = 599 MouseWheelEventWithLatencyInfo next_wheel_event =
580 coalesced_mouse_wheel_events_.front(); 600 coalesced_mouse_wheel_events_.front();
581 coalesced_mouse_wheel_events_.pop_front(); 601 coalesced_mouse_wheel_events_.pop_front();
582 SendWheelEvent(next_wheel_event); 602 SendWheelEvent(next_wheel_event);
583 } 603 }
584 } 604 }
585 605
586 void InputRouterImpl::ProcessGestureAck(WebInputEvent::Type type, 606 void InputRouterImpl::ProcessGestureAck(WebInputEvent::Type type,
587 InputEventAckState ack_result, 607 InputEventAckState ack_result,
588 const ui::LatencyInfo& latency) { 608 const ui::LatencyInfo& latency) {
609 if (type == blink::WebInputEvent::GestureFlingStart &&
610 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) {
611 ++active_fling_count_;
612 }
Yufeng Shen (Slow to review) 2015/03/13 15:53:42 I saw that gesture event queue also maintains a fl
jdduke (slow) 2015/03/13 16:08:04 Probably, although the gesture queue fling in prog
613
589 // |gesture_event_queue_| will forward to OnGestureEventAck when appropriate. 614 // |gesture_event_queue_| will forward to OnGestureEventAck when appropriate.
590 gesture_event_queue_.ProcessGestureAck(ack_result, type, latency); 615 gesture_event_queue_.ProcessGestureAck(ack_result, type, latency);
591 } 616 }
592 617
593 void InputRouterImpl::ProcessTouchAck( 618 void InputRouterImpl::ProcessTouchAck(
594 InputEventAckState ack_result, 619 InputEventAckState ack_result,
595 const ui::LatencyInfo& latency) { 620 const ui::LatencyInfo& latency) {
596 // |touch_event_queue_| will forward to OnTouchEventAck when appropriate. 621 // |touch_event_queue_| will forward to OnTouchEventAck when appropriate.
597 touch_event_queue_.ProcessTouchAck(ack_result, latency); 622 touch_event_queue_.ProcessTouchAck(ack_result, latency);
598 } 623 }
(...skipping 20 matching lines...) Expand all
619 if (!flush_requested_) 644 if (!flush_requested_)
620 return; 645 return;
621 646
622 if (HasPendingEvents()) 647 if (HasPendingEvents())
623 return; 648 return;
624 649
625 flush_requested_ = false; 650 flush_requested_ = false;
626 client_->DidFlush(); 651 client_->DidFlush();
627 } 652 }
628 653
629 bool InputRouterImpl::HasPendingEvents() const {
630 return !touch_event_queue_.empty() ||
631 !gesture_event_queue_.empty() ||
632 !key_queue_.empty() ||
633 mouse_move_pending_ ||
634 mouse_wheel_pending_ ||
635 select_message_pending_ ||
636 move_caret_pending_;
637 }
638
639 } // namespace content 654 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698