Commit 67301963 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Plumb the idea of unlimited main axis size through FlexLayout.

While such views are still sized based on their preferred size, this
allows marking them as "can flex" or "should be visible" in more cases.
In turn this allows FlexLayout to realize that e.g. zero min/unlimited
max width Views should have their heights included in parent preferred
size calculations.

Bug: 1012136
Change-Id: Icd13e1d672701c962e88d9ce55a26a34547fa02a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2021463
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806901}
parent 562e61e7
......@@ -525,7 +525,8 @@ void FlexLayout::InitializeChildData(
// Keep track of non-hidden flex controls.
if (flex_child.flex.weight() > 0 ||
flex_child.current_size.main() < flex_child.preferred_size.main())
flex_child.current_size.main() < flex_child.preferred_size.main() ||
flex_child.flex.unlimited_main_axis_size())
(*flex_order_to_index)[flex_child.flex.order()].push_back(view_index);
child_layout.visible = flex_child.current_size.main() > 0;
......@@ -837,10 +838,13 @@ void FlexLayout::AllocateFlexSpace(
const NormalizedSizeBounds available(
child_spacing->GetMaxSize(view_index, current_size, flex_amount),
GetCrossAxis(orientation(), child_layout.available_size));
const bool desires_unlimited_size =
!available.main().is_bounded() &&
flex_child.flex.unlimited_main_axis_size();
NormalizedSize desired_size = GetCurrentSizeForRule(
flex_child.flex.rule(), child_layout.child_view, available);
if (desired_size.main() <= 0)
if (desired_size.main() <= 0 && !desires_unlimited_size)
continue;
// Limit the expansion of views past their preferred size in the first
......@@ -848,9 +852,11 @@ void FlexLayout::AllocateFlexSpace(
// them to |expandable_views| so that the remaining space can be allocated
// later.
if (expandable_views &&
desired_size.main() > flex_child.preferred_size.main()) {
(desired_size.main() > flex_child.preferred_size.main() ||
desires_unlimited_size)) {
(*expandable_views)[flex_order].push_back(view_index);
desired_size.set_main(flex_child.preferred_size.main());
desired_size.set_main(
std::min(flex_child.preferred_size.main(), desired_size.main()));
}
// Increasing the child size should not result in a net total size
......@@ -864,7 +870,7 @@ void FlexLayout::AllocateFlexSpace(
DCHECK_GE(to_deduct, 0);
// If the desired size increases (but is still within bounds), we can make
// the control visible and allocate the additional space.
if (to_deduct > 0 && to_deduct <= remaining) {
if ((to_deduct > 0 && to_deduct <= remaining) || desires_unlimited_size) {
flex_child.current_size = desired_size;
child_layout.visible = true;
remaining -= to_deduct;
......
......@@ -175,7 +175,10 @@ FlexSpecification::FlexSpecification(MinimumFlexSizeRule minimum_size_rule,
maximum_size_rule,
minimum_size_rule,
maximum_size_rule,
adjust_height_for_width)) {}
adjust_height_for_width)) {
unlimited_main_axis_size_ =
maximum_size_rule == MaximumFlexSizeRule::kUnbounded;
}
FlexSpecification::FlexSpecification(
LayoutOrientation orientation,
......@@ -196,7 +199,10 @@ FlexSpecification::FlexSpecification(
orientation == LayoutOrientation::kVertical
? maximum_main_axis_rule
: kDefaultMaximumFlexSizeRule,
adjust_height_for_width)) {}
adjust_height_for_width)) {
unlimited_main_axis_size_ =
maximum_main_axis_rule == MaximumFlexSizeRule::kUnbounded;
}
FlexSpecification::FlexSpecification(const FlexSpecification& other) = default;
......
......@@ -152,12 +152,14 @@ class VIEWS_EXPORT FlexSpecification {
int weight() const { return weight_; }
int order() const { return order_; }
LayoutAlignment alignment() const { return alignment_; }
bool unlimited_main_axis_size() const { return unlimited_main_axis_size_; }
private:
FlexRule rule_;
int order_ = 1;
int weight_ = 0;
LayoutAlignment alignment_ = LayoutAlignment::kStretch;
bool unlimited_main_axis_size_ = false;
};
// Represents insets in a single dimension.
......
......@@ -3033,6 +3033,20 @@ TEST_F(NestedFlexLayoutTest, UsingDefaultFlexRule) {
EXPECT_FALSE(grandchild(2, 2)->GetVisible());
}
TEST_F(NestedFlexLayoutTest, UnboundedZeroSize) {
AddChildren(1);
child(1)->SetProperty(views::kFlexBehaviorKey, kUnboundedScaleToZero);
AddGrandchild(1, gfx::Size(0, 5));
grandchild(1, 1)->SetProperty(views::kFlexBehaviorKey, kUnboundedScaleToZero);
EXPECT_EQ(5, child(1)->GetPreferredSize().height());
host_->SetSize(gfx::Size(100, 5));
EXPECT_EQ(5, child(1)->GetPreferredSize().height());
host_->Layout();
EXPECT_EQ(5, child(1)->height());
}
namespace {
struct DirectionalFlexRuleTestParamRules {
......
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