Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_configuration_android.cc
blob54cb8c6798e3a514c871374690eff8f1704ce880
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;
13 namespace ui {
14 namespace {
16 // Touch radii on Android can be both noisy and inaccurate. The old Java
17 // gesture detection pipeline used a fixed value of 24 as the gesture bounds.
18 // We relax that value somewhat, but not by much; there's a fairly small window
19 // within which gesture bounds are useful for features like touch adjustment.
20 const float kMinGestureBoundsLengthDips = 20.f;
21 const float kMaxGestureBoundsLengthDips = 32.f;
23 class GestureConfigurationAndroid : public GestureConfiguration {
24 public:
25 ~GestureConfigurationAndroid() override {
28 static GestureConfigurationAndroid* GetInstance() {
29 return base::Singleton<GestureConfigurationAndroid>::get();
32 private:
33 GestureConfigurationAndroid() : GestureConfiguration() {
34 set_double_tap_enabled(true);
35 set_double_tap_timeout_in_ms(ViewConfiguration::GetDoubleTapTimeoutInMs());
36 set_gesture_begin_end_types_enabled(false);
37 set_long_press_time_in_ms(ViewConfiguration::GetLongPressTimeoutInMs());
38 set_max_distance_between_taps_for_double_tap(
39 ViewConfiguration::GetDoubleTapSlopInDips());
40 set_max_fling_velocity(
41 ViewConfiguration::GetMaximumFlingVelocityInDipsPerSecond());
42 set_max_gesture_bounds_length(kMaxGestureBoundsLengthDips);
43 set_max_touch_move_in_pixels_for_click(
44 ViewConfiguration::GetTouchSlopInDips());
45 set_min_fling_velocity(
46 ViewConfiguration::GetMinimumFlingVelocityInDipsPerSecond());
47 set_min_gesture_bounds_length(kMinGestureBoundsLengthDips);
48 set_min_pinch_update_span_delta(0.f);
49 set_min_scaling_span_in_pixels(
50 ViewConfiguration::GetMinScalingSpanInDips());
51 set_min_scaling_touch_major(
52 ViewConfiguration::GetMinScalingTouchMajorInDips());
53 set_show_press_delay_in_ms(ViewConfiguration::GetTapTimeoutInMs());
54 set_span_slop(ViewConfiguration::GetTouchSlopInDips() * 2.f);
55 set_fling_touchscreen_tap_suppression_enabled(true);
56 set_fling_touchpad_tap_suppression_enabled(false);
57 set_fling_max_cancel_to_down_time_in_ms(
58 ViewConfiguration::GetTapTimeoutInMs());
59 set_fling_max_tap_gap_time_in_ms(
60 ViewConfiguration::GetLongPressTimeoutInMs());
63 friend struct base::DefaultSingletonTraits<GestureConfigurationAndroid>;
64 DISALLOW_COPY_AND_ASSIGN(GestureConfigurationAndroid);
67 } // namespace
69 // Create a GestureConfigurationAura singleton instance when using Android.
70 GestureConfiguration* GestureConfiguration::GetPlatformSpecificInstance() {
71 return GestureConfigurationAndroid::GetInstance();
74 } // namespace ui