diff --git a/browser/ui/brave_browser.cc b/browser/ui/brave_browser.cc index 5bddc22a420a..a3417a5b9d1b 100644 --- a/browser/ui/brave_browser.cc +++ b/browser/ui/brave_browser.cc @@ -83,8 +83,13 @@ void BraveBrowser::OnTabStripModelChanged( Browser::OnTabStripModelChanged(tab_strip_model, change, selection); #if BUILDFLAG(ENABLE_SIDEBAR) - // We need to update sidebar UI whenever active tab is changed. - if (selection.active_tab_changed() && sidebar_controller_) + if (!sidebar_controller_) + return; + // We need to update sidebar UI whenever active tab is changed or + // inactive tab is added/removed. + if (change.type() == TabStripModelChange::Type::kInserted || + change.type() == TabStripModelChange::Type::kRemoved || + selection.active_tab_changed()) sidebar_controller_->sidebar()->UpdateSidebar(); #endif } diff --git a/browser/ui/sidebar/sidebar_browsertest.cc b/browser/ui/sidebar/sidebar_browsertest.cc index fc18e094ca13..057e95920bd8 100644 --- a/browser/ui/sidebar/sidebar_browsertest.cc +++ b/browser/ui/sidebar/sidebar_browsertest.cc @@ -155,9 +155,11 @@ IN_PROC_BROWSER_TEST_F(SidebarBrowserTest, IN_PROC_BROWSER_TEST_F(SidebarBrowserTest, IterateBuiltInWebTypeTest) { // Click builtin wallet item and it's loaded at current active tab. + auto item = model()->GetAllSidebarItems()[1]; + EXPECT_FALSE(controller()->DoesBrowserHaveOpenedTabForItem(item)); controller()->ActivateItemAt(1); + EXPECT_TRUE(controller()->DoesBrowserHaveOpenedTabForItem(item)); EXPECT_EQ(0, tab_model()->active_index()); - auto item = model()->GetAllSidebarItems()[1]; EXPECT_EQ(tab_model()->GetWebContentsAt(0)->GetVisibleURL().host(), item.url.host()); diff --git a/browser/ui/sidebar/sidebar_controller.cc b/browser/ui/sidebar/sidebar_controller.cc index 786e849ea9b9..ba434d80def3 100644 --- a/browser/ui/sidebar/sidebar_controller.cc +++ b/browser/ui/sidebar/sidebar_controller.cc @@ -55,6 +55,12 @@ bool SidebarController::IsActiveIndex(int index) const { return sidebar_model_->active_index() == index; } +bool SidebarController::DoesBrowserHaveOpenedTabForItem( + const SidebarItem& item) const { + DCHECK(!item.open_in_panel); + return !GetAllExistingTabIndexForHost(browser_, item.url.host()).empty(); +} + void SidebarController::ActivateItemAt(int index) { // -1 means there is no active item. DCHECK_GE(index, -1); diff --git a/browser/ui/sidebar/sidebar_controller.h b/browser/ui/sidebar/sidebar_controller.h index 7c7945fda3ac..b230e69675b6 100644 --- a/browser/ui/sidebar/sidebar_controller.h +++ b/browser/ui/sidebar/sidebar_controller.h @@ -47,6 +47,8 @@ class SidebarController : public SidebarService::Observer { bool IsActiveIndex(int index) const; + bool DoesBrowserHaveOpenedTabForItem(const SidebarItem& item) const; + void SetSidebar(Sidebar* sidebar); Sidebar* sidebar() const { return sidebar_; } diff --git a/browser/ui/views/sidebar/sidebar_control_view.cc b/browser/ui/views/sidebar/sidebar_control_view.cc index 4611beb0164e..5d5c563d3193 100644 --- a/browser/ui/views/sidebar/sidebar_control_view.cc +++ b/browser/ui/views/sidebar/sidebar_control_view.cc @@ -210,6 +210,7 @@ void SidebarControlView::OnButtonPressed(views::View* view) { void SidebarControlView::Update() { UpdateItemAddButtonState(); + sidebar_items_view_->Update(); } void SidebarControlView::UpdateItemAddButtonState() { diff --git a/browser/ui/views/sidebar/sidebar_items_contents_view.cc b/browser/ui/views/sidebar/sidebar_items_contents_view.cc index 7fc5bbcb452f..ed9eefb91531 100644 --- a/browser/ui/views/sidebar/sidebar_items_contents_view.cc +++ b/browser/ui/views/sidebar/sidebar_items_contents_view.cc @@ -88,6 +88,11 @@ gfx::Size SidebarItemsContentsView::CalculatePreferredSize() const { void SidebarItemsContentsView::OnThemeChanged() { View::OnThemeChanged(); + // BuiltIn items use different icon set based on theme. + UpdateAllBuiltInItemsViewState(); +} + +void SidebarItemsContentsView::Update() { UpdateAllBuiltInItemsViewState(); } @@ -97,13 +102,27 @@ void SidebarItemsContentsView::UpdateAllBuiltInItemsViewState() { if (children().size() != items.size()) return; - // BuiltIn items different colored images depends on theme. const int active_index = sidebar_model_->active_index(); - int index = 0; - for (const auto& item : items) { - if (sidebar::IsBuiltInType(item)) - UpdateItemViewStateAt(index, index == active_index); - index++; + const int items_num = items.size(); + for (int item_index = 0; item_index < items_num; ++item_index) { + const auto item = items[item_index]; + if (!sidebar::IsBuiltInType(item)) + continue; + + if (item.open_in_panel) { + UpdateItemViewStateAt(item_index, item_index == active_index); + continue; + } + + // If browser window has tab that loads brave talk, brave talk panel icon + // will use colored one for normal state also. + if (item.built_in_item_type == + sidebar::SidebarItem::BuiltInItemType::kBraveTalk) { + UpdateItemViewStateAt( + item_index, + browser_->sidebar_controller()->DoesBrowserHaveOpenedTabForItem( + item)); + } } } diff --git a/browser/ui/views/sidebar/sidebar_items_contents_view.h b/browser/ui/views/sidebar/sidebar_items_contents_view.h index 146f3157da59..50068e531932 100644 --- a/browser/ui/views/sidebar/sidebar_items_contents_view.h +++ b/browser/ui/views/sidebar/sidebar_items_contents_view.h @@ -75,6 +75,7 @@ class SidebarItemsContentsView : public views::View, void ClearDragIndicator(); bool IsBubbleVisible() const; + void Update(); private: enum ContextMenuIDs { diff --git a/browser/ui/views/sidebar/sidebar_items_scroll_view.cc b/browser/ui/views/sidebar/sidebar_items_scroll_view.cc index 32a3645b47dd..e93c97bddacb 100644 --- a/browser/ui/views/sidebar/sidebar_items_scroll_view.cc +++ b/browser/ui/views/sidebar/sidebar_items_scroll_view.cc @@ -459,3 +459,7 @@ bool SidebarItemsScrollView::IsItemReorderingInProgress() const { bool SidebarItemsScrollView::IsBubbleVisible() const { return contents_view_->IsBubbleVisible(); } + +void SidebarItemsScrollView::Update() { + contents_view_->Update(); +} diff --git a/browser/ui/views/sidebar/sidebar_items_scroll_view.h b/browser/ui/views/sidebar/sidebar_items_scroll_view.h index 129b8ffd5ebf..26c39d2ed31f 100644 --- a/browser/ui/views/sidebar/sidebar_items_scroll_view.h +++ b/browser/ui/views/sidebar/sidebar_items_scroll_view.h @@ -81,6 +81,7 @@ class SidebarItemsScrollView : public views::View, bool IsItemReorderingInProgress() const; bool IsBubbleVisible() const; + void Update(); private: void UpdateArrowViewsTheme();