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 "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 DCHECK(sender); | 81 DCHECK(sender); |
82 DCHECK(client); | 82 DCHECK(client); |
83 DCHECK(ack_handler); | 83 DCHECK(ack_handler); |
84 UpdateTouchAckTimeoutEnabled(); | 84 UpdateTouchAckTimeoutEnabled(); |
85 } | 85 } |
86 | 86 |
87 InputRouterImpl::~InputRouterImpl() { | 87 InputRouterImpl::~InputRouterImpl() { |
88 STLDeleteElements(&pending_select_messages_); | 88 STLDeleteElements(&pending_select_messages_); |
89 } | 89 } |
90 | 90 |
91 void InputRouterImpl::Flush() { | |
92 flush_requested_ = true; | |
93 SignalFlushedIfNecessary(); | |
94 } | |
95 | |
96 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) { | 91 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) { |
97 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart); | 92 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart); |
98 switch (message->type()) { | 93 switch (message->type()) { |
99 // Check for types that require an ACK. | 94 // Check for types that require an ACK. |
100 case InputMsg_SelectRange::ID: | 95 case InputMsg_SelectRange::ID: |
101 case InputMsg_MoveRangeSelectionExtent::ID: | 96 case InputMsg_MoveRangeSelectionExtent::ID: |
102 return SendSelectMessage(message.Pass()); | 97 return SendSelectMessage(message.Pass()); |
103 case InputMsg_MoveCaret::ID: | 98 case InputMsg_MoveCaret::ID: |
104 return SendMoveCaret(message.Pass()); | 99 return SendMoveCaret(message.Pass()); |
105 case InputMsg_HandleInputEvent::ID: | 100 case InputMsg_HandleInputEvent::ID: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 151 |
157 void InputRouterImpl::SendKeyboardEvent(const NativeWebKeyboardEvent& key_event, | 152 void InputRouterImpl::SendKeyboardEvent(const NativeWebKeyboardEvent& key_event, |
158 const ui::LatencyInfo& latency_info, | 153 const ui::LatencyInfo& latency_info, |
159 bool is_keyboard_shortcut) { | 154 bool is_keyboard_shortcut) { |
160 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 155 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
161 // renderer and we need to give something to the HandleKeyboardEvent | 156 // renderer and we need to give something to the HandleKeyboardEvent |
162 // handler. | 157 // handler. |
163 key_queue_.push_back(key_event); | 158 key_queue_.push_back(key_event); |
164 LOCAL_HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 159 LOCAL_HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
165 | 160 |
166 gesture_event_queue_.FlingHasBeenHalted(); | |
167 | |
168 // Only forward the non-native portions of our event. | 161 // Only forward the non-native portions of our event. |
169 FilterAndSendWebInputEvent(key_event, latency_info, is_keyboard_shortcut); | 162 FilterAndSendWebInputEvent(key_event, latency_info, is_keyboard_shortcut); |
170 } | 163 } |
171 | 164 |
172 void InputRouterImpl::SendGestureEvent( | 165 void InputRouterImpl::SendGestureEvent( |
173 const GestureEventWithLatencyInfo& original_gesture_event) { | 166 const GestureEventWithLatencyInfo& original_gesture_event) { |
174 input_stream_validator_.Validate(original_gesture_event.event); | 167 input_stream_validator_.Validate(original_gesture_event.event); |
175 | 168 |
176 GestureEventWithLatencyInfo gesture_event(original_gesture_event); | 169 GestureEventWithLatencyInfo gesture_event(original_gesture_event); |
177 | 170 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 return &key_queue_.front(); | 230 return &key_queue_.front(); |
238 } | 231 } |
239 | 232 |
240 void InputRouterImpl::OnViewUpdated(int view_flags) { | 233 void InputRouterImpl::OnViewUpdated(int view_flags) { |
241 current_view_flags_ = view_flags; | 234 current_view_flags_ = view_flags; |
242 | 235 |
243 // A fixed page scale or mobile viewport should disable the touch ack timeout. | 236 // A fixed page scale or mobile viewport should disable the touch ack timeout. |
244 UpdateTouchAckTimeoutEnabled(); | 237 UpdateTouchAckTimeoutEnabled(); |
245 } | 238 } |
246 | 239 |
| 240 void InputRouterImpl::RequestNotificationWhenFlushed() { |
| 241 flush_requested_ = true; |
| 242 SignalFlushedIfNecessary(); |
| 243 } |
| 244 |
| 245 bool InputRouterImpl::HasPendingEvents() const { |
| 246 return !touch_event_queue_.empty() || |
| 247 !gesture_event_queue_.empty() || |
| 248 gesture_event_queue_.active_fling_count() || |
| 249 !key_queue_.empty() || |
| 250 mouse_move_pending_ || |
| 251 mouse_wheel_pending_ || |
| 252 select_message_pending_ || |
| 253 move_caret_pending_; |
| 254 } |
| 255 |
247 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { | 256 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { |
248 bool handled = true; | 257 bool handled = true; |
249 IPC_BEGIN_MESSAGE_MAP(InputRouterImpl, message) | 258 IPC_BEGIN_MESSAGE_MAP(InputRouterImpl, message) |
250 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) | 259 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) |
251 IPC_MESSAGE_HANDLER(InputHostMsg_DidOverscroll, OnDidOverscroll) | 260 IPC_MESSAGE_HANDLER(InputHostMsg_DidOverscroll, OnDidOverscroll) |
252 IPC_MESSAGE_HANDLER(InputHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) | 261 IPC_MESSAGE_HANDLER(InputHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) |
253 IPC_MESSAGE_HANDLER(InputHostMsg_SelectRange_ACK, OnSelectMessageAck) | 262 IPC_MESSAGE_HANDLER(InputHostMsg_SelectRange_ACK, OnSelectMessageAck) |
254 IPC_MESSAGE_HANDLER(InputHostMsg_MoveRangeSelectionExtent_ACK, | 263 IPC_MESSAGE_HANDLER(InputHostMsg_MoveRangeSelectionExtent_ACK, |
255 OnSelectMessageAck) | 264 OnSelectMessageAck) |
256 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 265 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
257 OnHasTouchEventHandlers) | 266 OnHasTouchEventHandlers) |
258 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction, | 267 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction, |
259 OnSetTouchAction) | 268 OnSetTouchAction) |
| 269 IPC_MESSAGE_HANDLER(InputHostMsg_DidStopFlinging, OnDidStopFlinging) |
260 IPC_MESSAGE_UNHANDLED(handled = false) | 270 IPC_MESSAGE_UNHANDLED(handled = false) |
261 IPC_END_MESSAGE_MAP() | 271 IPC_END_MESSAGE_MAP() |
262 | 272 |
263 return handled; | 273 return handled; |
264 } | 274 } |
265 | 275 |
266 void InputRouterImpl::OnTouchEventAck(const TouchEventWithLatencyInfo& event, | 276 void InputRouterImpl::OnTouchEventAck(const TouchEventWithLatencyInfo& event, |
267 InputEventAckState ack_result) { | 277 InputEventAckState ack_result) { |
268 // Touchstart events sent to the renderer indicate a new touch sequence, but | 278 // 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. | 279 // 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 Loading... |
478 DCHECK(touch_event_queue_.IsPendingAckTouchStart()); | 488 DCHECK(touch_event_queue_.IsPendingAckTouchStart()); |
479 TRACE_EVENT1("input", "InputRouterImpl::OnSetTouchAction", | 489 TRACE_EVENT1("input", "InputRouterImpl::OnSetTouchAction", |
480 "action", touch_action); | 490 "action", touch_action); |
481 | 491 |
482 touch_action_filter_.OnSetTouchAction(touch_action); | 492 touch_action_filter_.OnSetTouchAction(touch_action); |
483 | 493 |
484 // TOUCH_ACTION_NONE should disable the touch ack timeout. | 494 // TOUCH_ACTION_NONE should disable the touch ack timeout. |
485 UpdateTouchAckTimeoutEnabled(); | 495 UpdateTouchAckTimeoutEnabled(); |
486 } | 496 } |
487 | 497 |
| 498 void InputRouterImpl::OnDidStopFlinging() { |
| 499 gesture_event_queue_.DidStopFlinging(); |
| 500 SignalFlushedIfNecessary(); |
| 501 client_->DidStopFlinging(); |
| 502 } |
| 503 |
488 void InputRouterImpl::ProcessInputEventAck( | 504 void InputRouterImpl::ProcessInputEventAck( |
489 WebInputEvent::Type event_type, | 505 WebInputEvent::Type event_type, |
490 InputEventAckState ack_result, | 506 InputEventAckState ack_result, |
491 const ui::LatencyInfo& latency_info, | 507 const ui::LatencyInfo& latency_info, |
492 AckSource ack_source) { | 508 AckSource ack_source) { |
493 TRACE_EVENT2("input", "InputRouterImpl::ProcessInputEventAck", | 509 TRACE_EVENT2("input", "InputRouterImpl::ProcessInputEventAck", |
494 "type", WebInputEventTraits::GetName(event_type), | 510 "type", WebInputEventTraits::GetName(event_type), |
495 "ack", GetEventAckName(ack_result)); | 511 "ack", GetEventAckName(ack_result)); |
496 | 512 |
497 // Note: The keyboard ack must be treated carefully, as it may result in | 513 // Note: The keyboard ack must be treated carefully, as it may result in |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 if (!flush_requested_) | 635 if (!flush_requested_) |
620 return; | 636 return; |
621 | 637 |
622 if (HasPendingEvents()) | 638 if (HasPendingEvents()) |
623 return; | 639 return; |
624 | 640 |
625 flush_requested_ = false; | 641 flush_requested_ = false; |
626 client_->DidFlush(); | 642 client_->DidFlush(); |
627 } | 643 } |
628 | 644 |
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 | 645 } // namespace content |
OLD | NEW |