base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_provider_config_helper.cc
blob8297aaed6dd78df5c03afe362af5ffe463b9548d
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 "ui/events/gesture_detection/gesture_provider_config_helper.h"
7 #include "ui/events/gesture_detection/gesture_configuration.h"
8 #include "ui/gfx/screen.h"
10 namespace ui {
11 namespace {
13 class GenericDesktopGestureConfiguration : public GestureConfiguration {
14 public:
15 // The default GestureConfiguration parameters are already tailored for a
16 // desktop environment (Aura).
17 GenericDesktopGestureConfiguration() {}
18 ~GenericDesktopGestureConfiguration() override {}
21 GestureDetector::Config BuildGestureDetectorConfig(
22 const GestureConfiguration& gesture_config) {
23 GestureDetector::Config config;
24 config.longpress_timeout =
25 base::TimeDelta::FromMilliseconds(gesture_config.long_press_time_in_ms());
26 config.showpress_timeout = base::TimeDelta::FromMilliseconds(
27 gesture_config.show_press_delay_in_ms());
28 config.double_tap_timeout = base::TimeDelta::FromMilliseconds(
29 gesture_config.double_tap_timeout_in_ms());
30 config.touch_slop = gesture_config.max_touch_move_in_pixels_for_click();
31 config.double_tap_slop =
32 gesture_config.max_distance_between_taps_for_double_tap();
33 config.minimum_fling_velocity = gesture_config.min_fling_velocity();
34 config.maximum_fling_velocity = gesture_config.max_fling_velocity();
35 config.swipe_enabled = gesture_config.swipe_enabled();
36 config.minimum_swipe_velocity = gesture_config.min_swipe_velocity();
37 config.maximum_swipe_deviation_angle =
38 gesture_config.max_swipe_deviation_angle();
39 config.two_finger_tap_enabled = gesture_config.two_finger_tap_enabled();
40 config.two_finger_tap_max_separation =
41 gesture_config.max_distance_for_two_finger_tap_in_pixels();
42 config.two_finger_tap_timeout = base::TimeDelta::FromMilliseconds(
43 gesture_config.max_touch_down_duration_for_click_in_ms());
44 config.velocity_tracker_strategy = gesture_config.velocity_tracker_strategy();
45 return config;
48 ScaleGestureDetector::Config BuildScaleGestureDetectorConfig(
49 const GestureConfiguration& gesture_config) {
50 ScaleGestureDetector::Config config;
51 config.span_slop = gesture_config.span_slop();
52 config.min_scaling_touch_major = gesture_config.min_scaling_touch_major();
53 config.min_scaling_span = gesture_config.min_scaling_span_in_pixels();
54 config.min_pinch_update_span_delta =
55 gesture_config.min_pinch_update_span_delta();
56 return config;
59 GestureProvider::Config BuildGestureProviderConfig(
60 const GestureConfiguration& gesture_config) {
61 GestureProvider::Config config;
62 config.gesture_detector_config = BuildGestureDetectorConfig(gesture_config);
63 config.scale_gesture_detector_config =
64 BuildScaleGestureDetectorConfig(gesture_config);
65 config.gesture_begin_end_types_enabled =
66 gesture_config.gesture_begin_end_types_enabled();
67 config.min_gesture_bounds_length = gesture_config.min_gesture_bounds_length();
68 config.max_gesture_bounds_length = gesture_config.max_gesture_bounds_length();
69 return config;
72 } // namespace
74 GestureProvider::Config GetGestureProviderConfig(
75 GestureProviderConfigType type) {
76 GestureProvider::Config config;
77 switch (type) {
78 case GestureProviderConfigType::CURRENT_PLATFORM:
79 config = BuildGestureProviderConfig(*GestureConfiguration::GetInstance());
80 break;
81 case GestureProviderConfigType::GENERIC_DESKTOP:
82 config = BuildGestureProviderConfig(GenericDesktopGestureConfiguration());
83 break;
84 case GestureProviderConfigType::GENERIC_MOBILE:
85 // The default GestureProvider::Config embeds a mobile configuration.
86 break;
89 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
90 // |screen| is sometimes NULL during tests.
91 if (screen)
92 config.display = screen->GetPrimaryDisplay();
94 return config;
97 } // namespace ui