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 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_CONFIGURATION_H_ 6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_CONFIGURATION_H_ 7 8 #include "base/macros.h" 9 #include "ui/events/gesture_detection/gesture_detection_export.h" 10 #include "ui/events/gesture_detection/velocity_tracker.h" 11 12 namespace ui { 13 14 class GESTURE_DETECTION_EXPORT GestureConfiguration { 15 public: 16 // Sets the shared instance. This does not take ownership of |config|. 17 static void SetInstance(GestureConfiguration* config); 18 // Returns the singleton GestureConfiguration. 19 static GestureConfiguration* GetInstance(); 20 21 // Ordered alphabetically ignoring underscores. default_radius()22 float default_radius() const { return default_radius_; } set_default_radius(float radius)23 void set_default_radius(float radius) { 24 default_radius_ = radius; 25 min_gesture_bounds_length_ = default_radius_; 26 } double_tap_enabled()27 bool double_tap_enabled() const { return double_tap_enabled_; } set_double_tap_enabled(bool enabled)28 void set_double_tap_enabled(bool enabled) { double_tap_enabled_ = enabled; } double_tap_timeout_in_ms()29 int double_tap_timeout_in_ms() const { return double_tap_timeout_in_ms_; } fling_touchpad_tap_suppression_enabled()30 bool fling_touchpad_tap_suppression_enabled() const { 31 return fling_touchpad_tap_suppression_enabled_; 32 } set_fling_touchpad_tap_suppression_enabled(bool enabled)33 void set_fling_touchpad_tap_suppression_enabled(bool enabled) { 34 fling_touchpad_tap_suppression_enabled_ = enabled; 35 } fling_touchscreen_tap_suppression_enabled()36 bool fling_touchscreen_tap_suppression_enabled() const { 37 return fling_touchscreen_tap_suppression_enabled_; 38 } set_fling_touchscreen_tap_suppression_enabled(bool enabled)39 void set_fling_touchscreen_tap_suppression_enabled(bool enabled) { 40 fling_touchscreen_tap_suppression_enabled_ = enabled; 41 } fling_max_cancel_to_down_time_in_ms()42 int fling_max_cancel_to_down_time_in_ms() const { 43 return fling_max_cancel_to_down_time_in_ms_; 44 } set_fling_max_cancel_to_down_time_in_ms(int val)45 void set_fling_max_cancel_to_down_time_in_ms(int val) { 46 fling_max_cancel_to_down_time_in_ms_ = val; 47 } fling_max_tap_gap_time_in_ms()48 int fling_max_tap_gap_time_in_ms() const { 49 return fling_max_tap_gap_time_in_ms_; 50 } set_fling_max_tap_gap_time_in_ms(int val)51 void set_fling_max_tap_gap_time_in_ms(int val) { 52 fling_max_tap_gap_time_in_ms_ = val; 53 } stylus_scale_enabled()54 bool stylus_scale_enabled() const { return stylus_scale_enabled_; } set_stylus_scale_enabled(bool enabled)55 void set_stylus_scale_enabled(bool enabled) { 56 stylus_scale_enabled_ = enabled; 57 } gesture_begin_end_types_enabled()58 bool gesture_begin_end_types_enabled() const { 59 return gesture_begin_end_types_enabled_; 60 } set_gesture_begin_end_types_enabled(bool val)61 void set_gesture_begin_end_types_enabled(bool val) { 62 gesture_begin_end_types_enabled_ = val; 63 } long_press_time_in_ms()64 int long_press_time_in_ms() const { return long_press_time_in_ms_; } set_long_press_time_in_ms(int val)65 void set_long_press_time_in_ms(int val) { long_press_time_in_ms_ = val; } max_distance_between_taps_for_double_tap()66 float max_distance_between_taps_for_double_tap() const { 67 return max_distance_between_taps_for_double_tap_; 68 } set_max_distance_between_taps_for_double_tap(float val)69 void set_max_distance_between_taps_for_double_tap(float val) { 70 max_distance_between_taps_for_double_tap_ = val; 71 } max_distance_for_two_finger_tap_in_pixels()72 float max_distance_for_two_finger_tap_in_pixels() const { 73 return max_distance_for_two_finger_tap_in_pixels_; 74 } set_max_distance_for_two_finger_tap_in_pixels(float val)75 void set_max_distance_for_two_finger_tap_in_pixels(float val) { 76 max_distance_for_two_finger_tap_in_pixels_ = val; 77 } max_tap_count()78 int max_tap_count() const { return max_tap_count_; } set_max_tap_count(int count)79 void set_max_tap_count(int count) { max_tap_count_ = count; } max_fling_velocity()80 float max_fling_velocity() const { return max_fling_velocity_; } set_max_fling_velocity(float val)81 void set_max_fling_velocity(float val) { max_fling_velocity_ = val; } max_gesture_bounds_length()82 float max_gesture_bounds_length() const { 83 return max_gesture_bounds_length_; 84 } set_max_gesture_bounds_length(float val)85 void set_max_gesture_bounds_length(float val) { 86 max_gesture_bounds_length_ = val; 87 } max_separation_for_gesture_touches_in_pixels()88 float max_separation_for_gesture_touches_in_pixels() const { 89 return max_separation_for_gesture_touches_in_pixels_; 90 } set_max_separation_for_gesture_touches_in_pixels(float val)91 void set_max_separation_for_gesture_touches_in_pixels(float val) { 92 max_separation_for_gesture_touches_in_pixels_ = val; 93 } max_swipe_deviation_angle()94 float max_swipe_deviation_angle() const { 95 return max_swipe_deviation_angle_; 96 } set_max_swipe_deviation_angle(float val)97 void set_max_swipe_deviation_angle(float val) { 98 max_swipe_deviation_angle_ = val; 99 } max_time_between_double_click_in_ms()100 int max_time_between_double_click_in_ms() const { 101 return max_time_between_double_click_in_ms_; 102 } set_max_time_between_double_click_in_ms(int val)103 void set_max_time_between_double_click_in_ms(int val) { 104 max_time_between_double_click_in_ms_ = val; 105 } max_touch_down_duration_for_click_in_ms()106 int max_touch_down_duration_for_click_in_ms() const { 107 return max_touch_down_duration_for_click_in_ms_; 108 } set_max_touch_down_duration_for_click_in_ms(int val)109 void set_max_touch_down_duration_for_click_in_ms(int val) { 110 max_touch_down_duration_for_click_in_ms_ = val; 111 } max_touch_move_in_pixels_for_click()112 float max_touch_move_in_pixels_for_click() const { 113 return max_touch_move_in_pixels_for_click_; 114 } set_max_touch_move_in_pixels_for_click(float val)115 void set_max_touch_move_in_pixels_for_click(float val) { 116 max_touch_move_in_pixels_for_click_ = val; 117 span_slop_ = max_touch_move_in_pixels_for_click_ * 2; 118 } min_distance_for_pinch_scroll_in_pixels()119 float min_distance_for_pinch_scroll_in_pixels() const { 120 return min_distance_for_pinch_scroll_in_pixels_; 121 } set_min_distance_for_pinch_scroll_in_pixels(float val)122 void set_min_distance_for_pinch_scroll_in_pixels(float val) { 123 min_distance_for_pinch_scroll_in_pixels_ = val; 124 } min_fling_velocity()125 float min_fling_velocity() const { return min_fling_velocity_; } set_min_fling_velocity(float val)126 void set_min_fling_velocity(float val) { min_fling_velocity_ = val; } min_gesture_bounds_length()127 float min_gesture_bounds_length() const { 128 return min_gesture_bounds_length_; 129 } min_pinch_update_span_delta()130 float min_pinch_update_span_delta() const { 131 return min_pinch_update_span_delta_; 132 } set_min_pinch_update_span_delta(float val)133 void set_min_pinch_update_span_delta(float val) { 134 min_pinch_update_span_delta_ = val; 135 } min_scaling_span_in_pixels()136 float min_scaling_span_in_pixels() const { 137 return min_scaling_span_in_pixels_; 138 } set_min_scaling_span_in_pixels(float val)139 void set_min_scaling_span_in_pixels(float val) { 140 min_scaling_span_in_pixels_ = val; 141 } min_swipe_velocity()142 float min_swipe_velocity() const { return min_swipe_velocity_; } set_min_swipe_velocity(float val)143 void set_min_swipe_velocity(float val) { min_swipe_velocity_ = val; } scroll_debounce_interval_in_ms()144 int scroll_debounce_interval_in_ms() const { 145 return scroll_debounce_interval_in_ms_; 146 } set_scroll_debounce_interval_in_ms(int val)147 int set_scroll_debounce_interval_in_ms(int val) { 148 return scroll_debounce_interval_in_ms_ = val; 149 } semi_long_press_time_in_ms()150 int semi_long_press_time_in_ms() const { 151 return semi_long_press_time_in_ms_; 152 } set_semi_long_press_time_in_ms(int val)153 void set_semi_long_press_time_in_ms(int val) { 154 semi_long_press_time_in_ms_ = val; 155 double_tap_timeout_in_ms_ = val; 156 } show_press_delay_in_ms()157 int show_press_delay_in_ms() const { return show_press_delay_in_ms_; } set_show_press_delay_in_ms(int val)158 int set_show_press_delay_in_ms(int val) { 159 return show_press_delay_in_ms_ = val; 160 } single_pointer_cancel_enabled()161 bool single_pointer_cancel_enabled() const { 162 return single_pointer_cancel_enabled_; 163 } set_single_pointer_cancel_enabled(bool enabled)164 void set_single_pointer_cancel_enabled(bool enabled) { 165 single_pointer_cancel_enabled_ = enabled; 166 } 167 span_slop()168 float span_slop() const { return span_slop_; } swipe_enabled()169 bool swipe_enabled() const { return swipe_enabled_; } set_swipe_enabled(bool val)170 void set_swipe_enabled(bool val) { swipe_enabled_ = val; } two_finger_tap_enabled()171 bool two_finger_tap_enabled() const { return two_finger_tap_enabled_; } set_two_finger_tap_enabled(bool val)172 void set_two_finger_tap_enabled(bool val) { two_finger_tap_enabled_ = val; } velocity_tracker_strategy()173 VelocityTracker::Strategy velocity_tracker_strategy() const { 174 return velocity_tracker_strategy_; 175 } set_velocity_tracker_strategy(VelocityTracker::Strategy val)176 void set_velocity_tracker_strategy(VelocityTracker::Strategy val) { 177 velocity_tracker_strategy_ = val; 178 } 179 180 protected: 181 GestureConfiguration(); 182 virtual ~GestureConfiguration(); 183 184 // The below configuration parameters are dependent on other parameters, 185 // whose setter functions will setup these values as well, so we will not 186 // provide public setter functions for them. set_double_tap_timeout_in_ms(int val)187 void set_double_tap_timeout_in_ms(int val) { 188 double_tap_timeout_in_ms_ = val; 189 } set_min_gesture_bounds_length(float val)190 void set_min_gesture_bounds_length(float val) { 191 min_gesture_bounds_length_ = val; 192 } set_span_slop(float val)193 void set_span_slop(float val) { span_slop_ = val; } 194 195 private: 196 // Returns the platform specific instance. This is invoked if a specific 197 // instance has not been set. 198 static GestureConfiguration* GetPlatformSpecificInstance(); 199 200 // These are listed in alphabetical order ignoring underscores. 201 // NOTE: Adding new configuration parameters requires initializing 202 // corresponding entries in aura_test_base.cc's SetUp(). 203 204 // The default touch radius length used when the only information given 205 // by the device is the touch center. 206 float default_radius_; 207 208 bool double_tap_enabled_; 209 int double_tap_timeout_in_ms_; 210 211 // Whether to suppress touchscreen/touchpad taps that occur during a fling ( 212 // in particular, when such taps cancel the active fling). 213 bool fling_touchpad_tap_suppression_enabled_; 214 bool fling_touchscreen_tap_suppression_enabled_; 215 216 // Maximum time between a GestureFlingCancel and a mousedown such that the 217 // mousedown is considered associated with the cancel event. 218 int fling_max_cancel_to_down_time_in_ms_; 219 220 // Maxium time between a mousedown/mouseup pair that is considered to be a 221 // suppressable tap. 222 int fling_max_tap_gap_time_in_ms_; 223 224 bool stylus_scale_enabled_; 225 bool gesture_begin_end_types_enabled_; 226 int long_press_time_in_ms_; 227 float max_distance_between_taps_for_double_tap_; 228 229 // The max length of a repeated tap sequence, e.g., to support double-click 230 // only this is 2, to support triple-click it's 3. 231 int max_tap_count_; 232 233 // The maximum allowed distance between two fingers for a two finger tap. If 234 // the distance between two fingers is greater than this value, we will not 235 // recognize a two finger tap. 236 float max_distance_for_two_finger_tap_in_pixels_; 237 float max_fling_velocity_; 238 float max_gesture_bounds_length_; 239 float max_separation_for_gesture_touches_in_pixels_; 240 float max_swipe_deviation_angle_; 241 int max_time_between_double_click_in_ms_; 242 int max_touch_down_duration_for_click_in_ms_; 243 float max_touch_move_in_pixels_for_click_; 244 float min_distance_for_pinch_scroll_in_pixels_; 245 float min_fling_velocity_; 246 float min_gesture_bounds_length_; 247 // Only used with --compensate-for-unstable-pinch-zoom. 248 float min_pinch_update_span_delta_; 249 float min_scaling_span_in_pixels_; 250 float min_swipe_velocity_; 251 int scroll_debounce_interval_in_ms_; 252 int semi_long_press_time_in_ms_; 253 int show_press_delay_in_ms_; 254 // When enabled, a cancel action affects only the corresponding pointer (vs 255 // all pointers active at that time). 256 bool single_pointer_cancel_enabled_; 257 float span_slop_; 258 bool swipe_enabled_; 259 bool two_finger_tap_enabled_; 260 VelocityTracker::Strategy velocity_tracker_strategy_; 261 262 DISALLOW_COPY_AND_ASSIGN(GestureConfiguration); 263 }; 264 265 } // namespace ui 266 267 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_CONFIGURATION_H_ 268