LibWeb: Improve justify-content in abspos static position of flex child

Also, add a test so we know these actually work correctly now. :^)
This commit is contained in:
Andreas Kling 2023-07-04 13:28:47 +02:00 committed by Jelle Raaijmakers
parent 859ac200b7
commit 80a734d42e
Notes: sideshowbarker 2024-07-17 10:54:57 +09:00
3 changed files with 300 additions and 28 deletions

View file

@ -0,0 +1,229 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (1,1) content-size 798x1754 [BFC] children: not-inline
BlockContainer <body> at (10,10) content-size 780x1736 children: not-inline
BlockContainer <(anonymous)> at (10,10) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.outer.start> at (11,11) content-size 300x60 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (11,12) content-size 150x50 positioned [BFC] children: inline
line 0 width: 41.234375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 5, rect: [11,12 41.234375x17.46875]
"start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,72) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.outer.flex-start> at (11,73) content-size 300x60 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (11,74) content-size 150x50 positioned [BFC] children: inline
line 0 width: 76.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 10, rect: [11,74 76.8125x17.46875]
"flex-start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,134) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.outer.end> at (11,135) content-size 300x60 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (161,136) content-size 150x50 positioned [BFC] children: inline
line 0 width: 26.1875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 3, rect: [161,136 26.1875x17.46875]
"end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,196) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.outer.flex-end> at (11,197) content-size 300x60 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (161,198) content-size 150x50 positioned [BFC] children: inline
line 0 width: 61.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 8, rect: [161,198 61.765625x17.46875]
"flex-end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,258) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.outer.center> at (11,259) content-size 300x60 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (86,260) content-size 150x50 positioned [BFC] children: inline
line 0 width: 51.625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 6, rect: [86,260 51.625x17.46875]
"center"
TextNode <#text>
BlockContainer <(anonymous)> at (10,320) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.outer.space-around> at (11,321) content-size 300x60 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (86,322) content-size 150x50 positioned [BFC] children: inline
line 0 width: 107.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 12, rect: [86,322 107.96875x17.46875]
"space-around"
TextNode <#text>
BlockContainer <(anonymous)> at (10,382) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.outer.space-between> at (11,383) content-size 300x60 flex-container(row) [FFC] children: not-inline
BlockContainer <div> at (11,384) content-size 150x50 positioned [BFC] children: inline
line 0 width: 115.515625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 13, rect: [11,384 115.515625x17.46875]
"space-between"
TextNode <#text>
BlockContainer <(anonymous)> at (10,444) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.reverse.outer.start> at (11,445) content-size 300x60 flex-container(row-reverse) [FFC] children: not-inline
BlockContainer <div> at (161,446) content-size 150x50 positioned [BFC] children: inline
line 0 width: 41.234375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 5, rect: [161,446 41.234375x17.46875]
"start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,506) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.reverse.outer.flex-start> at (11,507) content-size 300x60 flex-container(row-reverse) [FFC] children: not-inline
BlockContainer <div> at (161,508) content-size 150x50 positioned [BFC] children: inline
line 0 width: 76.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 10, rect: [161,508 76.8125x17.46875]
"flex-start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,568) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.reverse.outer.end> at (11,569) content-size 300x60 flex-container(row-reverse) [FFC] children: not-inline
BlockContainer <div> at (11,570) content-size 150x50 positioned [BFC] children: inline
line 0 width: 26.1875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 3, rect: [11,570 26.1875x17.46875]
"end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,630) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.reverse.outer.flex-end> at (11,631) content-size 300x60 flex-container(row-reverse) [FFC] children: not-inline
BlockContainer <div> at (11,632) content-size 150x50 positioned [BFC] children: inline
line 0 width: 61.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 8, rect: [11,632 61.765625x17.46875]
"flex-end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,692) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.reverse.outer.center> at (11,693) content-size 300x60 flex-container(row-reverse) [FFC] children: not-inline
BlockContainer <div> at (86,694) content-size 150x50 positioned [BFC] children: inline
line 0 width: 51.625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 6, rect: [86,694 51.625x17.46875]
"center"
TextNode <#text>
BlockContainer <(anonymous)> at (10,754) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.reverse.outer.space-around> at (11,755) content-size 300x60 flex-container(row-reverse) [FFC] children: not-inline
BlockContainer <div> at (86,756) content-size 150x50 positioned [BFC] children: inline
line 0 width: 107.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 12, rect: [86,756 107.96875x17.46875]
"space-around"
TextNode <#text>
BlockContainer <(anonymous)> at (10,816) content-size 780x0 children: inline
TextNode <#text>
Box <div.row.reverse.outer.space-between> at (11,817) content-size 300x60 flex-container(row-reverse) [FFC] children: not-inline
BlockContainer <div> at (11,818) content-size 150x50 positioned [BFC] children: inline
line 0 width: 115.515625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 13, rect: [11,818 115.515625x17.46875]
"space-between"
TextNode <#text>
BlockContainer <(anonymous)> at (10,878) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.outer.start> at (11,879) content-size 300x60 flex-container(column) [FFC] children: not-inline
BlockContainer <div> at (12,879) content-size 150x50 positioned [BFC] children: inline
line 0 width: 41.234375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 5, rect: [12,879 41.234375x17.46875]
"start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,940) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.outer.flex-start> at (11,941) content-size 300x60 flex-container(column) [FFC] children: not-inline
BlockContainer <div> at (12,941) content-size 150x50 positioned [BFC] children: inline
line 0 width: 76.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 10, rect: [12,941 76.8125x17.46875]
"flex-start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1002) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.outer.end> at (11,1003) content-size 300x60 flex-container(column) [FFC] children: not-inline
BlockContainer <div> at (12,1013) content-size 150x50 positioned [BFC] children: inline
line 0 width: 26.1875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 3, rect: [12,1013 26.1875x17.46875]
"end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1064) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.outer.flex-end> at (11,1065) content-size 300x60 flex-container(column) [FFC] children: not-inline
BlockContainer <div> at (12,1075) content-size 150x50 positioned [BFC] children: inline
line 0 width: 61.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 8, rect: [12,1075 61.765625x17.46875]
"flex-end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1126) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.outer.center> at (11,1127) content-size 300x60 flex-container(column) [FFC] children: not-inline
BlockContainer <div> at (12,1132) content-size 150x50 positioned [BFC] children: inline
line 0 width: 51.625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 6, rect: [12,1132 51.625x17.46875]
"center"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1188) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.outer.space-around> at (11,1189) content-size 300x60 flex-container(column) [FFC] children: not-inline
BlockContainer <div> at (12,1194) content-size 150x50 positioned [BFC] children: inline
line 0 width: 107.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 12, rect: [12,1194 107.96875x17.46875]
"space-around"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1250) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.outer.space-between> at (11,1251) content-size 300x60 flex-container(column) [FFC] children: not-inline
BlockContainer <div> at (12,1251) content-size 150x50 positioned [BFC] children: inline
line 0 width: 115.515625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 13, rect: [12,1251 115.515625x17.46875]
"space-between"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1312) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.reverse.outer.start> at (11,1313) content-size 300x60 flex-container(column-reverse) [FFC] children: not-inline
BlockContainer <div> at (12,1323) content-size 150x50 positioned [BFC] children: inline
line 0 width: 41.234375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 5, rect: [12,1323 41.234375x17.46875]
"start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1374) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.reverse.outer.flex-start> at (11,1375) content-size 300x60 flex-container(column-reverse) [FFC] children: not-inline
BlockContainer <div> at (12,1385) content-size 150x50 positioned [BFC] children: inline
line 0 width: 76.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 10, rect: [12,1385 76.8125x17.46875]
"flex-start"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1436) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.reverse.outer.end> at (11,1437) content-size 300x60 flex-container(column-reverse) [FFC] children: not-inline
BlockContainer <div> at (12,1437) content-size 150x50 positioned [BFC] children: inline
line 0 width: 26.1875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 3, rect: [12,1437 26.1875x17.46875]
"end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1498) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.reverse.outer.flex-end> at (11,1499) content-size 300x60 flex-container(column-reverse) [FFC] children: not-inline
BlockContainer <div> at (12,1499) content-size 150x50 positioned [BFC] children: inline
line 0 width: 61.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 8, rect: [12,1499 61.765625x17.46875]
"flex-end"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1560) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.reverse.outer.center> at (11,1561) content-size 300x60 flex-container(column-reverse) [FFC] children: not-inline
BlockContainer <div> at (12,1566) content-size 150x50 positioned [BFC] children: inline
line 0 width: 51.625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 6, rect: [12,1566 51.625x17.46875]
"center"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1622) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.reverse.outer.space-around> at (11,1623) content-size 300x60 flex-container(column-reverse) [FFC] children: not-inline
BlockContainer <div> at (12,1628) content-size 150x50 positioned [BFC] children: inline
line 0 width: 107.96875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 12, rect: [12,1628 107.96875x17.46875]
"space-around"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1684) content-size 780x0 children: inline
TextNode <#text>
Box <div.column.reverse.outer.space-between> at (11,1685) content-size 300x60 flex-container(column-reverse) [FFC] children: not-inline
BlockContainer <div> at (12,1685) content-size 150x50 positioned [BFC] children: inline
line 0 width: 115.515625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 13, rect: [12,1685 115.515625x17.46875]
"space-between"
TextNode <#text>
BlockContainer <(anonymous)> at (10,1746) content-size 780x0 children: inline
TextNode <#text>

