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

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

Issue 48973005: Move TouchEvent timeout code to the TouchEventQueue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years 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 "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 "base/strings/string_number_conversions.h"
10 #include "content/browser/renderer_host/input/gesture_event_filter.h" 11 #include "content/browser/renderer_host/input/gesture_event_filter.h"
11 #include "content/browser/renderer_host/input/input_ack_handler.h" 12 #include "content/browser/renderer_host/input/input_ack_handler.h"
12 #include "content/browser/renderer_host/input/input_router_client.h" 13 #include "content/browser/renderer_host/input/input_router_client.h"
13 #include "content/browser/renderer_host/input/touch_event_queue.h" 14 #include "content/browser/renderer_host/input/touch_event_queue.h"
14 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle r.h" 15 #include "content/browser/renderer_host/input/touchpad_tap_suppression_controlle r.h"
15 #include "content/browser/renderer_host/overscroll_controller.h" 16 #include "content/browser/renderer_host/overscroll_controller.h"
16 #include "content/common/content_constants_internal.h" 17 #include "content/common/content_constants_internal.h"
17 #include "content/common/edit_command.h" 18 #include "content/common/edit_command.h"
18 #include "content/common/input/touch_action.h" 19 #include "content/common/input/touch_action.h"
19 #include "content/common/input/web_input_event_traits.h" 20 #include "content/common/input/web_input_event_traits.h"
(...skipping 13 matching lines...) Expand all
33 using base::TimeTicks; 34 using base::TimeTicks;
34 using blink::WebGestureEvent; 35 using blink::WebGestureEvent;
35 using blink::WebInputEvent; 36 using blink::WebInputEvent;
36 using blink::WebKeyboardEvent; 37 using blink::WebKeyboardEvent;
37 using blink::WebMouseEvent; 38 using blink::WebMouseEvent;
38 using blink::WebMouseWheelEvent; 39 using blink::WebMouseWheelEvent;
39 40
40 namespace content { 41 namespace content {
41 namespace { 42 namespace {
42 43
44 bool GetTouchAckTimeoutDelayMs(size_t* touch_ack_timeout_delay_ms) {
45 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
46 if (!parsed_command_line->HasSwitch(switches::kTouchAckTimeoutDelayMs))
47 return false;
48
49 std::string timeout_string = parsed_command_line->GetSwitchValueASCII(
50 switches::kTouchAckTimeoutDelayMs);
51 size_t timeout_value;
52 if (!base::StringToSizeT(timeout_string, &timeout_value))
53 return false;
54
55 *touch_ack_timeout_delay_ms = timeout_value;
56 return true;
57 }
58
43 GestureEventWithLatencyInfo MakeGestureEvent(WebInputEvent::Type type, 59 GestureEventWithLatencyInfo MakeGestureEvent(WebInputEvent::Type type,
44 double timestamp_seconds, 60 double timestamp_seconds,
45 int x, 61 int x,
46 int y, 62 int y,
47 int modifiers, 63 int modifiers,
48 const ui::LatencyInfo latency) { 64 const ui::LatencyInfo latency) {
49 WebGestureEvent result; 65 WebGestureEvent result;
50 66
51 result.type = type; 67 result.type = type;
52 result.x = x; 68 result.x = x;
(...skipping 25 matching lines...) Expand all
78 int routing_id) 94 int routing_id)
79 : sender_(sender), 95 : sender_(sender),
80 client_(client), 96 client_(client),
81 ack_handler_(ack_handler), 97 ack_handler_(ack_handler),
82 routing_id_(routing_id), 98 routing_id_(routing_id),
83 select_range_pending_(false), 99 select_range_pending_(false),
84 move_caret_pending_(false), 100 move_caret_pending_(false),
85 mouse_move_pending_(false), 101 mouse_move_pending_(false),
86 mouse_wheel_pending_(false), 102 mouse_wheel_pending_(false),
87 has_touch_handler_(false), 103 has_touch_handler_(false),
104 touch_ack_timeout_enabled_(false),
105 touch_ack_timeout_delay_ms_(std::numeric_limits<size_t>::max()),
88 current_ack_source_(ACK_SOURCE_NONE), 106 current_ack_source_(ACK_SOURCE_NONE),
89 touch_event_queue_(new TouchEventQueue(this)),
90 gesture_event_filter_(new GestureEventFilter(this, this)) { 107 gesture_event_filter_(new GestureEventFilter(this, this)) {
91 DCHECK(sender); 108 DCHECK(sender);
92 DCHECK(client); 109 DCHECK(client);
93 DCHECK(ack_handler); 110 DCHECK(ack_handler);
111 touch_event_queue_.reset(new TouchEventQueue(this));
112 touch_ack_timeout_enabled_ =
113 GetTouchAckTimeoutDelayMs(&touch_ack_timeout_delay_ms_);
114 touch_event_queue_->SetAckTimeoutEnabled(touch_ack_timeout_enabled_,
115 touch_ack_timeout_delay_ms_);
94 } 116 }
95 117
96 InputRouterImpl::~InputRouterImpl() {} 118 InputRouterImpl::~InputRouterImpl() {}
97 119
98 void InputRouterImpl::Flush() {} 120 void InputRouterImpl::Flush() {}
99 121
100 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) { 122 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) {
101 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart); 123 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart);
102 switch (message->type()) { 124 switch (message->type()) {
103 // Check for types that require an ACK. 125 // Check for types that require an ACK.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 194
173 // Only forward the non-native portions of our event. 195 // Only forward the non-native portions of our event.
174 FilterAndSendWebInputEvent(key_event, latency_info, is_keyboard_shortcut); 196 FilterAndSendWebInputEvent(key_event, latency_info, is_keyboard_shortcut);
175 } 197 }
176 198
177 void InputRouterImpl::SendGestureEvent( 199 void InputRouterImpl::SendGestureEvent(
178 const GestureEventWithLatencyInfo& gesture_event) { 200 const GestureEventWithLatencyInfo& gesture_event) {
179 if (touch_action_filter_.FilterGestureEvent(gesture_event.event)) 201 if (touch_action_filter_.FilterGestureEvent(gesture_event.event))
180 return; 202 return;
181 203
182 HandleGestureScroll(gesture_event); 204 touch_event_queue_->OnGestureScrollEvent(gesture_event);
183 205
184 if (!IsInOverscrollGesture() && 206 if (!IsInOverscrollGesture() &&
185 !gesture_event_filter_->ShouldForward(gesture_event)) { 207 !gesture_event_filter_->ShouldForward(gesture_event)) {
186 OverscrollController* controller = client_->GetOverscrollController(); 208 OverscrollController* controller = client_->GetOverscrollController();
187 if (controller) 209 if (controller)
188 controller->DiscardingGestureEvent(gesture_event.event); 210 controller->DiscardingGestureEvent(gesture_event.event);
189 return; 211 return;
190 } 212 }
191 213
192 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false); 214 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false);
(...skipping 26 matching lines...) Expand all
219 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency, false); 241 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency, false);
220 } 242 }
221 243
222 void InputRouterImpl::SendTouchEventImmediately( 244 void InputRouterImpl::SendTouchEventImmediately(
223 const TouchEventWithLatencyInfo& touch_event) { 245 const TouchEventWithLatencyInfo& touch_event) {
224 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency, false); 246 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency, false);
225 } 247 }
226 248
227 void InputRouterImpl::SendGestureEventImmediately( 249 void InputRouterImpl::SendGestureEventImmediately(
228 const GestureEventWithLatencyInfo& gesture_event) { 250 const GestureEventWithLatencyInfo& gesture_event) {
229 HandleGestureScroll(gesture_event);
230 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false); 251 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false);
231 } 252 }
232 253
233 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { 254 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const {
234 if (key_queue_.empty()) 255 if (key_queue_.empty())
235 return NULL; 256 return NULL;
236 return &key_queue_.front(); 257 return &key_queue_.front();
237 } 258 }
238 259
239 bool InputRouterImpl::ShouldForwardTouchEvent() const { 260 bool InputRouterImpl::ShouldForwardTouchEvent() const {
240 // Always send a touch event if the renderer has a touch-event handler. It is 261 // Always send a touch event if the renderer has a touch-event handler. It is
241 // possible that a renderer stops listening to touch-events while there are 262 // possible that a renderer stops listening to touch-events while there are
242 // still events in the touch-queue. In such cases, the new events should still 263 // still events in the touch-queue. In such cases, the new events should still
243 // get into the queue. 264 // get into the queue.
244 return has_touch_handler_ || !touch_event_queue_->empty(); 265 return has_touch_handler_ || !touch_event_queue_->empty();
245 } 266 }
246 267
268 void InputRouterImpl::OnViewUpdated(int view_flags) {
269 bool fixed_page_scale = (view_flags & FIXED_PAGE_SCALE) != 0;
270 bool mobile_viewport = (view_flags & MOBILE_VIEWPORT) != 0;
271 touch_event_queue_->SetAckTimeoutEnabled(
272 touch_ack_timeout_enabled_ && !(fixed_page_scale || mobile_viewport),
273 touch_ack_timeout_delay_ms_);
274 }
275
247 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { 276 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) {
248 bool handled = true; 277 bool handled = true;
249 bool message_is_ok = true; 278 bool message_is_ok = true;
250 IPC_BEGIN_MESSAGE_MAP_EX(InputRouterImpl, message, message_is_ok) 279 IPC_BEGIN_MESSAGE_MAP_EX(InputRouterImpl, message, message_is_ok)
251 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) 280 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck)
252 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) 281 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck)
253 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) 282 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck)
254 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, 283 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
255 OnHasTouchEventHandlers) 284 OnHasTouchEventHandlers)
256 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction, 285 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction,
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 return; 631 return;
603 632
604 OverscrollController* controller = client_->GetOverscrollController(); 633 OverscrollController* controller = client_->GetOverscrollController();
605 if (!controller) 634 if (!controller)
606 return; 635 return;
607 636
608 controller->ReceivedEventACK( 637 controller->ReceivedEventACK(
609 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); 638 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
610 } 639 }
611 640
612 void InputRouterImpl::HandleGestureScroll(
613 const GestureEventWithLatencyInfo& gesture_event) {
614 touch_event_queue_->OnGestureScrollEvent(gesture_event);
615 }
616
617 void InputRouterImpl::SimulateTouchGestureWithMouse( 641 void InputRouterImpl::SimulateTouchGestureWithMouse(
618 const MouseEventWithLatencyInfo& event) { 642 const MouseEventWithLatencyInfo& event) {
619 const WebMouseEvent& mouse_event = event.event; 643 const WebMouseEvent& mouse_event = event.event;
620 int x = mouse_event.x, y = mouse_event.y; 644 int x = mouse_event.x, y = mouse_event.y;
621 float dx = mouse_event.movementX, dy = mouse_event.movementY; 645 float dx = mouse_event.movementX, dy = mouse_event.movementY;
622 static int startX = 0, startY = 0; 646 static int startX = 0, startY = 0;
623 647
624 switch (mouse_event.button) { 648 switch (mouse_event.button) {
625 case WebMouseEvent::ButtonLeft: 649 case WebMouseEvent::ButtonLeft:
626 if (mouse_event.type == WebInputEvent::MouseDown) { 650 if (mouse_event.type == WebInputEvent::MouseDown) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 break; 717 break;
694 } 718 }
695 } 719 }
696 720
697 bool InputRouterImpl::IsInOverscrollGesture() const { 721 bool InputRouterImpl::IsInOverscrollGesture() const {
698 OverscrollController* controller = client_->GetOverscrollController(); 722 OverscrollController* controller = client_->GetOverscrollController();
699 return controller && controller->overscroll_mode() != OVERSCROLL_NONE; 723 return controller && controller->overscroll_mode() != OVERSCROLL_NONE;
700 } 724 }
701 725
702 } // namespace content 726 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698