From d40e813b0e0c73660799dc735bded298363d0a98 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Tue, 21 Jan 2025 11:39:53 +0900 Subject: [PATCH] Show separator between pinned and unpinned when both are not empty fix https://github.com/brave/brave-browser/issues/43375 We're using pinned tab container's bottom border as a separator from unpinned tab container. It should be drawn when only both are not empty. --- .../tabs/brave_compound_tab_container.cc | 45 ++++++++++++++----- .../views/tabs/brave_compound_tab_container.h | 5 ++- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/browser/ui/views/tabs/brave_compound_tab_container.cc b/browser/ui/views/tabs/brave_compound_tab_container.cc index fd604be734b..155cdd5473c 100644 --- a/browser/ui/views/tabs/brave_compound_tab_container.cc +++ b/browser/ui/views/tabs/brave_compound_tab_container.cc @@ -330,9 +330,28 @@ Tab* BraveCompoundTabContainer::AddTab(std::unique_ptr tab, ScrollTabToBeVisible(model_index); } + UpdatePinnedTabContainerBorder(); + return new_tab; } +void BraveCompoundTabContainer::MoveTab(int from_model_index, + int to_model_index) { + CompoundTabContainer::MoveTab(from_model_index, to_model_index); + UpdatePinnedTabContainerBorder(); +} + +void BraveCompoundTabContainer::RemoveTab(int index, bool was_active) { + CompoundTabContainer::RemoveTab(index, was_active); + UpdatePinnedTabContainerBorder(); +} + +void BraveCompoundTabContainer::SetTabPinned(int model_index, + TabPinned pinned) { + CompoundTabContainer::SetTabPinned(model_index, pinned); + UpdatePinnedTabContainerBorder(); +} + int BraveCompoundTabContainer::GetUnpinnedContainerIdealLeadingX() const { if (!ShouldShowVerticalTabs()) { return CompoundTabContainer::GetUnpinnedContainerIdealLeadingX(); @@ -394,18 +413,6 @@ BrowserRootView::DropTarget* BraveCompoundTabContainer::GetDropTarget( return nullptr; } -void BraveCompoundTabContainer::OnThemeChanged() { - CompoundTabContainer::OnThemeChanged(); - - if (ShouldShowVerticalTabs()) { - pinned_tab_container_->SetBorder(views::CreateSolidSidedBorder( - gfx::Insets().set_bottom(1), - GetColorProvider()->GetColor(kColorBraveVerticalTabSeparator))); - } else { - pinned_tab_container_->SetBorder(nullptr); - } -} - void BraveCompoundTabContainer::PaintChildren(const views::PaintInfo& info) { if (ShouldShowVerticalTabs()) { // Bypass CompoundTabContainer::PaintChildren() implementation. @@ -493,6 +500,20 @@ bool BraveCompoundTabContainer::ShouldShowVerticalTabs() const { tab_slot_controller_->GetBrowser()); } +void BraveCompoundTabContainer::UpdatePinnedTabContainerBorder() { + // We're using pinned tab container's bottom border as a separator from + // unpinned tab container. It should be drawn when only both are not empty. + const bool should_have_separator_between_pinned_and_unpinned = + ShouldShowVerticalTabs() && pinned_tab_container_->GetTabCount() != 0 && + unpinned_tab_container_->GetTabCount() != 0; + if (should_have_separator_between_pinned_and_unpinned) { + pinned_tab_container_->SetBorder(views::CreateThemedSolidSidedBorder( + gfx::Insets().set_bottom(1), kColorBraveVerticalTabSeparator)); + } else { + pinned_tab_container_->SetBorder(nullptr); + } +} + void BraveCompoundTabContainer::UpdateUnpinnedContainerSize() { DCHECK(scroll_view_); diff --git a/browser/ui/views/tabs/brave_compound_tab_container.h b/browser/ui/views/tabs/brave_compound_tab_container.h index d4eee0f4930..4391e2c37ac 100644 --- a/browser/ui/views/tabs/brave_compound_tab_container.h +++ b/browser/ui/views/tabs/brave_compound_tab_container.h @@ -45,12 +45,14 @@ class BraveCompoundTabContainer : public CompoundTabContainer { Tab* AddTab(std::unique_ptr tab, int model_index, TabPinned pinned) override; + void MoveTab(int from_model_index, int to_model_index) override; + void RemoveTab(int index, bool was_active) override; + void SetTabPinned(int model_index, TabPinned pinned) override; int GetUnpinnedContainerIdealLeadingX() const override; TabContainer* GetTabContainerAt( gfx::Point point_in_local_coords) const override; gfx::Rect ConvertUnpinnedContainerIdealBoundsToLocal( gfx::Rect ideal_bounds) const override; - void OnThemeChanged() override; void PaintChildren(const views::PaintInfo& info) override; void ChildPreferredSizeChanged(views::View* child) override; void SetActiveTab(std::optional prev_active_index, @@ -68,6 +70,7 @@ class BraveCompoundTabContainer : public CompoundTabContainer { bool ShouldShowVerticalTabs() const; + void UpdatePinnedTabContainerBorder(); void UpdateUnpinnedContainerSize(); void ScrollTabToBeVisible(int model_index);