Commit fdc7d6d5 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

[css-flexbox] Resolve min-width:auto on table item to min preferred size.

Edge and Firefox seem to let table flex items use the sizing algorithm
of the table extensively, and are therefore generally broken when it
comes to flexing tables. We, on the other hand, let the flex sizing
algorithm be in charge of sizing tables, so that flexing actually works.
However, this causes tables with a specified main size of less than the
minimum intrinsic logical width of the table to shrink below their
minimum intrinsic logical width, a situation that's generally unwanted
for tables.

Amend by ignoring the specified main size when resolving min-width:auto
on table items. Also ignore max-width/max-height. Just use the
preferred minimum logical width.

Bug: 821832
Change-Id: I78ca0c8e0041ea69bb606ff72d340bb3f5f9bb96
Reviewed-on: https://chromium-review.googlesource.com/964203Reviewed-by: default avatarDavid Grogan <dgrogan@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545777}
parent c690c549
<!DOCTYPE html>
<title>CSS Flexbox Test: Flex item as table, specified width less than minimum intrinsic width</title>
<link rel="author" title="Morten Stenshorne" href="mailto:mstensho@chromium.org">
<link rel="help" href="https://www.w3.org/TR/css-flexbox-1/#layout-algorithm" title="9. Flex Layout Algorithm">
<link rel="match" href="../reference/ref-filled-green-100px-square.xht">
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div style="display:flex; width:100px; background:red;">
<div style="display:table; width:10px; max-width:10px; height:100px; background:green;">
<div style="width:100px; height:10px; background:green;"></div>
</div>
</div>
...@@ -1089,30 +1089,37 @@ MinMaxSize LayoutFlexibleBox::ComputeMinAndMaxSizesForChild( ...@@ -1089,30 +1089,37 @@ MinMaxSize LayoutFlexibleBox::ComputeMinAndMaxSizesForChild(
if (HasAspectRatio(child) && child.IntrinsicSize().Height() > 0) if (HasAspectRatio(child) && child.IntrinsicSize().Height() > 0)
content_size = content_size =
AdjustChildSizeForAspectRatioCrossAxisMinAndMax(child, content_size); AdjustChildSizeForAspectRatioCrossAxisMinAndMax(child, content_size);
if (sizes.max_size != -1 && content_size > sizes.max_size) if (child.IsTable() && !IsColumnFlow()) {
content_size = sizes.max_size; // Avoid resolving minimum size to something narrower than the minimum
// preferred logical width of the table.
Length main_size = IsHorizontalFlow() ? child.StyleRef().Width()
: child.StyleRef().Height();
if (MainAxisLengthIsDefinite(child, main_size)) {
LayoutUnit resolved_main_size =
ComputeMainAxisExtentForChild(child, kMainOrPreferredSize, main_size);
DCHECK_GE(resolved_main_size, LayoutUnit());
LayoutUnit specified_size =
sizes.max_size != -1 ? std::min(resolved_main_size, sizes.max_size)
: resolved_main_size;
sizes.min_size = std::min(specified_size, content_size);
} else if (UseChildAspectRatio(child)) {
Length cross_size_length = IsHorizontalFlow() ? child.StyleRef().Height()
: child.StyleRef().Width();
LayoutUnit transferred_size =
ComputeMainSizeFromAspectRatioUsing(child, cross_size_length);
transferred_size = AdjustChildSizeForAspectRatioCrossAxisMinAndMax(
child, transferred_size);
sizes.min_size = std::min(transferred_size, content_size);
} else {
sizes.min_size = content_size; sizes.min_size = content_size;
} else {
if (sizes.max_size != -1 && content_size > sizes.max_size)
content_size = sizes.max_size;
Length main_size = IsHorizontalFlow() ? child.StyleRef().Width()
: child.StyleRef().Height();
if (MainAxisLengthIsDefinite(child, main_size)) {
LayoutUnit resolved_main_size = ComputeMainAxisExtentForChild(
child, kMainOrPreferredSize, main_size);
DCHECK_GE(resolved_main_size, LayoutUnit());
LayoutUnit specified_size =
sizes.max_size != -1 ? std::min(resolved_main_size, sizes.max_size)
: resolved_main_size;
sizes.min_size = std::min(specified_size, content_size);
} else if (UseChildAspectRatio(child)) {
Length cross_size_length = IsHorizontalFlow()
? child.StyleRef().Height()
: child.StyleRef().Width();
LayoutUnit transferred_size =
ComputeMainSizeFromAspectRatioUsing(child, cross_size_length);
transferred_size = AdjustChildSizeForAspectRatioCrossAxisMinAndMax(
child, transferred_size);
sizes.min_size = std::min(transferred_size, content_size);
} else {
sizes.min_size = content_size;
}
} }
} }
DCHECK_GE(sizes.min_size, LayoutUnit()); DCHECK_GE(sizes.min_size, LayoutUnit());
......
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