gesture_configuration_android.cc 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #include "ui/events/gesture_detection/gesture_configuration.h"
  5. #include "base/android/build_info.h"
  6. #include "base/memory/singleton.h"
  7. #include "ui/display/screen.h"
  8. #include "ui/gfx/android/view_configuration.h"
  9. using gfx::ViewConfiguration;
  10. namespace ui {
  11. namespace {
  12. // Touch radii on Android can be both noisy and inaccurate. The old Java
  13. // gesture detection pipeline used a fixed value of 24 as the gesture bounds.
  14. // We relax that value somewhat, but not by much; there's a fairly small window
  15. // within which gesture bounds are useful for features like touch adjustment.
  16. const float kMinGestureBoundsLengthDips = 20.f;
  17. const float kMaxGestureBoundsLengthDips = 32.f;
  18. class GestureConfigurationAndroid : public GestureConfiguration {
  19. public:
  20. GestureConfigurationAndroid(const GestureConfigurationAndroid&) = delete;
  21. GestureConfigurationAndroid& operator=(const GestureConfigurationAndroid&) =
  22. delete;
  23. ~GestureConfigurationAndroid() override {
  24. }
  25. static GestureConfigurationAndroid* GetInstance() {
  26. return base::Singleton<GestureConfigurationAndroid>::get();
  27. }
  28. private:
  29. GestureConfigurationAndroid() : GestureConfiguration() {
  30. set_double_tap_enabled(true);
  31. set_double_tap_timeout_in_ms(ViewConfiguration::GetDoubleTapTimeoutInMs());
  32. // TODO(jdduke): Enable this on Android M after the implicit conflict with
  33. // stylus selection is resolved.
  34. set_stylus_scale_enabled(false);
  35. #if defined(USE_AURA)
  36. set_gesture_begin_end_types_enabled(true);
  37. #else
  38. set_gesture_begin_end_types_enabled(false);
  39. #endif
  40. set_long_press_time_in_ms(ViewConfiguration::GetLongPressTimeoutInMs());
  41. set_max_distance_between_taps_for_double_tap(
  42. ViewConfiguration::GetDoubleTapSlopInDips());
  43. set_max_fling_velocity(
  44. ViewConfiguration::GetMaximumFlingVelocityInDipsPerSecond());
  45. set_max_gesture_bounds_length(kMaxGestureBoundsLengthDips);
  46. set_max_touch_move_in_pixels_for_click(
  47. ViewConfiguration::GetTouchSlopInDips());
  48. set_min_fling_velocity(
  49. ViewConfiguration::GetMinimumFlingVelocityInDipsPerSecond());
  50. set_min_gesture_bounds_length(kMinGestureBoundsLengthDips);
  51. set_min_pinch_update_span_delta(0.f);
  52. set_min_scaling_span_in_pixels(
  53. ViewConfiguration::GetMinScalingSpanInDips());
  54. set_show_press_delay_in_ms(ViewConfiguration::GetTapTimeoutInMs());
  55. set_span_slop(ViewConfiguration::GetTouchSlopInDips() * 2.f);
  56. set_fling_touchscreen_tap_suppression_enabled(true);
  57. set_fling_touchpad_tap_suppression_enabled(false);
  58. set_fling_max_cancel_to_down_time_in_ms(
  59. ViewConfiguration::GetTapTimeoutInMs());
  60. set_fling_max_tap_gap_time_in_ms(
  61. ViewConfiguration::GetLongPressTimeoutInMs());
  62. // Android ViewConfiguration doesn't have a short-press timeout. We are
  63. // using the heuristic that it would be 100ms less than the long-press
  64. // provided this is not too close with show-press.
  65. //
  66. // TODO(https://crbug.com/1294280): Replace this with platform-defined
  67. // timeout when available.
  68. set_short_press_time(base::Milliseconds(
  69. std::max(long_press_time_in_ms() - 100, long_press_time_in_ms() / 2)));
  70. }
  71. friend struct base::DefaultSingletonTraits<GestureConfigurationAndroid>;
  72. };
  73. } // namespace
  74. // Create a GestureConfigurationAura singleton instance when using Android.
  75. GestureConfiguration* GestureConfiguration::GetPlatformSpecificInstance() {
  76. return GestureConfigurationAndroid::GetInstance();
  77. }
  78. } // namespace ui