Commit b6c0ca2a authored by Taylor Bergquist's avatar Taylor Bergquist Committed by Commit Bot

Tab strip only occupies the space needed for its tabs.

Bug: 1093972
Change-Id: I0ca6cc1a7dad9240b85745fefb39ac4f52eb9355
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2300993
Commit-Queue: Taylor Bergquist <tbergquist@chromium.org>
Reviewed-by: default avatarConnie Wan <connily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793270}
parent 52a9671b
...@@ -10,15 +10,28 @@ ...@@ -10,15 +10,28 @@
#include "ui/views/layout/flex_layout.h" #include "ui/views/layout/flex_layout.h"
#include "ui/views/view_class_properties.h" #include "ui/views/view_class_properties.h"
namespace {
// Size calculation used for tabstrip scroll container. Equivalent to using
// a (kPreferredScaleToMinimum, kPreferred) flex specification on the tabstrip
// itself, bypassing the ScrollView.
gfx::Size TabScrollContainerFlexRule(const views::View* tab_strip,
const views::View* view,
const views::SizeBounds& size_bounds) {
const gfx::Size preferred_size = tab_strip->GetPreferredSize();
int width = preferred_size.width();
if (size_bounds.width().has_value())
width = std::min(width, size_bounds.width().value());
return gfx::Size(width, preferred_size.height());
}
} // namespace
TabStripRegionView::TabStripRegionView(std::unique_ptr<TabStrip> tab_strip) { TabStripRegionView::TabStripRegionView(std::unique_ptr<TabStrip> tab_strip) {
views::FlexLayout* layout_manager = views::FlexLayout* layout_manager =
SetLayoutManager(std::make_unique<views::FlexLayout>()); SetLayoutManager(std::make_unique<views::FlexLayout>());
layout_manager->SetOrientation(views::LayoutOrientation::kHorizontal) layout_manager->SetOrientation(views::LayoutOrientation::kHorizontal);
.SetDefault(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToZero,
views::MaximumFlexSizeRule::kUnbounded));
tab_strip_ = tab_strip.get(); tab_strip_ = tab_strip.get();
tab_strip->SetAvailableWidthCallback( tab_strip->SetAvailableWidthCallback(
...@@ -31,8 +44,16 @@ TabStripRegionView::TabStripRegionView(std::unique_ptr<TabStrip> tab_strip) { ...@@ -31,8 +44,16 @@ TabStripRegionView::TabStripRegionView(std::unique_ptr<TabStrip> tab_strip) {
tab_strip_scroll_container->SetHideHorizontalScrollBar(true); tab_strip_scroll_container->SetHideHorizontalScrollBar(true);
tab_strip_container_ = tab_strip_scroll_container; tab_strip_container_ = tab_strip_scroll_container;
tab_strip_scroll_container->SetContents(std::move(tab_strip)); tab_strip_scroll_container->SetContents(std::move(tab_strip));
tab_strip_scroll_container->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(base::BindRepeating(
&TabScrollContainerFlexRule, base::Unretained(tab_strip_))));
} else { } else {
tab_strip_container_ = AddChildView(std::move(tab_strip)); tab_strip_container_ = AddChildView(std::move(tab_strip));
tab_strip_->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToZero,
views::MaximumFlexSizeRule::kPreferred));
} }
} }
......
...@@ -254,6 +254,9 @@ void TabDragControllerTest::AddTabsAndResetBrowser(Browser* browser, ...@@ -254,6 +254,9 @@ void TabDragControllerTest::AddTabsAndResetBrowser(Browser* browser,
} }
browser->window()->Show(); browser->window()->Show();
StopAnimating(GetTabStripForBrowser(browser)); StopAnimating(GetTabStripForBrowser(browser));
BrowserView::GetBrowserViewForBrowser(browser)
->GetWidget()
->LayoutRootViewIfNecessary();
ResetIDs(browser->tab_strip_model(), 0); ResetIDs(browser->tab_strip_model(), 0);
} }
......
...@@ -543,7 +543,8 @@ class TabStrip::TabDragContextImpl : public TabDragContext { ...@@ -543,7 +543,8 @@ class TabStrip::TabDragContextImpl : public TabDragContext {
int GetTabAreaWidth() const override { return tab_strip_->GetTabAreaWidth(); } int GetTabAreaWidth() const override { return tab_strip_->GetTabAreaWidth(); }
int GetTabDragAreaWidth() const override { int GetTabDragAreaWidth() const override {
return tab_strip_->width() - tab_strip_->FrameGrabWidth(); return std::max(tab_strip_->CalculateAvailableWidthForTabs(),
tab_strip_->GetTabAreaWidth());
} }
int TabDragAreaBeginX() const override { int TabDragAreaBeginX() const override {
......
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