Commit b7d8b731 authored by Charlene Yan's avatar Charlene Yan Committed by Commit Bot

[Tab Groups Collapse] Shift the active tab when collapsing the active tab.

Bug: 1018230
Change-Id: I837514789ae6809c3d2eb8f3927837c48c416eb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209236
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarTaylor Bergquist <tbergquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773819}
parent b9e8fcd6
...@@ -349,8 +349,20 @@ void BrowserTabStripController::MoveGroup(const tab_groups::TabGroupId& group, ...@@ -349,8 +349,20 @@ void BrowserTabStripController::MoveGroup(const tab_groups::TabGroupId& group,
void BrowserTabStripController::ToggleTabGroupCollapsedState( void BrowserTabStripController::ToggleTabGroupCollapsedState(
const tab_groups::TabGroupId group) { const tab_groups::TabGroupId group) {
// If the active tab is in the group that is toggling to collapse, the active
// tab should switch to the next available tab. If there are no available tabs
// for the active tab to switch to, the group will not toggle to collapse.
const bool is_currently_collapsed = IsGroupCollapsed(group);
if (!is_currently_collapsed) {
const base::Optional<int> next_active =
FindNextAvailableActiveTabForCollapsingGroup(group);
if (!next_active.has_value())
return;
model_->ActivateTabAt(next_active.value(),
{TabStripModel::GestureType::kOther});
}
tab_groups::TabGroupVisualData new_data( tab_groups::TabGroupVisualData new_data(
GetGroupTitle(group), GetGroupColorId(group), !IsGroupCollapsed(group)); GetGroupTitle(group), GetGroupColorId(group), !is_currently_collapsed);
model_->group_model()->GetTabGroup(group)->SetVisualData(new_data, true); model_->group_model()->GetTabGroup(group)->SetVisualData(new_data, true);
} }
...@@ -692,3 +704,29 @@ void BrowserTabStripController::UpdateStackedLayout() { ...@@ -692,3 +704,29 @@ void BrowserTabStripController::UpdateStackedLayout() {
tabstrip_->set_adjust_layout(adjust_layout); tabstrip_->set_adjust_layout(adjust_layout);
tabstrip_->SetStackedLayout(stacked_layout); tabstrip_->SetStackedLayout(stacked_layout);
} }
base::Optional<int>
BrowserTabStripController::FindNextAvailableActiveTabForCollapsingGroup(
const tab_groups::TabGroupId group) const {
const int starting_index = GetActiveIndex();
const std::vector<int> tabs_in_group = ListTabsInGroup(group);
if (starting_index < tabs_in_group.front() ||
starting_index > tabs_in_group.back()) {
return starting_index;
}
for (int i = 0; i < model_->count(); i++) {
int current_index = (i + starting_index) % model_->count();
base::Optional<tab_groups::TabGroupId> current_group =
model_->GetTabGroupForTab(current_index);
if (!current_group.has_value() ||
(!IsGroupCollapsed(current_group.value()) && current_group != group)) {
return current_index;
}
const std::vector<int> tabs_in_group =
ListTabsInGroup(current_group.value());
}
return base::nullopt;
}
...@@ -149,6 +149,11 @@ class BrowserTabStripController : public TabStripController, ...@@ -149,6 +149,11 @@ class BrowserTabStripController : public TabStripController,
// Resets the tabstrips stacked layout (true or false) from prefs. // Resets the tabstrips stacked layout (true or false) from prefs.
void UpdateStackedLayout(); void UpdateStackedLayout();
// Finds the next available tab to switch to as the active tab when the
// |index| is collapsing. Returns base::nullopt if there are no valid tabs.
base::Optional<int> FindNextAvailableActiveTabForCollapsingGroup(
const tab_groups::TabGroupId group) const;
TabStripModel* model_; TabStripModel* model_;
TabStrip* tabstrip_; TabStrip* tabstrip_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment