Chromium Code Reviews| 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 { | |
|
jdduke (slow)
2014/10/21 15:17:12
Nit: This class can be put in an anonymous namespa
lanwei
2014/10/21 20:52:31
Done.
| |
| 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; | |
|
jdduke (slow)
2014/10/21 15:17:12
Nit: Prefer non-member constants, so |k{Min,Max|Ge
lanwei
2014/10/21 20:52:31
Done.
| |
| 27 config.max_gesture_bounds_length = kMaxGestureBoundsLengthDips; | |
| 28 return config; | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 GestureConfigurationAndroid() : GestureConfiguration() { | |
| 33 set_long_press_time_in_ms(ViewConfiguration::GetLongPressTimeoutInMs()); | |
| 34 set_semi_long_press_time_in_ms( | |
| 35 ViewConfiguration::GetDoubleTapTimeoutInMs()); | |
| 36 set_show_press_delay_in_ms(ViewConfiguration::GetTapTimeoutInMs()); | |
| 37 set_fling_velocity_cap( | |
| 38 ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() * | |
| 39 GetRawPixelToDIPRatio()); | |
| 40 set_min_scroll_velocity( | |
| 41 ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() * | |
| 42 GetRawPixelToDIPRatio()); | |
| 43 set_max_touch_move_in_pixels_for_click( | |
| 44 ViewConfiguration::GetTouchSlopInPixels() * GetRawPixelToDIPRatio()); | |
| 45 set_max_distance_between_taps_for_double_tap( | |
| 46 ViewConfiguration::GetDoubleTapSlopInPixels() * | |
| 47 GetRawPixelToDIPRatio()); | |
| 48 set_span_slop(ViewConfiguration::GetTouchSlopInPixels() * 2.f * | |
| 49 GetRawPixelToDIPRatio()); | |
| 50 set_min_scaling_touch_major( | |
| 51 ViewConfiguration::GetMinScalingTouchMajorInPixels() * | |
| 52 GetRawPixelToDIPRatio()); | |
| 53 set_min_scaling_span_in_pixels( | |
| 54 ViewConfiguration::GetMinScalingSpanInPixels() * | |
| 55 GetRawPixelToDIPRatio()); | |
| 56 set_min_pinch_update_span_delta(0.f); | |
| 57 } | |
| 58 | |
| 59 friend struct DefaultSingletonTraits<GestureConfigurationAndroid>; | |
| 60 const gfx::Display GetDisplay() { | |
|
jdduke (slow)
2014/10/21 15:17:12
Nit: I would get rid of both of these helper funct
lanwei
2014/10/21 20:52:31
Done.
| |
| 61 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
| 62 } | |
| 63 | |
| 64 const float GetRawPixelToDIPRatio() { | |
| 65 return 1.f / GetDisplay().device_scale_factor(); | |
| 66 } | |
| 67 // This was the minimum tap/press size used on Android before the new gesture | |
| 68 // detection pipeline. | |
| 69 const float kMinGestureBoundsLengthDips = 24.f; | |
| 70 | |
| 71 // This value is somewhat arbitrary, but provides a reasonable maximum | |
| 72 // approximating a large thumb depression. | |
| 73 const float kMaxGestureBoundsLengthDips = kMinGestureBoundsLengthDips * 4.f; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(GestureConfigurationAndroid); | |
| 76 }; | |
| 77 | |
| 78 GestureConfiguration* GestureConfiguration::GetInstance() { | |
| 79 return GestureConfigurationAndroid::GetInstance(); | |
| 80 } | |
| 81 | |
| 82 GestureProvider::Config DefaultGestureProviderConfig() { | |
| 83 return GestureConfigurationAndroid::GetInstance() | |
| 84 ->DefaultGestureProviderConfig(); | |
| 85 } | |
| 86 | |
| 87 } // namespace ui | |
| OLD | NEW |