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