Skip to content

Commit 27ddfa8

Browse files
committed
LibWeb: Accept height: {min,max,fit}-content
And treat them as "auto" for now, per CSS-SIZING-3, with a FIXME about supporting more layout directions. This fixes an issue on MDN where `height: max-content` was not overriding height from non-CSS presentational hints.
1 parent 90e95d3 commit 27ddfa8

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (0,0) content-size 800x139.46875 [BFC] children: not-inline
3+
BlockContainer <body> at (8,8) content-size 784x123.46875 children: inline
4+
line 0 width: 376, height: 123.46875, bottom: 123.46875, baseline: 120
5+
frag 0 from ImageBox start: 0, length: 0, rect: [8,8 120x120]
6+
frag 1 from TextNode start: 0, length: 1, rect: [128,114 8x17.46875]
7+
" "
8+
frag 2 from ImageBox start: 0, length: 0, rect: [136,8 120x120]
9+
frag 3 from TextNode start: 0, length: 1, rect: [256,114 8x17.46875]
10+
" "
11+
frag 4 from ImageBox start: 0, length: 0, rect: [264,8 120x120]
12+
ImageBox <img.min> at (8,8) content-size 120x120 children: not-inline
13+
TextNode <#text>
14+
ImageBox <img.max> at (136,8) content-size 120x120 children: not-inline
15+
TextNode <#text>
16+
ImageBox <img.fit> at (264,8) content-size 120x120 children: not-inline
17+
TextNode <#text>
18+
19+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
20+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x139.46875]
21+
PaintableWithLines (BlockContainer<BODY>) [8,8 784x123.46875]
22+
ImagePaintable (ImageBox<IMG>.min) [8,8 120x120]
23+
TextPaintable (TextNode<#text>)
24+
ImagePaintable (ImageBox<IMG>.max) [136,8 120x120]
25+
TextPaintable (TextNode<#text>)
26+
ImagePaintable (ImageBox<IMG>.fit) [264,8 120x120]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!doctype html><style>
2+
.min{ height: min-content; }
3+
.max { height: max-content; }
4+
.fit { height: fit-content; }
5+
</style>
6+
<img class="min" src="120.png" width="120" height="60" />
7+
<img class="max" src="120.png" width="120" height="60" />
8+
<img class="fit" src="120.png" width="120" height="60" />

Userland/Libraries/LibWeb/CSS/Properties.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,10 @@
11821182
"percentage [0,∞]"
11831183
],
11841184
"valid-identifiers": [
1185-
"auto"
1185+
"auto",
1186+
"fit-content",
1187+
"max-content",
1188+
"min-content"
11861189
],
11871190
"percentages-resolve-to": "length",
11881191
"quirks": [

Userland/Libraries/LibWeb/Layout/FormattingContext.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,8 +1627,18 @@ bool FormattingContext::should_treat_width_as_auto(Box const& box, AvailableSpac
16271627

16281628
bool FormattingContext::should_treat_height_as_auto(Box const& box, AvailableSpace const& available_space)
16291629
{
1630-
if (box.computed_values().height().is_auto())
1630+
auto computed_height = box.computed_values().height();
1631+
if (computed_height.is_auto())
1632+
return true;
1633+
1634+
// https://www.w3.org/TR/css-sizing-3/#valdef-width-min-content
1635+
// https://www.w3.org/TR/css-sizing-3/#valdef-width-max-content
1636+
// https://www.w3.org/TR/css-sizing-3/#valdef-width-fit-content
1637+
// For a box’s block size, unless otherwise specified, this is equivalent to its automatic size.
1638+
// FIXME: If height is not the block axis size, then we should be concerned with the width instead.
1639+
if (computed_height.is_min_content() || computed_height.is_max_content() || computed_height.is_fit_content())
16311640
return true;
1641+
16321642
if (box.computed_values().height().contains_percentage()) {
16331643
if (available_space.height.is_max_content())
16341644
return true;

0 commit comments

Comments
 (0)