Skip to content

Commit f3556f2

Browse files
committed
LibWeb: Don't touch flex items after they we've been frozen
When using the flex shrink factor, the flexible length resolution algorithm was incorrectly ignoring the `frozen` flag on items and would update the same items again, causing overconsumption of the remaining free space on the flex line.
1 parent 0808463 commit f3556f2

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (1,1) content-size 798x70 children: not-inline
3+
BlockContainer <body> at (10,10) content-size 780x52 children: not-inline
4+
Box <div.flexbox> at (11,11) content-size 778x50 flex-container(row) children: not-inline
5+
BlockContainer <div> at (12,12) content-size 136.3125x48 flex-item children: inline
6+
line 0 width: 136.3125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
7+
frag 0 from TextNode start: 0, length: 15, rect: [12,12 136.3125x17.46875]
8+
"LongPieceOfText"
9+
TextNode <#text>
10+
BlockContainer <div> at (150.3125,12) content-size 136.3125x48 flex-item children: inline
11+
line 0 width: 136.3125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
12+
frag 0 from TextNode start: 0, length: 15, rect: [150.3125,12 136.3125x17.46875]
13+
"LongPieceOfText"
14+
TextNode <#text>
15+
BlockContainer <div> at (288.625,12) content-size 136.3125x48 flex-item children: inline
16+
line 0 width: 136.3125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
17+
frag 0 from TextNode start: 0, length: 15, rect: [288.625,12 136.3125x17.46875]
18+
"LongPieceOfText"
19+
TextNode <#text>
20+
BlockContainer <div> at (426.9375,12) content-size 136.3125x48 flex-item children: inline
21+
line 0 width: 136.3125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
22+
frag 0 from TextNode start: 0, length: 15, rect: [426.9375,12 136.3125x17.46875]
23+
"LongPieceOfText"
24+
TextNode <#text>
25+
BlockContainer <div.last.item> at (565.25,12) content-size 222.75x48 flex-item children: inline
26+
line 0 width: 136.3125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
27+
frag 0 from TextNode start: 0, length: 15, rect: [565.25,12 136.3125x17.46875]
28+
"LongPieceOfText"
29+
TextNode <#text>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html><html><head><style>
2+
* {
3+
border: 1px solid black;
4+
font-family: 'SerenitySans';
5+
}
6+
.flexbox {
7+
display: flex;
8+
height: 50px;
9+
}
10+
.last {
11+
width: 500px;
12+
}
13+
</style></head><body><div class="flexbox"><div>LongPieceOfText</div><div>LongPieceOfText</div><div>LongPieceOfText</div><div>LongPieceOfText</div><div class="last item">LongPieceOfText</div></div></div></body></html>

Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,14 @@ void FlexFormattingContext::resolve_flexible_lengths_for_line(FlexLine& line)
972972
else if (used_flex_factor == FlexFactor::FlexShrinkFactor) {
973973
// For every unfrozen item on the line, multiply its flex shrink factor by its inner flex base size, and note this as its scaled flex shrink factor.
974974
for (auto& item : line.items) {
975+
if (item.frozen)
976+
continue;
975977
item.scaled_flex_shrink_factor = item.flex_factor.value() * item.flex_base_size.value();
976978
}
977979
auto sum_of_scaled_flex_shrink_factors_of_all_unfrozen_items_on_line = line.sum_of_scaled_flex_shrink_factor_of_unfrozen_items();
978980
for (auto& item : line.items) {
981+
if (item.frozen)
982+
continue;
979983
// Find the ratio of the item’s scaled flex shrink factor to the sum of the scaled flex shrink factors of all unfrozen items on the line.
980984
float ratio = 1.0f;
981985
if (sum_of_scaled_flex_shrink_factors_of_all_unfrozen_items_on_line != 0)

0 commit comments

Comments
 (0)