OLD | NEW |
(Empty) | |
| 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 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 6 |
| 7 #include "ui/gfx/android/view_configuration.h" |
| 8 #include "ui/gfx/screen.h" |
| 9 |
| 10 using gfx::ViewConfiguration; |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 class GestureConfigurationAndroid : public GestureConfiguration { |
| 15 public: |
| 16 static GestureConfigurationAndroid* GetInstance() { |
| 17 return Singleton<GestureConfigurationAndroid>::get(); |
| 18 } |
| 19 |
| 20 GestureProvider::Config DefaultGestureProviderConfig() { |
| 21 GestureProvider::Config config; |
| 22 config.display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 23 config.gesture_detector_config = DefaultGestureDetectorConfig(); |
| 24 config.scale_gesture_detector_config = DefaultScaleGestureDetectorConfig(); |
| 25 config.gesture_begin_end_types_enabled = false; |
| 26 config.min_gesture_bounds_length = kMinGestureBoundsLengthDips; |
| 27 config.max_gesture_bounds_length = kMaxGestureBoundsLengthDips; |
| 28 return config; |
| 29 } |
| 30 |
| 31 virtual int long_press_timeout_in_ms() OVERRIDE { |
| 32 return ViewConfiguration::GetLongPressTimeoutInMs(); |
| 33 } |
| 34 |
| 35 virtual int double_tap_timeout_in_ms() OVERRIDE { |
| 36 return ViewConfiguration::GetDoubleTapTimeoutInMs(); |
| 37 } |
| 38 |
| 39 virtual int show_press_delay_in_ms() OVERRIDE { |
| 40 return ViewConfiguration::GetTapTimeoutInMs(); |
| 41 } |
| 42 |
| 43 virtual float fling_velocity_cap() OVERRIDE { |
| 44 return ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() * |
| 45 GetRawPixelToDIPRatio(); |
| 46 } |
| 47 |
| 48 virtual float min_scroll_velocity() OVERRIDE { |
| 49 return ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() * |
| 50 GetRawPixelToDIPRatio(); |
| 51 } |
| 52 |
| 53 virtual double max_touch_move_in_pixels_for_click() OVERRIDE { |
| 54 return ViewConfiguration::GetTouchSlopInPixels() * GetRawPixelToDIPRatio(); |
| 55 } |
| 56 |
| 57 virtual int span_slop_in_pixels() OVERRIDE { |
| 58 return ViewConfiguration::GetTouchSlopInPixels() * 2.f * |
| 59 GetRawPixelToDIPRatio(); |
| 60 } |
| 61 |
| 62 virtual double max_distance_between_taps_for_double_tap() OVERRIDE { |
| 63 return ViewConfiguration::GetDoubleTapSlopInPixels() * |
| 64 GetRawPixelToDIPRatio(); |
| 65 } |
| 66 |
| 67 virtual int min_scaling_span_in_pixels() OVERRIDE { |
| 68 return ViewConfiguration::GetMinScalingSpanInPixels() * |
| 69 GetRawPixelToDIPRatio(); |
| 70 } |
| 71 |
| 72 virtual int min_scaling_touch_major_in_pixels() OVERRIDE { |
| 73 return ViewConfiguration::GetMinScalingTouchMajorInPixels() * |
| 74 GetRawPixelToDIPRatio(); |
| 75 } |
| 76 |
| 77 virtual double min_pinch_update_distance_in_pixels() OVERRIDE { return 0.f; } |
| 78 |
| 79 private: |
| 80 GestureConfigurationAndroid() {} |
| 81 |
| 82 friend struct DefaultSingletonTraits<GestureConfigurationAndroid>; |
| 83 const gfx::Display GetDisplay() { |
| 84 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 85 } |
| 86 |
| 87 const float GetRawPixelToDIPRatio() { |
| 88 return 1.f / GetDisplay().device_scale_factor(); |
| 89 } |
| 90 // This was the minimum tap/press size used on Android before the new gesture |
| 91 // detection pipeline. |
| 92 const float kMinGestureBoundsLengthDips = 24.f; |
| 93 |
| 94 // This value is somewhat arbitrary, but provides a reasonable maximum |
| 95 // approximating a large thumb depression. |
| 96 const float kMaxGestureBoundsLengthDips = kMinGestureBoundsLengthDips * 4.f; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(GestureConfigurationAndroid); |
| 99 }; |
| 100 |
| 101 GestureConfiguration* GestureConfiguration::GetInstance() { |
| 102 return GestureConfigurationAndroid::GetInstance(); |
| 103 } |
| 104 |
| 105 GestureProvider::Config DefaultGestureProviderConfig() { |
| 106 return GestureConfigurationAndroid::GetInstance() |
| 107 ->DefaultGestureProviderConfig(); |
| 108 } |
| 109 |
| 110 } // namespace ui |
OLD | NEW |