Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / input / input_router_config_helper.cc
blob18c5560a5391f2cca0063ca61c22a937cf8088ff
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 config.debounce_interval = base::TimeDelta::FromMilliseconds(
27 ui::GestureConfiguration::scroll_debounce_interval_in_ms());
29 config.touchscreen_tap_suppression_config.enabled = true;
30 config.touchscreen_tap_suppression_config.max_cancel_to_down_time =
31 base::TimeDelta::FromMilliseconds(
32 ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms());
34 config.touchscreen_tap_suppression_config.max_tap_gap_time =
35 base::TimeDelta::FromMilliseconds(static_cast<int>(
36 ui::GestureConfiguration::semi_long_press_time_in_seconds() * 1000));
38 config.touchpad_tap_suppression_config.enabled = true;
39 config.touchpad_tap_suppression_config.max_cancel_to_down_time =
40 base::TimeDelta::FromMilliseconds(
41 ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms());
43 config.touchpad_tap_suppression_config.max_tap_gap_time =
44 base::TimeDelta::FromMilliseconds(static_cast<int>(
45 ui::GestureConfiguration::fling_max_tap_gap_time_in_ms() * 1000));
47 return config;
50 TouchEventQueue::Config GetTouchEventQueueConfig() {
51 TouchEventQueue::Config config;
53 config.touchmove_slop_suppression_length_dips =
54 ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
56 return config;
59 #elif defined(OS_ANDROID)
61 // Default time allowance for the touch ack delay before the touch sequence is
62 // cancelled.
63 const int kTouchAckTimeoutDelayMs = 200;
65 GestureEventQueue::Config GetGestureEventQueueConfig() {
66 GestureEventQueue::Config config;
68 config.touchscreen_tap_suppression_config.enabled = true;
69 config.touchscreen_tap_suppression_config.max_cancel_to_down_time =
70 base::TimeDelta::FromMilliseconds(
71 gfx::ViewConfiguration::GetTapTimeoutInMs());
72 config.touchscreen_tap_suppression_config.max_tap_gap_time =
73 base::TimeDelta::FromMilliseconds(
74 gfx::ViewConfiguration::GetLongPressTimeoutInMs());
76 return config;
79 TouchEventQueue::Config GetTouchEventQueueConfig() {
80 TouchEventQueue::Config config;
82 config.touch_ack_timeout_delay =
83 base::TimeDelta::FromMilliseconds(kTouchAckTimeoutDelayMs);
84 config.touch_ack_timeout_supported = true;
86 const double touch_slop_length_pixels =
87 static_cast<double>(gfx::ViewConfiguration::GetTouchSlopInPixels());
88 const double device_scale_factor =
89 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
90 config.touchmove_slop_suppression_length_dips =
91 touch_slop_length_pixels / device_scale_factor;
93 return config;
96 #else
98 GestureEventQueue::Config GetGestureEventQueueConfig() {
99 return GestureEventQueue::Config();
102 TouchEventQueue::Config GetTouchEventQueueConfig() {
103 TouchEventQueue::Config config;
104 config.touchmove_slop_suppression_length_dips =
105 ui::GestureDetector::Config().touch_slop;
106 return config;
109 #endif
111 TouchEventQueue::TouchScrollingMode GetTouchScrollingMode() {
112 std::string modeString =
113 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
114 switches::kTouchScrollingMode);
115 if (modeString == switches::kTouchScrollingModeAsyncTouchmove)
116 return TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE;
117 if (modeString == switches::kTouchScrollingModeSyncTouchmove)
118 return TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE;
119 if (modeString == switches::kTouchScrollingModeTouchcancel)
120 return TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL;
121 if (modeString != "")
122 LOG(ERROR) << "Invalid --touch-scrolling-mode option: " << modeString;
123 return TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT;
126 } // namespace
128 InputRouterImpl::Config GetInputRouterConfigForPlatform() {
129 InputRouterImpl::Config config;
130 config.gesture_config = GetGestureEventQueueConfig();
131 config.touch_config = GetTouchEventQueueConfig();
132 config.touch_config.touch_scrolling_mode = GetTouchScrollingMode();
133 return config;
136 } // namespace content