Skip to content
Permalink
Browse files
Use intrinsic ratio of replaced elements when computing flex sizes
https://bugs.webkit.org/show_bug.cgi?id=247447
rdar://101922427

Reviewed by Alan Baradlay.

When computing sizes for replaced element flex items, we should check
to see if there is an intrinsic ratio and not rely on the intrinsic
sizes directly. This is because there are scenarios where an element
can only have an intrinsic size in only one dimension but still have
an aspect ratio. For example, a SVG could have an intrinsic width and
an intrinsic ratio. Since we could not compute the aspect ratio from
the intrinsic sizes, we must use the specified intrinsic ratio.

* LayoutTests/TestExpectations:
* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::computeMainSizeFromAspectRatioUsing const):
(WebCore::RenderFlexibleBox::computeFlexItemMinMaxSizes):
Here the call to childHasComputableAspectRatio was too strong. In cases
like the example above, the item would still have an aspect ratio but
this call would still return false.

Canonical link: https://commits.webkit.org/257474@main
  • Loading branch information
sgill26 committed Dec 7, 2022
1 parent 174dc21 commit 7e525946fafc8d09d531e4ac18b029b37fb3becb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
@@ -4372,8 +4372,6 @@ webkit.org/b/209080 imported/w3c/web-platform-tests/css/css-writing-modes/vertic
webkit.org/b/209080 imported/w3c/web-platform-tests/css/css-writing-modes/vertical-alignment-srl-040.xht [ ImageOnlyFailure ]

webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-img-column-012.html [ ImageOnlyFailure ]
webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-img-column-015.html [ ImageOnlyFailure ]
webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-img-row-010.html [ ImageOnlyFailure ]
webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/aspect-ratio-intrinsic-size-005.html [ ImageOnlyFailure ]

webkit.org/b/145176 imported/w3c/web-platform-tests/css/css-flexbox/flexbox_align-items-stretch-3.html [ ImageOnlyFailure ]
@@ -54,7 +54,7 @@
#include <wtf/IsoMallocInlines.h>
#include <wtf/MathExtras.h>
#include <wtf/SetForScope.h>

#include <wtf/TypeCasts.h>
namespace WebCore {

WTF_MAKE_ISO_ALLOCATED_IMPL(RenderFlexibleBox);
@@ -994,8 +994,12 @@ LayoutUnit RenderFlexibleBox::computeMainSizeFromAspectRatioUsing(const RenderBo
else
borderAndPadding = isHorizontalFlow() ? child.horizontalBorderAndPaddingExtent() : child.verticalBorderAndPaddingExtent();
} else {
ASSERT(childIntrinsicSize.height());
ratio = childIntrinsicSize.width().toFloat() / childIntrinsicSize.height().toFloat();
if (auto* replacedElement = dynamicDowncast<RenderReplaced>(child))
ratio = replacedElement->computeIntrinsicAspectRatio();
else {
ASSERT(childIntrinsicSize.height());
ratio = childIntrinsicSize.width().toFloat() / childIntrinsicSize.height().toFloat();
}
crossSize = adjustForBoxSizing(child, crossSize);
}
}
@@ -1447,7 +1451,7 @@ std::pair<LayoutUnit, LayoutUnit> RenderFlexibleBox::computeFlexItemMinMaxSizes(
else
contentSize = computeMainAxisExtentForChild(child, MinSize, Length(LengthType::MinContent)).value_or(0_lu);

if (childHasComputableAspectRatio(child) && (!crossSizeLengthForChild(MinSize, child).isAuto() || !crossSizeLengthForChild(MaxSize, child).isAuto()))
if (childHasAspectRatio(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 7e52594

Please sign in to comment.