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

[Tab Groups] Add animation for tab group headers.

Bug: 1021689

Change-Id: Ida4f922471b9e53684acfc683623150b82e2a7cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906873
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarConnie Wan <connily@chromium.org>
Reviewed-by: default avatarTaylor Bergquist <tbergquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721269}
parent 1bb504ec
......@@ -1273,6 +1273,7 @@ void TabStrip::OnGroupVisualsChanged(TabGroupId group) {
}
void TabStrip::OnGroupDeleted(TabGroupId group) {
bounds_animator_.StopAnimatingView(group_header(group));
layout_helper_->RemoveGroupHeader(group);
UpdateIdealBounds();
AnimateToIdealBounds();
......@@ -2452,6 +2453,15 @@ void TabStrip::AnimateToIdealBounds(ClosingTabsBehavior closing_tabs_behavior) {
: std::make_unique<TabAnimationDelegate>(this, tab));
}
std::map<TabGroupId, TabGroupHeader*> group_headers = GetGroupHeaders();
std::map<TabGroupId, gfx::Rect> group_headers_bounds =
layout_helper_->group_header_ideal_bounds();
for (const auto& header_pair : group_headers) {
bounds_animator_.AnimateViewTo(header_pair.second,
group_headers_bounds.at(header_pair.first));
}
if (bounds_animator_.GetTargetBounds(new_tab_button_) !=
new_tab_button_ideal_bounds_) {
bounds_animator_.AnimateViewTo(new_tab_button_,
......@@ -2631,8 +2641,6 @@ void TabStrip::StoppedDraggingView(TabSlotView* view, bool* is_first_view) {
// Ensure the drag status is updated even if the view is not a valid tab.
// This is primarily to make sure group headers are updated correctly.
// Otherwise, tab drag status is only updated in PrepareForAnimation().
// TODO(crbug.com/1021689): Incorporate group headers in the normal
// animation flow instead of handling it here and then ignoring it.
if (view)
view->set_dragging(false);
......
......@@ -242,7 +242,6 @@ void TabStripLayoutHelper::InsertGroupHeader(
TabGroupId group,
TabGroupHeader* header,
base::OnceClosure header_removed_callback) {
// TODO(958173): Animate open.
std::vector<int> tabs_in_group = controller_->ListTabsInGroup(group);
const int header_slot_index =
GetSlotIndexForTabModelIndex(tabs_in_group[0], group);
......@@ -250,6 +249,11 @@ void TabStripLayoutHelper::InsertGroupHeader(
slots_.begin() + header_slot_index,
TabSlot::CreateForGroupHeader(group, header, TabPinned::kUnpinned,
std::move(header_removed_callback)));
// Set the starting location of the header to something reasonable for the
// animation.
slots_[header_slot_index].view->SetBoundsRect(
GetTabs()[tabs_in_group[0]]->bounds());
}
void TabStripLayoutHelper::RemoveGroupHeader(TabGroupId group) {
......@@ -357,7 +361,7 @@ void TabStripLayoutHelper::UpdateIdealBounds(int available_width) {
}
break;
case ViewType::kGroupHeader:
slot.view->SetBoundsRect(bounds[i]);
group_header_ideal_bounds_[slot.view->group().value()] = bounds[i];
break;
}
}
......
......@@ -54,6 +54,11 @@ class TabStripLayoutHelper {
// Returns the number of pinned tabs in the tabstrip.
int GetPinnedTabCount() const;
// Returns a map of all tab groups and their bounds.
const std::map<TabGroupId, gfx::Rect>& group_header_ideal_bounds() const {
return group_header_ideal_bounds_;
}
// Inserts a new tab at |index|, without animation. |tab_removed_callback|
// will be invoked if the tab is removed at the end of a remove animation.
void InsertTabAtNoAnimation(int model_index,
......@@ -205,6 +210,9 @@ class TabStripLayoutHelper {
// run layout and animations for those Views.
std::vector<TabSlot> slots_;
// Contains the ideal bounds of tab group headers.
std::map<TabGroupId, gfx::Rect> group_header_ideal_bounds_;
// When in tab closing mode, if we want the next tab to the right to end up
// under the cursor, each tab needs to stay the same size. When defined,
// this specifies that size.
......
......@@ -1123,6 +1123,7 @@ TEST_P(TabStripTest, GroupHeaderMovesOnRegrouping) {
// Change groups in a way so that the header should swap with the tab, without
// an explicit MoveTab call.
controller_->MoveTabIntoGroup(1, group0);
CompleteAnimationAndLayout();
// Header is now right of tab 1.
EXPECT_LT(tab_strip_->tab_at(1)->x(), header1->x());
......
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