Commit 0f4e580a authored by Taylor Bergquist's avatar Taylor Bergquist Committed by Commit Bot

Greatly simplify tabstrip available width calculation.

Previously, this calculation used LayoutManager::GetAvailableSize,
which relied on cached information that was cleared during layout.
An extra layout was added to fill this cache, which caused no end
of complexities in tabstrip layout.

This is totally unnecessary, as all of the siblings of TabStrip
are simple fixed-width controls - NTB, grab handle, tab search
button, and scroll controls. A wee bit of arithmetic suffices.

Bug: 1093972
Change-Id: I7758bd80ba37b31d5efeeafd208e093094ef5e17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426978Reviewed-by: default avatarConnie Wan <connily@chromium.org>
Reviewed-by: default avatarCharlene Yan <cyan@chromium.org>
Commit-Queue: Charlene Yan <cyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810541}
parent 696cb783
...@@ -92,7 +92,7 @@ bool TabStripRegionView::IsRectInWindowCaption(const gfx::Rect& rect) { ...@@ -92,7 +92,7 @@ bool TabStripRegionView::IsRectInWindowCaption(const gfx::Rect& rect) {
// Check to see if the rect intersects the non-button parts of the tab search // Check to see if the rect intersects the non-button parts of the tab search
// button. The enclosed button has a non-rectangular shape, so if it's not in // button. The enclosed button has a non-rectangular shape, so if it's not in
// the visual portions of the buttons we treat it as a click to the caption. // the visual portions of the buttons we treat it as a click to the caption.
if (tab_search_button_->GetLocalBounds().Intersects( if (tab_search_button_ && tab_search_button_->GetLocalBounds().Intersects(
get_target_rect(tab_search_button_))) { get_target_rect(tab_search_button_))) {
return !tab_search_button_->HitTestRect( return !tab_search_button_->HitTestRect(
get_target_rect(tab_search_button_)); get_target_rect(tab_search_button_));
...@@ -136,12 +136,13 @@ void TabStripRegionView::OnThemeChanged() { ...@@ -136,12 +136,13 @@ void TabStripRegionView::OnThemeChanged() {
} }
int TabStripRegionView::CalculateTabStripAvailableWidth() { int TabStripRegionView::CalculateTabStripAvailableWidth() {
Layout(); // The tab strip can occupy the space not currently taken by its fixed-width
views::SizeBound available_width = // sibling views.
GetAvailableSize(tab_strip_container_).width(); int reserved_width = 0;
// |available_width| might still be unbounded in cases where the tabstrip is for (View* const child : children()) {
// hidden (e.g. presentation mode on MacOS). In these cases we don't care if (child != tab_strip_container_)
// about the resulting layout, since the tabstrip is not visible, so we can reserved_width += child->size().width();
// substitute 0 to ensure that we relayout once the width is defined again. }
return available_width.is_bounded() ? available_width.value() : 0;
return size().width() - reserved_width;
} }
...@@ -2200,10 +2200,6 @@ SkColor TabStrip::GetPaintedGroupColor( ...@@ -2200,10 +2200,6 @@ SkColor TabStrip::GetPaintedGroupColor(
// TabStrip, views::AccessiblePaneView overrides: // TabStrip, views::AccessiblePaneView overrides:
void TabStrip::Layout() { void TabStrip::Layout() {
if (is_doing_layout_)
return;
base::AutoReset<bool> layout_guard(&is_doing_layout_, true);
if (IsAnimating()) { if (IsAnimating()) {
// Hide tabs that have animated at least partially out of the clip region. // Hide tabs that have animated at least partially out of the clip region.
SetTabSlotVisibility(); SetTabSlotVisibility();
......
...@@ -747,9 +747,6 @@ class TabStrip : public views::AccessiblePaneView, ...@@ -747,9 +747,6 @@ class TabStrip : public views::AccessiblePaneView,
// The width available for tabs at the time of last layout. // The width available for tabs at the time of last layout.
int last_available_width_ = 0; int last_available_width_ = 0;
// Guard to protect against layout loops.
bool is_doing_layout_ = false;
// See description above stacked_layout(). // See description above stacked_layout().
bool stacked_layout_ = false; bool stacked_layout_ = false;
......
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