From c8655df73f311851f46d8247ef8bd843ba27356e Mon Sep 17 00:00:00 2001 From: "sangwoo.ko" Date: Fri, 2 Feb 2024 13:21:37 +0900 Subject: [PATCH] Expose "MiddleButtonAutoscroll" runtime feature to brave://flags This feature is disabled on Linux and MacOS. But as per a feature request, it's worth trying to enable it on those platforms. --- browser/about_flags.cc | 14 ++++++++++++++ chromium_src/third_party/blink/common/features.cc | 6 ++++++ .../third_party/blink/public/common/features.h | 4 ++++ renderer/brave_content_renderer_client.cc | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/browser/about_flags.cc b/browser/about_flags.cc index 5632e922ecf6..458e97127682 100644 --- a/browser/about_flags.cc +++ b/browser/about_flags.cc @@ -404,6 +404,19 @@ #define BRAVE_TABS_FEATURE_ENTRIES #endif +#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) +#define BRAVE_MIDDLE_CLICK_AUTOSCROLL_FEATURE_ENTRY \ + EXPAND_FEATURE_ENTRIES({ \ + "middle-button-autoscroll", \ + "Middle button autoscroll", \ + "Enables autoscrolling when the middle mouse button is clicked", \ + kOsMac | kOsLinux, \ + FEATURE_VALUE_TYPE(blink::features::kMiddleButtonClickAutoscroll), \ + }) +#else +#define BRAVE_MIDDLE_CLICK_AUTOSCROLL_FEATURE_ENTRY +#endif + #if BUILDFLAG(ENABLE_AI_CHAT) #define BRAVE_AI_CHAT \ EXPAND_FEATURE_ENTRIES({ \ @@ -969,6 +982,7 @@ BRAVE_AI_CHAT_HISTORY \ BRAVE_OMNIBOX_FEATURES \ BRAVE_PLAYER_FEATURE_ENTRIES \ + BRAVE_MIDDLE_CLICK_AUTOSCROLL_FEATURE_ENTRY \ LAST_BRAVE_FEATURE_ENTRIES_ITEM // Keep it as the last item. namespace flags_ui { namespace { diff --git a/chromium_src/third_party/blink/common/features.cc b/chromium_src/third_party/blink/common/features.cc index 82b998f1fff6..1bbc5c8f9bc3 100644 --- a/chromium_src/third_party/blink/common/features.cc +++ b/chromium_src/third_party/blink/common/features.cc @@ -109,6 +109,12 @@ BASE_FEATURE(kRestrictEventSourcePool, #endif ); +#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) +BASE_FEATURE(kMiddleButtonClickAutoscroll, + "MiddelButtonClickAutoscroll", + base::FEATURE_DISABLED_BY_DEFAULT); +#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) + bool IsPrerender2Enabled() { return false; } diff --git a/chromium_src/third_party/blink/public/common/features.h b/chromium_src/third_party/blink/public/common/features.h index 445789dffffe..ca3d486eb4a0 100644 --- a/chromium_src/third_party/blink/public/common/features.h +++ b/chromium_src/third_party/blink/public/common/features.h @@ -23,6 +23,10 @@ BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kBraveGlobalPrivacyControl); BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kBraveRoundTimeStamps); BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kRestrictEventSourcePool); +#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) +BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kMiddleButtonClickAutoscroll); +#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) + // Chromium used this function to control Prerender2 feature, but then the // feature was permanently enabled and the function was removed. We still want // to keep the Prerender2 functionality disabled, so putting back the function diff --git a/renderer/brave_content_renderer_client.cc b/renderer/brave_content_renderer_client.cc index 35181e137bdc..3207d79310e4 100644 --- a/renderer/brave_content_renderer_client.cc +++ b/renderer/brave_content_renderer_client.cc @@ -103,6 +103,14 @@ void BraveContentRendererClient:: blink::WebRuntimeFeatures::EnableFeatureFromString("Serial", false); } blink::WebRuntimeFeatures::EnableFeatureFromString("AdTagging", false); + +#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) + if (base::FeatureList::IsEnabled( + blink::features::kMiddleButtonClickAutoscroll)) { + blink::WebRuntimeFeatures::EnableFeatureFromString("MiddleClickAutoscroll", + true); + } +#endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) } BraveContentRendererClient::~BraveContentRendererClient() = default;