blob: 7ae3350f19603cd11ecfe1be6a9a7ad21ac0b813 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]1cd76c2d82012-11-29 07:36:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/public/browser/overscroll_configuration.h"
6
mfomitchev6277b5c2017-03-20 18:13:017#include "base/command_line.h"
mfomitchev6277b5c2017-03-20 18:13:018#include "base/strings/string_number_conversions.h"
Arthur Sonzognibdeca8e2023-09-11 08:32:129#include "content/common/features.h"
mfomitchev6277b5c2017-03-20 18:13:0110#include "content/public/common/content_switches.h"
[email protected]1cd76c2d82012-11-29 07:36:4711
12namespace {
13
Mohsen Izadi8c59ba52018-04-12 18:52:0114bool g_is_ptr_mode_initialized = false;
15content::OverscrollConfig::PullToRefreshMode g_ptr_mode =
16 content::OverscrollConfig::PullToRefreshMode::kDisabled;
Mohsen Izadi88b392a2018-02-15 06:57:4817
chaopengcd44c7622018-04-13 04:08:2118bool g_is_touchpad_overscroll_history_navigation_enabled_initialized = false;
19bool g_touchpad_overscroll_history_navigation_enabled = false;
20
chaopeng9736c522018-05-08 18:32:2721// On Windows, we only process 0.3 second inertial events then cancel the
22// overscroll if it is not completed yet.
23int g_max_inertial_events_before_overscroll_cancellation_in_ms = 300;
24
mfomitchev6277b5c2017-03-20 18:13:0125} // namespace
26
[email protected]1cd76c2d82012-11-29 07:36:4727namespace content {
28
Mohsen Izadi88b392a2018-02-15 06:57:4829// static
Elly Fong-Jones47960972019-05-16 18:40:5930const float OverscrollConfig::kCompleteTouchpadThresholdPercent = 0.3f;
31const float OverscrollConfig::kCompleteTouchscreenThresholdPercent = 0.25f;
32
33// static
34const float OverscrollConfig::kStartTouchpadThresholdDips = 60.f;
35const float OverscrollConfig::kStartTouchscreenThresholdDips = 50.f;
36
37// static
Mohsen Izadi8c59ba52018-04-12 18:52:0138OverscrollConfig::PullToRefreshMode OverscrollConfig::GetPullToRefreshMode() {
39 if (g_is_ptr_mode_initialized)
40 return g_ptr_mode;
41
42 const std::string mode =
43 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
44 switches::kPullToRefresh);
45 if (mode == "1")
46 g_ptr_mode = PullToRefreshMode::kEnabled;
47 else if (mode == "2")
48 g_ptr_mode = PullToRefreshMode::kEnabledTouchschreen;
49 g_is_ptr_mode_initialized = true;
50 return g_ptr_mode;
Mohsen Izadi88b392a2018-02-15 06:57:4851}
52
53// static
Mohsen Izadi8c59ba52018-04-12 18:52:0154void OverscrollConfig::SetPullToRefreshMode(PullToRefreshMode mode) {
55 g_ptr_mode = mode;
56 g_is_ptr_mode_initialized = true;
57}
58
59// static
60void OverscrollConfig::ResetPullToRefreshMode() {
61 g_is_ptr_mode_initialized = false;
62 g_ptr_mode = OverscrollConfig::PullToRefreshMode::kDisabled;
Mohsen Izadi88b392a2018-02-15 06:57:4863}
64
chaopengcd44c7622018-04-13 04:08:2165// static
66bool OverscrollConfig::TouchpadOverscrollHistoryNavigationEnabled() {
67 if (!g_is_touchpad_overscroll_history_navigation_enabled_initialized) {
68 g_is_touchpad_overscroll_history_navigation_enabled_initialized = true;
69 g_touchpad_overscroll_history_navigation_enabled =
70 base::FeatureList::IsEnabled(
71 features::kTouchpadOverscrollHistoryNavigation);
72 }
73
74 return g_touchpad_overscroll_history_navigation_enabled;
75}
76
77// static
78void OverscrollConfig::ResetTouchpadOverscrollHistoryNavigationEnabled() {
79 g_is_touchpad_overscroll_history_navigation_enabled_initialized = false;
80}
81
chaopeng9736c522018-05-08 18:32:2782// static
83base::TimeDelta
84OverscrollConfig::MaxInertialEventsBeforeOverscrollCancellation() {
Peter Kastinge5a38ed2021-10-02 03:06:3585 return base::Milliseconds(
chaopeng9736c522018-05-08 18:32:2786 g_max_inertial_events_before_overscroll_cancellation_in_ms);
87}
88
[email protected]1cd76c2d82012-11-29 07:36:4789} // namespace content