gesture_config_helper_android.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 {
13
14// TODO(jdduke): Adopt GestureConfiguration on Android, crbug/339203.
15
16GestureDetector::Config DefaultGestureDetectorConfig() {
17  GestureDetector::Config config;
18
19  config.longpress_timeout = base::TimeDelta::FromMilliseconds(
20      ViewConfiguration::GetLongPressTimeoutInMs());
21  config.showpress_timeout = base::TimeDelta::FromMilliseconds(
22      ViewConfiguration::GetTapTimeoutInMs());
23  config.double_tap_timeout = base::TimeDelta::FromMilliseconds(
24      ViewConfiguration::GetDoubleTapTimeoutInMs());
25
26  config.scaled_touch_slop = ViewConfiguration::GetTouchSlopInPixels();
27  config.scaled_double_tap_slop = ViewConfiguration::GetDoubleTapSlopInPixels();
28  config.scaled_minimum_fling_velocity =
29      ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond();
30  config.scaled_maximum_fling_velocity =
31      ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond();
32
33  return config;
34}
35
36ScaleGestureDetector::Config DefaultScaleGestureDetectorConfig() {
37  ScaleGestureDetector::Config config;
38
39  config.gesture_detector_config = DefaultGestureDetectorConfig();
40  // TODO(jdduke): Enable "quick scale" on the ScaleGestureDetector, and remove
41  // corresponding double tap drag zoom code from GestureProvider, crbug/331092.
42  config.quick_scale_enabled = false;
43  config.min_scaling_touch_major =
44      ViewConfiguration::GetMinScalingTouchMajorInPixels();
45  config.min_scaling_span = ViewConfiguration::GetMinScalingSpanInPixels();
46
47  return config;
48}
49
50SnapScrollController::Config DefaultSnapScrollControllerConfig() {
51  SnapScrollController::Config config;
52
53  const gfx::Display& display =
54      gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
55
56  config.screen_width_pixels = display.GetSizeInPixel().width();
57  config.screen_height_pixels = display.GetSizeInPixel().height();
58  config.device_scale_factor = display.device_scale_factor();
59
60  return config;
61}
62
63GestureProvider::Config DefaultGestureProviderConfig() {
64  GestureProvider::Config config;
65  config.gesture_detector_config = DefaultGestureDetectorConfig();
66  config.scale_gesture_detector_config = DefaultScaleGestureDetectorConfig();
67  config.snap_scroll_controller_config = DefaultSnapScrollControllerConfig();
68  return config;
69}
70
71}  // namespace ui
72