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_timeout_in_ms(ViewConfiguration::GetDoubleTapTimeoutInMs());
37 set_gesture_begin_end_types_enabled(false);
38 set_long_press_time_in_ms(ViewConfiguration::GetLongPressTimeoutInMs());
39 set_max_distance_between_taps_for_double_tap(
40 ViewConfiguration::GetDoubleTapSlopInPixels() * raw_pixel_to_dip_ratio
);
41 set_max_fling_velocity(
42 ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() *
43 raw_pixel_to_dip_ratio
);
44 set_max_gesture_bounds_length(kMaxGestureBoundsLengthDips
);
45 set_max_touch_move_in_pixels_for_click(
46 ViewConfiguration::GetTouchSlopInPixels() * raw_pixel_to_dip_ratio
);
47 set_min_fling_velocity(
48 ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() *
49 raw_pixel_to_dip_ratio
);
50 set_min_gesture_bounds_length(kMinGestureBoundsLengthDips
);
51 set_min_pinch_update_span_delta(0.f
);
52 set_min_scaling_span_in_pixels(
53 ViewConfiguration::GetMinScalingSpanInPixels() *
54 raw_pixel_to_dip_ratio
);
55 set_min_scaling_touch_major(
56 ViewConfiguration::GetMinScalingTouchMajorInPixels() *
57 raw_pixel_to_dip_ratio
);
58 set_show_press_delay_in_ms(ViewConfiguration::GetTapTimeoutInMs());
59 set_span_slop(ViewConfiguration::GetTouchSlopInPixels() * 2.f
*
60 raw_pixel_to_dip_ratio
);
63 friend struct DefaultSingletonTraits
<GestureConfigurationAndroid
>;
64 DISALLOW_COPY_AND_ASSIGN(GestureConfigurationAndroid
);
69 // Create a GestureConfigurationAura singleton instance when using Android.
70 GestureConfiguration
* GestureConfiguration::GetInstance() {
71 return GestureConfigurationAndroid::GetInstance();