at (8,8) content-size 784x17.46875 [BFC] children: not-inline
+ BlockContainer
at (8,8) content-size 784x17.46875 children: inline
+ line 0 width: 210.484375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 26, rect: [8,8 210.484375x17.46875]
+ "Taika Waititi's Best Roles"
+ TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+ PaintableWithLines (BlockContainer) [0,0 800x33.46875]
+ PaintableBox (Box) [8,8 784x17.46875]
+ PaintableWithLines (BlockContainer
#item) [8,8 784x17.46875]
+ PaintableWithLines (BlockContainer
#block) [8,8 784x17.46875]
+ TextPaintable (TextNode<#text>)
diff --git a/Tests/LibWeb/Layout/input/grid/should-not-hang-in-size-distribution.html b/Tests/LibWeb/Layout/input/grid/should-not-hang-in-size-distribution.html
new file mode 100644
index 0000000000..bf85de9606
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/grid/should-not-hang-in-size-distribution.html
@@ -0,0 +1,17 @@
+
Taika Waititi's Best Roles
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index 649bf8ba4e..4d3a0c5b74 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -935,7 +935,7 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
auto extra_space = max(CSSPixels(0), item_size_contribution - spanned_tracks_sizes_sum);
// 2. Distribute space up to limits:
- while (true) {
+ while (extra_space > 0) {
auto all_frozen = all_of(affected_tracks, [](auto const& track) { return track.growth_limit_frozen; });
if (all_frozen)
break;
@@ -943,23 +943,24 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
// Find the item-incurred increase for each spanned track with an affected size by: distributing the space
// equally among such tracks, freezing a track’s item-incurred increase as its affected size + item-incurred
// increase reaches its limit
- CSSPixels increase_per_track = extra_space / affected_tracks.size();
- if (increase_per_track == 0)
- break;
+ CSSPixels increase_per_track = max(CSSPixels::smallest_positive_value(), extra_space / affected_tracks.size());
for (auto& track : affected_tracks) {
if (track.growth_limit_frozen)
continue;
+ auto increase = min(increase_per_track, extra_space);
+
// For growth limits, the limit is infinity if it is marked as infinitely growable, and equal to the
// growth limit otherwise.
- if (track.infinitely_growable || !track.growth_limit.has_value()) {
- track.item_incurred_increase += increase_per_track;
- extra_space -= increase_per_track;
- } else if (track.growth_limit.has_value() && increase_per_track >= track.growth_limit.value()) {
- track.growth_limit_frozen = true;
- track.item_incurred_increase = track.growth_limit.value();
- extra_space -= track.growth_limit.value();
+ if (!track.infinitely_growable && track.growth_limit.has_value()) {
+ auto maximum_increase = track.growth_limit.value() - track.base_size;
+ if (track.item_incurred_increase + increase >= maximum_increase) {
+ track.growth_limit_frozen = true;
+ increase = maximum_increase - track.item_incurred_increase;
+ }
}
+ track.item_incurred_increase += increase;
+ extra_space -= increase;
}
}