Skip to content

Commit 1eee13b

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
Fix transferred min/max constraints inflating percentage-default zero intrinsic dimensions
https://bugs.webkit.org/show_bug.cgi?id=308075 rdar://170765025 Reviewed by Alan Baradlay. When an SVG image has a percentage-based width or height (the default "100%" when the attribute is omitted), the intrinsic dimension is reported as 0. The transferred min/max constraint logic in computeIntrinsicSizesConstrainedByTransferredMinMaxSizes was applying min-height/min-width via the aspect ratio to clamp these zeros upward, making the dimension appear intrinsic and causing the wrong sizing path to be taken. For example, an SVG with only an intrinsic height of 25px and a 2:1 ratio would get its zero intrinsic width clamped to 40px via a transferred min-height: 20px, producing 40x20 instead of the correct 50x25. Fix by skipping the min-constraint when the dimension is zero, since zero here means "no intrinsic dimension" rather than an explicit zero. Max-constraints are still applied unconditionally as they can only shrink non-zero values. * Source/WebCore/rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::computeIntrinsicSizesConstrainedByTransferredMinMaxSizes): * LayoutTests/TestExpectations: Progressions Canonical link: https://commits.webkit.org/308212@main
1 parent 5718d09 commit 1eee13b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

LayoutTests/TestExpectations

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4485,7 +4485,6 @@ imported/w3c/web-platform-tests/css/css-sizing/block-size-with-min-or-max-conten
44854485
imported/w3c/web-platform-tests/css/css-sizing/block-size-with-min-or-max-content-4.html [ ImageOnlyFailure ]
44864486
imported/w3c/web-platform-tests/css/css-sizing/fit-content-max-inline-size.tentative.html [ ImageOnlyFailure ]
44874487
imported/w3c/web-platform-tests/css/css-sizing/fit-content-min-inline-size.html [ ImageOnlyFailure ]
4488-
imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-replaced-019.html [ ImageOnlyFailure ]
44894488
imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-replaced-023.html [ ImageOnlyFailure ]
44904489
imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-replaced-026.html [ ImageOnlyFailure ]
44914490
imported/w3c/web-platform-tests/css/css-sizing/intrinsic-percent-replaced-030.tentative.html [ ImageOnlyFailure ]
@@ -8171,10 +8170,6 @@ imported/w3c/web-platform-tests/css/CSS2/visudet/inline-block-baseline-003.xht [
81718170
imported/w3c/web-platform-tests/css/CSS2/visudet/inline-block-baseline-004.xht [ ImageOnlyFailure ]
81728171
imported/w3c/web-platform-tests/css/CSS2/visudet/inline-block-baseline-005.xht [ ImageOnlyFailure ]
81738172
imported/w3c/web-platform-tests/css/CSS2/visudet/inline-block-baseline-006.xht [ ImageOnlyFailure ]
8174-
imported/w3c/web-platform-tests/css/CSS2/visudet/replaced-elements-min-height-20.html [ ImageOnlyFailure ]
8175-
imported/w3c/web-platform-tests/css/CSS2/visudet/replaced-elements-min-height-40.html [ ImageOnlyFailure ]
8176-
imported/w3c/web-platform-tests/css/CSS2/visudet/replaced-elements-min-width-40.html [ ImageOnlyFailure ]
8177-
imported/w3c/web-platform-tests/css/CSS2/visudet/replaced-elements-min-width-80.html [ ImageOnlyFailure ]
81788173

81798174
imported/w3c/web-platform-tests/css/CSS2/abspos/remove-block-between-inline-and-abspos.html [ ImageOnlyFailure ]
81808175

Source/WebCore/rendering/RenderReplaced.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,17 @@ void RenderReplaced::computeIntrinsicSizesConstrainedByTransferredMinMaxSizes(Re
526526
auto [minLogicalHeight, maxLogicalHeight] = computeMinMaxLogicalHeightFromAspectRatio();
527527
removeBorderAndPaddingFromMinMaxSizes(minLogicalHeight, maxLogicalHeight, borderAndPaddingLogicalHeight());
528528

529-
intrinsicSize.setWidth(std::clamp(LayoutUnit { intrinsicSize.width() }, minLogicalWidth, maxLogicalWidth));
530-
intrinsicSize.setHeight(std::clamp(LayoutUnit { intrinsicSize.height() }, minLogicalHeight, maxLogicalHeight));
529+
// Only apply min-constraints upward when the dimension is actually intrinsic (non-zero).
530+
// Max-constraints can always be applied since they only shrink values.
531+
LayoutUnit width { intrinsicSize.width() };
532+
if (width > 0)
533+
width = std::max(width, minLogicalWidth);
534+
intrinsicSize.setWidth(std::min(width, maxLogicalWidth));
535+
536+
LayoutUnit height { intrinsicSize.height() };
537+
if (height > 0)
538+
height = std::max(height, minLogicalHeight);
539+
intrinsicSize.setHeight(std::min(height, maxLogicalHeight));
531540
}
532541
}
533542

0 commit comments

Comments
 (0)