Commit 2d0aebd8 authored by Charlene Yan's avatar Charlene Yan Committed by Commit Bot

[Tab Groups Collapse] Use TabAnimationState rather than a new boolean

for the collapsed TabWidthConstraint.

When the tab group collapses, the available tabstrip width is not
updated to reflect the collapsed group.
Also easier and less code >_>

Bug: 1018230
Change-Id: If3e0907ce3b881e736c748a6db7b040e66a5c172
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207617
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarConnie Wan <connily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769980}
parent f8df65fa
...@@ -152,11 +152,9 @@ std::vector<gfx::Rect> CalculateTabBounds( ...@@ -152,11 +152,9 @@ std::vector<gfx::Rect> CalculateTabBounds(
int next_x = 0; int next_x = 0;
std::vector<gfx::Rect> bounds; std::vector<gfx::Rect> bounds;
for (const TabWidthConstraints& tab : tabs) { for (const TabWidthConstraints& tab : tabs) {
const int tab_width = const int tab_width = tab_sizer.CalculateTabWidth(tab);
tab.IsCollapsed() ? 0 : tab_sizer.CalculateTabWidth(tab);
bounds.push_back( bounds.push_back(
gfx::Rect(next_x, 0, tab_width, layout_constants.tab_height)); gfx::Rect(next_x, 0, tab_width, layout_constants.tab_height));
if (!tab.IsCollapsed())
next_x += tab_width - layout_constants.tab_overlap; next_x += tab_width - layout_constants.tab_overlap;
} }
......
...@@ -336,23 +336,26 @@ std::vector<gfx::Rect> TabStripLayoutHelper::CalculateIdealBounds( ...@@ -336,23 +336,26 @@ std::vector<gfx::Rect> TabStripLayoutHelper::CalculateIdealBounds(
i == active_tab_slot_index ? TabActive::kActive : TabActive::kInactive; i == active_tab_slot_index ? TabActive::kActive : TabActive::kInactive;
auto pinned = i <= last_pinned_tab_slot_index ? TabPinned::kPinned auto pinned = i <= last_pinned_tab_slot_index ? TabPinned::kPinned
: TabPinned::kUnpinned; : TabPinned::kUnpinned;
auto open =
slots_[i].animation->IsClosing() ? TabOpen::kClosed : TabOpen::kOpen;
TabAnimationState ideal_animation_state =
TabAnimationState::ForIdealTabState(open, pinned, active, 0);
TabSizeInfo size_info = slots_[i].view->GetTabSizeInfo();
base::Optional<tab_groups::TabGroupId> id = slots_[i].view->group();
// The slot can only be collapsed if it is a tab and in a collapsed group. // The slot can only be collapsed if it is a tab and in a collapsed group.
// If the slot is indeed a tab and in a group, check the collapsed state of // If the slot is indeed a tab and in a group, check the collapsed state of
// the group to determine if it is collapsed. // the group to determine if it is collapsed.
// A collapsed tab animates close like a closed tab.
base::Optional<tab_groups::TabGroupId> id = slots_[i].view->group();
bool slot_is_collapsed_tab = bool slot_is_collapsed_tab =
(slots_[i].type == ViewType::kTab && id.has_value()) (slots_[i].type == ViewType::kTab && id.has_value())
? controller_->GetGroupCollapsedState(id.value()) ? controller_->GetGroupCollapsedState(id.value())
: false; : false;
auto open = (slots_[i].animation->IsClosing() || slot_is_collapsed_tab)
? TabOpen::kClosed
: TabOpen::kOpen;
TabAnimationState ideal_animation_state =
TabAnimationState::ForIdealTabState(open, pinned, active, 0);
TabSizeInfo size_info = slots_[i].view->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));
slot_is_collapsed_tab));
} }
return CalculateTabBounds(layout_constants, tab_widths, tabstrip_width, return CalculateTabBounds(layout_constants, tab_widths, tabstrip_width,
......
...@@ -10,12 +10,10 @@ ...@@ -10,12 +10,10 @@
TabWidthConstraints::TabWidthConstraints( TabWidthConstraints::TabWidthConstraints(
const TabAnimationState& state, const TabAnimationState& state,
const TabLayoutConstants& layout_constants, const TabLayoutConstants& layout_constants,
const TabSizeInfo& size_info, const TabSizeInfo& size_info)
bool is_collapsed)
: state_(state), : state_(state),
layout_constants_(layout_constants), layout_constants_(layout_constants),
size_info_(size_info), size_info_(size_info) {}
is_collapsed_(is_collapsed) {}
float TabWidthConstraints::GetMinimumWidth() const { float TabWidthConstraints::GetMinimumWidth() const {
const float min_width = gfx::Tween::FloatValueBetween( const float min_width = gfx::Tween::FloatValueBetween(
......
...@@ -15,8 +15,7 @@ class TabWidthConstraints { ...@@ -15,8 +15,7 @@ class TabWidthConstraints {
public: public:
TabWidthConstraints(const TabAnimationState& state, TabWidthConstraints(const TabAnimationState& state,
const TabLayoutConstants& layout_constants, const TabLayoutConstants& layout_constants,
const TabSizeInfo& size_info, const TabSizeInfo& size_info);
bool is_collapsed = false);
// The smallest width this tab should ever have. // The smallest width this tab should ever have.
float GetMinimumWidth() const; float GetMinimumWidth() const;
...@@ -30,8 +29,6 @@ class TabWidthConstraints { ...@@ -30,8 +29,6 @@ class TabWidthConstraints {
// The width this tab would like to have, if space is available. // The width this tab would like to have, if space is available.
float GetPreferredWidth() const; float GetPreferredWidth() const;
bool IsCollapsed() const { return is_collapsed_; }
private: private:
// All widths are affected by pinnedness and activeness in the same way. // All widths are affected by pinnedness and activeness in the same way.
float TransformForPinnednessAndOpenness(float width) const; float TransformForPinnednessAndOpenness(float width) const;
...@@ -39,8 +36,6 @@ class TabWidthConstraints { ...@@ -39,8 +36,6 @@ class TabWidthConstraints {
TabAnimationState state_; TabAnimationState state_;
TabLayoutConstants layout_constants_; TabLayoutConstants layout_constants_;
TabSizeInfo size_info_; TabSizeInfo size_info_;
bool is_collapsed_;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_WIDTH_CONSTRAINTS_H_ #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_WIDTH_CONSTRAINTS_H_
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