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.
5 #include "ui/events/gesture_detection/gesture_configuration.h"
7 #include "base/memory/singleton.h"
8 #include "ui/gfx/android/view_configuration.h"
9 #include "ui/gfx/screen.h"
11 using gfx::ViewConfiguration
;
15 // This was the minimum tap/press size used on Android before the new gesture
16 // detection pipeline.
17 const float kMinGestureBoundsLengthDips
= 24.f
;
19 // This value is somewhat arbitrary, but provides a reasonable maximum
20 // approximating a large thumb depression.
21 const float kMaxGestureBoundsLengthDips
= kMinGestureBoundsLengthDips
* 4.f
;
23 class GestureConfigurationAndroid
: public GestureConfiguration
{
25 ~GestureConfigurationAndroid() override
{
28 static GestureConfigurationAndroid
* GetInstance() {
29 return Singleton
<GestureConfigurationAndroid
>::get();
33 GestureConfigurationAndroid() : GestureConfiguration() {
34 float raw_pixel_to_dip_ratio
= 1.f
/ gfx::Screen::GetNativeScreen()
36 .device_scale_factor();
37 set_double_tap_enabled(true);
38 set_double_tap_timeout_in_ms(ViewConfiguration::GetDoubleTapTimeoutInMs());
39 set_gesture_begin_end_types_enabled(false);
40 set_long_press_time_in_ms(ViewConfiguration::GetLongPressTimeoutInMs());
41 set_max_distance_between_taps_for_double_tap(
42 ViewConfiguration::GetDoubleTapSlopInPixels() * raw_pixel_to_dip_ratio
);
43 set_max_fling_velocity(
44 ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() *
45 raw_pixel_to_dip_ratio
);
46 set_max_gesture_bounds_length(kMaxGestureBoundsLengthDips
);
47 set_max_touch_move_in_pixels_for_click(
48 ViewConfiguration::GetTouchSlopInPixels() * raw_pixel_to_dip_ratio
);
49 set_min_fling_velocity(
50 ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() *
51 raw_pixel_to_dip_ratio
);
52 set_min_gesture_bounds_length(kMinGestureBoundsLengthDips
);
53 set_min_pinch_update_span_delta(0.f
);
54 set_min_scaling_span_in_pixels(
55 ViewConfiguration::GetMinScalingSpanInPixels() *
56 raw_pixel_to_dip_ratio
);
57 set_min_scaling_touch_major(
58 ViewConfiguration::GetMinScalingTouchMajorInPixels() *
59 raw_pixel_to_dip_ratio
);
60 set_show_press_delay_in_ms(ViewConfiguration::GetTapTimeoutInMs());
61 set_span_slop(ViewConfiguration::GetTouchSlopInPixels() * 2.f
*
62 raw_pixel_to_dip_ratio
);
65 friend struct DefaultSingletonTraits
<GestureConfigurationAndroid
>;
66 DISALLOW_COPY_AND_ASSIGN(GestureConfigurationAndroid
);
71 // Create a GestureConfigurationAura singleton instance when using Android.
72 GestureConfiguration
* GestureConfiguration::GetPlatformSpecificInstance() {
73 return GestureConfigurationAndroid::GetInstance();