Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Side by Side Diff: ui/events/gesture_detection/gesture_provider_config_helper.cc

Issue 679633005: Expose native, desktop and mobile gesture detection defaults (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 5 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
6 6
7 #include "ui/events/gesture_detection/gesture_configuration.h" 7 #include "ui/events/gesture_detection/gesture_configuration.h"
8 #include "ui/gfx/screen.h" 8 #include "ui/gfx/screen.h"
9 9
10 namespace ui { 10 namespace ui {
11 namespace { 11 namespace {
12 12
13 GestureDetector::Config DefaultGestureDetectorConfig( 13 class GenericDesktopGestureConfiguration : public GestureConfiguration {
14 GestureConfiguration* gesture_config) { 14 public:
15 // The default GestureConfiguration parameters are already tailored for a
16 // desktop environment (Aura).
17 GenericDesktopGestureConfiguration() {}
18 ~GenericDesktopGestureConfiguration() override {}
19 };
20
21 GestureDetector::Config BuildGestureDetectorConfig(
22 const GestureConfiguration& gesture_config) {
15 GestureDetector::Config config; 23 GestureDetector::Config config;
16 config.longpress_timeout = base::TimeDelta::FromMilliseconds( 24 config.longpress_timeout =
17 gesture_config->long_press_time_in_ms()); 25 base::TimeDelta::FromMilliseconds(gesture_config.long_press_time_in_ms());
18 config.showpress_timeout = base::TimeDelta::FromMilliseconds( 26 config.showpress_timeout = base::TimeDelta::FromMilliseconds(
19 gesture_config->show_press_delay_in_ms()); 27 gesture_config.show_press_delay_in_ms());
20 config.double_tap_timeout = base::TimeDelta::FromMilliseconds( 28 config.double_tap_timeout = base::TimeDelta::FromMilliseconds(
21 gesture_config->double_tap_timeout_in_ms()); 29 gesture_config.double_tap_timeout_in_ms());
22 config.touch_slop = gesture_config->max_touch_move_in_pixels_for_click(); 30 config.touch_slop = gesture_config.max_touch_move_in_pixels_for_click();
23 config.double_tap_slop = 31 config.double_tap_slop =
24 gesture_config->max_distance_between_taps_for_double_tap(); 32 gesture_config.max_distance_between_taps_for_double_tap();
25 config.minimum_fling_velocity = gesture_config->min_fling_velocity(); 33 config.minimum_fling_velocity = gesture_config.min_fling_velocity();
26 config.maximum_fling_velocity = gesture_config->max_fling_velocity(); 34 config.maximum_fling_velocity = gesture_config.max_fling_velocity();
27 config.swipe_enabled = gesture_config->swipe_enabled(); 35 config.swipe_enabled = gesture_config.swipe_enabled();
28 config.minimum_swipe_velocity = gesture_config->min_swipe_velocity(); 36 config.minimum_swipe_velocity = gesture_config.min_swipe_velocity();
29 config.maximum_swipe_deviation_angle = 37 config.maximum_swipe_deviation_angle =
30 gesture_config->max_swipe_deviation_angle(); 38 gesture_config.max_swipe_deviation_angle();
31 config.two_finger_tap_enabled = gesture_config->two_finger_tap_enabled(); 39 config.two_finger_tap_enabled = gesture_config.two_finger_tap_enabled();
32 config.two_finger_tap_max_separation = 40 config.two_finger_tap_max_separation =
33 gesture_config->max_distance_for_two_finger_tap_in_pixels(); 41 gesture_config.max_distance_for_two_finger_tap_in_pixels();
34 config.two_finger_tap_timeout = base::TimeDelta::FromMilliseconds( 42 config.two_finger_tap_timeout = base::TimeDelta::FromMilliseconds(
35 gesture_config->max_touch_down_duration_for_click_in_ms()); 43 gesture_config.max_touch_down_duration_for_click_in_ms());
36 config.velocity_tracker_strategy = 44 config.velocity_tracker_strategy = gesture_config.velocity_tracker_strategy();
37 gesture_config->velocity_tracker_strategy();
38 return config; 45 return config;
39 } 46 }
40 47
41 ScaleGestureDetector::Config DefaultScaleGestureDetectorConfig( 48 ScaleGestureDetector::Config BuildScaleGestureDetectorConfig(
42 GestureConfiguration* gesture_config) { 49 const GestureConfiguration& gesture_config) {
43 ScaleGestureDetector::Config config; 50 ScaleGestureDetector::Config config;
44 config.span_slop = gesture_config->span_slop(); 51 config.span_slop = gesture_config.span_slop();
45 config.min_scaling_touch_major = gesture_config->min_scaling_touch_major(); 52 config.min_scaling_touch_major = gesture_config.min_scaling_touch_major();
46 config.min_scaling_span = gesture_config->min_scaling_span_in_pixels(); 53 config.min_scaling_span = gesture_config.min_scaling_span_in_pixels();
47 config.min_pinch_update_span_delta = 54 config.min_pinch_update_span_delta =
48 gesture_config->min_pinch_update_span_delta(); 55 gesture_config.min_pinch_update_span_delta();
56 return config;
57 }
58
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();
49 return config; 69 return config;
50 } 70 }
51 71
52 } // namespace 72 } // namespace
53 73
54 GestureProvider::Config DefaultGestureProviderConfig() { 74 GestureProvider::Config GetGestureProviderConfig(
55 GestureConfiguration* gesture_config = GestureConfiguration::GetInstance(); 75 GestureProviderConfigType type) {
56 GestureProvider::Config config; 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;
87 }
88
57 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); 89 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
58 // |screen| is sometimes NULL during tests. 90 // |screen| is sometimes NULL during tests.
59 if (screen) 91 if (screen)
60 config.display = screen->GetPrimaryDisplay(); 92 config.display = screen->GetPrimaryDisplay();
61 config.gesture_detector_config = DefaultGestureDetectorConfig(gesture_config); 93
62 config.scale_gesture_detector_config =
63 DefaultScaleGestureDetectorConfig(gesture_config);
64 config.gesture_begin_end_types_enabled =
65 gesture_config->gesture_begin_end_types_enabled();
66 config.min_gesture_bounds_length =
67 gesture_config->min_gesture_bounds_length();
68 config.max_gesture_bounds_length =
69 gesture_config->max_gesture_bounds_length();
70 return config; 94 return config;
71 } 95 }
72 96
73 } // namespace ui 97 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider_config_helper.h ('k') | ui/events/gesture_detection/scale_gesture_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698