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

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: Handle no consumer 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/web_input_event_traits.h" 19 #include "content/common/input/web_input_event_traits.h"
19 #include "content/common/input_messages.h" 20 #include "content/common/input_messages.h"
(...skipping 12 matching lines...) Expand all
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;
36 using blink::WebMouseEvent; 37 using blink::WebMouseEvent;
37 using blink::WebMouseWheelEvent; 38 using blink::WebMouseWheelEvent;
38 39
39 namespace content { 40 namespace content {
40 namespace { 41 namespace {
41 42
43 bool GetTouchAckTimeoutDelayMs(size_t* touch_ack_timeout_delay_ms) {
44 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
45 if (!parsed_command_line->HasSwitch(switches::kTouchAckTimeoutDelayMs))
46 return false;
47
48 std::string timeout_string = parsed_command_line->GetSwitchValueASCII(
49 switches::kTouchAckTimeoutDelayMs);
50 size_t timeout_value;
51 if (!base::StringToSizeT(timeout_string, &timeout_value))
52 return false;
53
54 *touch_ack_timeout_delay_ms = timeout_value;
55 return true;
56 }
57
42 GestureEventWithLatencyInfo MakeGestureEvent(WebInputEvent::Type type, 58 GestureEventWithLatencyInfo MakeGestureEvent(WebInputEvent::Type type,
43 double timestamp_seconds, 59 double timestamp_seconds,
44 int x, 60 int x,
45 int y, 61 int y,
46 int modifiers, 62 int modifiers,
47 const ui::LatencyInfo latency) { 63 const ui::LatencyInfo latency) {
48 WebGestureEvent result; 64 WebGestureEvent result;
49 65
50 result.type = type; 66 result.type = type;
51 result.x = x; 67 result.x = x;
(...skipping 26 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); 191 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size());
170 192
171 gesture_event_filter_->FlingHasBeenHalted(); 193 gesture_event_filter_->FlingHasBeenHalted();
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 HandleGestureScroll(gesture_event); 201 touch_event_queue_->OnGestureScrollEvent(gesture_event);
180 202
181 if (!IsInOverscrollGesture() && 203 if (!IsInOverscrollGesture() &&
182 !gesture_event_filter_->ShouldForward(gesture_event)) { 204 !gesture_event_filter_->ShouldForward(gesture_event)) {
183 OverscrollController* controller = client_->GetOverscrollController(); 205 OverscrollController* controller = client_->GetOverscrollController();
184 if (controller) 206 if (controller)
185 controller->DiscardingGestureEvent(gesture_event.event); 207 controller->DiscardingGestureEvent(gesture_event.event);
186 return; 208 return;
187 } 209 }
188 210
189 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false); 211 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false);
(...skipping 26 matching lines...) Expand all
216 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency, false); 238 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency, false);
217 } 239 }
218 240
219 void InputRouterImpl::SendTouchEventImmediately( 241 void InputRouterImpl::SendTouchEventImmediately(
220 const TouchEventWithLatencyInfo& touch_event) { 242 const TouchEventWithLatencyInfo& touch_event) {
221 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency, false); 243 FilterAndSendWebInputEvent(touch_event.event, touch_event.latency, false);
222 } 244 }
223 245
224 void InputRouterImpl::SendGestureEventImmediately( 246 void InputRouterImpl::SendGestureEventImmediately(
225 const GestureEventWithLatencyInfo& gesture_event) { 247 const GestureEventWithLatencyInfo& gesture_event) {
226 HandleGestureScroll(gesture_event);
227 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false); 248 FilterAndSendWebInputEvent(gesture_event.event, gesture_event.latency, false);
228 } 249 }
229 250
230 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const { 251 const NativeWebKeyboardEvent* InputRouterImpl::GetLastKeyboardEvent() const {
231 if (key_queue_.empty()) 252 if (key_queue_.empty())
232 return NULL; 253 return NULL;
233 return &key_queue_.front(); 254 return &key_queue_.front();
234 } 255 }
235 256
236 bool InputRouterImpl::ShouldForwardTouchEvent() const { 257 bool InputRouterImpl::ShouldForwardTouchEvent() const {
237 // Always send a touch event if the renderer has a touch-event handler. It is 258 // Always send a touch event if the renderer has a touch-event handler. It is
238 // possible that a renderer stops listening to touch-events while there are 259 // possible that a renderer stops listening to touch-events while there are
239 // still events in the touch-queue. In such cases, the new events should still 260 // still events in the touch-queue. In such cases, the new events should still
240 // get into the queue. 261 // get into the queue.
241 return has_touch_handler_ || !touch_event_queue_->empty(); 262 return has_touch_handler_ || !touch_event_queue_->empty();
242 } 263 }
243 264
265 void InputRouterImpl::OnViewUpdated(int view_flags) {
266 bool fixed_page_scale = (view_flags & FIXED_PAGE_SCALE);
267 bool mobile_viewport = (view_flags & MOBILE_VIEWPORT);
268 touch_event_queue_->SetAckTimeoutEnabled(
269 touch_ack_timeout_enabled_ && !(fixed_page_scale || mobile_viewport),
270 touch_ack_timeout_delay_ms_);
271 }
272
244 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { 273 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) {
245 bool handled = true; 274 bool handled = true;
246 bool message_is_ok = true; 275 bool message_is_ok = true;
247 IPC_BEGIN_MESSAGE_MAP_EX(InputRouterImpl, message, message_is_ok) 276 IPC_BEGIN_MESSAGE_MAP_EX(InputRouterImpl, message, message_is_ok)
248 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) 277 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck)
249 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) 278 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck)
250 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) 279 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck)
251 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, 280 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
252 OnHasTouchEventHandlers) 281 OnHasTouchEventHandlers)
253 IPC_MESSAGE_UNHANDLED(handled = false) 282 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 return; 618 return;
590 619
591 OverscrollController* controller = client_->GetOverscrollController(); 620 OverscrollController* controller = client_->GetOverscrollController();
592 if (!controller) 621 if (!controller)
593 return; 622 return;
594 623
595 controller->ReceivedEventACK( 624 controller->ReceivedEventACK(
596 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); 625 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
597 } 626 }
598 627
599 void InputRouterImpl::HandleGestureScroll(
600 const GestureEventWithLatencyInfo& gesture_event) {
601 touch_event_queue_->OnGestureScrollEvent(gesture_event);
602 }
603
604 void InputRouterImpl::SimulateTouchGestureWithMouse( 628 void InputRouterImpl::SimulateTouchGestureWithMouse(
605 const MouseEventWithLatencyInfo& event) { 629 const MouseEventWithLatencyInfo& event) {
606 const WebMouseEvent& mouse_event = event.event; 630 const WebMouseEvent& mouse_event = event.event;
607 int x = mouse_event.x, y = mouse_event.y; 631 int x = mouse_event.x, y = mouse_event.y;
608 float dx = mouse_event.movementX, dy = mouse_event.movementY; 632 float dx = mouse_event.movementX, dy = mouse_event.movementY;
609 static int startX = 0, startY = 0; 633 static int startX = 0, startY = 0;
610 634
611 switch (mouse_event.button) { 635 switch (mouse_event.button) {
612 case WebMouseEvent::ButtonLeft: 636 case WebMouseEvent::ButtonLeft:
613 if (mouse_event.type == WebInputEvent::MouseDown) { 637 if (mouse_event.type == WebInputEvent::MouseDown) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 break; 704 break;
681 } 705 }
682 } 706 }
683 707
684 bool InputRouterImpl::IsInOverscrollGesture() const { 708 bool InputRouterImpl::IsInOverscrollGesture() const {
685 OverscrollController* controller = client_->GetOverscrollController(); 709 OverscrollController* controller = client_->GetOverscrollController();
686 return controller && controller->overscroll_mode() != OVERSCROLL_NONE; 710 return controller && controller->overscroll_mode() != OVERSCROLL_NONE;
687 } 711 }
688 712
689 } // namespace content 713 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698