gesture_config_helper_android.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
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
16GestureDetector::Config DefaultGestureDetectorConfig(
17    const gfx::Display& display) {
18  GestureDetector::Config config;
19
20  config.longpress_timeout = base::TimeDelta::FromMilliseconds(
21      ViewConfiguration::GetLongPressTimeoutInMs());
22  config.showpress_timeout =
23      base::TimeDelta::FromMilliseconds(ViewConfiguration::GetTapTimeoutInMs());
24  config.double_tap_timeout = base::TimeDelta::FromMilliseconds(
25      ViewConfiguration::GetDoubleTapTimeoutInMs());
26
27  const float px_to_dp = 1.f / display.device_scale_factor();
28  config.touch_slop =
29      ViewConfiguration::GetTouchSlopInPixels() * px_to_dp;
30  config.double_tap_slop =
31      ViewConfiguration::GetDoubleTapSlopInPixels() * px_to_dp;
32  config.minimum_fling_velocity =
33      ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() * px_to_dp;
34  config.maximum_fling_velocity =
35      ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() * px_to_dp;
36
37  return config;
38}
39
40ScaleGestureDetector::Config DefaultScaleGestureDetectorConfig(
41    const gfx::Display& display) {
42  ScaleGestureDetector::Config config;
43
44  config.gesture_detector_config = DefaultGestureDetectorConfig(display);
45  config.quick_scale_enabled = true;
46
47  const float px_to_dp = 1.f / display.device_scale_factor();
48  config.min_scaling_touch_major =
49      ViewConfiguration::GetMinScalingTouchMajorInPixels() * px_to_dp;
50  config.min_scaling_span =
51      ViewConfiguration::GetMinScalingSpanInPixels() * px_to_dp;
52
53  return config;
54}
55
56}  // namespace
57
58GestureProvider::Config DefaultGestureProviderConfig() {
59  GestureProvider::Config config;
60  config.display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
61  config.gesture_detector_config = DefaultGestureDetectorConfig(config.display);
62  config.scale_gesture_detector_config =
63      DefaultScaleGestureDetectorConfig(config.display);
64  config.gesture_begin_end_types_enabled = false;
65  return config;
66}
67
68}  // namespace ui
69