Chromium Code Reviews| 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/immediate_input_router.h" | 5 #include "content/browser/renderer_host/input/immediate_input_router.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "content/browser/renderer_host/input/gesture_event_filter.h" | 10 #include "content/browser/renderer_host/input/gesture_event_filter.h" |
| 11 #include "content/browser/renderer_host/input/input_ack_handler.h" | 11 #include "content/browser/renderer_host/input/input_ack_handler.h" |
| 12 #include "content/browser/renderer_host/input/input_router_client.h" | 12 #include "content/browser/renderer_host/input/input_router_client.h" |
| 13 #include "content/browser/renderer_host/input/touch_event_queue.h" | 13 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 14 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle r.h" | 14 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle r.h" |
| 15 #include "content/browser/renderer_host/overscroll_controller.h" | 15 #include "content/browser/renderer_host/overscroll_controller.h" |
| 16 #include "content/common/content_constants_internal.h" | 16 #include "content/common/content_constants_internal.h" |
| 17 #include "content/common/edit_command.h" | 17 #include "content/common/edit_command.h" |
| 18 #include "content/common/input/web_input_event_traits.h" | 18 #include "content/common/input/web_input_event_traits.h" |
| 19 #include "content/common/input_messages.h" | 19 #include "content/common/input_messages.h" |
| 20 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
| 21 #include "content/port/common/input_event_ack_state.h" | 21 #include "content/port/common/input_event_ack_state.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/touch_action.h" | |
| 26 #include "ipc/ipc_sender.h" | 27 #include "ipc/ipc_sender.h" |
| 27 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
| 28 #include "ui/events/keycodes/keyboard_codes.h" | 29 #include "ui/events/keycodes/keyboard_codes.h" |
| 29 | 30 |
| 30 using base::Time; | 31 using base::Time; |
| 31 using base::TimeDelta; | 32 using base::TimeDelta; |
| 32 using base::TimeTicks; | 33 using base::TimeTicks; |
| 33 using blink::WebGestureEvent; | 34 using blink::WebGestureEvent; |
| 34 using blink::WebInputEvent; | 35 using blink::WebInputEvent; |
| 35 using blink::WebKeyboardEvent; | 36 using blink::WebKeyboardEvent; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 174 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
| 174 | 175 |
| 175 gesture_event_filter_->FlingHasBeenHalted(); | 176 gesture_event_filter_->FlingHasBeenHalted(); |
| 176 | 177 |
| 177 // Only forward the non-native portions of our event. | 178 // Only forward the non-native portions of our event. |
| 178 FilterAndSendWebInputEvent(key_event, latency_info, is_keyboard_shortcut); | 179 FilterAndSendWebInputEvent(key_event, latency_info, is_keyboard_shortcut); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void ImmediateInputRouter::SendGestureEvent( | 182 void ImmediateInputRouter::SendGestureEvent( |
| 182 const GestureEventWithLatencyInfo& gesture_event) { | 183 const GestureEventWithLatencyInfo& gesture_event) { |
| 184 if (touch_action_filter_.FilterGestureEvent(gesture_event.event)) | |
| 185 return; | |
| 186 | |
| 183 HandleGestureScroll(gesture_event); | 187 HandleGestureScroll(gesture_event); |
| 184 | 188 |
| 185 if (!IsInOverscrollGesture() && | 189 if (!IsInOverscrollGesture() && |
| 186 !gesture_event_filter_->ShouldForward(gesture_event)) { | 190 !gesture_event_filter_->ShouldForward(gesture_event)) { |
| 187 OverscrollController* controller = client_->GetOverscrollController(); | 191 OverscrollController* controller = client_->GetOverscrollController(); |
| 188 if (controller) | 192 if (controller) |
| 189 controller->DiscardingGestureEvent(gesture_event.event); | 193 controller->DiscardingGestureEvent(gesture_event.event); |
| 190 return; | 194 return; |
| 191 } | 195 } |
| 192 | 196 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 220 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency, false); | 224 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency, false); |
| 221 } | 225 } |
| 222 | 226 |
| 223 void ImmediateInputRouter::SendTouchEventImmediately( | 227 void ImmediateInputRouter::SendTouchEventImmediately( |
| 224 const TouchEventWithLatencyInfo& touch_event) { | 228 const TouchEventWithLatencyInfo& touch_event) { |
| 225 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency, false); | 229 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency, false); |
| 226 } | 230 } |
| 227 | 231 |
| 228 void ImmediateInputRouter::SendGestureEventImmediately( | 232 void ImmediateInputRouter::SendGestureEventImmediately( |
| 229 const GestureEventWithLatencyInfo& gesture_event) { | 233 const GestureEventWithLatencyInfo& gesture_event) { |
| 234 if (touch_action_filter_.FilterGestureEvent(gesture_event.event)) | |
|
jdduke (slow)
2013/11/18 15:56:00
Hmm, do you know why |HandleGestureScroll()| is in
Rick Byers
2013/11/19 22:14:59
Ah, I was thinking a gesture event could come in b
| |
| 235 return; | |
| 230 HandleGestureScroll(gesture_event); | 236 HandleGestureScroll(gesture_event); |
| 231 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false); | 237 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false); |
| 232 } | 238 } |
| 233 | 239 |
| 234 const NativeWebKeyboardEvent* | 240 const NativeWebKeyboardEvent* |
| 235 ImmediateInputRouter::GetLastKeyboardEvent() const { | 241 ImmediateInputRouter::GetLastKeyboardEvent() const { |
| 236 if (key_queue_.empty()) | 242 if (key_queue_.empty()) |
| 237 return NULL; | 243 return NULL; |
| 238 return &key_queue_.front(); | 244 return &key_queue_.front(); |
| 239 } | 245 } |
| 240 | 246 |
| 241 bool ImmediateInputRouter::ShouldForwardTouchEvent() const { | 247 bool ImmediateInputRouter::ShouldForwardTouchEvent() const { |
| 242 // Always send a touch event if the renderer has a touch-event handler. It is | 248 // Always send a touch event if the renderer has a touch-event handler. It is |
| 243 // possible that a renderer stops listening to touch-events while there are | 249 // possible that a renderer stops listening to touch-events while there are |
| 244 // still events in the touch-queue. In such cases, the new events should still | 250 // still events in the touch-queue. In such cases, the new events should still |
| 245 // get into the queue. | 251 // get into the queue. |
| 246 return has_touch_handler_ || !touch_event_queue_->empty(); | 252 return has_touch_handler_ || !touch_event_queue_->empty(); |
| 247 } | 253 } |
| 248 | 254 |
| 249 bool ImmediateInputRouter::OnMessageReceived(const IPC::Message& message) { | 255 bool ImmediateInputRouter::OnMessageReceived(const IPC::Message& message) { |
| 250 bool handled = true; | 256 bool handled = true; |
| 251 bool message_is_ok = true; | 257 bool message_is_ok = true; |
| 252 IPC_BEGIN_MESSAGE_MAP_EX(ImmediateInputRouter, message, message_is_ok) | 258 IPC_BEGIN_MESSAGE_MAP_EX(ImmediateInputRouter, message, message_is_ok) |
| 253 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) | 259 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) |
| 254 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) | 260 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) |
| 255 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) | 261 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) |
| 256 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 262 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
| 257 OnHasTouchEventHandlers) | 263 OnHasTouchEventHandlers) |
| 264 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTouchAction, | |
| 265 OnSetTouchAction) | |
| 258 IPC_MESSAGE_UNHANDLED(handled = false) | 266 IPC_MESSAGE_UNHANDLED(handled = false) |
| 259 IPC_END_MESSAGE_MAP() | 267 IPC_END_MESSAGE_MAP() |
| 260 | 268 |
| 261 if (!message_is_ok) | 269 if (!message_is_ok) |
| 262 ack_handler_->OnUnexpectedEventAck(InputAckHandler::BAD_ACK_MESSAGE); | 270 ack_handler_->OnUnexpectedEventAck(InputAckHandler::BAD_ACK_MESSAGE); |
| 263 | 271 |
| 264 return handled; | 272 return handled; |
| 265 } | 273 } |
| 266 | 274 |
| 267 void ImmediateInputRouter::OnTouchEventAck( | 275 void ImmediateInputRouter::OnTouchEventAck( |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 | 475 |
| 468 void ImmediateInputRouter::OnHasTouchEventHandlers(bool has_handlers) { | 476 void ImmediateInputRouter::OnHasTouchEventHandlers(bool has_handlers) { |
| 469 if (has_touch_handler_ == has_handlers) | 477 if (has_touch_handler_ == has_handlers) |
| 470 return; | 478 return; |
| 471 has_touch_handler_ = has_handlers; | 479 has_touch_handler_ = has_handlers; |
| 472 if (!has_handlers) | 480 if (!has_handlers) |
| 473 touch_event_queue_->FlushQueue(); | 481 touch_event_queue_->FlushQueue(); |
| 474 client_->OnHasTouchEventHandlers(has_handlers); | 482 client_->OnHasTouchEventHandlers(has_handlers); |
| 475 } | 483 } |
| 476 | 484 |
| 485 void ImmediateInputRouter::OnSetTouchAction( | |
| 486 int touch_id, | |
| 487 content::TouchAction touchAction) | |
|
jdduke (slow)
2013/11/18 15:56:00
Nit: Brace on same line as closing paren.
sadrul
2013/11/19 10:36:44
touch_action
Rick Byers
2013/11/19 22:14:59
Done.
Rick Byers
2013/11/19 22:14:59
Done.
| |
| 488 { | |
| 489 // Don't process touch-action messages for synthetic touches we know | |
| 490 // nothing about. | |
| 491 if (touch_event_queue_->IsPendingAckTouchStart(touch_id)) | |
| 492 touch_action_filter_.OnSetTouchAction(touch_id, touchAction); | |
| 493 } | |
| 494 | |
| 477 void ImmediateInputRouter::ProcessInputEventAck( | 495 void ImmediateInputRouter::ProcessInputEventAck( |
| 478 WebInputEvent::Type event_type, | 496 WebInputEvent::Type event_type, |
| 479 InputEventAckState ack_result, | 497 InputEventAckState ack_result, |
| 480 const ui::LatencyInfo& latency_info, | 498 const ui::LatencyInfo& latency_info, |
| 481 AckSource ack_source) { | 499 AckSource ack_source) { |
| 482 TRACE_EVENT2("input", "ImmediateInputRouter::ProcessInputEventAck", | 500 TRACE_EVENT2("input", "ImmediateInputRouter::ProcessInputEventAck", |
| 483 "type", WebInputEventTraits::GetName(event_type), | 501 "type", WebInputEventTraits::GetName(event_type), |
| 484 "ack", GetEventAckName(ack_result)); | 502 "ack", GetEventAckName(ack_result)); |
| 485 | 503 |
| 486 // Note: The keyboard ack must be treated carefully, as it may result in | 504 // Note: The keyboard ack must be treated carefully, as it may result in |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 break; | 705 break; |
| 688 } | 706 } |
| 689 } | 707 } |
| 690 | 708 |
| 691 bool ImmediateInputRouter::IsInOverscrollGesture() const { | 709 bool ImmediateInputRouter::IsInOverscrollGesture() const { |
| 692 OverscrollController* controller = client_->GetOverscrollController(); | 710 OverscrollController* controller = client_->GetOverscrollController(); |
| 693 return controller && controller->overscroll_mode() != OVERSCROLL_NONE; | 711 return controller && controller->overscroll_mode() != OVERSCROLL_NONE; |
| 694 } | 712 } |
| 695 | 713 |
| 696 } // namespace content | 714 } // namespace content |
| OLD | NEW |