1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

LibWeb: Support max-content for width, min-width and max-width

We're gonna need to handle this in many more places, this patch only
adds it to calculate_inner_width().
This commit is contained in:
Andreas Kling 2023-05-28 18:18:34 +02:00
parent 358d94b57a
commit 97c510329c
4 changed files with 53 additions and 1 deletions

View file

@ -0,0 +1,24 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (1,1) content-size 798x76.40625 [BFC] children: not-inline
BlockContainer <body> at (10,10) content-size 780x58.40625 children: not-inline
BlockContainer <div.foo> at (11,11) content-size 150.21875x17.46875 children: inline
line 0 width: 150.21875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 18, rect: [11,11 150.21875x17.46875]
"width: max-content"
TextNode <#text>
BlockContainer <(anonymous)> at (10,29.46875) content-size 780x0 children: inline
TextNode <#text>
BlockContainer <div.bar> at (11,30.46875) content-size 187.953125x17.46875 children: inline
line 0 width: 187.953125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 22, rect: [11,30.46875 187.953125x17.46875]
"max-width: max-content"
TextNode <#text>
BlockContainer <(anonymous)> at (10,48.9375) content-size 780x0 children: inline
TextNode <#text>
BlockContainer <div.baz> at (11,49.9375) content-size 183.078125x17.46875 children: inline
line 0 width: 183.078125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 22, rect: [11,49.9375 183.078125x17.46875]
"min-width: max-content"
TextNode <#text>
BlockContainer <(anonymous)> at (10,68.40625) content-size 780x0 children: inline
TextNode <#text>

View file

@ -0,0 +1,22 @@
<!doctype html><style>
* {
border: 1px solid black;
}
.foo {
background: pink;
width: max-content;
}
.bar {
background: orange;
width: 50%;
max-width: max-content;
}
.baz {
background: magenta;
width: 1%;
min-width: max-content;
}
</style>
<div class="foo">width: max-content</div>
<div class="bar">max-width: max-content</div>
<div class="baz">min-width: max-content</div>

View file

@ -1338,6 +1338,7 @@
],
"valid-identifiers": [
"fit-content",
"max-content",
"none"
],
"quirks": [
@ -1374,6 +1375,7 @@
"valid-identifiers": [
"auto",
"fit-content",
"max-content",
"none"
],
"quirks": [
@ -1773,7 +1775,8 @@
],
"valid-identifiers": [
"auto",
"fit-content"
"fit-content",
"max-content"
],
"quirks": [
"unitless-length"

View file

@ -1349,6 +1349,9 @@ CSS::Length FormattingContext::calculate_inner_width(Layout::Box const& box, Ava
if (width.is_fit_content()) {
return CSS::Length::make_px(calculate_fit_content_width(box, AvailableSpace { available_width, AvailableSize::make_indefinite() }));
}
if (width.is_max_content()) {
return CSS::Length::make_px(calculate_max_content_width(box));
}
auto& computed_values = box.computed_values();
if (computed_values.box_sizing() == CSS::BoxSizing::BorderBox) {