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 // Default debouncing interval duration: if a scroll is in progress, non-scroll | |
24 // events during this interval are deferred to either its end or discarded on | |
25 // receipt of another GestureScrollUpdate. | |
26 const int kDebouncingIntervalTimeMs = 30; | |
jdduke (slow)
2014/04/30 19:42:34
I originally had these separated out into separate
tdresser
2014/05/01 13:51:56
A single config file is fine with me.
| |
27 | |
28 GestureEventQueue::Config GetGestureEventQueueConfig() { | |
29 GestureEventQueue::Config config; | |
30 | |
31 config.enable_debounce_during_scroll = true; | |
32 config.debounce_interval = | |
33 base::TimeDelta::FromMilliseconds(kDebouncingIntervalTimeMs); | |
34 | |
35 config.touchscreen_tap_suppression_config.enabled = true; | |
36 config.touchscreen_tap_suppression_config.max_cancel_to_down_time = | |
37 base::TimeDelta::FromMilliseconds( | |
38 ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms()); | |
39 | |
40 config.touchscreen_tap_suppression_config.max_tap_gap_time = | |
41 base::TimeDelta::FromMilliseconds(static_cast<int>( | |
42 ui::GestureConfiguration::semi_long_press_time_in_seconds() * 1000)); | |
43 | |
44 config.touchpad_tap_suppression_config.enabled = true; | |
45 config.touchpad_tap_suppression_config.max_cancel_to_down_time = | |
46 base::TimeDelta::FromMilliseconds( | |
47 ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms()); | |
48 | |
49 config.touchpad_tap_suppression_config.max_tap_gap_time = | |
50 base::TimeDelta::FromMilliseconds(static_cast<int>( | |
51 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms() * 1000)); | |
52 | |
53 return config; | |
54 } | |
55 | |
56 TouchEventQueue::Config GetTouchEventQueueConfig() { | |
57 TouchEventQueue::Config config; | |
58 | |
59 config.touchmove_slop_suppression_length_dips = | |
60 ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); | |
61 | |
62 return config; | |
63 } | |
64 | |
65 #elif defined(OS_ANDROID) | |
66 | |
67 // Default time allowance for the touch ack delay before the touch sequence is | |
68 // cancelled. | |
69 const int kTouchAckTimeoutDelayMs = 200; | |
70 | |
71 GestureEventQueue::Config GetGestureEventQueueConfig() { | |
72 GestureEventQueue::Config config; | |
73 | |
74 config.touchscreen_tap_suppression_config.enabled = true; | |
75 config.touchscreen_tap_suppression_config.max_cancel_to_down_time = | |
76 base::TimeDelta::FromMilliseconds( | |
77 gfx::ViewConfiguration::GetTapTimeoutInMs()); | |
78 config.touchscreen_tap_suppression_config.max_tap_gap_time = | |
79 base::TimeDelta::FromMilliseconds( | |
80 gfx::ViewConfiguration::GetLongPressTimeoutInMs()); | |
81 | |
82 return config; | |
83 } | |
84 | |
85 TouchEventQueue::Config GetTouchEventQueueConfig() { | |
86 TouchEventQueue::Config config; | |
87 | |
88 config.touch_ack_timeout_delay = | |
89 base::TimeDelta::FromMilliseconds(kTouchAckTimeoutDelayMs); | |
90 config.touch_ack_timeout_supported = true; | |
91 | |
92 const double touch_slop_length_pixels = | |
93 static_cast<double>(gfx::ViewConfiguration::GetTouchSlopInPixels()); | |
94 const double device_scale_factor = | |
95 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor(); | |
96 config.touchmove_slop_suppression_length_dips = | |
97 touch_slop_length_pixels / device_scale_factor; | |
98 | |
99 return config; | |
100 } | |
101 | |
102 #else | |
103 | |
104 GestureEventQueue::Config GetGestureEventQueueConfig() { | |
105 return GestureEventQueue::Config(); | |
106 } | |
107 | |
108 TouchEventQueue::Config GetTouchEventQueueConfig() { | |
109 TouchEventQueue::Config config; | |
110 config.touchmove_slop_suppression_length_dips = | |
111 GestureDetector::Config().touch_slop; | |
112 return config; | |
113 } | |
114 | |
115 #endif | |
116 | |
117 TouchEventQueue::TouchScrollingMode GetTouchScrollingMode() { | |
118 std::string modeString = | |
119 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
120 switches::kTouchScrollingMode); | |
121 if (modeString == switches::kTouchScrollingModeAsyncTouchmove) | |
122 return TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE; | |
123 if (modeString == switches::kTouchScrollingModeSyncTouchmove) | |
124 return TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE; | |
125 if (modeString == switches::kTouchScrollingModeTouchcancel) | |
126 return TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL; | |
127 if (modeString != "") | |
128 LOG(ERROR) << "Invalid --touch-scrolling-mode option: " << modeString; | |
129 return TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT; | |
130 } | |
131 | |
132 } // namespace | |
133 | |
134 InputRouterImpl::Config GetInputRouterConfigForPlatform() { | |
135 InputRouterImpl::Config config; | |
136 config.gesture_config = GetGestureEventQueueConfig(); | |
137 config.touch_config = GetTouchEventQueueConfig(); | |
138 config.touch_config.touch_scrolling_mode = GetTouchScrollingMode(); | |
139 return config; | |
140 } | |
141 | |
142 } // namespace content | |
OLD | NEW |