Skip to content

Commit

Permalink
Use colored brave talk icon when windows has brave talk tab
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Feb 4, 2022
1 parent 1298620 commit 2f328ed
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 9 deletions.
9 changes: 7 additions & 2 deletions browser/ui/brave_browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion browser/ui/sidebar/sidebar_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
6 changes: 6 additions & 0 deletions browser/ui/sidebar/sidebar_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/sidebar/sidebar_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/sidebar/sidebar_control_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void SidebarControlView::OnButtonPressed(views::View* view) {

void SidebarControlView::Update() {
UpdateItemAddButtonState();
sidebar_items_view_->Update();
}

void SidebarControlView::UpdateItemAddButtonState() {
Expand Down
31 changes: 25 additions & 6 deletions browser/ui/views/sidebar/sidebar_items_contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/sidebar/sidebar_items_contents_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class SidebarItemsContentsView : public views::View,
void ClearDragIndicator();

bool IsBubbleVisible() const;
void Update();

private:
enum ContextMenuIDs {
Expand Down
4 changes: 4 additions & 0 deletions browser/ui/views/sidebar/sidebar_items_scroll_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,7 @@ bool SidebarItemsScrollView::IsItemReorderingInProgress() const {
bool SidebarItemsScrollView::IsBubbleVisible() const {
return contents_view_->IsBubbleVisible();
}

void SidebarItemsScrollView::Update() {
contents_view_->Update();
}
1 change: 1 addition & 0 deletions browser/ui/views/sidebar/sidebar_items_scroll_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SidebarItemsScrollView : public views::View,

bool IsItemReorderingInProgress() const;
bool IsBubbleVisible() const;
void Update();

private:
void UpdateArrowViewsTheme();
Expand Down

0 comments on commit 2f328ed

Please sign in to comment.