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.
4
5#include "ui/events/gesture_detection/gesture_config_helper.h"
6
7#include "ui/gfx/android/view_configuration.h"
8#include "ui/gfx/screen.h"
9
10using gfx::ViewConfiguration;
11
12namespace ui {
13namespace {
14// TODO(jdduke): Adopt GestureConfiguration on Android, crbug/339203.
15
16// This was the minimum tap/press size used on Android before the new gesture
17// detection pipeline.
18const float kMinGestureBoundsLengthDips = 24.f;
19
20// This value is somewhat arbitrary, but provides a reasonable maximum
21// approximating a large thumb depression.
22const float kMaxGestureBoundsLengthDips = kMinGestureBoundsLengthDips * 4.f;
23
24GestureDetector::Config DefaultGestureDetectorConfig(
25    const gfx::Display& display) {
26  GestureDetector::Config config;
27
28  config.longpress_timeout = base::TimeDelta::FromMilliseconds(
29      ViewConfiguration::GetLongPressTimeoutInMs());
30  config.showpress_timeout =
31      base::TimeDelta::FromMilliseconds(ViewConfiguration::GetTapTimeoutInMs());
32  config.double_tap_timeout = base::TimeDelta::FromMilliseconds(
33      ViewConfiguration::GetDoubleTapTimeoutInMs());
34
35  const float px_to_dp = 1.f / display.device_scale_factor();
36  config.touch_slop =
37      ViewConfiguration::GetTouchSlopInPixels() * px_to_dp;
38  config.double_tap_slop =
39      ViewConfiguration::GetDoubleTapSlopInPixels() * px_to_dp;
40  config.minimum_fling_velocity =
41      ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() * px_to_dp;
42  config.maximum_fling_velocity =
43      ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() * px_to_dp;
44
45  return config;
46}
47
48ScaleGestureDetector::Config DefaultScaleGestureDetectorConfig(
49    const gfx::Display& display) {
50  ScaleGestureDetector::Config config;
51
52  const float px_to_dp = 1.f / display.device_scale_factor();
53  config.span_slop = ViewConfiguration::GetTouchSlopInPixels() * 2.f * px_to_dp;
54  config.min_scaling_touch_major =
55      ViewConfiguration::GetMinScalingTouchMajorInPixels() * px_to_dp;
56  config.min_scaling_span =
57      ViewConfiguration::GetMinScalingSpanInPixels() * px_to_dp;
58  config.min_pinch_update_span_delta = 0.f;
59
60  return config;
61}
62
63}  // namespace
64
65GestureProvider::Config DefaultGestureProviderConfig() {
66  GestureProvider::Config config;
67  config.display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
68  config.gesture_detector_config = DefaultGestureDetectorConfig(config.display);
69  config.scale_gesture_detector_config =
70      DefaultScaleGestureDetectorConfig(config.display);
71  config.gesture_begin_end_types_enabled = false;
72  config.min_gesture_bounds_length = kMinGestureBoundsLengthDips;
73  config.max_gesture_bounds_length = kMaxGestureBoundsLengthDips;
74  return config;
75}
76
77}  // namespace ui
78