gesture_config_helper_android.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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  config.gesture_detector_config = DefaultGestureDetectorConfig(display);
53  config.quick_scale_enabled = true;
54
55  const float px_to_dp = 1.f / display.device_scale_factor();
56  config.min_scaling_touch_major =
57      ViewConfiguration::GetMinScalingTouchMajorInPixels() * px_to_dp;
58  config.use_touch_major_in_span =
59      ViewConfiguration::ShouldUseTouchMajorInScalingSpan();
60  config.min_scaling_span =
61      ViewConfiguration::GetMinScalingSpanInPixels() * px_to_dp;
62  // As the |min_scaling_span| platform constant assumes that touch major values
63  // are used when computing the span, subtract off a reasonable touch major
64  // value for the case where the touch major values are not used.
65  if (!config.use_touch_major_in_span) {
66    config.min_scaling_span = std::max(
67        0.f, config.min_scaling_span - 2.f * config.min_scaling_touch_major);
68  }
69
70  return config;
71}
72
73}  // namespace
74
75GestureProvider::Config DefaultGestureProviderConfig() {
76  GestureProvider::Config config;
77  config.display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
78  config.gesture_detector_config = DefaultGestureDetectorConfig(config.display);
79  config.scale_gesture_detector_config =
80      DefaultScaleGestureDetectorConfig(config.display);
81  config.gesture_begin_end_types_enabled = false;
82  config.min_gesture_bounds_length = kMinGestureBoundsLengthDips;
83  config.max_gesture_bounds_length = kMaxGestureBoundsLengthDips;
84  return config;
85}
86
87}  // namespace ui
88