View file

@ -0,0 +1,61 @@
<!DOCTYPE html><style>
* {
border: 1px solid black !important;
}
.outer {
display: flex;
width: 300px;
height: 60px;
background: wheat;
}
.outer > div {
position: absolute;
width: 150px;
height: 50px;
background: orange;
}
.flex-start { justify-content: flex-start; }
.flex-end { justify-content: flex-end; }
.start { justify-content: start; }
.end { justify-content: end; }
.center { justify-content: center; }
.space-around { justify-content: space-around; }
.space-between { justify-content: space-between; }
.row { flex-direction: row; }
.row.reverse { flex-direction: row-reverse; }
.column { flex-direction: column; }
.column.reverse { flex-direction: column-reverse; }
.reverse > div {
background: magenta;
}
</style>
<body>
<div class="row outer start"><div>start</div></div>
<div class="row outer flex-start"><div>flex-start</div></div>
<div class="row outer end"><div>end</div></div>
<div class="row outer flex-end"><div>flex-end</div></div>
<div class="row outer center"><div>center</div></div>
<div class="row outer space-around"><div>space-around</div></div>
<div class="row outer space-between"><div>space-between</div></div>
<div class="row reverse outer start"><div>start</div></div>
<div class="row reverse outer flex-start"><div>flex-start</div></div>
<div class="row reverse outer end"><div>end</div></div>
<div class="row reverse outer flex-end"><div>flex-end</div></div>
<div class="row reverse outer center"><div>center</div></div>
<div class="row reverse outer space-around"><div>space-around</div></div>
<div class="row reverse outer space-between"><div>space-between</div></div>
<div class="column outer start"><div>start</div></div>
<div class="column outer flex-start"><div>flex-start</div></div>
<div class="column outer end"><div>end</div></div>
<div class="column outer flex-end"><div>flex-end</div></div>
<div class="column outer center"><div>center</div></div>
<div class="column outer space-around"><div>space-around</div></div>
<div class="column outer space-between"><div>space-between</div></div>
<div class="column reverse outer start"><div>start</div></div>
<div class="column reverse outer flex-start"><div>flex-start</div></div>
<div class="column reverse outer end"><div>end</div></div>
<div class="column reverse outer flex-end"><div>flex-end</div></div>
<div class="column reverse outer center"><div>center</div></div>
<div class="column reverse outer space-around"><div>space-around</div></div>
<div class="column reverse outer space-between"><div>space-between</div></div>

