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

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

Issue 657803002: Update touch selection to only modify one selection point at a time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More updates Created 6 years, 2 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 InputRouterImpl::InputRouterImpl(IPC::Sender* sender, 62 InputRouterImpl::InputRouterImpl(IPC::Sender* sender,
63 InputRouterClient* client, 63 InputRouterClient* client,
64 InputAckHandler* ack_handler, 64 InputAckHandler* ack_handler,
65 int routing_id, 65 int routing_id,
66 const Config& config) 66 const Config& config)
67 : sender_(sender), 67 : sender_(sender),
68 client_(client), 68 client_(client),
69 ack_handler_(ack_handler), 69 ack_handler_(ack_handler),
70 routing_id_(routing_id), 70 routing_id_(routing_id),
71 select_range_pending_(false), 71 select_message_pending_(false),
72 move_caret_pending_(false), 72 move_caret_pending_(false),
73 mouse_move_pending_(false), 73 mouse_move_pending_(false),
74 mouse_wheel_pending_(false), 74 mouse_wheel_pending_(false),
75 current_view_flags_(0), 75 current_view_flags_(0),
76 current_ack_source_(ACK_SOURCE_NONE), 76 current_ack_source_(ACK_SOURCE_NONE),
77 flush_requested_(false), 77 flush_requested_(false),
78 touch_event_queue_(this, config.touch_config), 78 touch_event_queue_(this, config.touch_config),
79 gesture_event_queue_(this, this, config.gesture_config) { 79 gesture_event_queue_(this, this, config.gesture_config) {
80 DCHECK(sender); 80 DCHECK(sender);
81 DCHECK(client); 81 DCHECK(client);
82 DCHECK(ack_handler); 82 DCHECK(ack_handler);
83 UpdateTouchAckTimeoutEnabled(); 83 UpdateTouchAckTimeoutEnabled();
84 } 84 }
85 85
86 InputRouterImpl::~InputRouterImpl() {} 86 InputRouterImpl::~InputRouterImpl() {
87 for (auto* message : pending_select_messages_) {
jdduke (slow) 2014/10/27 15:22:13 Woo, range for! For now, let's stick with STLDele
88 delete message;
89 }
90 }
87 91
88 void InputRouterImpl::Flush() { 92 void InputRouterImpl::Flush() {
89 flush_requested_ = true; 93 flush_requested_ = true;
90 SignalFlushedIfNecessary(); 94 SignalFlushedIfNecessary();
91 } 95 }
92 96
93 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) { 97 bool InputRouterImpl::SendInput(scoped_ptr<IPC::Message> message) {
94 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart); 98 DCHECK(IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart);
95 switch (message->type()) { 99 switch (message->type()) {
96 // Check for types that require an ACK. 100 // Check for types that require an ACK.
97 case InputMsg_SelectRange::ID: 101 case InputMsg_SelectRange::ID:
98 return SendSelectRange(message.Pass()); 102 case InputMsg_MoveRangeSelectionExtent::ID:
103 return SendSelectMessage(message.Pass());
99 case InputMsg_MoveCaret::ID: 104 case InputMsg_MoveCaret::ID:
100 return SendMoveCaret(message.Pass()); 105 return SendMoveCaret(message.Pass());
101 case InputMsg_HandleInputEvent::ID: 106 case InputMsg_HandleInputEvent::ID:
102 NOTREACHED() << "WebInputEvents should never be sent via SendInput."; 107 NOTREACHED() << "WebInputEvents should never be sent via SendInput.";
103 return false; 108 return false;
104 default: 109 default:
105 return Send(message.release()); 110 return Send(message.release());
106 } 111 }
107 } 112 }
108 113
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 265
261 // A fixed page scale or mobile viewport should disable the touch ack timeout. 266 // A fixed page scale or mobile viewport should disable the touch ack timeout.
262 UpdateTouchAckTimeoutEnabled(); 267 UpdateTouchAckTimeoutEnabled();
263 } 268 }
264 269
265 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { 270 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) {
266 bool handled = true; 271 bool handled = true;
267 IPC_BEGIN_MESSAGE_MAP(InputRouterImpl, message) 272 IPC_BEGIN_MESSAGE_MAP(InputRouterImpl, message)
268 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck) 273 IPC_MESSAGE_HANDLER(InputHostMsg_HandleInputEvent_ACK, OnInputEventAck)
269 IPC_MESSAGE_HANDLER(InputHostMsg_DidOverscroll, OnDidOverscroll) 274 IPC_MESSAGE_HANDLER(InputHostMsg_DidOverscroll, OnDidOverscroll)
270 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck) 275 IPC_MESSAGE_HANDLER(InputHostMsg_MoveCaret_ACK, OnMsgMoveCaretAck)
271 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnSelectRangeAck) 276 IPC_MESSAGE_HANDLER(InputHostMsg_SelectRange_ACK, OnSelectMessageAck)
277 IPC_MESSAGE_HANDLER(InputHostMsg_MoveRangeSelectionExtent_ACK,
278 OnSelectMessageAck)
272 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, 279 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
273 OnHasTouchEventHandlers) 280 OnHasTouchEventHandlers)
274 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction, 281 IPC_MESSAGE_HANDLER(InputHostMsg_SetTouchAction,
275 OnSetTouchAction) 282 OnSetTouchAction)
276 IPC_MESSAGE_UNHANDLED(handled = false) 283 IPC_MESSAGE_UNHANDLED(handled = false)
277 IPC_END_MESSAGE_MAP() 284 IPC_END_MESSAGE_MAP()
278 285
279 return handled; 286 return handled;
280 } 287 }
281 288
282 void InputRouterImpl::OnTouchEventAck(const TouchEventWithLatencyInfo& event, 289 void InputRouterImpl::OnTouchEventAck(const TouchEventWithLatencyInfo& event,
283 InputEventAckState ack_result) { 290 InputEventAckState ack_result) {
284 // Touchstart events sent to the renderer indicate a new touch sequence, but 291 // Touchstart events sent to the renderer indicate a new touch sequence, but
285 // in some cases we may filter out sending the touchstart - catch those here. 292 // in some cases we may filter out sending the touchstart - catch those here.
286 if (WebTouchEventTraits::IsTouchSequenceStart(event.event) && 293 if (WebTouchEventTraits::IsTouchSequenceStart(event.event) &&
287 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) { 294 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) {
288 touch_action_filter_.ResetTouchAction(); 295 touch_action_filter_.ResetTouchAction();
289 UpdateTouchAckTimeoutEnabled(); 296 UpdateTouchAckTimeoutEnabled();
290 } 297 }
291 ack_handler_->OnTouchEventAck(event, ack_result); 298 ack_handler_->OnTouchEventAck(event, ack_result);
292 } 299 }
293 300
294 void InputRouterImpl::OnGestureEventAck( 301 void InputRouterImpl::OnGestureEventAck(
295 const GestureEventWithLatencyInfo& event, 302 const GestureEventWithLatencyInfo& event,
296 InputEventAckState ack_result) { 303 InputEventAckState ack_result) {
297 touch_event_queue_.OnGestureEventAck(event, ack_result); 304 touch_event_queue_.OnGestureEventAck(event, ack_result);
298 ack_handler_->OnGestureEventAck(event, ack_result); 305 ack_handler_->OnGestureEventAck(event, ack_result);
299 } 306 }
300 307
301 bool InputRouterImpl::SendSelectRange(scoped_ptr<IPC::Message> message) { 308 bool InputRouterImpl::SendSelectMessage(
302 DCHECK(message->type() == InputMsg_SelectRange::ID); 309 scoped_ptr<IPC::Message> message) {
303 if (select_range_pending_) { 310 DCHECK(message->type() == InputMsg_SelectRange::ID ||
304 next_selection_range_ = message.Pass(); 311 message->type() == InputMsg_MoveRangeSelectionExtent::ID);
312
313 // TODO(jdduke): Factor out common logic between selection and caret-related
314 // IPC messages.
315 if (select_message_pending_) {
316 if (!pending_select_messages_.empty() &&
317 pending_select_messages_.back()->type() == message->type()) {
318 delete pending_select_messages_.back();
319 pending_select_messages_.pop_back();
320 }
321
322 pending_select_messages_.push_back(message.release());
305 return true; 323 return true;
306 } 324 }
307 325
308 select_range_pending_ = true; 326 select_message_pending_ = true;
309 return Send(message.release()); 327 return Send(message.release());
310 } 328 }
311 329
312 bool InputRouterImpl::SendMoveCaret(scoped_ptr<IPC::Message> message) { 330 bool InputRouterImpl::SendMoveCaret(scoped_ptr<IPC::Message> message) {
313 DCHECK(message->type() == InputMsg_MoveCaret::ID); 331 DCHECK(message->type() == InputMsg_MoveCaret::ID);
314 if (move_caret_pending_) { 332 if (move_caret_pending_) {
315 next_move_caret_ = message.Pass(); 333 next_move_caret_ = message.Pass();
316 return true; 334 return true;
317 } 335 }
318 336
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 void InputRouterImpl::OnDidOverscroll(const DidOverscrollParams& params) { 498 void InputRouterImpl::OnDidOverscroll(const DidOverscrollParams& params) {
481 client_->DidOverscroll(params); 499 client_->DidOverscroll(params);
482 } 500 }
483 501
484 void InputRouterImpl::OnMsgMoveCaretAck() { 502 void InputRouterImpl::OnMsgMoveCaretAck() {
485 move_caret_pending_ = false; 503 move_caret_pending_ = false;
486 if (next_move_caret_) 504 if (next_move_caret_)
487 SendMoveCaret(next_move_caret_.Pass()); 505 SendMoveCaret(next_move_caret_.Pass());
488 } 506 }
489 507
490 void InputRouterImpl::OnSelectRangeAck() { 508 void InputRouterImpl::OnSelectMessageAck() {
491 select_range_pending_ = false; 509 select_message_pending_ = false;
492 if (next_selection_range_) 510 if (!pending_select_messages_.empty()) {
493 SendSelectRange(next_selection_range_.Pass()); 511 SendSelectMessage(make_scoped_ptr(pending_select_messages_.front()));
512 pending_select_messages_.pop_front();
jdduke (slow) 2014/10/27 15:22:13 As a precaution, let's store |front()| in a local
513 }
494 } 514 }
495 515
496 void InputRouterImpl::OnHasTouchEventHandlers(bool has_handlers) { 516 void InputRouterImpl::OnHasTouchEventHandlers(bool has_handlers) {
497 TRACE_EVENT1("input", "InputRouterImpl::OnHasTouchEventHandlers", 517 TRACE_EVENT1("input", "InputRouterImpl::OnHasTouchEventHandlers",
498 "has_handlers", has_handlers); 518 "has_handlers", has_handlers);
499 519
500 // Lack of a touch handler indicates that the page either has no touch-action 520 // Lack of a touch handler indicates that the page either has no touch-action
501 // modifiers or that all its touch-action modifiers are auto. Resetting the 521 // modifiers or that all its touch-action modifiers are auto. Resetting the
502 // touch-action here allows forwarding of subsequent gestures even if the 522 // touch-action here allows forwarding of subsequent gestures even if the
503 // underlying touches never reach the router. 523 // underlying touches never reach the router.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 flush_requested_ = false; 692 flush_requested_ = false;
673 client_->DidFlush(); 693 client_->DidFlush();
674 } 694 }
675 695
676 bool InputRouterImpl::HasPendingEvents() const { 696 bool InputRouterImpl::HasPendingEvents() const {
677 return !touch_event_queue_.empty() || 697 return !touch_event_queue_.empty() ||
678 !gesture_event_queue_.empty() || 698 !gesture_event_queue_.empty() ||
679 !key_queue_.empty() || 699 !key_queue_.empty() ||
680 mouse_move_pending_ || 700 mouse_move_pending_ ||
681 mouse_wheel_pending_ || 701 mouse_wheel_pending_ ||
682 select_range_pending_ || 702 select_message_pending_ ||
683 move_caret_pending_; 703 move_caret_pending_;
684 } 704 }
685 705
686 InputRouterImpl::QueuedWheelEvent::QueuedWheelEvent() 706 InputRouterImpl::QueuedWheelEvent::QueuedWheelEvent()
687 : synthesized_from_pinch(false) { 707 : synthesized_from_pinch(false) {
688 } 708 }
689 709
690 InputRouterImpl::QueuedWheelEvent::QueuedWheelEvent( 710 InputRouterImpl::QueuedWheelEvent::QueuedWheelEvent(
691 const MouseWheelEventWithLatencyInfo& event, 711 const MouseWheelEventWithLatencyInfo& event,
692 bool synthesized_from_pinch) 712 bool synthesized_from_pinch)
693 : event(event), synthesized_from_pinch(synthesized_from_pinch) { 713 : event(event), synthesized_from_pinch(synthesized_from_pinch) {
694 } 714 }
695 715
696 InputRouterImpl::QueuedWheelEvent::~QueuedWheelEvent() { 716 InputRouterImpl::QueuedWheelEvent::~QueuedWheelEvent() {
697 } 717 }
698 718
699 } // namespace content 719 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698