1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/input/input_router_config_helper.h"
7 #include "base/command_line.h"
8 #include "content/public/common/content_switches.h"
9 #include "ui/events/gesture_detection/gesture_detector.h"
12 #include "ui/events/gestures/gesture_configuration.h"
13 #elif defined(OS_ANDROID)
14 #include "ui/gfx/android/view_configuration.h"
15 #include "ui/gfx/screen.h"
23 GestureEventQueue::Config
GetGestureEventQueueConfig() {
24 GestureEventQueue::Config config
;
26 #if defined(OS_CHROMEOS)
27 // Default debouncing interval duration on ChromeOS: if a scroll is in
28 // progress, non-scroll events during this interval are deferred to either its
29 // end or discarded on receipt of another GestureScrollUpdate.
30 // TODO(jdduke): Disable and remove entirely when issues with spurious
31 // scroll end detection on the Pixel are resolved, crbug.com/353702.
32 const int kDebouncingIntervalTimeMs
= 30;
33 config
.debounce_interval
=
34 base::TimeDelta::FromMilliseconds(kDebouncingIntervalTimeMs
);
37 config
.touchscreen_tap_suppression_config
.enabled
= true;
38 config
.touchscreen_tap_suppression_config
.max_cancel_to_down_time
=
39 base::TimeDelta::FromMilliseconds(
40 ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms());
42 config
.touchscreen_tap_suppression_config
.max_tap_gap_time
=
43 base::TimeDelta::FromMilliseconds(static_cast<int>(
44 ui::GestureConfiguration::semi_long_press_time_in_seconds() * 1000));
46 config
.touchpad_tap_suppression_config
.enabled
= true;
47 config
.touchpad_tap_suppression_config
.max_cancel_to_down_time
=
48 base::TimeDelta::FromMilliseconds(
49 ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms());
51 config
.touchpad_tap_suppression_config
.max_tap_gap_time
=
52 base::TimeDelta::FromMilliseconds(static_cast<int>(
53 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms() * 1000));
58 TouchEventQueue::Config
GetTouchEventQueueConfig() {
59 TouchEventQueue::Config config
;
61 config
.touchmove_slop_suppression_length_dips
=
62 ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
67 #elif defined(OS_ANDROID)
69 // Default time allowance for the touch ack delay before the touch sequence is
71 const int kTouchAckTimeoutDelayMs
= 200;
73 GestureEventQueue::Config
GetGestureEventQueueConfig() {
74 GestureEventQueue::Config config
;
76 config
.touchscreen_tap_suppression_config
.enabled
= true;
77 config
.touchscreen_tap_suppression_config
.max_cancel_to_down_time
=
78 base::TimeDelta::FromMilliseconds(
79 gfx::ViewConfiguration::GetTapTimeoutInMs());
80 config
.touchscreen_tap_suppression_config
.max_tap_gap_time
=
81 base::TimeDelta::FromMilliseconds(
82 gfx::ViewConfiguration::GetLongPressTimeoutInMs());
87 TouchEventQueue::Config
GetTouchEventQueueConfig() {
88 TouchEventQueue::Config config
;
90 config
.touch_ack_timeout_delay
=
91 base::TimeDelta::FromMilliseconds(kTouchAckTimeoutDelayMs
);
92 config
.touch_ack_timeout_supported
= true;
94 const double touch_slop_length_pixels
=
95 static_cast<double>(gfx::ViewConfiguration::GetTouchSlopInPixels());
96 const double device_scale_factor
=
97 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
98 config
.touchmove_slop_suppression_length_dips
=
99 touch_slop_length_pixels
/ device_scale_factor
;
106 GestureEventQueue::Config
GetGestureEventQueueConfig() {
107 return GestureEventQueue::Config();
110 TouchEventQueue::Config
GetTouchEventQueueConfig() {
111 TouchEventQueue::Config config
;
112 config
.touchmove_slop_suppression_length_dips
=
113 ui::GestureDetector::Config().touch_slop
;
119 TouchEventQueue::TouchScrollingMode
GetTouchScrollingMode() {
120 std::string modeString
=
121 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
122 switches::kTouchScrollingMode
);
123 if (modeString
== switches::kTouchScrollingModeAsyncTouchmove
)
124 return TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE
;
125 if (modeString
== switches::kTouchScrollingModeSyncTouchmove
)
126 return TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE
;
127 if (modeString
== switches::kTouchScrollingModeTouchcancel
)
128 return TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL
;
129 if (modeString
!= "")
130 LOG(ERROR
) << "Invalid --touch-scrolling-mode option: " << modeString
;
131 return TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT
;
136 InputRouterImpl::Config
GetInputRouterConfigForPlatform() {
137 InputRouterImpl::Config config
;
138 config
.gesture_config
= GetGestureEventQueueConfig();
139 config
.touch_config
= GetTouchEventQueueConfig();
140 config
.touch_config
.touch_scrolling_mode
= GetTouchScrollingMode();
144 } // namespace content