Skip to content

Commit

Permalink
SidePanel: fixes button pressed state.
Browse files Browse the repository at this point in the history
Fixes pressed state for side panel action buttons when performing
actions on tabs (adding/deleting/switching).
  • Loading branch information
mkarolin committed Sep 20, 2024
1 parent 034c918 commit c47552c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
33 changes: 24 additions & 9 deletions browser/ui/views/sidebar/sidebar_container_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,16 @@ void SidebarContainerView::OnEntryWillDeregister(SidePanelRegistry* registry,
void SidebarContainerView::OnRegistryDestroying(SidePanelRegistry* registry) {
if (panel_registry_observations_.IsObservingSource(registry)) {
StopObservingContextualSidePanelRegistry(registry);
// If this is the active tab being destroyed, then reset the active item.
// Note, that items persisted across tabs like reading list or bookmarks
// don't show as active_entry, in which case leave the active item as is.
if (registry == active_contextual_registry_) {
if (registry->active_entry()) {
auto* controller = browser_->sidebar_controller();
controller->ActivateItemAt(std::nullopt);
}
active_contextual_registry_ = nullptr;
}
}
}

Expand Down Expand Up @@ -843,17 +853,11 @@ void SidebarContainerView::OnTabStripModelChanged(
}
}
}
return;
}

if (change.type() == TabStripModelChange::kInserted) {
} else if (change.type() == TabStripModelChange::kInserted) {
for (const auto& contents : change.GetInsert()->contents) {
StartObservingContextualSidePanelRegistry(contents.contents);
}
return;
}

if (change.type() == TabStripModelChange::kRemoved) {
} else if (change.type() == TabStripModelChange::kRemoved) {
bool removed_for_deletion =
(change.GetRemove()->contents[0].remove_reason ==
TabStripModelChange::RemoveReason::kDeleted);
Expand All @@ -864,7 +868,18 @@ void SidebarContainerView::OnTabStripModelChanged(
for (const auto& contents : change.GetRemove()->contents) {
StopObservingContextualSidePanelRegistry(contents.contents);
}
return;
}
}

// Keep track of the active contextual registry
if (selection.active_tab_changed()) {
active_contextual_registry_ =
selection.new_contents
? SidePanelRegistry::GetDeprecated(selection.new_contents)
: nullptr;
if (active_contextual_registry_) {
DCHECK(panel_registry_observations_.IsObservingSource(
active_contextual_registry_));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/sidebar/sidebar_container_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class SidebarContainerView
raw_ptr<BraveSidePanel> side_panel_ = nullptr;
raw_ptr<sidebar::SidebarModel> sidebar_model_ = nullptr;
raw_ptr<SidebarControlView> sidebar_control_view_ = nullptr;
raw_ptr<SidePanelRegistry> active_contextual_registry_ = nullptr;
bool initialized_ = false;
bool sidebar_on_left_ = true;
bool operation_from_active_tab_change_ = false;
Expand Down

0 comments on commit c47552c

Please sign in to comment.