Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 1cd76c2d8 | 2012-11-29 07:36:47 | [diff] [blame] | 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 "content/public/browser/overscroll_configuration.h" |
| 6 | |
mfomitchev | 6277b5c | 2017-03-20 18:13:01 | [diff] [blame] | 7 | #include "base/command_line.h" |
mfomitchev | 6277b5c | 2017-03-20 18:13:01 | [diff] [blame] | 8 | #include "base/strings/string_number_conversions.h" |
Arthur Sonzogni | bdeca8e | 2023-09-11 08:32:12 | [diff] [blame] | 9 | #include "content/common/features.h" |
mfomitchev | 6277b5c | 2017-03-20 18:13:01 | [diff] [blame] | 10 | #include "content/public/common/content_switches.h" |
[email protected] | 1cd76c2d8 | 2012-11-29 07:36:47 | [diff] [blame] | 11 | |
| 12 | namespace { |
| 13 | |
Mohsen Izadi | 8c59ba5 | 2018-04-12 18:52:01 | [diff] [blame] | 14 | bool g_is_ptr_mode_initialized = false; |
| 15 | content::OverscrollConfig::PullToRefreshMode g_ptr_mode = |
| 16 | content::OverscrollConfig::PullToRefreshMode::kDisabled; |
Mohsen Izadi | 88b392a | 2018-02-15 06:57:48 | [diff] [blame] | 17 | |
chaopeng | cd44c762 | 2018-04-13 04:08:21 | [diff] [blame] | 18 | bool g_is_touchpad_overscroll_history_navigation_enabled_initialized = false; |
| 19 | bool g_touchpad_overscroll_history_navigation_enabled = false; |
| 20 | |
chaopeng | 9736c52 | 2018-05-08 18:32:27 | [diff] [blame] | 21 | // On Windows, we only process 0.3 second inertial events then cancel the |
| 22 | // overscroll if it is not completed yet. |
| 23 | int g_max_inertial_events_before_overscroll_cancellation_in_ms = 300; |
| 24 | |
mfomitchev | 6277b5c | 2017-03-20 18:13:01 | [diff] [blame] | 25 | } // namespace |
| 26 | |
[email protected] | 1cd76c2d8 | 2012-11-29 07:36:47 | [diff] [blame] | 27 | namespace content { |
| 28 | |
Mohsen Izadi | 88b392a | 2018-02-15 06:57:48 | [diff] [blame] | 29 | // static |
Elly Fong-Jones | 4796097 | 2019-05-16 18:40:59 | [diff] [blame] | 30 | const float OverscrollConfig::kCompleteTouchpadThresholdPercent = 0.3f; |
| 31 | const float OverscrollConfig::kCompleteTouchscreenThresholdPercent = 0.25f; |
| 32 | |
| 33 | // static |
| 34 | const float OverscrollConfig::kStartTouchpadThresholdDips = 60.f; |
| 35 | const float OverscrollConfig::kStartTouchscreenThresholdDips = 50.f; |
| 36 | |
| 37 | // static |
Mohsen Izadi | 8c59ba5 | 2018-04-12 18:52:01 | [diff] [blame] | 38 | OverscrollConfig::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 Izadi | 88b392a | 2018-02-15 06:57:48 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // static |
Mohsen Izadi | 8c59ba5 | 2018-04-12 18:52:01 | [diff] [blame] | 54 | void OverscrollConfig::SetPullToRefreshMode(PullToRefreshMode mode) { |
| 55 | g_ptr_mode = mode; |
| 56 | g_is_ptr_mode_initialized = true; |
| 57 | } |
| 58 | |
| 59 | // static |
| 60 | void OverscrollConfig::ResetPullToRefreshMode() { |
| 61 | g_is_ptr_mode_initialized = false; |
| 62 | g_ptr_mode = OverscrollConfig::PullToRefreshMode::kDisabled; |
Mohsen Izadi | 88b392a | 2018-02-15 06:57:48 | [diff] [blame] | 63 | } |
| 64 | |
chaopeng | cd44c762 | 2018-04-13 04:08:21 | [diff] [blame] | 65 | // static |
| 66 | bool 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 |
| 78 | void OverscrollConfig::ResetTouchpadOverscrollHistoryNavigationEnabled() { |
| 79 | g_is_touchpad_overscroll_history_navigation_enabled_initialized = false; |
| 80 | } |
| 81 | |
chaopeng | 9736c52 | 2018-05-08 18:32:27 | [diff] [blame] | 82 | // static |
| 83 | base::TimeDelta |
| 84 | OverscrollConfig::MaxInertialEventsBeforeOverscrollCancellation() { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 85 | return base::Milliseconds( |
chaopeng | 9736c52 | 2018-05-08 18:32:27 | [diff] [blame] | 86 | g_max_inertial_events_before_overscroll_cancellation_in_ms); |
| 87 | } |
| 88 | |
[email protected] | 1cd76c2d8 | 2012-11-29 07:36:47 | [diff] [blame] | 89 | } // namespace content |