Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Toggle Vertical Tabs Expanded" command for independent expanded states per window #27691

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions browser/ui/browser_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "brave/browser/ui/tabs/brave_tab_strip_model.h"
#include "brave/browser/ui/tabs/features.h"
#include "brave/browser/ui/tabs/split_view_browser_data.h"
#include "brave/browser/ui/views/frame/vertical_tab_strip_region_view.h"
#include "brave/browser/ui/views/frame/vertical_tab_strip_widget_delegate_view.h"
#include "brave/browser/url_sanitizer/url_sanitizer_service_factory.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "brave/components/constants/pref_names.h"
Expand Down Expand Up @@ -396,8 +398,26 @@ void ToggleVerticalTabStripFloatingMode(Browser* browser) {

void ToggleVerticalTabStripExpanded(Browser* browser) {
auto* prefs = browser->profile()->GetPrefs();
prefs->SetBoolean(brave_tabs::kVerticalTabsCollapsed,
!prefs->GetBoolean(brave_tabs::kVerticalTabsCollapsed));
bool expanded_state_per_window =
prefs->GetBoolean(brave_tabs::kVerticalTabsExpandedStatePerWindow);
// Toggle preference if all tabs share the same state (derived from prefs)
if (!expanded_state_per_window) {
prefs->SetBoolean(brave_tabs::kVerticalTabsCollapsed,
!prefs->GetBoolean(brave_tabs::kVerticalTabsCollapsed));
return;
}
// Otherwise, retrieve current vertical tab strip region view
auto* browser_view = static_cast<BraveBrowserView*>(browser->window());
if (!browser_view) {
return;
}
auto* vtsr_view = browser_view->vertical_tab_strip_widget_delegate_view()
->vertical_tab_strip_region_view();
if (!vtsr_view) {
return;
}
// toggle state for only this vtsr view
vtsr_view->ToggleState();
}

void ToggleActiveTabAudioMute(Browser* browser) {
Expand Down
25 changes: 12 additions & 13 deletions browser/ui/views/frame/vertical_tab_strip_region_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,19 +612,8 @@ VerticalTabStripRegionView::VerticalTabStripRegionView(
width_animation_.Reset(1.0);

header_view_ = AddChildView(std::make_unique<HeaderView>(
base::BindRepeating(
[](VerticalTabStripRegionView* container, const ui::Event& event) {
// Note that Calling SetValue() doesn't trigger
// OnCollapsedPrefChanged() for this view.
if (container->state_ == State::kExpanded) {
container->collapsed_pref_.SetValue(true);
container->SetState(State::kCollapsed);
} else {
container->collapsed_pref_.SetValue(false);
container->SetState(State::kExpanded);
}
},
this),
base::BindRepeating(&VerticalTabStripRegionView::ToggleState,
base::Unretained(this)),
this, browser_));
contents_view_ =
AddChildView(std::make_unique<VerticalTabStripScrollContentsView>(
Expand Down Expand Up @@ -718,6 +707,16 @@ VerticalTabStripRegionView::~VerticalTabStripRegionView() {
"callback";
}

void VerticalTabStripRegionView::ToggleState() {
if (state_ == State::kExpanded) {
collapsed_pref_.SetValue(true);
SetState(State::kCollapsed);
} else {
collapsed_pref_.SetValue(false);
SetState(State::kExpanded);
}
}

void VerticalTabStripRegionView::OnWidgetActivationChanged(
views::Widget* widget,
bool active) {
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/views/frame/vertical_tab_strip_region_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class VerticalTabStripRegionView : public views::View,

const Browser* browser() const { return browser_; }

void ToggleState();

// Expand vertical tabstrip temporarily. When the returned
// ScopedCallbackRunner is destroyed, the state will be restored to the
// previous state.
Expand Down