helium/ui/vertical: fix alignment of top buttons in collapsed state

also fix the top button insets & remove unused projects button
This commit is contained in:
wukko
2026-02-12 00:15:46 +06:00
parent 22a84c5105
commit bdffe08340
+124 -17
View File
@@ -29,7 +29,7 @@
}
--- a/chrome/browser/ui/views/frame/layout/browser_view_tabbed_layout_impl.cc
+++ b/chrome/browser/ui/views/frame/layout/browser_view_tabbed_layout_impl.cc
@@ -654,7 +654,7 @@ BrowserViewTabbedLayoutImpl::CalculatePr
@@ -654,10 +654,12 @@ BrowserViewTabbedLayoutImpl::CalculatePr
? std::max(0, base::ClampCeil(browser_params.leading_exclusion
.ContentWithPadding()
.width()) -
@@ -38,7 +38,12 @@
: 0;
views().vertical_tab_strip_region_view->SetExclusionWidthForLayout(
exclusion_width);
@@ -714,7 +714,8 @@ gfx::Rect BrowserViewTabbedLayoutImpl::C
+ views().vertical_tab_strip_region_view->SetHasLeadingExclusionForLayout(
+ exclusion_width > 0);
}
return layout;
@@ -714,7 +716,8 @@ gfx::Rect BrowserViewTabbedLayoutImpl::C
gfx::Rect toolbar_bounds;
if (toolbar_visible) {
// Visually clamp two conflicting margins: window controls & toolbar
@@ -64,6 +69,32 @@
// TODO(crbug.com/465833741): Determine snapping behavior.
static constexpr int kCollapseSnapWidth =
(kUncollapsedMinWidth + kCollapsedWidth) / 2;
@@ -134,12 +134,15 @@ class VerticalTabStripRegionView final :
// the leading, top corner.
void SetToolbarHeightForLayout(const int toolbar_height);
void SetExclusionWidthForLayout(const int exclusion_width);
+ void SetHasLeadingExclusionForLayout(bool has_leading_exclusion);
TabDragTarget* GetTabDragTarget(const gfx::Point& point_in_screen);
private:
views::View* SetTabStripView(std::unique_ptr<views::View> view);
+ void UpdateInteriorMargin();
+
void OnCollapsedStateChanged(
tabs::VerticalTabStripStateController* state_controller);
void UpdateCollapseState(tabs::VerticalTabStripState new_state);
@@ -191,6 +194,9 @@ class VerticalTabStripRegionView final :
// The width of the exclusion zone. This is used to determine when to toggle
// the collapse state of the state controller.
std::optional<int> exclusion_width_ = std::nullopt;
+
+ // Whether a leading exclusion exists due to window controls.
+ bool has_leading_exclusion_ = false;
};
#endif // CHROME_BROWSER_UI_VIEWS_FRAME_VERTICAL_TAB_STRIP_REGION_VIEW_H_
--- a/chrome/browser/ui/views/frame/vertical_tab_strip_region_view.cc
+++ b/chrome/browser/ui/views/frame/vertical_tab_strip_region_view.cc
@@ -50,7 +50,7 @@
@@ -92,7 +123,23 @@
resize_animation_.SetTweenType(gfx::Tween::Type::EASE_IN_OUT_EMPHASIZED);
resize_animation_.Reset(!state_controller_->IsCollapsed());
@@ -393,9 +391,9 @@ views::View* VerticalTabStripRegionView:
@@ -371,6 +369,15 @@ void VerticalTabStripRegionView::SetExcl
top_button_container_->SetExclusionWidthForLayout(exclusion_width);
}
+void VerticalTabStripRegionView::SetHasLeadingExclusionForLayout(
+ bool has_leading_exclusion) {
+ if (has_leading_exclusion_ == has_leading_exclusion) {
+ return;
+ }
+ has_leading_exclusion_ = has_leading_exclusion;
+ UpdateInteriorMargin();
+}
+
VerticalPinnedTabContainerView*
VerticalTabStripRegionView::GetPinnedTabsContainer() {
return tab_strip_view_->GetPinnedTabsContainer();
@@ -393,12 +400,29 @@ views::View* VerticalTabStripRegionView:
views::MaximumFlexSizeRule::kPreferred));
tab_strip_view_->SetProperty(views::kMarginsKey,
gfx::Insets::VH(kRegionVerticalPadding, 0));
@@ -105,26 +152,46 @@
return tab_strip_view_;
}
@@ -414,8 +412,6 @@ void VerticalTabStripRegionView::OnColla
+void VerticalTabStripRegionView::UpdateInteriorMargin() {
+ const int padding = GetLayoutConstant(
+ state_controller_->IsCollapsed()
+ ? LayoutConstant::kVerticalTabStripCollapsedPadding
+ : LayoutConstant::kVerticalTabStripUncollapsedPadding);
+
+ // When collapsed and under the toolbar, the top padding has to be 0
+ // in order to align with webview.
+ int top_padding =
+ state_controller_->IsCollapsed() && has_leading_exclusion_
+ ? 0
+ : kRegionVerticalPadding;
+
+ flex_layout_->SetInteriorMargin(
+ gfx::Insets::TLBR(top_padding, 0, padding, 0));
+}
+
void VerticalTabStripRegionView::OnCollapsedStateChanged(
tabs::VerticalTabStripStateController* state_controller) {
if (target_collapse_state_.collapsed != state_controller->IsCollapsed()) {
@@ -414,8 +438,7 @@ void VerticalTabStripRegionView::OnColla
state_controller_->IsCollapsed()
? LayoutConstant::kVerticalTabStripCollapsedPadding
: LayoutConstant::kVerticalTabStripUncollapsedPadding);
- top_button_separator_->SetProperty(
- views::kMarginsKey, gfx::Insets::VH(kRegionVerticalPadding, padding));
+
top_button_container_->SetProperty(
views::kMarginsKey,
gfx::Insets::TLBR(0, padding, kRegionVerticalPadding, padding));
@@ -423,7 +419,8 @@ void VerticalTabStripRegionView::OnColla
@@ -423,7 +446,7 @@ void VerticalTabStripRegionView::OnColla
views::kMarginsKey,
gfx::Insets::TLBR(kRegionVerticalPadding, padding, 0, padding));
- flex_layout_->SetInteriorMargin(gfx::Insets::VH(padding, 0));
+ flex_layout_->SetInteriorMargin(
+ gfx::Insets::TLBR(kRegionVerticalPadding, 0, padding, 0));
+ UpdateInteriorMargin();
if (tab_strip_view_) {
tab_strip_view_->SetCollapsedState(state_controller->IsCollapsed());
@@ -464,9 +461,6 @@ void VerticalTabStripRegionView::ResizeT
@@ -464,9 +487,6 @@ void VerticalTabStripRegionView::ResizeT
}
void VerticalTabStripRegionView::UpdateBackgroundColors() {
@@ -145,7 +212,32 @@
} // namespace
VerticalTabStripTopContainer::VerticalTabStripTopContainer(
@@ -88,15 +88,16 @@ views::ProposedLayout VerticalTabStripTo
@@ -38,12 +38,6 @@ VerticalTabStripTopContainer::VerticalTa
collapse_button_ = AddChildButtonFor(kActionToggleCollapseVertical);
collapse_button_->SetProperty(views::kElementIdentifierKey,
kVerticalTabStripCollapseButtonElementId);
-
- if (tabs::IsProjectsPanelFeatureEnabled()) {
- projects_button_ = AddChildButtonFor(kActionToggleProjectsPanel);
- projects_button_->SetProperty(views::kElementIdentifierKey,
- kVerticalTabStripProjectsButtonElementId);
- }
}
VerticalTabStripTopContainer::~VerticalTabStripTopContainer() = default;
@@ -64,11 +58,6 @@ views::ProposedLayout VerticalTabStripTo
CHECK(collapse_button_);
container_buttons.push_back(collapse_button_);
- if (tabs::IsProjectsPanelFeatureEnabled()) {
- CHECK(projects_button_);
- container_buttons.push_back(projects_button_);
- }
-
if (state_controller_->IsCollapsed()) {
// If the vertical tab strip is collapsed, then lay out the buttons
// vertically in reverse order from top-to-bottom.
@@ -88,52 +77,40 @@ views::ProposedLayout VerticalTabStripTo
for (views::LabelButton* container_button :
base::Reversed(container_buttons)) {
const gfx::Size pref_size = container_button->GetPreferredSize();
@@ -164,20 +256,24 @@
+ current_y += button_size + kTopButtonPadding;
}
} else {
// If the vertical tab strip is uncollapsed, then lay out the buttons
@@ -108,32 +109,28 @@ views::ProposedLayout VerticalTabStripTo
total_width += (container_buttons.size() - 1) * kTopButtonPadding;
- // If the vertical tab strip is uncollapsed, then lay out the buttons
- // horizontally from right-to-left.
- int total_width = exclusion_width_;
- for (views::LabelButton* container_button : container_buttons) {
- total_width += container_button->GetPreferredSize().width();
- }
-
- total_width += (container_buttons.size() - 1) * kTopButtonPadding;
-
- // If there is not enough space for the buttons on a single line with
- // caption buttons, shift them below.
- if (exclusion_width_ > 0 && total_width > host_size.width()) {
- host_size.Enlarge(0, toolbar_height_);
- }
-
- int current_x = host_size.width();
+ int current_x = exclusion_width_;
- int current_x = host_size.width();
-
- // Calculate bounds to right-align the button horizontally and center it
+ // Calculate bounds to left-align the buttons horizontally and center them
// vertically within the available space.
@@ -207,7 +303,18 @@
}
}
@@ -185,7 +182,11 @@ void VerticalTabStripTopContainer::SetTo
@@ -171,10 +148,6 @@ bool VerticalTabStripTopContainer::IsPos
return false;
}
- if (projects_button_ && IsHitInView(projects_button_, point)) {
- return false;
- }
-
return true;
}
@@ -185,7 +158,11 @@ void VerticalTabStripTopContainer::SetTo
void VerticalTabStripTopContainer::SetExclusionWidthForLayout(
const int exclusion_width) {