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

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

Issue 235003005: Consolidate all touch/gesture related constants in content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused headers Created 6 years, 7 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 "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 "base/strings/string_number_conversions.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
23 #include "content/port/common/input_event_ack_state.h" 23 #include "content/port/common/input_event_ack_state.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/notification_types.h" 25 #include "content/public/browser/notification_types.h"
26 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
27 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
28 #include "ipc/ipc_sender.h" 28 #include "ipc/ipc_sender.h"
29 #include "ui/events/event.h" 29 #include "ui/events/event.h"
30 #include "ui/events/keycodes/keyboard_codes.h" 30 #include "ui/events/keycodes/keyboard_codes.h"
31 31
32 #if defined(OS_ANDROID)
33 #include "ui/gfx/android/view_configuration.h"
34 #include "ui/gfx/screen.h"
35 #else
36 #include "ui/events/gestures/gesture_configuration.h"
37 #endif
38
39 using base::Time; 32 using base::Time;
40 using base::TimeDelta; 33 using base::TimeDelta;
41 using base::TimeTicks; 34 using base::TimeTicks;
42 using blink::WebGestureEvent; 35 using blink::WebGestureEvent;
43 using blink::WebInputEvent; 36 using blink::WebInputEvent;
44 using blink::WebKeyboardEvent; 37 using blink::WebKeyboardEvent;
45 using blink::WebMouseEvent; 38 using blink::WebMouseEvent;
46 using blink::WebMouseWheelEvent; 39 using blink::WebMouseWheelEvent;
47 40
48 namespace content { 41 namespace content {
49 namespace { 42 namespace {
50 43
51 // TODO(jdduke): Instead of relying on command line flags or conditional
52 // conditional compilation here, we should instead use an InputRouter::Settings
53 // construct, supplied and customized by the RenderWidgetHostView. See
54 // crbug.com/343917.
55 bool GetTouchAckTimeoutDelay(base::TimeDelta* touch_ack_timeout_delay) {
56 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
57 if (!parsed_command_line->HasSwitch(switches::kTouchAckTimeoutDelayMs))
58 return false;
59
60 std::string timeout_string = parsed_command_line->GetSwitchValueASCII(
61 switches::kTouchAckTimeoutDelayMs);
62 size_t timeout_ms;
63 if (!base::StringToSizeT(timeout_string, &timeout_ms))
64 return false;
65
66 *touch_ack_timeout_delay = base::TimeDelta::FromMilliseconds(timeout_ms);
67 return true;
68 }
69
70 #if defined(OS_ANDROID)
71 double GetTouchMoveSlopSuppressionLengthDips() {
72 const double touch_slop_length_pixels =
73 static_cast<double>(gfx::ViewConfiguration::GetTouchSlopInPixels());
74 const double device_scale_factor =
75 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
76 return touch_slop_length_pixels / device_scale_factor;
77 }
78 #elif defined(USE_AURA)
79 double GetTouchMoveSlopSuppressionLengthDips() {
80 return ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
81 }
82 #else
83 double GetTouchMoveSlopSuppressionLengthDips() {
84 return 0;
85 }
86 #endif
87
88 TouchEventQueue::TouchScrollingMode GetTouchScrollingMode() {
89 std::string modeString = CommandLine::ForCurrentProcess()->
90 GetSwitchValueASCII(switches::kTouchScrollingMode);
91 if (modeString == switches::kTouchScrollingModeAsyncTouchmove)
92 return TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE;
93 if (modeString == switches::kTouchScrollingModeSyncTouchmove)
94 return TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE;
95 if (modeString == switches::kTouchScrollingModeTouchcancel)
96 return TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL;
97 if (modeString != "")
98 LOG(ERROR) << "Invalid --touch-scrolling-mode option: " << modeString;
99 return TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT;
100 }
101
102 const char* GetEventAckName(InputEventAckState ack_result) { 44 const char* GetEventAckName(InputEventAckState ack_result) {
103 switch(ack_result) { 45 switch(ack_result) {
104 case INPUT_EVENT_ACK_STATE_UNKNOWN: return "UNKNOWN"; 46 case INPUT_EVENT_ACK_STATE_UNKNOWN: return "UNKNOWN";
105 case INPUT_EVENT_ACK_STATE_CONSUMED: return "CONSUMED"; 47 case INPUT_EVENT_ACK_STATE_CONSUMED: return "CONSUMED";
106 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: return "NOT_CONSUMED"; 48 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: return "NOT_CONSUMED";
107 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: return "NO_CONSUMER_EXISTS"; 49 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: return "NO_CONSUMER_EXISTS";
108 case INPUT_EVENT_ACK_STATE_IGNORED: return "IGNORED"; 50 case INPUT_EVENT_ACK_STATE_IGNORED: return "IGNORED";
109 } 51 }
110 DLOG(WARNING) << "Unhandled InputEventAckState in GetEventAckName."; 52 DLOG(WARNING) << "Unhandled InputEventAckState in GetEventAckName.";
111 return ""; 53 return "";
112 } 54 }
113 55
114 } // namespace 56 } // namespace
115 57
58 InputRouterImpl::Config::Config() {
59 }
60
116 InputRouterImpl::InputRouterImpl(IPC::Sender* sender, 61 InputRouterImpl::InputRouterImpl(IPC::Sender* sender,
117 InputRouterClient* client, 62 InputRouterClient* client,
118 InputAckHandler* ack_handler, 63 InputAckHandler* ack_handler,
119 int routing_id) 64 int routing_id,
65 const Config& config)
120 : sender_(sender), 66 : sender_(sender),
121 client_(client), 67 client_(client),
122 ack_handler_(ack_handler), 68 ack_handler_(ack_handler),
123 routing_id_(routing_id), 69 routing_id_(routing_id),
124 select_range_pending_(false), 70 select_range_pending_(false),
125 move_caret_pending_(false), 71 move_caret_pending_(false),
126 mouse_move_pending_(false), 72 mouse_move_pending_(false),
127 mouse_wheel_pending_(false), 73 mouse_wheel_pending_(false),
128 touch_ack_timeout_supported_(false),
129 current_view_flags_(0), 74 current_view_flags_(0),
130 current_ack_source_(ACK_SOURCE_NONE), 75 current_ack_source_(ACK_SOURCE_NONE),
131 flush_requested_(false), 76 flush_requested_(false),
132 touch_event_queue_(this, 77 touch_event_queue_(this, config.touch_config),
133 GetTouchScrollingMode(), 78 gesture_event_queue_(this, this, config.gesture_config) {
134 GetTouchMoveSlopSuppressionLengthDips()),
135 gesture_event_queue_(this, this) {
136 DCHECK(sender); 79 DCHECK(sender);
137 DCHECK(client); 80 DCHECK(client);
138 DCHECK(ack_handler); 81 DCHECK(ack_handler);
139 touch_ack_timeout_supported_ =
140 GetTouchAckTimeoutDelay(&touch_ack_timeout_delay_);
141 UpdateTouchAckTimeoutEnabled(); 82 UpdateTouchAckTimeoutEnabled();
142 } 83 }
143 84
144 InputRouterImpl::~InputRouterImpl() {} 85 InputRouterImpl::~InputRouterImpl() {}
145 86
146 void InputRouterImpl::Flush() { 87 void InputRouterImpl::Flush() {
147 flush_requested_ = true; 88 flush_requested_ = true;
148 SignalFlushedIfNecessary(); 89 SignalFlushedIfNecessary();
149 } 90 }
150 91
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 637
697 OverscrollController* controller = client_->GetOverscrollController(); 638 OverscrollController* controller = client_->GetOverscrollController();
698 if (!controller) 639 if (!controller)
699 return; 640 return;
700 641
701 controller->ReceivedEventACK( 642 controller->ReceivedEventACK(
702 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); 643 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
703 } 644 }
704 645
705 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { 646 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() {
706 if (!touch_ack_timeout_supported_) {
707 touch_event_queue_.SetAckTimeoutEnabled(false, base::TimeDelta());
708 return;
709 }
710
711 // Mobile sites tend to be well-behaved with respect to touch handling, so 647 // Mobile sites tend to be well-behaved with respect to touch handling, so
712 // they have less need for the touch timeout fallback. 648 // they have less need for the touch timeout fallback.
713 const bool fixed_page_scale = (current_view_flags_ & FIXED_PAGE_SCALE) != 0; 649 const bool fixed_page_scale = (current_view_flags_ & FIXED_PAGE_SCALE) != 0;
714 const bool mobile_viewport = (current_view_flags_ & MOBILE_VIEWPORT) != 0; 650 const bool mobile_viewport = (current_view_flags_ & MOBILE_VIEWPORT) != 0;
715 651
716 // TOUCH_ACTION_NONE will prevent scrolling, in which case the timeout serves 652 // TOUCH_ACTION_NONE will prevent scrolling, in which case the timeout serves
717 // little purpose. It's also a strong signal that touch handling is critical 653 // little purpose. It's also a strong signal that touch handling is critical
718 // to page functionality, so the timeout could do more harm than good. 654 // to page functionality, so the timeout could do more harm than good.
719 const bool touch_action_none = 655 const bool touch_action_none =
720 touch_action_filter_.allowed_touch_action() == TOUCH_ACTION_NONE; 656 touch_action_filter_.allowed_touch_action() == TOUCH_ACTION_NONE;
721 657
722 const bool touch_ack_timeout_enabled = !fixed_page_scale && 658 const bool touch_ack_timeout_enabled = !fixed_page_scale &&
723 !mobile_viewport && 659 !mobile_viewport &&
724 !touch_action_none; 660 !touch_action_none;
725 touch_event_queue_.SetAckTimeoutEnabled(touch_ack_timeout_enabled, 661 touch_event_queue_.SetAckTimeoutEnabled(touch_ack_timeout_enabled);
726 touch_ack_timeout_delay_);
727 } 662 }
728 663
729 void InputRouterImpl::SignalFlushedIfNecessary() { 664 void InputRouterImpl::SignalFlushedIfNecessary() {
730 if (!flush_requested_) 665 if (!flush_requested_)
731 return; 666 return;
732 667
733 if (HasPendingEvents()) 668 if (HasPendingEvents())
734 return; 669 return;
735 670
736 flush_requested_ = false; 671 flush_requested_ = false;
737 client_->DidFlush(); 672 client_->DidFlush();
738 } 673 }
739 674
740 bool InputRouterImpl::HasPendingEvents() const { 675 bool InputRouterImpl::HasPendingEvents() const {
741 return !touch_event_queue_.empty() || 676 return !touch_event_queue_.empty() ||
742 !gesture_event_queue_.empty() || 677 !gesture_event_queue_.empty() ||
743 !key_queue_.empty() || 678 !key_queue_.empty() ||
744 mouse_move_pending_ || 679 mouse_move_pending_ ||
745 mouse_wheel_pending_ || 680 mouse_wheel_pending_ ||
746 select_range_pending_ || 681 select_range_pending_ ||
747 move_caret_pending_; 682 move_caret_pending_;
748 } 683 }
749 684
750 bool InputRouterImpl::IsInOverscrollGesture() const { 685 bool InputRouterImpl::IsInOverscrollGesture() const {
751 OverscrollController* controller = client_->GetOverscrollController(); 686 OverscrollController* controller = client_->GetOverscrollController();
752 return controller && controller->overscroll_mode() != OVERSCROLL_NONE; 687 return controller && controller->overscroll_mode() != OVERSCROLL_NONE;
753 } 688 }
754 689
755 } // namespace content 690 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698