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..9f198f2eae413a10705172a6a603c8906a25735b |
--- /dev/null |
+++ b/ui/events/gesture_detection/gesture_configuration_android.cc |
@@ -0,0 +1,110 @@ |
+// 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 { |
+ 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; |
+ config.max_gesture_bounds_length = kMaxGestureBoundsLengthDips; |
+ return config; |
+ } |
+ |
+ virtual int long_press_timeout_in_ms() OVERRIDE { |
+ return ViewConfiguration::GetLongPressTimeoutInMs(); |
+ } |
+ |
+ virtual int double_tap_timeout_in_ms() OVERRIDE { |
+ return ViewConfiguration::GetDoubleTapTimeoutInMs(); |
+ } |
+ |
+ virtual int show_press_delay_in_ms() OVERRIDE { |
+ return ViewConfiguration::GetTapTimeoutInMs(); |
+ } |
+ |
+ virtual float fling_velocity_cap() OVERRIDE { |
+ return ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() * |
+ GetRawPixelToDIPRatio(); |
+ } |
+ |
+ virtual float min_scroll_velocity() OVERRIDE { |
+ return ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() * |
+ GetRawPixelToDIPRatio(); |
+ } |
+ |
+ virtual double max_touch_move_in_pixels_for_click() OVERRIDE { |
+ return ViewConfiguration::GetTouchSlopInPixels() * GetRawPixelToDIPRatio(); |
+ } |
+ |
+ virtual int span_slop_in_pixels() OVERRIDE { |
+ return ViewConfiguration::GetTouchSlopInPixels() * 2.f * |
+ GetRawPixelToDIPRatio(); |
+ } |
+ |
+ virtual double max_distance_between_taps_for_double_tap() OVERRIDE { |
+ return ViewConfiguration::GetDoubleTapSlopInPixels() * |
+ GetRawPixelToDIPRatio(); |
+ } |
+ |
+ virtual int min_scaling_span_in_pixels() OVERRIDE { |
+ return ViewConfiguration::GetMinScalingSpanInPixels() * |
+ GetRawPixelToDIPRatio(); |
+ } |
+ |
+ virtual int min_scaling_touch_major_in_pixels() OVERRIDE { |
+ return ViewConfiguration::GetMinScalingTouchMajorInPixels() * |
+ GetRawPixelToDIPRatio(); |
+ } |
+ |
+ virtual double min_pinch_update_distance_in_pixels() OVERRIDE { return 0.f; } |
+ |
+ private: |
+ GestureConfigurationAndroid() {} |
+ |
+ friend struct DefaultSingletonTraits<GestureConfigurationAndroid>; |
+ const gfx::Display GetDisplay() { |
+ 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 |