Commit bb21fa7b authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[AspectRatio] Support min-size: auto in legacy

R=ikilpatrick@chromium.org

Bug: 1083010
Change-Id: I2c3bfe0990df216e499142194d4ecb20cd9405e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401502
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Auto-Submit: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806145}
parent b0fdfebe
...@@ -1072,9 +1072,7 @@ LayoutUnit LayoutBox::ConstrainLogicalWidthByMinMax( ...@@ -1072,9 +1072,7 @@ LayoutUnit LayoutBox::ConstrainLogicalWidthByMinMax(
// This implements the transferred min/max sizes per // This implements the transferred min/max sizes per
// https://drafts.csswg.org/css-sizing-4/#aspect-ratio // https://drafts.csswg.org/css-sizing-4/#aspect-ratio
Length h = style_to_use.LogicalHeight(); Length h = style_to_use.LogicalHeight();
if (style_to_use.AspectRatio() && if (ShouldComputeLogicalHeightFromAspectRatio()) {
(h.IsAuto() || (h.IsPercentOrCalc() &&
ComputePercentageLogicalHeight(h) == kIndefiniteSize))) {
MinMaxSizes transferred_min_max = MinMaxSizes transferred_min_max =
ComputeMinMaxLogicalWidthFromAspectRatio(); ComputeMinMaxLogicalWidthFromAspectRatio();
logical_width = transferred_min_max.ClampSizeToMinAndMax(logical_width); logical_width = transferred_min_max.ClampSizeToMinAndMax(logical_width);
...@@ -1085,9 +1083,18 @@ LayoutUnit LayoutBox::ConstrainLogicalWidthByMinMax( ...@@ -1085,9 +1083,18 @@ LayoutUnit LayoutBox::ConstrainLogicalWidthByMinMax(
logical_width, logical_width,
ComputeLogicalWidthUsing(kMaxSize, style_to_use.LogicalMaxWidth(), ComputeLogicalWidthUsing(kMaxSize, style_to_use.LogicalMaxWidth(),
available_width, cb)); available_width, cb));
return std::max(logical_width, ComputeLogicalWidthUsing(
kMinSize, style_to_use.LogicalMinWidth(), // If we have an aspect-ratio, check if we need to apply min-width: auto.
available_width, cb)); Length min_length = style_to_use.LogicalMinWidth();
if (style_to_use.AspectRatio() && style_to_use.LogicalWidth().IsAuto() &&
min_length.IsAuto() &&
style_to_use.OverflowInlineDirection() == EOverflow::kVisible) {
// Make sure we actually used the aspect ratio.
if (ShouldComputeLogicalWidthFromAspectRatio())
min_length = Length::MinIntrinsic();
}
return std::max(logical_width, ComputeLogicalWidthUsing(kMinSize, min_length,
available_width, cb));
} }
LayoutUnit LayoutBox::ConstrainLogicalHeightByMinMax( LayoutUnit LayoutBox::ConstrainLogicalHeightByMinMax(
...@@ -1106,6 +1113,12 @@ LayoutUnit LayoutBox::ConstrainLogicalHeightByMinMax( ...@@ -1106,6 +1113,12 @@ LayoutUnit LayoutBox::ConstrainLogicalHeightByMinMax(
logical_height = std::min(logical_height, max_h); logical_height = std::min(logical_height, max_h);
} }
Length logical_min_height = StyleRef().LogicalMinHeight(); Length logical_min_height = StyleRef().LogicalMinHeight();
if (logical_min_height.IsAuto() &&
ShouldComputeLogicalHeightFromAspectRatio() &&
intrinsic_content_height != kIndefiniteSize &&
StyleRef().OverflowBlockDirection() == EOverflow::kVisible) {
logical_min_height = Length::Fixed(intrinsic_content_height);
}
if (logical_min_height.IsMinContent() || logical_min_height.IsMaxContent() || if (logical_min_height.IsMinContent() || logical_min_height.IsMaxContent() ||
logical_min_height.IsMinIntrinsic() || logical_min_height.IsFitContent()) logical_min_height.IsMinIntrinsic() || logical_min_height.IsFitContent())
logical_min_height = Length::Auto(); logical_min_height = Length::Auto();
...@@ -3597,18 +3610,29 @@ LayoutUnit LayoutBox::ContainerWidthInInlineDirection() const { ...@@ -3597,18 +3610,29 @@ LayoutUnit LayoutBox::ContainerWidthInInlineDirection() const {
return PerpendicularContainingBlockLogicalHeight().ClampNegativeToZero(); return PerpendicularContainingBlockLogicalHeight().ClampNegativeToZero();
} }
bool LayoutBox::ComputeLogicalWidthFromAspectRatio( bool LayoutBox::ShouldComputeLogicalWidthFromAspectRatio(
LayoutUnit* out_logical_width) const { LayoutUnit* out_logical_height) const {
LayoutUnit logical_height_for_ar = kIndefiniteSize; if (!StyleRef().AspectRatio() ||
if (StyleRef().AspectRatio() && (!StyleRef().LogicalHeight().IsFixed() &&
(StyleRef().LogicalHeight().IsFixed() || !StyleRef().LogicalHeight().IsPercentOrCalc())) {
StyleRef().LogicalHeight().IsPercentOrCalc())) { return false;
logical_height_for_ar = ComputeLogicalHeightUsing(
kMainOrPreferredSize, StyleRef().LogicalHeight(),
/* intrinsic_content_height */ kIndefiniteSize);
} }
if (logical_height_for_ar == kIndefiniteSize) LayoutUnit logical_height = ComputeLogicalHeightUsing(
kMainOrPreferredSize, StyleRef().LogicalHeight(),
/* intrinsic_content_height */ kIndefiniteSize);
if (logical_height == kIndefiniteSize)
return false;
if (out_logical_height)
*out_logical_height = logical_height;
return true;
}
bool LayoutBox::ComputeLogicalWidthFromAspectRatio(
LayoutUnit* out_logical_width) const {
LayoutUnit logical_height_for_ar;
if (!ShouldComputeLogicalWidthFromAspectRatio(&logical_height_for_ar))
return false; return false;
LayoutUnit container_width_in_inline_direction = LayoutUnit container_width_in_inline_direction =
...@@ -4197,9 +4221,7 @@ void LayoutBox::ComputeLogicalHeight( ...@@ -4197,9 +4221,7 @@ void LayoutBox::ComputeLogicalHeight(
LayoutUnit height_result; LayoutUnit height_result;
if (check_min_max_height) { if (check_min_max_height) {
if (StyleRef().AspectRatio() && if (ShouldComputeLogicalHeightFromAspectRatio()) {
(h.IsAuto() || (h.IsPercentOrCalc() && ComputePercentageLogicalHeight(
h) == kIndefiniteSize))) {
NGBoxStrut border_padding(BorderStart() + ComputedCSSPaddingStart(), NGBoxStrut border_padding(BorderStart() + ComputedCSSPaddingStart(),
BorderEnd() + ComputedCSSPaddingEnd(), BorderEnd() + ComputedCSSPaddingEnd(),
BorderBefore() + ComputedCSSPaddingBefore(), BorderBefore() + ComputedCSSPaddingBefore(),
......
...@@ -492,6 +492,19 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject { ...@@ -492,6 +492,19 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
bool CanResize() const; bool CanResize() const;
LayoutUnit ContainerWidthInInlineDirection() const; LayoutUnit ContainerWidthInInlineDirection() const;
// Whether we should (and are able to) compute the logical width using the
// aspect ratio. Since we compute the logical *height* as part of this check,
// we provide it in an optional out parameter in case the caller needs it
// (only valid if this function returns true).
bool ShouldComputeLogicalWidthFromAspectRatio(
LayoutUnit* logical_height = nullptr) const;
bool ShouldComputeLogicalHeightFromAspectRatio() const {
Length h = StyleRef().LogicalHeight();
return StyleRef().AspectRatio() &&
(h.IsAuto() ||
(h.IsPercentOrCalc() &&
ComputePercentageLogicalHeight(h) == kIndefiniteSize));
}
bool ComputeLogicalWidthFromAspectRatio(LayoutUnit* logical_width) const; bool ComputeLogicalWidthFromAspectRatio(LayoutUnit* logical_width) const;
MinMaxSizes ComputeMinMaxLogicalWidthFromAspectRatio() const; MinMaxSizes ComputeMinMaxLogicalWidthFromAspectRatio() const;
......
...@@ -128,13 +128,8 @@ crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-008.tentative. ...@@ -128,13 +128,8 @@ crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-008.tentative.
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-009.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-009.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-010.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-010.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-011.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/abspos-011.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-009.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-014.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-015.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-017.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-024.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-024.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-028.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/block-aspect-ratio-028.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/flex-aspect-ratio-008.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/flex-aspect-ratio-009.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/flex-aspect-ratio-009.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/percentage-resolution-001.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/percentage-resolution-001.tentative.html [ Failure ]
crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/percentage-resolution-002.tentative.html [ Failure ] crbug.com/1045668 external/wpt/css/css-sizing/aspect-ratio/percentage-resolution-002.tentative.html [ Failure ]
......
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