Commit 54ad211b authored by Connie Wan's avatar Connie Wan Committed by Commit Bot

Replace TabAnimationState Active/Open/Pinned enums with universal ones

This also disambiguates the Active, Open, and Pinned states from their -ness suffixed equivalents. The -ness versions are floats that are animation-specific -- TabAnimationState keeps track of the tweened values between 0 and 1. Most implementations only need to care about the binary non-suffixed versions.

For now this is just a find-and-replace and does not change any boolean APIs (e.g. https://cs.chromium.org/chromium/src/chrome/browser/ui/views/tabs/tab_strip.cc?l=982,1004-1005&rcl=1ad5374935374da746af65d05b41104c711fd5cc). There are many examples in tab_strip.cc where ternary operators could be removed if a boolean were converted into enum values. That is next on the list of refactors.

Bug: 966627
Change-Id: Icc2a0aaea0a06186d0bd3fefda645e97252968cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764419
Commit-Queue: Connie Wan <connily@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarTaylor Bergquist <tbergquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692182}
parent 0c9d1f5c
...@@ -4,17 +4,17 @@ ...@@ -4,17 +4,17 @@
#include "chrome/browser/ui/views/tabs/tab_animation_state.h" #include "chrome/browser/ui/views/tabs/tab_animation_state.h"
#include "chrome/browser/ui/tabs/tab_types.h"
#include "chrome/browser/ui/views/tabs/tab_strip_layout_types.h" #include "chrome/browser/ui/views/tabs/tab_strip_layout_types.h"
#include "ui/gfx/animation/tween.h" #include "ui/gfx/animation/tween.h"
TabAnimationState TabAnimationState::ForIdealTabState(TabOpenness open, TabAnimationState TabAnimationState::ForIdealTabState(TabOpen open,
TabPinnedness pinned, TabPinned pinned,
TabActiveness active, TabActive active,
int tab_index_offset) { int tab_index_offset) {
return TabAnimationState(open == TabOpenness::kOpen ? 1 : 0, return TabAnimationState(
pinned == TabPinnedness::kPinned ? 1 : 0, open == TabOpen::kOpen ? 1 : 0, pinned == TabPinned::kPinned ? 1 : 0,
active == TabActiveness::kActive ? 1 : 0, active == TabActive::kActive ? 1 : 0, tab_index_offset);
tab_index_offset);
} }
TabAnimationState TabAnimationState::Interpolate(float value, TabAnimationState TabAnimationState::Interpolate(float value,
...@@ -30,21 +30,19 @@ TabAnimationState TabAnimationState::Interpolate(float value, ...@@ -30,21 +30,19 @@ TabAnimationState TabAnimationState::Interpolate(float value,
target.normalized_leading_edge_x_)); target.normalized_leading_edge_x_));
} }
TabAnimationState TabAnimationState::WithOpenness(TabOpenness open) const { TabAnimationState TabAnimationState::WithOpen(TabOpen open) const {
return TabAnimationState(open == TabOpenness::kOpen ? 1 : 0, pinnedness_, return TabAnimationState(open == TabOpen::kOpen ? 1 : 0, pinnedness_,
activeness_, normalized_leading_edge_x_); activeness_, normalized_leading_edge_x_);
} }
TabAnimationState TabAnimationState::WithPinnedness( TabAnimationState TabAnimationState::WithPinned(TabPinned pinned) const {
TabPinnedness pinned) const { return TabAnimationState(openness_, pinned == TabPinned::kPinned ? 1 : 0,
return TabAnimationState(openness_, pinned == TabPinnedness::kPinned ? 1 : 0,
activeness_, normalized_leading_edge_x_); activeness_, normalized_leading_edge_x_);
} }
TabAnimationState TabAnimationState::WithActiveness( TabAnimationState TabAnimationState::WithActive(TabActive active) const {
TabActiveness active) const {
return TabAnimationState(openness_, pinnedness_, return TabAnimationState(openness_, pinnedness_,
active == TabActiveness::kActive ? 1 : 0, active == TabActive::kActive ? 1 : 0,
normalized_leading_edge_x_); normalized_leading_edge_x_);
} }
......
...@@ -6,27 +6,22 @@ ...@@ -6,27 +6,22 @@
#define CHROME_BROWSER_UI_VIEWS_TABS_TAB_ANIMATION_STATE_H_ #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_ANIMATION_STATE_H_
#include <vector> #include <vector>
#include "chrome/browser/ui/tabs/tab_types.h"
// Contains the data necessary to determine the bounds of a tab even while // Contains the data necessary to determine the bounds of a tab even while
// it's in the middle of animating between states. Immutable (except for // it's in the middle of animating between states. Immutable (except for
// replacement via assignment). // replacement via assignment).
class TabAnimationState { class TabAnimationState {
public: public:
enum class TabOpenness { kOpen, kClosed };
enum class TabPinnedness { kPinned, kUnpinned };
enum class TabActiveness { kActive, kInactive };
// Returns the TabAnimationState that expresses the provided // Returns the TabAnimationState that expresses the provided
// ideal tab state. These correspond to the endpoints of animations. // ideal tab state. These correspond to the endpoints of animations.
// |open| controls whether the returned TabAnimationState is fully open or // |open| controls whether the returned TabAnimationState is fully open or
// closed. |pinned| and |active| are analogous. |tab_index_offset| is the // closed. |pinned| and |active| are analogous. |tab_index_offset| is the
// distance, in tab indices, away from its current model position the tab // distance, in tab indices, away from its current model position the tab
// should be drawn at. It may be negative. // should be drawn at. It may be negative.
static TabAnimationState ForIdealTabState(TabOpenness open, static TabAnimationState ForIdealTabState(TabOpen open,
TabPinnedness pinned, TabPinned pinned,
TabActiveness active, TabActive active,
int tab_index_offset); int tab_index_offset);
// Interpolates from |origin| to |target| by |value|. // Interpolates from |origin| to |target| by |value|.
...@@ -40,9 +35,9 @@ class TabAnimationState { ...@@ -40,9 +35,9 @@ class TabAnimationState {
float pinnedness() const { return pinnedness_; } float pinnedness() const { return pinnedness_; }
float activeness() const { return activeness_; } float activeness() const { return activeness_; }
TabAnimationState WithOpenness(TabOpenness open) const; TabAnimationState WithOpen(TabOpen open) const;
TabAnimationState WithPinnedness(TabPinnedness pinned) const; TabAnimationState WithPinned(TabPinned pinned) const;
TabAnimationState WithActiveness(TabActiveness active) const; TabAnimationState WithActive(TabActive active) const;
int GetLeadingEdgeOffset(std::vector<int> tab_widths, int my_index) const; int GetLeadingEdgeOffset(std::vector<int> tab_widths, int my_index) const;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/ui/tabs/tab_types.h"
#include "chrome/browser/ui/views/tabs/tab_animation_state.h" #include "chrome/browser/ui/views/tabs/tab_animation_state.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -32,9 +33,7 @@ class TabAnimationTest : public testing::Test { ...@@ -32,9 +33,7 @@ class TabAnimationTest : public testing::Test {
TEST_F(TabAnimationTest, StaticAnimationDoesNotChange) { TEST_F(TabAnimationTest, StaticAnimationDoesNotChange) {
TabAnimationState static_state = TabAnimationState::ForIdealTabState( TabAnimationState static_state = TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen, TabPinned::kUnpinned, TabActive::kInactive, 0);
TabAnimationState::TabPinnedness::kUnpinned,
TabAnimationState::TabActiveness::kInactive, 0);
TabAnimation static_animation(static_state, base::BindOnce([]() {})); TabAnimation static_animation(static_state, base::BindOnce([]() {}));
EXPECT_EQ(kZeroDuration, static_animation.GetTimeRemaining()); EXPECT_EQ(kZeroDuration, static_animation.GetTimeRemaining());
...@@ -48,11 +47,8 @@ TEST_F(TabAnimationTest, StaticAnimationDoesNotChange) { ...@@ -48,11 +47,8 @@ TEST_F(TabAnimationTest, StaticAnimationDoesNotChange) {
TEST_F(TabAnimationTest, AnimationAnimates) { TEST_F(TabAnimationTest, AnimationAnimates) {
TabAnimationState initial_state = TabAnimationState::ForIdealTabState( TabAnimationState initial_state = TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen, TabPinned::kUnpinned, TabActive::kInactive, 0);
TabAnimationState::TabPinnedness::kUnpinned, TabAnimationState target_state = initial_state.WithPinned(TabPinned::kPinned);
TabAnimationState::TabActiveness::kInactive, 0);
TabAnimationState target_state =
initial_state.WithPinnedness(TabAnimationState::TabPinnedness::kPinned);
TabAnimation animation(initial_state, base::BindOnce([]() {})); TabAnimation animation(initial_state, base::BindOnce([]() {}));
animation.AnimateTo(target_state); animation.AnimateTo(target_state);
...@@ -72,11 +68,8 @@ TEST_F(TabAnimationTest, AnimationAnimates) { ...@@ -72,11 +68,8 @@ TEST_F(TabAnimationTest, AnimationAnimates) {
TEST_F(TabAnimationTest, CompletedAnimationSnapsToTarget) { TEST_F(TabAnimationTest, CompletedAnimationSnapsToTarget) {
TabAnimationState initial_state = TabAnimationState::ForIdealTabState( TabAnimationState initial_state = TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen, TabPinned::kUnpinned, TabActive::kInactive, 0);
TabAnimationState::TabPinnedness::kUnpinned, TabAnimationState target_state = initial_state.WithPinned(TabPinned::kPinned);
TabAnimationState::TabActiveness::kInactive, 0);
TabAnimationState target_state =
initial_state.WithPinnedness(TabAnimationState::TabPinnedness::kPinned);
TabAnimation animation(initial_state, base::BindOnce([]() {})); TabAnimation animation(initial_state, base::BindOnce([]() {}));
animation.AnimateTo(target_state); animation.AnimateTo(target_state);
...@@ -89,11 +82,8 @@ TEST_F(TabAnimationTest, CompletedAnimationSnapsToTarget) { ...@@ -89,11 +82,8 @@ TEST_F(TabAnimationTest, CompletedAnimationSnapsToTarget) {
TEST_F(TabAnimationTest, ReplacedAnimationRestartsDuration) { TEST_F(TabAnimationTest, ReplacedAnimationRestartsDuration) {
TabAnimationState initial_state = TabAnimationState::ForIdealTabState( TabAnimationState initial_state = TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen, TabPinned::kUnpinned, TabActive::kInactive, 0);
TabAnimationState::TabPinnedness::kUnpinned, TabAnimationState target_state = initial_state.WithPinned(TabPinned::kPinned);
TabAnimationState::TabActiveness::kInactive, 0);
TabAnimationState target_state =
initial_state.WithPinnedness(TabAnimationState::TabPinnedness::kPinned);
TabAnimation animation(initial_state, base::BindOnce([]() {})); TabAnimation animation(initial_state, base::BindOnce([]() {}));
animation.AnimateTo(target_state); animation.AnimateTo(target_state);
...@@ -108,11 +98,8 @@ TEST_F(TabAnimationTest, ReplacedAnimationRestartsDuration) { ...@@ -108,11 +98,8 @@ TEST_F(TabAnimationTest, ReplacedAnimationRestartsDuration) {
TEST_F(TabAnimationTest, RetargetedAnimationKeepsDuration) { TEST_F(TabAnimationTest, RetargetedAnimationKeepsDuration) {
TabAnimationState initial_state = TabAnimationState::ForIdealTabState( TabAnimationState initial_state = TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen, TabPinned::kUnpinned, TabActive::kInactive, 0);
TabAnimationState::TabPinnedness::kUnpinned, TabAnimationState target_state = initial_state.WithPinned(TabPinned::kPinned);
TabAnimationState::TabActiveness::kInactive, 0);
TabAnimationState target_state =
initial_state.WithPinnedness(TabAnimationState::TabPinnedness::kPinned);
TabAnimation animation(initial_state, base::BindOnce([]() {})); TabAnimation animation(initial_state, base::BindOnce([]() {}));
animation.AnimateTo(target_state); animation.AnimateTo(target_state);
...@@ -136,9 +123,7 @@ TEST_F(TabAnimationTest, TestNotifyCloseCompleted) { ...@@ -136,9 +123,7 @@ TEST_F(TabAnimationTest, TestNotifyCloseCompleted) {
bool was_closed_ = false; bool was_closed_ = false;
}; };
TabAnimationState static_state = TabAnimationState::ForIdealTabState( TabAnimationState static_state = TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen, TabPinned::kUnpinned, TabActive::kInactive, 0);
TabAnimationState::TabPinnedness::kUnpinned,
TabAnimationState::TabActiveness::kInactive, 0);
TabClosedDetector tab_closed_detector; TabClosedDetector tab_closed_detector;
TabAnimation animation( TabAnimation animation(
static_state, base::BindOnce(&TabClosedDetector::NotifyTabClosed, static_state, base::BindOnce(&TabClosedDetector::NotifyTabClosed,
......
...@@ -1003,17 +1003,15 @@ void TabStrip::AddTabAt(int model_index, TabRendererData data, bool is_active) { ...@@ -1003,17 +1003,15 @@ void TabStrip::AddTabAt(int model_index, TabRendererData data, bool is_active) {
// Don't animate the first tab, it looks weird, and don't animate anything // Don't animate the first tab, it looks weird, and don't animate anything
// if the containing window isn't visible yet. // if the containing window isn't visible yet.
TabAnimationState::TabPinnedness pinnedness =
pinned ? TabAnimationState::TabPinnedness::kPinned
: TabAnimationState::TabPinnedness::kUnpinned;
if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible()) { if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible()) {
StartInsertTabAnimation(model_index, pinnedness); StartInsertTabAnimation(model_index,
pinned ? TabPinned::kPinned : TabPinned::kUnpinned);
} else { } else {
layout_helper_->InsertTabAtNoAnimation( layout_helper_->InsertTabAtNoAnimation(
model_index, tab, model_index, tab,
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted, base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this), base::Unretained(tab)), base::Unretained(this), base::Unretained(tab)),
pinnedness); pinned ? TabPinned::kPinned : TabPinned::kUnpinned);
CompleteAnimationAndLayout(); CompleteAnimationAndLayout();
} }
...@@ -1072,10 +1070,8 @@ void TabStrip::MoveTab(int from_model_index, ...@@ -1072,10 +1070,8 @@ void TabStrip::MoveTab(int from_model_index,
layout_helper_->MoveTab(moving_tab->group(), from_model_index, layout_helper_->MoveTab(moving_tab->group(), from_model_index,
to_model_index); to_model_index);
layout_helper_->SetTabPinnedness( layout_helper_->SetTabPinned(
to_model_index, data.pinned to_model_index, data.pinned ? TabPinned::kPinned : TabPinned::kUnpinned);
? TabAnimationState::TabPinnedness::kPinned
: TabAnimationState::TabPinnedness::kUnpinned);
StartMoveTabAnimation(); StartMoveTabAnimation();
if (TabDragController::IsAttachedTo(GetDragContext()) && if (TabDragController::IsAttachedTo(GetDragContext()) &&
(last_tab != GetLastVisibleTab() || last_tab->dragging())) { (last_tab != GetLastVisibleTab() || last_tab->dragging())) {
...@@ -1132,9 +1128,8 @@ void TabStrip::SetTabData(int model_index, TabRendererData data) { ...@@ -1132,9 +1128,8 @@ void TabStrip::SetTabData(int model_index, TabRendererData data) {
touch_layout_->SetXAndPinnedCount(start_x, pinned_tab_count); touch_layout_->SetXAndPinnedCount(start_x, pinned_tab_count);
} }
layout_helper_->SetTabPinnedness( layout_helper_->SetTabPinned(
model_index, data.pinned ? TabAnimationState::TabPinnedness::kPinned model_index, data.pinned ? TabPinned::kPinned : TabPinned::kUnpinned);
: TabAnimationState::TabPinnedness::kUnpinned);
if (GetWidget() && GetWidget()->IsVisible()) if (GetWidget() && GetWidget()->IsVisible())
StartPinnedTabAnimation(); StartPinnedTabAnimation();
else else
...@@ -2080,16 +2075,14 @@ std::map<TabGroupId, TabGroupHeader*> TabStrip::GetGroupHeaders() { ...@@ -2080,16 +2075,14 @@ std::map<TabGroupId, TabGroupHeader*> TabStrip::GetGroupHeaders() {
return group_headers; return group_headers;
} }
void TabStrip::StartInsertTabAnimation( void TabStrip::StartInsertTabAnimation(int model_index, TabPinned pinned) {
int model_index,
TabAnimationState::TabPinnedness pinnedness) {
if (!bounds_animator_.IsAnimating() && !in_tab_close_) { if (!bounds_animator_.IsAnimating() && !in_tab_close_) {
layout_helper_->InsertTabAt( layout_helper_->InsertTabAt(
model_index, tab_at(model_index), model_index, tab_at(model_index),
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted, base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this), base::Unretained(this),
base::Unretained(tab_at(model_index))), base::Unretained(tab_at(model_index))),
pinnedness); pinned);
} else { } else {
// TODO(958173): Delete this branch once |TabStripLayoutHelper::animator_| // TODO(958173): Delete this branch once |TabStripLayoutHelper::animator_|
// has taken over all animation responsibilities. // has taken over all animation responsibilities.
...@@ -2098,7 +2091,7 @@ void TabStrip::StartInsertTabAnimation( ...@@ -2098,7 +2091,7 @@ void TabStrip::StartInsertTabAnimation(
base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted, base::BindOnce(&TabStrip::OnTabCloseAnimationCompleted,
base::Unretained(this), base::Unretained(this),
base::Unretained(tab_at(model_index))), base::Unretained(tab_at(model_index))),
pinnedness); pinned);
PrepareForAnimation(); PrepareForAnimation();
......
...@@ -358,8 +358,7 @@ class TabStrip : public views::AccessiblePaneView, ...@@ -358,8 +358,7 @@ class TabStrip : public views::AccessiblePaneView,
std::map<TabGroupId, TabGroupHeader*> GetGroupHeaders(); std::map<TabGroupId, TabGroupHeader*> GetGroupHeaders();
// 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, TabPinned pinned);
TabAnimationState::TabPinnedness pinnedness);
// Animates the removal of the tab at |model_index|. Defers to the old // Animates the removal of the tab at |model_index|. Defers to the old
// animation style when appropriate. // animation style when appropriate.
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/ui/layout_constants.h" #include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_style.h" #include "chrome/browser/ui/tabs/tab_style.h"
#include "chrome/browser/ui/tabs/tab_types.h"
#include "chrome/browser/ui/views/tabs/tab.h" #include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_animation.h" #include "chrome/browser/ui/views/tabs/tab_animation.h"
#include "chrome/browser/ui/views/tabs/tab_animation_state.h" #include "chrome/browser/ui/views/tabs/tab_animation_state.h"
...@@ -44,14 +45,14 @@ TabLayoutConstants GetTabLayoutConstants() { ...@@ -44,14 +45,14 @@ TabLayoutConstants GetTabLayoutConstants() {
struct TabStripLayoutHelper::TabSlot { struct TabStripLayoutHelper::TabSlot {
static TabStripLayoutHelper::TabSlot CreateForTab( static TabStripLayoutHelper::TabSlot CreateForTab(
Tab* tab, Tab* tab,
TabAnimationState::TabOpenness openness, TabOpen open,
TabAnimationState::TabPinnedness pinned, TabPinned pinned,
base::OnceClosure removed_callback) { base::OnceClosure removed_callback) {
TabStripLayoutHelper::TabSlot slot; TabStripLayoutHelper::TabSlot slot;
slot.type = ViewType::kTab; slot.type = ViewType::kTab;
slot.view = tab; slot.view = tab;
TabAnimationState initial_state = TabAnimationState::ForIdealTabState( TabAnimationState initial_state = TabAnimationState::ForIdealTabState(
openness, pinned, TabAnimationState::TabActiveness::kInactive, 0); open, pinned, TabActive::kInactive, 0);
slot.animation = std::make_unique<TabAnimation>( slot.animation = std::make_unique<TabAnimation>(
initial_state, std::move(removed_callback)); initial_state, std::move(removed_callback));
return slot; return slot;
...@@ -60,14 +61,13 @@ struct TabStripLayoutHelper::TabSlot { ...@@ -60,14 +61,13 @@ struct TabStripLayoutHelper::TabSlot {
static TabStripLayoutHelper::TabSlot CreateForGroupHeader( static TabStripLayoutHelper::TabSlot CreateForGroupHeader(
TabGroupId group, TabGroupId group,
TabGroupHeader* header, TabGroupHeader* header,
TabAnimationState::TabPinnedness pinned, TabPinned pinned,
base::OnceClosure removed_callback) { base::OnceClosure removed_callback) {
TabStripLayoutHelper::TabSlot slot; TabStripLayoutHelper::TabSlot slot;
slot.type = ViewType::kGroupHeader; slot.type = ViewType::kGroupHeader;
slot.view = header; slot.view = header;
TabAnimationState initial_state = TabAnimationState::ForIdealTabState( TabAnimationState initial_state = TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, pinned, TabOpen::kOpen, pinned, TabActive::kInactive, 0);
TabAnimationState::TabActiveness::kInactive, 0);
slot.animation = std::make_unique<TabAnimation>( slot.animation = std::make_unique<TabAnimation>(
initial_state, std::move(removed_callback)); initial_state, std::move(removed_callback));
return slot; return slot;
...@@ -122,44 +122,39 @@ void TabStripLayoutHelper::InsertTabAtNoAnimation( ...@@ -122,44 +122,39 @@ void TabStripLayoutHelper::InsertTabAtNoAnimation(
int model_index, int model_index,
Tab* tab, Tab* tab,
base::OnceClosure tab_removed_callback, base::OnceClosure tab_removed_callback,
TabAnimationState::TabPinnedness pinned) { TabPinned pinned) {
const int slot_index = const int slot_index =
GetSlotIndexForTabModelIndex(model_index, tab->group()); GetSlotIndexForTabModelIndex(model_index, tab->group());
slots_.insert( slots_.insert(slots_.begin() + slot_index,
slots_.begin() + slot_index, TabSlot::CreateForTab(tab, TabOpen::kOpen, pinned,
TabSlot::CreateForTab(tab, TabAnimationState::TabOpenness::kOpen, pinned,
std::move(tab_removed_callback))); std::move(tab_removed_callback)));
} }
void TabStripLayoutHelper::InsertTabAt( void TabStripLayoutHelper::InsertTabAt(int model_index,
int model_index,
Tab* tab, Tab* tab,
base::OnceClosure tab_removed_callback, base::OnceClosure tab_removed_callback,
TabAnimationState::TabPinnedness pinned) { TabPinned pinned) {
const int slot_index = const int slot_index =
GetSlotIndexForTabModelIndex(model_index, tab->group()); GetSlotIndexForTabModelIndex(model_index, tab->group());
slots_.insert( slots_.insert(slots_.begin() + slot_index,
slots_.begin() + slot_index, TabSlot::CreateForTab(tab, TabOpen::kClosed, pinned,
TabSlot::CreateForTab(tab, TabAnimationState::TabOpenness::kClosed, std::move(tab_removed_callback)));
pinned, std::move(tab_removed_callback))); AnimateSlot(slot_index, slots_[slot_index].animation->target_state().WithOpen(
AnimateSlot(slot_index, TabOpen::kOpen));
slots_[slot_index].animation->target_state().WithOpenness(
TabAnimationState::TabOpenness::kOpen));
} }
void TabStripLayoutHelper::RemoveTabNoAnimation(int model_index, Tab* tab) { void TabStripLayoutHelper::RemoveTabNoAnimation(int model_index, Tab* tab) {
TabAnimation* animation = TabAnimation* animation =
slots_[GetSlotIndexForTabModelIndex(model_index, tab->group())] slots_[GetSlotIndexForTabModelIndex(model_index, tab->group())]
.animation.get(); .animation.get();
animation->AnimateTo(animation->target_state().WithOpenness( animation->AnimateTo(animation->target_state().WithOpen(TabOpen::kClosed));
TabAnimationState::TabOpenness::kClosed)); animation->CompleteAnimation();
} }
void TabStripLayoutHelper::RemoveTab(int model_index, Tab* tab) { void TabStripLayoutHelper::RemoveTab(int model_index, Tab* tab) {
int slot_index = GetSlotIndexForTabModelIndex(model_index, tab->group()); int slot_index = GetSlotIndexForTabModelIndex(model_index, tab->group());
AnimateSlot(slot_index, AnimateSlot(slot_index, slots_[slot_index].animation->target_state().WithOpen(
slots_[slot_index].animation->target_state().WithOpenness( TabOpen::kClosed));
TabAnimationState::TabOpenness::kClosed));
} }
void TabStripLayoutHelper::EnterTabClosingMode(int available_width) { void TabStripLayoutHelper::EnterTabClosingMode(int available_width) {
...@@ -201,16 +196,14 @@ void TabStripLayoutHelper::MoveTab(base::Optional<TabGroupId> moving_tab_group, ...@@ -201,16 +196,14 @@ void TabStripLayoutHelper::MoveTab(base::Optional<TabGroupId> moving_tab_group,
UpdateGroupHeaderIndex(moving_tab_group.value()); UpdateGroupHeaderIndex(moving_tab_group.value());
} }
void TabStripLayoutHelper::SetTabPinnedness( void TabStripLayoutHelper::SetTabPinned(int model_index, TabPinned pinned) {
int model_index,
TabAnimationState::TabPinnedness pinnedness) {
// TODO(958173): Animate state change. // TODO(958173): Animate state change.
views::ViewModelT<Tab>* tabs = get_tabs_callback_.Run(); views::ViewModelT<Tab>* tabs = get_tabs_callback_.Run();
TabAnimation* animation = TabAnimation* animation =
slots_[GetSlotIndexForTabModelIndex(model_index, slots_[GetSlotIndexForTabModelIndex(model_index,
tabs->view_at(model_index)->group())] tabs->view_at(model_index)->group())]
.animation.get(); .animation.get();
animation->AnimateTo(animation->target_state().WithPinnedness(pinnedness)); animation->AnimateTo(animation->target_state().WithPinned(pinned));
animation->CompleteAnimation(); animation->CompleteAnimation();
} }
...@@ -222,9 +215,9 @@ void TabStripLayoutHelper::InsertGroupHeader( ...@@ -222,9 +215,9 @@ void TabStripLayoutHelper::InsertGroupHeader(
std::vector<int> tabs_in_group = controller_->ListTabsInGroup(group); std::vector<int> tabs_in_group = controller_->ListTabsInGroup(group);
const int header_slot_index = const int header_slot_index =
GetSlotIndexForTabModelIndex(tabs_in_group[0], group); GetSlotIndexForTabModelIndex(tabs_in_group[0], group);
slots_.insert(slots_.begin() + header_slot_index, slots_.insert(
TabSlot::CreateForGroupHeader( slots_.begin() + header_slot_index,
group, header, TabAnimationState::TabPinnedness::kUnpinned, TabSlot::CreateForGroupHeader(group, header, TabPinned::kUnpinned,
std::move(header_removed_callback))); std::move(header_removed_callback)));
} }
...@@ -249,20 +242,20 @@ void TabStripLayoutHelper::UpdateGroupHeaderIndex(TabGroupId group) { ...@@ -249,20 +242,20 @@ void TabStripLayoutHelper::UpdateGroupHeaderIndex(TabGroupId group) {
void TabStripLayoutHelper::SetActiveTab(int prev_active_index, void TabStripLayoutHelper::SetActiveTab(int prev_active_index,
int new_active_index) { int new_active_index) {
views::ViewModelT<Tab>* tabs = get_tabs_callback_.Run(); views::ViewModelT<Tab>* tabs = get_tabs_callback_.Run();
// Set activeness without animating by retargeting the existing animation. // Set active state without animating by retargeting the existing animation.
if (prev_active_index >= 0) { if (prev_active_index >= 0) {
const int prev_slot_index = GetSlotIndexForTabModelIndex( const int prev_slot_index = GetSlotIndexForTabModelIndex(
prev_active_index, tabs->view_at(prev_active_index)->group()); prev_active_index, tabs->view_at(prev_active_index)->group());
TabAnimation* animation = slots_[prev_slot_index].animation.get(); TabAnimation* animation = slots_[prev_slot_index].animation.get();
animation->RetargetTo(animation->target_state().WithActiveness( animation->RetargetTo(
TabAnimationState::TabActiveness::kInactive)); animation->target_state().WithActive(TabActive::kInactive));
} }
if (new_active_index >= 0) { if (new_active_index >= 0) {
const int new_slot_index = GetSlotIndexForTabModelIndex( const int new_slot_index = GetSlotIndexForTabModelIndex(
new_active_index, tabs->view_at(new_active_index)->group()); new_active_index, tabs->view_at(new_active_index)->group());
TabAnimation* animation = slots_[new_slot_index].animation.get(); TabAnimation* animation = slots_[new_slot_index].animation.get();
animation->RetargetTo(animation->target_state().WithActiveness( animation->RetargetTo(
TabAnimationState::TabActiveness::kActive)); animation->target_state().WithActive(TabActive::kActive));
} }
} }
...@@ -300,15 +293,12 @@ void TabStripLayoutHelper::UpdateIdealBounds(int available_width) { ...@@ -300,15 +293,12 @@ void TabStripLayoutHelper::UpdateIdealBounds(int available_width) {
TabLayoutConstants layout_constants = GetTabLayoutConstants(); TabLayoutConstants layout_constants = GetTabLayoutConstants();
std::vector<TabWidthConstraints> tab_widths; std::vector<TabWidthConstraints> tab_widths;
for (int i = 0; i < int{slots_.size()}; i++) { for (int i = 0; i < int{slots_.size()}; i++) {
auto active = i == active_tab_slot_index auto active =
? TabAnimationState::TabActiveness::kActive i == active_tab_slot_index ? TabActive::kActive : TabActive::kInactive;
: TabAnimationState::TabActiveness::kInactive; auto pinned = i <= last_pinned_tab_slot_index ? TabPinned::kPinned
auto pinned = i <= last_pinned_tab_slot_index : TabPinned::kUnpinned;
? TabAnimationState::TabPinnedness::kPinned auto open =
: TabAnimationState::TabPinnedness::kUnpinned; slots_[i].animation->IsClosing() ? TabOpen::kClosed : TabOpen::kOpen;
auto open = slots_[i].animation->IsClosing()
? TabAnimationState::TabOpenness::kClosed
: TabAnimationState::TabOpenness::kOpen;
TabAnimationState ideal_animation_state = TabAnimationState ideal_animation_state =
TabAnimationState::ForIdealTabState(open, pinned, active, 0); TabAnimationState::ForIdealTabState(open, pinned, active, 0);
TabSizeInfo size_info = slots_[i].view->GetTabSizeInfo(); TabSizeInfo size_info = slots_[i].view->GetTabSizeInfo();
...@@ -352,9 +342,7 @@ void TabStripLayoutHelper::UpdateIdealBoundsForPinnedTabs() { ...@@ -352,9 +342,7 @@ void TabStripLayoutHelper::UpdateIdealBoundsForPinnedTabs() {
for (int tab_index = 0; tab_index < pinned_tab_count; tab_index++) { for (int tab_index = 0; tab_index < pinned_tab_count; tab_index++) {
TabAnimationState ideal_animation_state = TabAnimationState ideal_animation_state =
TabAnimationState::ForIdealTabState( TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen, TabPinned::kPinned, TabActive::kInactive, 0);
TabAnimationState::TabPinnedness::kPinned,
TabAnimationState::TabActiveness::kInactive, 0);
TabSizeInfo size_info = tabs->view_at(tab_index)->GetTabSizeInfo(); TabSizeInfo size_info = tabs->view_at(tab_index)->GetTabSizeInfo();
tab_widths.push_back(TabWidthConstraints(ideal_animation_state, tab_widths.push_back(TabWidthConstraints(ideal_animation_state,
layout_constants, size_info)); layout_constants, size_info));
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/ui/tabs/tab_types.h"
#include "chrome/browser/ui/views/tabs/tab_animation_state.h" #include "chrome/browser/ui/views/tabs/tab_animation_state.h"
#include "chrome/browser/ui/views/tabs/tab_strip_layout.h" #include "chrome/browser/ui/views/tabs/tab_strip_layout.h"
#include "chrome/browser/ui/views/tabs/tab_width_constraints.h" #include "chrome/browser/ui/views/tabs/tab_width_constraints.h"
...@@ -58,14 +59,14 @@ class TabStripLayoutHelper { ...@@ -58,14 +59,14 @@ class TabStripLayoutHelper {
void InsertTabAtNoAnimation(int model_index, void InsertTabAtNoAnimation(int model_index,
Tab* tab, Tab* tab,
base::OnceClosure tab_removed_callback, base::OnceClosure tab_removed_callback,
TabAnimationState::TabPinnedness pinned); TabPinned pinned);
// Inserts a new tab at |index|, with animation. |tab_removed_callback| will // Inserts a new tab at |index|, with animation. |tab_removed_callback| will
// be invoked if the tab is removed at the end of a remove animation. // be invoked if the tab is removed at the end of a remove animation.
void InsertTabAt(int model_index, void InsertTabAt(int model_index,
Tab* tab, Tab* tab,
base::OnceClosure tab_removed_callback, base::OnceClosure tab_removed_callback,
TabAnimationState::TabPinnedness pinned); TabPinned pinned);
// Marks the tab at |model_index| as closed without animating it. Use when // Marks the tab at |model_index| as closed without animating it. Use when
// the tab has been removed from the model but the old animation style owns // the tab has been removed from the model but the old animation style owns
...@@ -96,9 +97,8 @@ class TabStripLayoutHelper { ...@@ -96,9 +97,8 @@ class TabStripLayoutHelper {
int prev_index, int prev_index,
int new_index); int new_index);
// Sets the tab at |index|'s pinnedness to |pinnedness|. // Sets the tab at |index|'s pinned state to |pinned|.
void SetTabPinnedness(int model_index, void SetTabPinned(int model_index, TabPinned pinned);
TabAnimationState::TabPinnedness pinnedness);
// Inserts a new group header for |group|. |header_removed_callback| will be // Inserts a new group header for |group|. |header_removed_callback| will be
// invoked if the group is removed at the end of a remove animation. // invoked if the group is removed at the end of a remove animation.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/browser/ui/tabs/tab_types.h"
#include "chrome/browser/ui/views/tabs/tab_animation_state.h" #include "chrome/browser/ui/views/tabs/tab_animation_state.h"
#include "chrome/browser/ui/views/tabs/tab_width_constraints.h" #include "chrome/browser/ui/views/tabs/tab_width_constraints.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -69,13 +70,11 @@ std::vector<gfx::Rect> CalculateTabBounds(TestCase test_case) { ...@@ -69,13 +70,11 @@ std::vector<gfx::Rect> CalculateTabBounds(TestCase test_case) {
for (int tab_index = 0; tab_index < test_case.num_tabs; tab_index++) { for (int tab_index = 0; tab_index < test_case.num_tabs; tab_index++) {
TabAnimationState ideal_animation_state = TabAnimationState ideal_animation_state =
TabAnimationState::ForIdealTabState( TabAnimationState::ForIdealTabState(
TabAnimationState::TabOpenness::kOpen, TabOpen::kOpen,
tab_index < test_case.num_pinned_tabs tab_index < test_case.num_pinned_tabs ? TabPinned::kPinned
? TabAnimationState::TabPinnedness::kPinned : TabPinned::kUnpinned,
: TabAnimationState::TabPinnedness::kUnpinned, tab_index == test_case.active_index ? TabActive::kActive
tab_index == test_case.active_index : TabActive::kInactive,
? TabAnimationState::TabActiveness::kActive
: TabAnimationState::TabActiveness::kInactive,
0); 0);
tab_states.push_back(TabWidthConstraints(ideal_animation_state, tab_states.push_back(TabWidthConstraints(ideal_animation_state,
layout_constants, size_info)); layout_constants, size_info));
......
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