gesture_config_helper_android.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file.
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/events/gesture_detection/gesture_config_helper.h"
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/android/view_configuration.h"
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/screen.h"
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using gfx::ViewConfiguration;
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace ui {
1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace {
1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// TODO(jdduke): Adopt GestureConfiguration on Android, crbug/339203.
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)GestureDetector::Config DefaultGestureDetectorConfig(
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const gfx::Display& display) {
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  GestureDetector::Config config;
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  config.longpress_timeout = base::TimeDelta::FromMilliseconds(
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      ViewConfiguration::GetLongPressTimeoutInMs());
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  config.showpress_timeout =
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      base::TimeDelta::FromMilliseconds(ViewConfiguration::GetTapTimeoutInMs());
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  config.double_tap_timeout = base::TimeDelta::FromMilliseconds(
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      ViewConfiguration::GetDoubleTapTimeoutInMs());
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const float px_to_dp = 1.f / display.device_scale_factor();
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  config.touch_slop =
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      ViewConfiguration::GetTouchSlopInPixels() * px_to_dp;
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  config.double_tap_slop =
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      ViewConfiguration::GetDoubleTapSlopInPixels() * px_to_dp;
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  config.minimum_fling_velocity =
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() * px_to_dp;
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  config.maximum_fling_velocity =
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() * px_to_dp;
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return config;
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)ScaleGestureDetector::Config DefaultScaleGestureDetectorConfig(
4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    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