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) { ...@@ -1001,14 +1001,14 @@ void TabStrip::AddTabAt(int model_index, TabRendererData data, bool is_active) {
TabAnimationState::TabPinnedness pinnedness = TabAnimationState::TabPinnedness pinnedness =
pinned ? TabAnimationState::TabPinnedness::kPinned pinned ? TabAnimationState::TabPinnedness::kPinned
: TabAnimationState::TabPinnedness::kUnpinned; : TabAnimationState::TabPinnedness::kUnpinned;
if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible()) {
StartInsertTabAnimation(model_index, activeness, pinnedness);
} else {
animator_->InsertTabAtNoAnimation( animator_->InsertTabAtNoAnimation(
model_index, model_index,
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted, base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this), base::Unretained(tab)), base::Unretained(this), base::Unretained(tab)),
activeness, pinnedness); activeness, pinnedness);
if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible()) {
StartInsertTabAnimation(model_index);
} else {
CompleteAnimationAndLayout(); CompleteAnimationAndLayout();
} }
...@@ -2081,7 +2081,27 @@ void TabStrip::Init() { ...@@ -2081,7 +2081,27 @@ void TabStrip::Init() {
bounds_animator_.SetAnimationDuration(0); bounds_animator_.SetAnimationDuration(0);
} }
void TabStrip::StartInsertTabAnimation(int model_index) { 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);
PrepareForAnimation(); PrepareForAnimation();
// The TabStrip can now use its entire width to lay out Tabs. // The TabStrip can now use its entire width to lay out Tabs.
...@@ -2097,14 +2117,15 @@ void TabStrip::StartInsertTabAnimation(int model_index) { ...@@ -2097,14 +2117,15 @@ void TabStrip::StartInsertTabAnimation(int model_index) {
if (model_index > 0) if (model_index > 0)
bounds.set_x(tab_at(model_index - 1)->bounds().right() - tab_overlap); bounds.set_x(tab_at(model_index - 1)->bounds().right() - tab_overlap);
// Start at the width of the overlap in order to animate at the same speed the // Start at the width of the overlap in order to animate at the same speed
// surrounding tabs are moving, since at this width the subsequent tab is // the surrounding tabs are moving, since at this width the subsequent tab
// naturally positioned at the same X coordinate. // is naturally positioned at the same X coordinate.
bounds.set_width(tab_overlap); bounds.set_width(tab_overlap);
// Animate in to the full width. // Animate in to the full width.
tab_at(model_index)->SetBoundsRect(bounds); tab_at(model_index)->SetBoundsRect(bounds);
AnimateToIdealBounds(); AnimateToIdealBounds();
}
} }
void TabStrip::StartMoveTabAnimation() { void TabStrip::StartMoveTabAnimation() {
......
...@@ -336,7 +336,9 @@ class TabStrip : public views::AccessiblePaneView, ...@@ -336,7 +336,9 @@ class TabStrip : public views::AccessiblePaneView,
void Init(); void Init();
// Invoked from |AddTabAt| after the newly created tab has been inserted. // 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 // Invoked from |MoveTab| after |tab_data_| has been updated to animate the
// move. // move.
......
...@@ -81,18 +81,16 @@ void TabStripAnimator::RemoveTab(int index) { ...@@ -81,18 +81,16 @@ void TabStripAnimator::RemoveTab(int index) {
void TabStripAnimator::SetActiveTab(int prev_active_index, void TabStripAnimator::SetActiveTab(int prev_active_index,
int new_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) { if (prev_active_index >= 0) {
animations_[prev_active_index].AnimateTo( animations_[prev_active_index].RetargetTo(
animations_[prev_active_index].target_state().WithActiveness( animations_[prev_active_index].target_state().WithActiveness(
TabAnimationState::TabActiveness::kInactive)); TabAnimationState::TabActiveness::kInactive));
animations_[prev_active_index].CompleteAnimation();
} }
if (new_active_index >= 0) { if (new_active_index >= 0) {
animations_[new_active_index].AnimateTo( animations_[new_active_index].RetargetTo(
animations_[new_active_index].target_state().WithActiveness( animations_[new_active_index].target_state().WithActiveness(
TabAnimationState::TabActiveness::kActive)); TabAnimationState::TabActiveness::kActive));
animations_[new_active_index].CompleteAnimation();
} }
} }
......
...@@ -794,8 +794,11 @@ TEST_P(TabStripTest, ActiveTabWidthWhenTabsAreTiny) { ...@@ -794,8 +794,11 @@ TEST_P(TabStripTest, ActiveTabWidthWhenTabsAreTiny) {
// Create a lot of tabs in order to make inactive tabs tiny. // Create a lot of tabs in order to make inactive tabs tiny.
const int min_inactive_width = TabStyleViews::GetMinimumInactiveWidth(); const int min_inactive_width = TabStyleViews::GetMinimumInactiveWidth();
while (GetInactiveTabWidth() != min_inactive_width) while (GetInactiveTabWidth() != min_inactive_width) {
controller_->CreateNewTab(); controller_->CreateNewTab();
CompleteAnimationAndLayout();
}
EXPECT_GT(tab_strip_->tab_count(), 1); EXPECT_GT(tab_strip_->tab_count(), 1);
const int active_index = controller_->GetActiveIndex(); const int active_index = controller_->GetActiveIndex();
...@@ -826,6 +829,7 @@ TEST_P(TabStripTest, InactiveTabWidthWhenTabsAreTiny) { ...@@ -826,6 +829,7 @@ TEST_P(TabStripTest, InactiveTabWidthWhenTabsAreTiny) {
const int min_active_width = TabStyleViews::GetMinimumActiveWidth(); const int min_active_width = TabStyleViews::GetMinimumActiveWidth();
while (GetInactiveTabWidth() >= (min_inactive_width + min_active_width) / 2) { while (GetInactiveTabWidth() >= (min_inactive_width + min_active_width) / 2) {
controller_->CreateNewTab(); controller_->CreateNewTab();
CompleteAnimationAndLayout();
} }
// During mouse-based tab closure, inactive tabs shouldn't shrink // During mouse-based tab closure, inactive tabs shouldn't shrink
......
...@@ -612,7 +612,8 @@ float GM2TabStyle::GetHoverOpacity() const { ...@@ -612,7 +612,8 @@ float GM2TabStyle::GetHoverOpacity() const {
const float range_start = float{GetStandardWidth()}; const float range_start = float{GetStandardWidth()};
const float range_end = float{GetMinimumInactiveWidth()}; const float range_end = float{GetMinimumInactiveWidth()};
const float value_in_range = float{tab_->width()}; 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); 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