View file

@ -2150,40 +2150,22 @@ CSSPixelPoint FlexFormattingContext::calculate_static_position(Box const& box) c
CSSPixels main_offset = 0;
switch (flex_container().computed_values().justify_content()) {
case CSS::JustifyContent::Start:
if (is_direction_reverse()) {
main_offset = inner_main_size(flex_container());
} else {
main_offset = 0;
}
case CSS::JustifyContent::FlexStart:
main_offset = 0;
pack_from_end = is_direction_reverse();
break;
case CSS::JustifyContent::End:
if (is_direction_reverse()) {
main_offset = 0;
} else {
main_offset = inner_main_size(flex_container());
}
break;
case CSS::JustifyContent::FlexStart:
if (is_direction_reverse()) {
pack_from_end = false;
main_offset = inner_main_size(flex_container());
} else {
main_offset = 0;
}
break;
case CSS::JustifyContent::FlexEnd:
if (is_direction_reverse()) {
main_offset = 0;
} else {
pack_from_end = false;
main_offset = inner_main_size(flex_container());
}
main_offset = 0;
pack_from_end = !is_direction_reverse();
break;
case CSS::JustifyContent::SpaceBetween:
pack_from_end = false;
main_offset = 0;
break;
case CSS::JustifyContent::Center:
case CSS::JustifyContent::SpaceAround:
pack_from_end = false;
main_offset = inner_main_size(flex_container()) / 2.0 - inner_main_size(box) / 2.0;
break;
}
@ -2191,12 +2173,12 @@ CSSPixelPoint FlexFormattingContext::calculate_static_position(Box const& box) c
// NOTE: Next, we add the flex container's padding since abspos boxes are placed relative to the padding edge
// of their abspos containing block.
if (pack_from_end) {
main_offset += is_row_layout() ? m_flex_container_state.padding_left : m_flex_container_state.padding_top;
} else {
main_offset += is_row_layout() ? m_flex_container_state.padding_right : m_flex_container_state.padding_bottom;
} else {
main_offset += is_row_layout() ? m_flex_container_state.padding_left : m_flex_container_state.padding_top;
}
if (!pack_from_end)
if (pack_from_end)
main_offset += inner_main_size(flex_container()) - inner_main_size(box);
auto static_position_offset = is_row_layout() ? CSSPixelPoint { main_offset, cross_offset } : CSSPixelPoint { cross_offset, main_offset };