From 7d576b736cd02764553da1c01a7fe6661b8b5739 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Tue, 26 Nov 2019 18:44:42 +0900 Subject: [PATCH] Make speaker icon on pinned tab un-clickable Getting context menu of pinned tab is very difficult when tab has sound. To fix this, speaker icon becomes un-clickable on pinned tab. --- .../ui/views/tabs/brave_alert_indicator.cc | 22 ++++++++++++++----- browser/ui/views/tabs/brave_alert_indicator.h | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/browser/ui/views/tabs/brave_alert_indicator.cc b/browser/ui/views/tabs/brave_alert_indicator.cc index d7a76cc8e554..60106e5f5f4d 100644 --- a/browser/ui/views/tabs/brave_alert_indicator.cc +++ b/browser/ui/views/tabs/brave_alert_indicator.cc @@ -35,6 +35,9 @@ class BraveAlertIndicator::BraveAlertBackground : public views::Background { // 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(SkPath::kEvenOdd_FillType); @@ -58,7 +61,7 @@ BraveAlertIndicator::BraveAlertIndicator(Tab* parent_tab) SkColor BraveAlertIndicator::GetBackgroundColor() const { TabStyle::TabColors colors = parent_tab_->tab_style()->CalculateColors(); - if (!IsAudioState(alert_state_) || !IsMouseHovered()) + if (!IsTabAudioToggleable() || !IsMouseHovered()) return colors.background_color; // Approximating the InkDrop behavior of the close button. @@ -70,7 +73,7 @@ bool BraveAlertIndicator::OnMousePressed(const ui::MouseEvent& event) { mouse_pressed_ = true; SchedulePaint(); - if (!IsAudioState(alert_state_)) + if (!IsTabAudioToggleable()) return AlertIndicator::OnMousePressed(event); return true; @@ -80,7 +83,7 @@ void BraveAlertIndicator::OnMouseReleased(const ui::MouseEvent& event) { mouse_pressed_ = false; SchedulePaint(); - if (!IsAudioState(alert_state_) || !IsMouseHovered()) + if (!IsTabAudioToggleable() || !IsMouseHovered()) return AlertIndicator::OnMouseReleased(event); auto* tab_strip = static_cast(parent_tab_->controller()); @@ -99,19 +102,26 @@ void BraveAlertIndicator::OnMouseReleased(const ui::MouseEvent& event) { } void BraveAlertIndicator::OnMouseEntered(const ui::MouseEvent& event) { - if (IsAudioState(alert_state_)) + if (IsTabAudioToggleable()) SchedulePaint(); AlertIndicator::OnMouseExited(event); } void BraveAlertIndicator::OnMouseExited(const ui::MouseEvent& event) { - if (IsAudioState(alert_state_)) + if (IsTabAudioToggleable()) SchedulePaint(); AlertIndicator::OnMouseExited(event); } bool BraveAlertIndicator::OnMouseDragged(const ui::MouseEvent& event) { - if (IsAudioState(alert_state_)) + if (IsTabAudioToggleable()) SchedulePaint(); return AlertIndicator::OnMouseDragged(event); } + +bool BraveAlertIndicator::IsTabAudioToggleable() const { + if (parent_tab_->controller()->IsTabPinned(parent_tab_)) + return false; + + return IsAudioState(alert_state_); +} diff --git a/browser/ui/views/tabs/brave_alert_indicator.h b/browser/ui/views/tabs/brave_alert_indicator.h index c09ffb8bc76c..aaea37a89bc4 100644 --- a/browser/ui/views/tabs/brave_alert_indicator.h +++ b/browser/ui/views/tabs/brave_alert_indicator.h @@ -24,6 +24,8 @@ class BraveAlertIndicator : public AlertIndicator { SkColor GetBackgroundColor() const; + bool IsTabAudioToggleable() const; + bool mouse_pressed_ = false; DISALLOW_COPY_AND_ASSIGN(BraveAlertIndicator);