mirror of
https://github.com/RGBCube/serenity
synced 2025-06-29 07:52:12 +00:00
LibWeb: Use a special value to represent an infinite growth limit in GFC
This is preparation for introducing fixed-point CSSPixels in upcoming commits. Infinity is a valid state for the growth limit value of a grid track. It was possible to use INFINITY when CSSPixels were represented using floating point, but it won't work after the transition to fixed point, which is represented using integers. This change addresses this by using -1 as a special value to represent the infinite state of the growth limit.
This commit is contained in:
parent
66c92ebe3d
commit
c66dbc99ee
1 changed files with 15 additions and 13 deletions
|
@ -10,6 +10,8 @@
|
|||
|
||||
namespace Web::Layout {
|
||||
|
||||
static int const infinity = -1;
|
||||
|
||||
GridFormattingContext::GridTrack GridFormattingContext::GridTrack::create_from_definition(CSS::ExplicitGridTrack const& definition)
|
||||
{
|
||||
// NOTE: repeat() is expected to be expanded beforehand.
|
||||
|
@ -718,16 +720,16 @@ void GridFormattingContext::initialize_track_sizes(AvailableSpace const& availab
|
|||
if (track.max_track_sizing_function.is_fixed(available_size)) {
|
||||
track.growth_limit = track.max_track_sizing_function.css_size().to_px(grid_container(), available_size.to_px());
|
||||
} else if (track.max_track_sizing_function.is_flexible_length()) {
|
||||
track.growth_limit = INFINITY;
|
||||
track.growth_limit = infinity;
|
||||
} else if (track.max_track_sizing_function.is_intrinsic(available_size)) {
|
||||
track.growth_limit = INFINITY;
|
||||
track.growth_limit = infinity;
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// In all cases, if the growth limit is less than the base size, increase the growth limit to match
|
||||
// the base size.
|
||||
if (track.growth_limit < track.base_size)
|
||||
if (track.growth_limit != infinity && track.growth_limit < track.base_size)
|
||||
track.growth_limit = track.base_size;
|
||||
}
|
||||
}
|
||||
|
@ -766,7 +768,7 @@ void GridFormattingContext::resolve_intrinsic_track_sizes(AvailableSpace const&
|
|||
// 5. If any track still has an infinite growth limit (because, for example, it had no items placed in
|
||||
// it or it is a flexible track), set its growth limit to its base size.
|
||||
for (auto& track : tracks_and_gaps) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
if (track.growth_limit == infinity) {
|
||||
track.growth_limit = track.base_size;
|
||||
}
|
||||
}
|
||||
|
@ -811,7 +813,7 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_base_si
|
|||
if (track.base_size_frozen)
|
||||
continue;
|
||||
|
||||
if (increase_per_track >= track.growth_limit) {
|
||||
if (track.growth_limit != infinity && increase_per_track >= track.growth_limit) {
|
||||
track.base_size_frozen = true;
|
||||
track.item_incurred_increase = track.growth_limit;
|
||||
extra_space -= track.growth_limit;
|
||||
|
@ -871,7 +873,7 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
|
|||
// 1. Find the space to distribute:
|
||||
CSSPixels spanned_tracks_sizes_sum = 0;
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (isfinite(track.growth_limit.to_double())) {
|
||||
if (track.growth_limit != infinity) {
|
||||
spanned_tracks_sizes_sum += track.growth_limit;
|
||||
} else {
|
||||
spanned_tracks_sizes_sum += track.base_size;
|
||||
|
@ -900,8 +902,8 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
|
|||
|
||||
// For growth limits, the limit is infinity if it is marked as infinitely growable, and equal to the
|
||||
// growth limit otherwise.
|
||||
auto limit = track.infinitely_growable ? INFINITY : track.growth_limit;
|
||||
if (increase_per_track >= limit) {
|
||||
auto limit = track.infinitely_growable ? infinity : track.growth_limit;
|
||||
if (limit != infinity && increase_per_track >= limit) {
|
||||
track.growth_limit_frozen = true;
|
||||
track.item_incurred_increase = limit;
|
||||
extra_space -= limit;
|
||||
|
@ -988,7 +990,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
// 4. If at this point any track’s growth limit is now less than its base size, increase its growth limit to
|
||||
// match its base size.
|
||||
for (auto& track : tracks) {
|
||||
if (track.growth_limit < track.base_size)
|
||||
if (track.growth_limit != infinity && track.growth_limit < track.base_size)
|
||||
track.growth_limit = track.base_size;
|
||||
}
|
||||
|
||||
|
@ -997,7 +999,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
return track.max_track_sizing_function.is_intrinsic(available_size);
|
||||
});
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
if (track.growth_limit == infinity) {
|
||||
// If the affected size is an infinite growth limit, set it to the track’s base size plus the planned increase.
|
||||
track.growth_limit = track.base_size + track.planned_increase;
|
||||
// Mark any tracks whose growth limit changed from infinite to finite in this step as infinitely growable
|
||||
|
@ -1017,7 +1019,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
return track.max_track_sizing_function.is_max_content() || track.max_track_sizing_function.is_auto(available_size);
|
||||
});
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
if (track.growth_limit == infinity) {
|
||||
// If the affected size is an infinite growth limit, set it to the track’s base size plus the planned increase.
|
||||
track.growth_limit = track.base_size + track.planned_increase;
|
||||
} else {
|
||||
|
@ -1058,7 +1060,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
// 4. If at this point any track’s growth limit is now less than its base size, increase its growth limit to
|
||||
// match its base size.
|
||||
for (auto& track : tracks) {
|
||||
if (track.growth_limit < track.base_size)
|
||||
if (track.growth_limit != infinity && track.growth_limit < track.base_size)
|
||||
track.growth_limit = track.base_size;
|
||||
}
|
||||
}
|
||||
|
@ -1093,7 +1095,7 @@ void GridFormattingContext::maximize_tracks(AvailableSpace const& available_spac
|
|||
for (auto& track : tracks) {
|
||||
if (track.base_size_frozen)
|
||||
continue;
|
||||
VERIFY(isfinite(track.growth_limit.to_double()));
|
||||
VERIFY(track.growth_limit != infinity);
|
||||
track.base_size = min(track.growth_limit, track.base_size + free_space_to_distribute_per_track);
|
||||
}
|
||||
if (get_free_space_px() == free_space_px)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue