diff --git a/browser/ui/views/frame/vertical_tab_strip_region_view.cc b/browser/ui/views/frame/vertical_tab_strip_region_view.cc index 22b69d5fd1c0..630853416843 100644 --- a/browser/ui/views/frame/vertical_tab_strip_region_view.cc +++ b/browser/ui/views/frame/vertical_tab_strip_region_view.cc @@ -918,13 +918,7 @@ void VerticalTabStripRegionView::Layout(PassKey) { // As we have to update ScrollView's viewport size and its contents size, // laying out children manually will be more handy. - // 1. New tab should be fixed at the bottom of container. const auto contents_bounds = GetContentsBounds(); - new_tab_button_->SetSize( - {contents_bounds.width(), new_tab_button_->GetPreferredSize().height()}); - new_tab_button_->SetPosition( - {contents_bounds.x(), - contents_bounds.bottom() - new_tab_button_->height()}); const gfx::Size header_size{contents_bounds.width(), tabs::kVerticalTabHeight + kHeaderInset * 2}; @@ -932,11 +926,33 @@ void VerticalTabStripRegionView::Layout(PassKey) { header_view_->SetSize(header_size); contents_view_->SetSize( - {contents_bounds.width(), contents_bounds.height() - - new_tab_button_->height() - - header_view_->height()}); + {contents_bounds.width(), + original_region_view_->tab_strip_->tab_container_->GetPreferredSize() + .height()}); + contents_view_->SetPosition({contents_bounds.origin().x(), header_view_->y() + header_view_->height()}); + + int new_tab_height = new_tab_button_->GetPreferredSize().height(); + new_tab_button_->SetSize(gfx::Size(contents_bounds.width(), new_tab_height)); + + int contents_view_max_height = contents_bounds.height() - + new_tab_button_->height() - + header_view_->height(); + + // Position New Tab Button and update the size of contents view if needed. + int contents_view_bottom_y = contents_view_->y() + contents_view_->height(); + int new_tab_button_max_y = contents_bounds.bottom() - new_tab_height; + if (contents_view_bottom_y >= new_tab_button_max_y) { + contents_view_->SetSize( + gfx::Size(contents_bounds.width(), contents_view_max_height)); + new_tab_button_->SetPosition(gfx::Point( + contents_bounds.x(), contents_bounds.bottom() - new_tab_height)); + } else { + new_tab_button_->SetPosition(gfx::Point( + contents_bounds.x(), contents_view_->y() + contents_view_->height())); + } + UpdateOriginalTabSearchButtonVisibility(); // Put resize area, overlapped with contents. diff --git a/browser/ui/views/tabs/brave_compound_tab_container.cc b/browser/ui/views/tabs/brave_compound_tab_container.cc index 4cb1161da269..abd4f9ace87e 100644 --- a/browser/ui/views/tabs/brave_compound_tab_container.cc +++ b/browser/ui/views/tabs/brave_compound_tab_container.cc @@ -271,7 +271,11 @@ gfx::Size BraveCompoundTabContainer::CalculatePreferredSize( auto preferred_size = CompoundTabContainer::CalculatePreferredSize(available_size); - // Check if we can expand height to fill the entire scroll area's viewport. + const int combined_height = + pinned_tab_container_->GetPreferredSize().height() + + unpinned_tab_container_->GetPreferredSize().height(); + + // Traverse up the parent hierarchy to find the |VerticalTabStripRegionView| for (auto* parent_view = parent(); parent_view; parent_view = parent_view->parent()) { auto* region_view = @@ -280,7 +284,8 @@ gfx::Size BraveCompoundTabContainer::CalculatePreferredSize( continue; } - preferred_size.set_height(region_view->GetTabStripViewportHeight()); + preferred_size.set_height( + std::min(combined_height, region_view->GetTabStripViewportHeight())); break; } diff --git a/browser/ui/views/tabs/brave_tab_strip.cc b/browser/ui/views/tabs/brave_tab_strip.cc index f5bcd00083d8..9cea21086654 100644 --- a/browser/ui/views/tabs/brave_tab_strip.cc +++ b/browser/ui/views/tabs/brave_tab_strip.cc @@ -68,7 +68,11 @@ bool BraveTabStrip::IsVerticalTabsFloating() const { auto* vertical_region_view = browser_view->vertical_tab_strip_widget_delegate_view() ->vertical_tab_strip_region_view(); - DCHECK(vertical_region_view); + + if (!vertical_region_view) { + // Could be null while closing a window. + return false; + } return vertical_region_view->state() == VerticalTabStripRegionView::State::kFloating ||