From 95faf4c35c0b6047e1fc0e9634fc5236d20142e4 Mon Sep 17 00:00:00 2001 From: Emerick Rogul Date: Wed, 23 Mar 2022 21:31:28 -0400 Subject: [PATCH] Fix tab audio muting button --- app/brave_main_delegate_browsertest.cc | 1 + browser/about_flags.cc | 11 -- browser/ui/BUILD.gn | 2 - .../tabs/brave_alert_indicator_button.cc | 142 ------------------ .../views/tabs/brave_alert_indicator_button.h | 35 ----- .../chrome/browser/ui/views/tabs/tab.cc | 4 - chromium_src/media/base/media_switches.cc | 1 + common/brave_features.cc | 3 - common/brave_features.h | 2 - ...-views-tabs-alert_indicator_button.h.patch | 12 -- 10 files changed, 2 insertions(+), 211 deletions(-) delete mode 100644 browser/ui/views/tabs/brave_alert_indicator_button.cc delete mode 100644 browser/ui/views/tabs/brave_alert_indicator_button.h delete mode 100644 patches/chrome-browser-ui-views-tabs-alert_indicator_button.h.patch diff --git a/app/brave_main_delegate_browsertest.cc b/app/brave_main_delegate_browsertest.cc index 613ab24eb0e..36b1f5a4200 100644 --- a/app/brave_main_delegate_browsertest.cc +++ b/app/brave_main_delegate_browsertest.cc @@ -133,6 +133,7 @@ IN_PROC_BROWSER_TEST_F(BraveMainDelegateBrowserTest, DisabledFeatures) { IN_PROC_BROWSER_TEST_F(BraveMainDelegateBrowserTest, EnabledFeatures) { const base::Feature* enabled_features[] = { + &media::kEnableTabMuting, &blink::features::kPrefetchPrivacyChanges, &blink::features::kReducedReferrerGranularity, #if BUILDFLAG(IS_WIN) diff --git a/browser/about_flags.cc b/browser/about_flags.cc index fa24096d279..6ba7ac7beb1 100644 --- a/browser/about_flags.cc +++ b/browser/about_flags.cc @@ -278,12 +278,6 @@ constexpr char kBraveTranslateGoDescription[] = "and brave translation backed. Also disables suggestions to install google " "translate extension."; -constexpr char kTabAudioIconInteractiveName[] = - "Interactive Tab audio indicator"; -constexpr char kTabAudioIconInteractiveDescription[] = - "Enable the Tab audio indicator to also be a button which can mute and " - "unmute the Tab."; - // Blink features. constexpr char kFileSystemAccessAPIName[] = "File System Access API"; constexpr char kFileSystemAccessAPIDescription[] = @@ -559,11 +553,6 @@ const flags_ui::FeatureEntry::Choice kBraveSkusEnvChoices[] = { flag_descriptions::kRestrictWebSocketsPoolName, \ flag_descriptions::kRestrictWebSocketsPoolDescription, kOsAll, \ FEATURE_VALUE_TYPE(blink::features::kRestrictWebSocketsPool)}, \ - {"tab-audio-icon-interactive", \ - flag_descriptions::kTabAudioIconInteractiveName, \ - flag_descriptions::kTabAudioIconInteractiveDescription, \ - kOsDesktop, \ - FEATURE_VALUE_TYPE(features::kTabAudioIconInteractive)}, \ BRAVE_DECENTRALIZED_DNS_FEATURE_ENTRIES \ BRAVE_IPFS_FEATURE_ENTRIES \ BRAVE_NATIVE_WALLET_FEATURE_ENTRIES \ diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index fa97fe12d76..68055732294 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -472,8 +472,6 @@ source_set("ui") { "views/location_bar/brave_star_view.h", "views/profiles/brave_avatar_toolbar_button.cc", "views/profiles/brave_avatar_toolbar_button.h", - "views/tabs/brave_alert_indicator_button.cc", - "views/tabs/brave_alert_indicator_button.h", "views/tabs/brave_new_tab_button.cc", "views/tabs/brave_new_tab_button.h", "views/tabs/brave_tab_search_button.cc", diff --git a/browser/ui/views/tabs/brave_alert_indicator_button.cc b/browser/ui/views/tabs/brave_alert_indicator_button.cc deleted file mode 100644 index 5e15bce577a..00000000000 --- a/browser/ui/views/tabs/brave_alert_indicator_button.cc +++ /dev/null @@ -1,142 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/browser/ui/views/tabs/brave_alert_indicator_button.h" - -#include -#include - -#include "base/feature_list.h" -#include "base/memory/raw_ptr.h" -#include "brave/common/brave_features.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/ui/tabs/tab_types.h" -#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" -#include "chrome/browser/ui/views/tabs/tab_controller.h" -#include "chrome/browser/ui/views/tabs/tab_strip.h" -#include "chrome/browser/ui/views/tabs/tab_strip_controller.h" -#include "chrome/browser/ui/views/tabs/tab_style_views.h" -#include "content/public/browser/web_contents.h" -#include "third_party/abseil-cpp/absl/types/optional.h" -#include "third_party/skia/include/core/SkPathTypes.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/color_utils.h" -#include "ui/views/background.h" - -namespace { - -bool IsAudioState(const absl::optional& state) { - return (state.has_value() && (state.value() == TabAlertState::AUDIO_PLAYING || - state.value() == TabAlertState::AUDIO_MUTING)); -} - -} // namespace - -class BraveAlertIndicatorButton::BraveAlertBackground - : public views::Background { - public: - explicit BraveAlertBackground(BraveAlertIndicatorButton* host_view) - : host_view_(host_view) {} - - BraveAlertBackground(const BraveAlertBackground&) = delete; - BraveAlertBackground& operator=(const BraveAlertBackground&) = delete; - - // views::Background overrides: - void Paint(gfx::Canvas* canvas, views::View* view) const override { - if (!host_view_->IsTabAudioToggleable()) - return; - - gfx::Point center = host_view_->GetContentsBounds().CenterPoint(); - SkPath path; - path.setFillType(SkPathFillType::kEvenOdd); - path.addCircle(center.x(), center.y(), host_view_->width() / 2); - cc::PaintFlags flags; - flags.setAntiAlias(true); - flags.setColor(host_view_->GetBackgroundColor()); - canvas->DrawPath(path, flags); - } - - private: - raw_ptr host_view_ = nullptr; -}; - -BraveAlertIndicatorButton::BraveAlertIndicatorButton(Tab* parent_tab) - : AlertIndicatorButton(parent_tab) { - SetBackground(std::make_unique(this)); -} - -SkColor BraveAlertIndicatorButton::GetBackgroundColor() const { - SkColor fill_color = parent_tab_->controller()->GetTabBackgroundColor( - parent_tab_->IsActive() ? TabActive::kInactive : TabActive::kActive, - BrowserFrameActiveState::kUseCurrent); - - if (!IsTabAudioToggleable() || !IsMouseHovered()) - return fill_color; - - // Approximating the InkDrop behavior of the close button. - return color_utils::BlendTowardMaxContrast(fill_color, - mouse_pressed_ ? 72 : 36); -} - -bool BraveAlertIndicatorButton::OnMousePressed(const ui::MouseEvent& event) { - mouse_pressed_ = true; - SchedulePaint(); - - if (!IsTabAudioToggleable()) - return AlertIndicatorButton::OnMousePressed(event); - - return true; -} - -void BraveAlertIndicatorButton::OnMouseReleased(const ui::MouseEvent& event) { - mouse_pressed_ = false; - SchedulePaint(); - - if (!IsTabAudioToggleable() || !IsMouseHovered()) - return AlertIndicatorButton::OnMouseReleased(event); - - auto* tab_strip = static_cast(parent_tab_->controller()); - const int tab_index = tab_strip->GetModelIndexOf(parent_tab_); - if (tab_index == -1) - return; - auto* tab_strip_model = - static_cast(tab_strip->controller())->model(); - auto* web_contents = tab_strip_model->GetWebContentsAt(tab_index); - if (web_contents == nullptr) - return; - chrome::SetTabAudioMuted(web_contents, !web_contents->IsAudioMuted(), - TabMutedReason::CONTENT_SETTING, std::string()); -} - -void BraveAlertIndicatorButton::OnMouseEntered(const ui::MouseEvent& event) { - if (IsTabAudioToggleable()) - SchedulePaint(); - AlertIndicatorButton::OnMouseExited(event); -} - -void BraveAlertIndicatorButton::OnMouseExited(const ui::MouseEvent& event) { - if (IsTabAudioToggleable()) - SchedulePaint(); - AlertIndicatorButton::OnMouseExited(event); -} - -bool BraveAlertIndicatorButton::OnMouseDragged(const ui::MouseEvent& event) { - if (IsTabAudioToggleable()) - SchedulePaint(); - return AlertIndicatorButton::OnMouseDragged(event); -} - -bool BraveAlertIndicatorButton::IsTabAudioToggleable() const { - // The alert indicator being interactive can be disabled entirely - if (!base::FeatureList::IsEnabled(features::kTabAudioIconInteractive)) { - return false; - } - - // Pinned tabs are too small to select if alert indicator is a button - if (parent_tab_->controller()->IsTabPinned(parent_tab_)) - return false; - - return IsAudioState(alert_state_); -} diff --git a/browser/ui/views/tabs/brave_alert_indicator_button.h b/browser/ui/views/tabs/brave_alert_indicator_button.h deleted file mode 100644 index 0f8735559a2..00000000000 --- a/browser/ui/views/tabs/brave_alert_indicator_button.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_ALERT_INDICATOR_BUTTON_H_ -#define BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_ALERT_INDICATOR_BUTTON_H_ - -#include "chrome/browser/ui/views/tabs/alert_indicator_button.h" - -class BraveAlertIndicatorButton : public AlertIndicatorButton { - public: - explicit BraveAlertIndicatorButton(Tab* parent_tab); - BraveAlertIndicatorButton(const BraveAlertIndicatorButton&) = delete; - BraveAlertIndicatorButton& operator=(const BraveAlertIndicatorButton&) = - delete; - - private: - class BraveAlertBackground; - - // views::View overrides: - bool OnMousePressed(const ui::MouseEvent& event) override; - void OnMouseReleased(const ui::MouseEvent& event) override; - void OnMouseEntered(const ui::MouseEvent& event) override; - void OnMouseExited(const ui::MouseEvent& event) override; - bool OnMouseDragged(const ui::MouseEvent& event) override; - - SkColor GetBackgroundColor() const; - - bool IsTabAudioToggleable() const; - - bool mouse_pressed_ = false; -}; - -#endif // BRAVE_BROWSER_UI_VIEWS_TABS_BRAVE_ALERT_INDICATOR_BUTTON_H_ diff --git a/chromium_src/chrome/browser/ui/views/tabs/tab.cc b/chromium_src/chrome/browser/ui/views/tabs/tab.cc index 527518351ef..73383bc9ef8 100644 --- a/chromium_src/chrome/browser/ui/views/tabs/tab.cc +++ b/chromium_src/chrome/browser/ui/views/tabs/tab.cc @@ -3,8 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "brave/browser/ui/views/tabs/brave_alert_indicator_button.h" - // Set alert indicator's pos to start of the title and // move title after the alert indicator. // Title right should respect close btn's space @@ -19,8 +17,6 @@ #define BRAVE_UI_VIEWS_TABS_TAB_UPDATE_ICON_VISIBILITY \ showing_close_button_ &= mouse_hovered(); -#define AlertIndicatorButton BraveAlertIndicatorButton #include "src/chrome/browser/ui/views/tabs/tab.cc" -#undef AlertIndicatorButton #undef BRAVE_UI_VIEWS_TABS_TAB_UPDATE_ICON_VISIBILITY #undef BRAVE_UI_VIEWS_TABS_TAB_ALERT_INDICATOR_POSITION diff --git a/chromium_src/media/base/media_switches.cc b/chromium_src/media/base/media_switches.cc index c8952546db8..3c8a39f7598 100644 --- a/chromium_src/media/base/media_switches.cc +++ b/chromium_src/media/base/media_switches.cc @@ -11,6 +11,7 @@ namespace media { OVERRIDE_FEATURE_DEFAULT_STATES({{ {kLiveCaption, base::FEATURE_DISABLED_BY_DEFAULT}, + {kEnableTabMuting, base::FEATURE_ENABLED_BY_DEFAULT}, }}); } // namespace media diff --git a/common/brave_features.cc b/common/brave_features.cc index 384aec78bfa..30ccb15a236 100644 --- a/common/brave_features.cc +++ b/common/brave_features.cc @@ -19,7 +19,4 @@ const base::Feature kBraveRewards{"BraveRewards", #endif #endif // BUILDFLAG(IS_ANDROID) -const base::Feature kTabAudioIconInteractive{"TabAudioIconInteractive", - base::FEATURE_ENABLED_BY_DEFAULT}; - } // namespace features diff --git a/common/brave_features.h b/common/brave_features.h index be09129cc62..aae050d5b25 100644 --- a/common/brave_features.h +++ b/common/brave_features.h @@ -15,8 +15,6 @@ namespace features { extern const base::Feature kBraveRewards; #endif // BUILDFLAG(IS_ANDROID) -extern const base::Feature kTabAudioIconInteractive; - } // namespace features #endif // BRAVE_COMMON_BRAVE_FEATURES_H_ diff --git a/patches/chrome-browser-ui-views-tabs-alert_indicator_button.h.patch b/patches/chrome-browser-ui-views-tabs-alert_indicator_button.h.patch deleted file mode 100644 index 254d5101d21..00000000000 --- a/patches/chrome-browser-ui-views-tabs-alert_indicator_button.h.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/browser/ui/views/tabs/alert_indicator_button.h b/chrome/browser/ui/views/tabs/alert_indicator_button.h -index b22209ca9a16afbae492cd08df6b49b214de06e2..63de769d9273b4705fe62ecc34690f38c5c478db 100644 ---- a/chrome/browser/ui/views/tabs/alert_indicator_button.h -+++ b/chrome/browser/ui/views/tabs/alert_indicator_button.h -@@ -78,6 +78,7 @@ class AlertIndicatorButton : public views::ImageButton, - gfx::ImageSkia GetImageToPaint() override; - - private: -+ friend class BraveAlertIndicatorButton; - friend class AlertIndicatorButtonTest; - friend class TabTest; - class FadeAnimationDelegate;