Commit b074d489 authored by Taylor Bergquist's avatar Taylor Bergquist Committed by Commit Bot

Implement tab insertion animation in new style.

Bug: 958173
Change-Id: I99cd5c3ed9e2326db14a8e8d225b565aaac82ea7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1639731
Commit-Queue: Taylor Bergquist <tbergquist@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666387}
parent 2d78618c
......@@ -1001,14 +1001,14 @@ void TabStrip::AddTabAt(int model_index, TabRendererData data, bool is_active) {
TabAnimationState::TabPinnedness pinnedness =
pinned ? TabAnimationState::TabPinnedness::kPinned
: TabAnimationState::TabPinnedness::kUnpinned;
animator_->InsertTabAtNoAnimation(
model_index,
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this), base::Unretained(tab)),
activeness, pinnedness);
if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible()) {
StartInsertTabAnimation(model_index);
StartInsertTabAnimation(model_index, activeness, pinnedness);
} else {
animator_->InsertTabAtNoAnimation(
model_index,
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this), base::Unretained(tab)),
activeness, pinnedness);
CompleteAnimationAndLayout();
}
......@@ -2081,30 +2081,51 @@ void TabStrip::Init() {
bounds_animator_.SetAnimationDuration(0);
}
void TabStrip::StartInsertTabAnimation(int model_index) {
PrepareForAnimation();
void TabStrip::StartInsertTabAnimation(
int model_index,
TabAnimationState::TabActiveness activeness,
TabAnimationState::TabPinnedness pinnedness) {
if (!bounds_animator_.IsAnimating() && !in_tab_close_) {
animator_->InsertTabAt(
model_index,
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this),
base::Unretained(tab_at(model_index))),
activeness, pinnedness);
} else {
// TODO(958173): Delete this branch once |animator_| has taken over all
// animation responsibilities.
animator_->InsertTabAtNoAnimation(
model_index,
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this),
base::Unretained(tab_at(model_index))),
activeness, pinnedness);
// The TabStrip can now use its entire width to lay out Tabs.
in_tab_close_ = false;
available_width_for_tabs_ = -1;
PrepareForAnimation();
UpdateIdealBounds();
// The TabStrip can now use its entire width to lay out Tabs.
in_tab_close_ = false;
available_width_for_tabs_ = -1;
// Insert the tab just after the current right edge of the previous tab, if
// any.
gfx::Rect bounds = ideal_bounds(model_index);
const int tab_overlap = TabStyle::GetTabOverlap();
if (model_index > 0)
bounds.set_x(tab_at(model_index - 1)->bounds().right() - tab_overlap);
UpdateIdealBounds();
// Start at the width of the overlap in order to animate at the same speed the
// surrounding tabs are moving, since at this width the subsequent tab is
// naturally positioned at the same X coordinate.
bounds.set_width(tab_overlap);
// Insert the tab just after the current right edge of the previous tab, if
// any.
gfx::Rect bounds = ideal_bounds(model_index);
const int tab_overlap = TabStyle::GetTabOverlap();
if (model_index > 0)
bounds.set_x(tab_at(model_index - 1)->bounds().right() - tab_overlap);
// Animate in to the full width.
tab_at(model_index)->SetBoundsRect(bounds);
AnimateToIdealBounds();
// Start at the width of the overlap in order to animate at the same speed
// the surrounding tabs are moving, since at this width the subsequent tab
// is naturally positioned at the same X coordinate.
bounds.set_width(tab_overlap);
// Animate in to the full width.
tab_at(model_index)->SetBoundsRect(bounds);
AnimateToIdealBounds();
}
}
void TabStrip::StartMoveTabAnimation() {
......
......@@ -336,7 +336,9 @@ class TabStrip : public views::AccessiblePaneView,
void Init();
// Invoked from |AddTabAt| after the newly created tab has been inserted.
void StartInsertTabAnimation(int model_index);
void StartInsertTabAnimation(int model_index,
TabAnimationState::TabActiveness activeness,
TabAnimationState::TabPinnedness pinnedness);
// Invoked from |MoveTab| after |tab_data_| has been updated to animate the
// move.
......
......@@ -81,18 +81,16 @@ void TabStripAnimator::RemoveTab(int index) {
void TabStripAnimator::SetActiveTab(int prev_active_index,
int new_active_index) {
// Set activeness without animating by immediately completing animations.
// Set activeness without animating by retargeting the existing animation.
if (prev_active_index >= 0) {
animations_[prev_active_index].AnimateTo(
animations_[prev_active_index].RetargetTo(
animations_[prev_active_index].target_state().WithActiveness(
TabAnimationState::TabActiveness::kInactive));
animations_[prev_active_index].CompleteAnimation();
}
if (new_active_index >= 0) {
animations_[new_active_index].AnimateTo(
animations_[new_active_index].RetargetTo(
animations_[new_active_index].target_state().WithActiveness(
TabAnimationState::TabActiveness::kActive));
animations_[new_active_index].CompleteAnimation();
}
}
......
......@@ -794,8 +794,11 @@ TEST_P(TabStripTest, ActiveTabWidthWhenTabsAreTiny) {
// Create a lot of tabs in order to make inactive tabs tiny.
const int min_inactive_width = TabStyleViews::GetMinimumInactiveWidth();
while (GetInactiveTabWidth() != min_inactive_width)
while (GetInactiveTabWidth() != min_inactive_width) {
controller_->CreateNewTab();
CompleteAnimationAndLayout();
}
EXPECT_GT(tab_strip_->tab_count(), 1);
const int active_index = controller_->GetActiveIndex();
......@@ -826,6 +829,7 @@ TEST_P(TabStripTest, InactiveTabWidthWhenTabsAreTiny) {
const int min_active_width = TabStyleViews::GetMinimumActiveWidth();
while (GetInactiveTabWidth() >= (min_inactive_width + min_active_width) / 2) {
controller_->CreateNewTab();
CompleteAnimationAndLayout();
}
// During mouse-based tab closure, inactive tabs shouldn't shrink
......
......@@ -612,7 +612,8 @@ float GM2TabStyle::GetHoverOpacity() const {
const float range_start = float{GetStandardWidth()};
const float range_end = float{GetMinimumInactiveWidth()};
const float value_in_range = float{tab_->width()};
const float t = (value_in_range - range_start) / (range_end - range_start);
const float t = base::ClampToRange(
(value_in_range - range_start) / (range_end - range_start), 0.0f, 1.0f);
return tab_->controller()->GetHoverOpacityForTab(t * t);
}
......
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