Skip to content
Permalink
Browse files
Include aspect-ratio when calculating inline min-content size and add…
… min-content block computation

https://bugs.webkit.org/show_bug.cgi?id=243473

Reviewed by Rob Buis.

When we compute the content size suggestion of an element with a
preferred aspect ratio, we need to make sure that the minimum-content
size of the element is computed through the aspect ratio.
When the main axis is in the inline direction, we have to consider
whether or not an aspect-ratio is specified. If there is an aspect-ratio,
we must calculate the minimum-content size using that. Otherwise, we
will just compute the main axis extent for the child.

However, the definition of of the minimum-content size in the block
direction is slightly different. According to the CSS Sizing spec,
the min-content block size is: he box's "ideal" size in the block axis.
Usually the block size of the content after layout.

* LayoutTests/TestExpectations:
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::inlineSizeFromAspectRatio):

* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::computeFlexItemMinMaxSizes):
(WebCore::RenderFlexibleBox::adjustChildSizeForAspectRatioCrossAxisMinAndMax):

Canonical link: https://commits.webkit.org/253740@main
  • Loading branch information
sgill26 authored and Brent Fulgham committed Aug 24, 2022
1 parent e5bd3f4 commit 588e20666a36f28117f49082462513f03e25960e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
@@ -4718,12 +4718,9 @@ webkit.org/b/214462 imported/w3c/web-platform-tests/css/css-scoping/slotted-plac
# aspect-ratio (some of these rely on contain-intrinsic-size)
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-014.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/abspos-020.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-002.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-004.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-025.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-026.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-038.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-039.html [ ImageOnlyFailure ]
webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/floats-aspect-ratio-001.html [ ImageOnlyFailure ]

# contain-intrinsic-size
@@ -47,6 +47,8 @@
#include "RenderTable.h"
#include "RenderView.h"
#include "WritingMode.h"
#include "platform/LayoutUnit.h"
#include "rendering/RenderBox.h"
#include <limits>
#include <wtf/IsoMallocInlines.h>
#include <wtf/MathExtras.h>
@@ -1390,11 +1392,26 @@ std::pair<LayoutUnit, LayoutUnit> RenderFlexibleBox::computeFlexItemMinMaxSizes(
// ensure it's valid through the virtual calls of computeIntrinsicLogicalContentHeightUsing.
LayoutUnit contentSize;
Length childCrossSizeLength = crossSizeLengthForChild(MainOrPreferredSize, child);
if (child.isRenderReplaced() && childHasComputableAspectRatio(child) && childCrossSizeIsDefinite(child, childCrossSizeLength))
contentSize = computeMainSizeFromAspectRatioUsing(child, childCrossSizeLength);



bool mainSizeAxisIsInline = mainAxisIsChildInlineAxis(child);
bool canComputeSizeThroughAspectRatio = childHasComputableAspectRatio(child) && childCrossSizeIsDefinite(child, childCrossSizeLength);
auto computeMinContentSize = [this](RenderBox &child) -> LayoutUnit {
return computeMainAxisExtentForChild(child, MinSize, Length(LengthType::MinContent)).value_or(0);
};
auto computeSizeThroughAspectRatio = [this, canComputeSizeThroughAspectRatio] (RenderBox &child, Length childCrossSizeLength) {
return canComputeSizeThroughAspectRatio ? computeMainSizeFromAspectRatioUsing(child, childCrossSizeLength) : 0_lu;
};

if (mainSizeAxisIsInline && canComputeSizeThroughAspectRatio)
contentSize = computeSizeThroughAspectRatio(child, childCrossSizeLength);
else if (mainSizeAxisIsInline)
contentSize = computeMinContentSize(child);
else
contentSize = computeMainAxisExtentForChild(child, MinSize, Length(LengthType::MinContent)).value_or(0);
if (child.hasIntrinsicAspectRatio() && child.intrinsicSize().height())
contentSize = std::max(computeSizeThroughAspectRatio(child, childCrossSizeLength), computeMinContentSize(child));

if (childHasComputableAspectRatio(child) && (!crossSizeLengthForChild(MinSize, child).isAuto() || !crossSizeLengthForChild(MaxSize, child).isAuto()))
contentSize = adjustChildSizeForAspectRatioCrossAxisMinAndMax(child, contentSize);
ASSERT(contentSize >= 0);
contentSize = std::min(contentSize, maxExtent.value_or(contentSize));

0 comments on commit 588e206

Please sign in to comment.