OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/browser/renderer_host/input/input_router_config_helper.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "content/public/common/content_switches.h" | |
9 #include "ui/events/gesture_detection/gesture_detector.h" | |
10 | |
11 #if defined(USE_AURA) | |
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" | |
16 #endif | |
17 | |
18 namespace content { | |
19 namespace { | |
20 | |
21 #if defined(USE_AURA) | |
22 | |
23 GestureEventQueue::Config GetGestureEventQueueConfig() { | |
24 GestureEventQueue::Config config; | |
25 | |
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); | |
35 #endif | |
36 | |
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()); | |
41 | |
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)); | |
45 | |
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()); | |
50 | |
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)); | |
54 | |
55 return config; | |
56 } | |
57 | |
58 TouchEventQueue::Config GetTouchEventQueueConfig() { | |
59 TouchEventQueue::Config config; | |
60 | |
61 config.touchmove_slop_suppression_length_dips = | |
62 ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); | |
63 | |
64 return config; | |
65 } | |
66 | |
67 #elif defined(OS_ANDROID) | |
68 | |
69 // Default time allowance for the touch ack delay before the touch sequence is | |
70 // cancelled. | |
71 const int kTouchAckTimeoutDelayMs = 200; | |
72 | |
73 GestureEventQueue::Config GetGestureEventQueueConfig() { | |
74 GestureEventQueue::Config config; | |
75 | |
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()); | |
83 | |
84 return config; | |
85 } | |
86 | |
87 TouchEventQueue::Config GetTouchEventQueueConfig() { | |
88 TouchEventQueue::Config config; | |
89 | |
90 config.touch_ack_timeout_delay = | |
91 base::TimeDelta::FromMilliseconds(kTouchAckTimeoutDelayMs); | |
92 config.touch_ack_timeout_supported = true; | |
93 | |
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; | |
100 | |
101 return config; | |
102 } | |
103 | |
104 #else | |
105 | |
106 GestureEventQueue::Config GetGestureEventQueueConfig() { | |
107 return GestureEventQueue::Config(); | |
108 } | |
109 | |
110 TouchEventQueue::Config GetTouchEventQueueConfig() { | |
111 TouchEventQueue::Config config; | |
112 config.touchmove_slop_suppression_length_dips = | |
113 ui::GestureDetector::Config().touch_slop; | |
114 return config; | |
115 } | |
116 | |
117 #endif | |
118 | |
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; | |
132 } | |
133 | |
134 } // namespace | |
135 | |
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(); | |
141 return config; | |
142 } | |
143 | |
144 } // namespace content | |
OLD | NEW |