gesture_configuration.h 9.8 KB

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