Commit 3909443b authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Allow account icon container to flex.

This allows the text associated with the account icon in the toolbar to
elide when displaying the entire text would cause the omnibox to become
unusably small or force the kebab/wrench menu icon off the side of the
toolbar and out of view (see attached bug).

We also include some changes in view and label_button so that we don't
accidentally report a stale size. The change to caching only text size
is because that's the expensive part of the operation - the rest is
relatively simple math.

Bug: 1012681
Change-Id: I10db6848a317dfa120472b749bcd77762ce6f62b
Fixes: 1012681
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876128
Commit-Queue: Dana Fried <dfried@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Reviewed-by: default avatarCaroline Rising <corising@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709220}
parent 9c373862
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h" #include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
// static // static
...@@ -45,6 +47,10 @@ ToolbarAccountIconContainerView::ToolbarAccountIconContainerView( ...@@ -45,6 +47,10 @@ ToolbarAccountIconContainerView::ToolbarAccountIconContainerView(
page_action_icon_container_view_ = page_action_icon_container_view_ =
AddChildView(std::make_unique<PageActionIconContainerView>(params)); AddChildView(std::make_unique<PageActionIconContainerView>(params));
avatar_->SetProperty(views::kFlexBehaviorKey,
views::FlexSpecification::ForSizeRule(
views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred));
AddMainButton(avatar_); AddMainButton(avatar_);
} }
......
...@@ -656,15 +656,20 @@ void ToolbarView::InitLayout() { ...@@ -656,15 +656,20 @@ void ToolbarView::InitLayout() {
const int default_margin = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); const int default_margin = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
// TODO(dfried): rename this constant. // TODO(dfried): rename this constant.
const int location_bar_margin = GetLayoutConstant(TOOLBAR_STANDARD_SPACING); const int location_bar_margin = GetLayoutConstant(TOOLBAR_STANDARD_SPACING);
const views::FlexSpecification browser_actions_flex_rule = const views::FlexSpecification account_container_flex_rule =
views::FlexSpecification::ForCustomRule( views::FlexSpecification::ForSizeRule(
BrowserActionsContainer::GetFlexRule()) views::MinimumFlexSizeRule::kScaleToMinimum,
.WithOrder(2); views::MaximumFlexSizeRule::kPreferred)
.WithOrder(1);
const views::FlexSpecification location_bar_flex_rule = const views::FlexSpecification location_bar_flex_rule =
views::FlexSpecification::ForSizeRule( views::FlexSpecification::ForSizeRule(
views::MinimumFlexSizeRule::kScaleToMinimum, views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kUnbounded) views::MaximumFlexSizeRule::kUnbounded)
.WithOrder(1); .WithOrder(2);
const views::FlexSpecification browser_actions_flex_rule =
views::FlexSpecification::ForCustomRule(
BrowserActionsContainer::GetFlexRule())
.WithOrder(3);
layout_manager_ = SetLayoutManager(std::make_unique<views::FlexLayout>()); layout_manager_ = SetLayoutManager(std::make_unique<views::FlexLayout>());
...@@ -685,6 +690,11 @@ void ToolbarView::InitLayout() { ...@@ -685,6 +690,11 @@ void ToolbarView::InitLayout() {
gfx::Insets(0, location_bar_margin)); gfx::Insets(0, location_bar_margin));
} }
if (toolbar_account_icon_container_) {
toolbar_account_icon_container_->SetProperty(views::kFlexBehaviorKey,
account_container_flex_rule);
}
LayoutCommon(); LayoutCommon();
} }
......
...@@ -1623,9 +1623,14 @@ void View::OnBoundsChanged(const gfx::Rect& previous_bounds) { ...@@ -1623,9 +1623,14 @@ void View::OnBoundsChanged(const gfx::Rect& previous_bounds) {
} }
void View::PreferredSizeChanged() { void View::PreferredSizeChanged() {
InvalidateLayout();
if (parent_) if (parent_)
parent_->ChildPreferredSizeChanged(this); parent_->ChildPreferredSizeChanged(this);
// Since some layout managers (specifically AnimatingLayoutManager) can react
// to InvalidateLayout() by doing calculations and since the parent can
// potentially change preferred size, etc. as a result of calling
// ChildPreferredSizeChanged(), postpone invalidation until the events have
// run all the way up the hierarchy.
InvalidateLayout();
for (ViewObserver& observer : observers_) for (ViewObserver& observer : observers_)
observer.OnViewPreferredSizeChanged(this); observer.OnViewPreferredSizeChanged(this);
} }
......
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