gesture_config_helper_android.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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.min_scaling_span = 59 ViewConfiguration::GetMinScalingSpanInPixels() * px_to_dp; 60 61 return config; 62} 63 64} // namespace 65 66GestureProvider::Config DefaultGestureProviderConfig() { 67 GestureProvider::Config config; 68 config.display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 69 config.gesture_detector_config = DefaultGestureDetectorConfig(config.display); 70 config.scale_gesture_detector_config = 71 DefaultScaleGestureDetectorConfig(config.display); 72 config.gesture_begin_end_types_enabled = false; 73 config.min_gesture_bounds_length = kMinGestureBoundsLengthDips; 74 config.max_gesture_bounds_length = kMaxGestureBoundsLengthDips; 75 return config; 76} 77 78} // namespace ui 79