Skip to content

Commit c6f77f4

Browse files
Magnus Johanssonawesomekling
authored andcommitted
LibWeb: Fallback to auto when aspect ratio is degenerate as per spec
When aspect-ratio is degenerate (e.g. 0/1 or 1/0) we should fallback to the same behaviour as `aspect-ratio: auto` according to spec This commit explicitly handles this case and fixes five WPT test in css/css-sizing/aspect-ratio (zero-or-infinity-[006-010])
1 parent 20376ad commit c6f77f4

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (0,0) content-size 800x216 [BFC] children: not-inline
3+
BlockContainer <body> at (8,8) content-size 784x200 children: inline
4+
frag 0 from ImageBox start: 0, length: 0, rect: [8,8 200x200] baseline: 200
5+
ImageBox <img> at (8,8) content-size 200x200 children: not-inline
6+
7+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
8+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x216]
9+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x200]
10+
ImagePaintable (ImageBox<IMG>) [8,8 200x200]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!doctype html><style>
2+
img {
3+
width: 200px;
4+
aspect-ratio: 0/1;
5+
}
6+
</style><img src="120.png"/>

Userland/Libraries/LibWeb/Layout/Node.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,12 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
880880
} else if (aspect_ratio->is_keyword() && aspect_ratio->as_keyword().keyword() == CSS::Keyword::Auto) {
881881
computed_values.set_aspect_ratio({ true, {} });
882882
} else if (aspect_ratio->is_ratio()) {
883-
computed_values.set_aspect_ratio({ false, aspect_ratio->as_ratio().ratio() });
883+
// https://drafts.csswg.org/css-sizing-4/#aspect-ratio
884+
// If the <ratio> is degenerate, the property instead behaves as auto.
885+
if (aspect_ratio->as_ratio().ratio().is_degenerate())
886+
computed_values.set_aspect_ratio({ true, {} });
887+
else
888+
computed_values.set_aspect_ratio({ false, aspect_ratio->as_ratio().ratio() });
884889
}
885890

886891
auto math_shift_value = computed_style.property(CSS::PropertyID::MathShift);

0 commit comments

Comments
 (0)