Fix tab audio muting button
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 <memory>
|
||||
#include <string>
|
||||
|
||||
#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<TabAlertState>& 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<BraveAlertIndicatorButton> host_view_ = nullptr;
|
||||
};
|
||||
|
||||
BraveAlertIndicatorButton::BraveAlertIndicatorButton(Tab* parent_tab)
|
||||
: AlertIndicatorButton(parent_tab) {
|
||||
SetBackground(std::make_unique<BraveAlertBackground>(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<TabStrip*>(parent_tab_->controller());
|
||||
const int tab_index = tab_strip->GetModelIndexOf(parent_tab_);
|
||||
if (tab_index == -1)
|
||||
return;
|
||||
auto* tab_strip_model =
|
||||
static_cast<BrowserTabStripController*>(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_);
|
||||
}
|
||||
@@ -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_
|
||||
@@ -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
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace media {
|
||||
|
||||
OVERRIDE_FEATURE_DEFAULT_STATES({{
|
||||
{kLiveCaption, base::FEATURE_DISABLED_BY_DEFAULT},
|
||||
{kEnableTabMuting, base::FEATURE_ENABLED_BY_DEFAULT},
|
||||
}});
|
||||
|
||||
} // namespace media
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user