Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / renderer_host / input / input_router_config_helper.cc
blobbbd6f792acf1b8c217918c1f5ab23ec9c8ab6d54
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"
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
18 namespace content {
19 namespace {
21 #if defined(USE_AURA)
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);
35 #endif
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));
55 return config;
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();
64 return config;
67 #elif defined(OS_ANDROID)
69 // Default time allowance for the touch ack delay before the touch sequence is
70 // cancelled.
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());
84 return config;
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;
101 return config;
104 #else
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;
114 return config;
117 #endif
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;
134 } // namespace
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;
144 } // namespace content