Chromium Code Reviews| Index: ui/events/gesture_detection/gesture_configuration_android.cc |
| diff --git a/ui/events/gesture_detection/gesture_configuration_android.cc b/ui/events/gesture_detection/gesture_configuration_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a95f3c9875eaf7206938a4896e63b8b262d3da17 |
| --- /dev/null |
| +++ b/ui/events/gesture_detection/gesture_configuration_android.cc |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/events/gesture_detection/gesture_configuration.h" |
| + |
| +#include "ui/gfx/android/view_configuration.h" |
| +#include "ui/gfx/screen.h" |
| + |
| +using gfx::ViewConfiguration; |
| + |
| +namespace ui { |
| + |
| +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.
|
| + public: |
| + static GestureConfigurationAndroid* GetInstance() { |
| + return Singleton<GestureConfigurationAndroid>::get(); |
| + } |
| + |
| + GestureProvider::Config DefaultGestureProviderConfig() { |
| + GestureProvider::Config config; |
| + config.display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| + config.gesture_detector_config = DefaultGestureDetectorConfig(); |
| + config.scale_gesture_detector_config = DefaultScaleGestureDetectorConfig(); |
| + config.gesture_begin_end_types_enabled = false; |
| + 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.
|
| + config.max_gesture_bounds_length = kMaxGestureBoundsLengthDips; |
| + return config; |
| + } |
| + |
| + private: |
| + GestureConfigurationAndroid() : GestureConfiguration() { |
| + set_long_press_time_in_ms(ViewConfiguration::GetLongPressTimeoutInMs()); |
| + set_semi_long_press_time_in_ms( |
| + ViewConfiguration::GetDoubleTapTimeoutInMs()); |
| + set_show_press_delay_in_ms(ViewConfiguration::GetTapTimeoutInMs()); |
| + set_fling_velocity_cap( |
| + ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() * |
| + GetRawPixelToDIPRatio()); |
| + set_min_scroll_velocity( |
| + ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() * |
| + GetRawPixelToDIPRatio()); |
| + set_max_touch_move_in_pixels_for_click( |
| + ViewConfiguration::GetTouchSlopInPixels() * GetRawPixelToDIPRatio()); |
| + set_max_distance_between_taps_for_double_tap( |
| + ViewConfiguration::GetDoubleTapSlopInPixels() * |
| + GetRawPixelToDIPRatio()); |
| + set_span_slop(ViewConfiguration::GetTouchSlopInPixels() * 2.f * |
| + GetRawPixelToDIPRatio()); |
| + set_min_scaling_touch_major( |
| + ViewConfiguration::GetMinScalingTouchMajorInPixels() * |
| + GetRawPixelToDIPRatio()); |
| + set_min_scaling_span_in_pixels( |
| + ViewConfiguration::GetMinScalingSpanInPixels() * |
| + GetRawPixelToDIPRatio()); |
| + set_min_pinch_update_span_delta(0.f); |
| + } |
| + |
| + friend struct DefaultSingletonTraits<GestureConfigurationAndroid>; |
| + 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.
|
| + return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| + } |
| + |
| + const float GetRawPixelToDIPRatio() { |
| + return 1.f / GetDisplay().device_scale_factor(); |
| + } |
| + // This was the minimum tap/press size used on Android before the new gesture |
| + // detection pipeline. |
| + const float kMinGestureBoundsLengthDips = 24.f; |
| + |
| + // This value is somewhat arbitrary, but provides a reasonable maximum |
| + // approximating a large thumb depression. |
| + const float kMaxGestureBoundsLengthDips = kMinGestureBoundsLengthDips * 4.f; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GestureConfigurationAndroid); |
| +}; |
| + |
| +GestureConfiguration* GestureConfiguration::GetInstance() { |
| + return GestureConfigurationAndroid::GetInstance(); |
| +} |
| + |
| +GestureProvider::Config DefaultGestureProviderConfig() { |
| + return GestureConfigurationAndroid::GetInstance() |
| + ->DefaultGestureProviderConfig(); |
| +} |
| + |
| +} // namespace ui |