Modified: trunk/Source/WebCore/ChangeLog (278449 => 278450)
--- trunk/Source/WebCore/ChangeLog 2021-06-04 06:35:37 UTC (rev 278449)
+++ trunk/Source/WebCore/ChangeLog 2021-06-04 08:03:35 UTC (rev 278450)
@@ -1,3 +1,32 @@
+2021-05-27 Sergio Villar Senin <svil...@igalia.com>
+
+ [css-flexbox] Sanitize the aspect ratio handling code
+ https://bugs.webkit.org/show_bug.cgi?id=226324
+
+ Reviewed by Javier Fernandez.
+
+ Sanitized the code that detects whether aspect ratio should be used to compute sizes. The
+ useChildAspectRatio() method was removed as it was very misleading, the name was a bad choice
+ and it was very confusing. A new method childHasComputableAspectRatio() was added. It verifies
+ whether the item has an aspect ratio (of any type) and whether we could compute it.
+
+ Also two calls to detect whether the cross size was definite (or considered definite) were
+ unified in a single method.
+
+ No new tests as there is no change in behaviour.
+
+ * rendering/RenderFlexibleBox.cpp:
+ (WebCore::RenderFlexibleBox::childHasComputableAspectRatio const): New method which takes the
+ checks from useChildAspectRatio.
+ (WebCore::RenderFlexibleBox::childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite):
+ New method doing 3 different checks.
+ (WebCore::RenderFlexibleBox::childCrossSizeShouldUseContainerCrossSize const): Removed the aspect
+ ratio checks which make no sense there.
+ (WebCore::RenderFlexibleBox::computeInnerFlexBaseSizeForChild): Use the new method.
+ (WebCore::RenderFlexibleBox::adjustChildSizeForMinAndMax): Ditto.
+ (WebCore::RenderFlexibleBox::useChildAspectRatio): Deleted.
+ * rendering/RenderFlexibleBox.h:
+
2021-06-03 Jean-Yves Avenard <j...@apple.com>
fast/dom/Window/property-access-on-cached-window-after-frame-removed.html (layout-test) may crash
Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (278449 => 278450)
--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp 2021-06-04 06:35:37 UTC (rev 278449)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp 2021-06-04 08:03:35 UTC (rev 278450)
@@ -791,17 +791,6 @@
return { };
}
-bool RenderFlexibleBox::useChildAspectRatio(const RenderBox& child)
-{
- if (!childHasAspectRatio(child))
- return false;
- if (!child.intrinsicSize().height() && !child.style().hasAspectRatio()) {
- // We can't compute a ratio in this case.
- return false;
- }
- return childCrossSizeIsDefinite(child, crossSizeLengthForChild(MainOrPreferredSize, child));
-}
-
// FIXME: computeMainSizeFromAspectRatioUsing may need to return an std::optional<LayoutUnit> in the future
// rather than returning indefinite sizes as 0/-1.
LayoutUnit RenderFlexibleBox::computeMainSizeFromAspectRatioUsing(const RenderBox& child, Length crossSizeLength) const
@@ -882,15 +871,21 @@
return true;
}
-bool RenderFlexibleBox::childCrossSizeShouldUseContainerCrossSize(const RenderBox& child) const
+bool RenderFlexibleBox::childHasComputableAspectRatio(const RenderBox& child) const
{
if (!childHasAspectRatio(child))
return false;
- if (!child.intrinsicSize().height() && !child.style().hasAspectRatio()) {
- // We can't compute a ratio in this case.
- return false;
- }
+ return child.intrinsicSize().height() || child.style().hasAspectRatio();
+}
+bool RenderFlexibleBox::childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite(const RenderBox& child)
+{
+ return childHasComputableAspectRatio(child)
+ && (childCrossSizeIsDefinite(child, crossSizeLengthForChild(MainOrPreferredSize, child)) || childCrossSizeShouldUseContainerCrossSize(child));
+}
+
+bool RenderFlexibleBox::childCrossSizeShouldUseContainerCrossSize(const RenderBox& child) const
+{
// 9.8 https://drafts.csswg.org/css-flexbox/#definite-sizes
// 1. If a single-line flex container has a definite cross size, the automatic preferred outer cross size of any
// stretched flex items is the flex container's inner cross size (clamped to the flex item's min and max cross size)
@@ -952,7 +947,7 @@
if (childMainSizeIsDefinite(child, flexBasis))
return std::max(0_lu, computeMainAxisExtentForChild(child, MainOrPreferredSize, flexBasis).value());
- if (useChildAspectRatio(child) || childCrossSizeShouldUseContainerCrossSize(child)) {
+ if (childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite(child)) {
const Length& crossSizeLength = crossSizeLengthForChild(MainOrPreferredSize, child);
return adjustChildSizeForAspectRatioCrossAxisMinAndMax(child, computeMainSizeFromAspectRatioUsing(child, crossSizeLength));
}
@@ -1225,7 +1220,7 @@
// ensure it's valid through the virtual calls of computeIntrinsicLogicalContentHeightUsing.
LayoutUnit contentSize;
Length childCrossSizeLength = crossSizeLengthForChild(MainOrPreferredSize, child);
- if (child.isRenderReplaced() && useChildAspectRatio(child))
+ if (child.isRenderReplaced() && childHasComputableAspectRatio(child) && childCrossSizeIsDefinite(child, childCrossSizeLength))
contentSize = computeMainSizeFromAspectRatioUsing(child, childCrossSizeLength);
else
contentSize = computeMainAxisExtentForChild(child, MinSize, Length(LengthType::MinContent)).value_or(0);
@@ -1242,7 +1237,7 @@
return std::max(childSize, std::min(specifiedSize, contentSize));
}
- if (child.isRenderReplaced() && (useChildAspectRatio(child) || childCrossSizeShouldUseContainerCrossSize(child))) {
+ if (child.isRenderReplaced() && childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite(child)) {
LayoutUnit transferredSize = computeMainSizeFromAspectRatioUsing(child, childCrossSizeLength);
transferredSize = adjustChildSizeForAspectRatioCrossAxisMinAndMax(child, transferredSize);
return std::max(childSize, std::min(transferredSize, contentSize));
Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (278449 => 278450)
--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h 2021-06-04 06:35:37 UTC (rev 278449)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h 2021-06-04 08:03:35 UTC (rev 278450)
@@ -142,7 +142,8 @@
LayoutUnit crossAxisScrollbarExtent() const;
LayoutUnit crossAxisScrollbarExtentForChild(const RenderBox& child) const;
LayoutPoint flowAwareLocationForChild(const RenderBox& child) const;
- bool useChildAspectRatio(const RenderBox& child);
+ bool childHasComputableAspectRatio(const RenderBox&) const;
+ bool childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite(const RenderBox&);
bool childCrossSizeShouldUseContainerCrossSize(const RenderBox& child) const;
LayoutUnit computeMainSizeFromAspectRatioUsing(const RenderBox& child, Length crossSizeLength) const;
void setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint&);