mirror of
https://github.com/RGBCube/serenity
synced 2025-06-19 23:32:07 +00:00
LibWeb: Use more CSSPixelFractions in GFC::expand_flexible_tracks
Also contains a drive-by expression simplification, and accidental double truncation fix.
This commit is contained in:
parent
9b30dea889
commit
d262670729
3 changed files with 25 additions and 24 deletions
|
@ -2,22 +2,22 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
BlockContainer <html> at (1,1) content-size 798x600 [BFC] children: not-inline
|
BlockContainer <html> at (1,1) content-size 798x600 [BFC] children: not-inline
|
||||||
BlockContainer <body> at (10,10) content-size 780x21.46875 children: not-inline
|
BlockContainer <body> at (10,10) content-size 780x21.46875 children: not-inline
|
||||||
Box <div.grid-container> at (11,11) content-size 778x19.46875 [GFC] children: not-inline
|
Box <div.grid-container> at (11,11) content-size 778x19.46875 [GFC] children: not-inline
|
||||||
BlockContainer <div.a> at (12,12) content-size 516.75x17.46875 [BFC] children: inline
|
BlockContainer <div.a> at (12,12) content-size 516.625x17.46875 [BFC] children: inline
|
||||||
line 0 width: 6.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
line 0 width: 6.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
frag 0 from TextNode start: 0, length: 1, rect: [12,12 6.34375x17.46875]
|
frag 0 from TextNode start: 0, length: 1, rect: [12,12 6.34375x17.46875]
|
||||||
"1"
|
"1"
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
BlockContainer <div.b> at (530.75,12) content-size 257.375x17.46875 [BFC] children: inline
|
BlockContainer <div.b> at (530.625,12) content-size 257.3125x17.46875 [BFC] children: inline
|
||||||
line 0 width: 8.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
line 0 width: 8.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
frag 0 from TextNode start: 0, length: 1, rect: [530.75,12 8.8125x17.46875]
|
frag 0 from TextNode start: 0, length: 1, rect: [530.625,12 8.8125x17.46875]
|
||||||
"2"
|
"2"
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
|
|
||||||
ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x602]
|
ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x602]
|
||||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x602]
|
PaintableWithLines (BlockContainer<HTML>) [0,0 800x602]
|
||||||
PaintableWithLines (BlockContainer<BODY>) [9,9 782x23.46875]
|
PaintableWithLines (BlockContainer<BODY>) [9,9 782x23.46875]
|
||||||
PaintableBox (Box<DIV>.grid-container) [10,10 780x21.46875] overflow: [11,11 778.125x19.46875]
|
PaintableBox (Box<DIV>.grid-container) [10,10 780x21.46875]
|
||||||
PaintableWithLines (BlockContainer<DIV>.a) [11,11 518.75x19.46875]
|
PaintableWithLines (BlockContainer<DIV>.a) [11,11 518.625x19.46875]
|
||||||
TextPaintable (TextNode<#text>)
|
TextPaintable (TextNode<#text>)
|
||||||
PaintableWithLines (BlockContainer<DIV>.b) [529.75,11 259.375x19.46875]
|
PaintableWithLines (BlockContainer<DIV>.b) [529.625,11 259.3125x19.46875]
|
||||||
TextPaintable (TextNode<#text>)
|
TextPaintable (TextNode<#text>)
|
||||||
|
|
|
@ -2,22 +2,22 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
BlockContainer <html> at (1,1) content-size 798x600 [BFC] children: not-inline
|
BlockContainer <html> at (1,1) content-size 798x600 [BFC] children: not-inline
|
||||||
BlockContainer <body> at (10,10) content-size 780x21.46875 children: not-inline
|
BlockContainer <body> at (10,10) content-size 780x21.46875 children: not-inline
|
||||||
Box <div.grid-container> at (11,11) content-size 778x19.46875 [GFC] children: not-inline
|
Box <div.grid-container> at (11,11) content-size 778x19.46875 [GFC] children: not-inline
|
||||||
BlockContainer <div.grid-item.a> at (12,12) content-size 257.375x17.46875 [BFC] children: inline
|
BlockContainer <div.grid-item.a> at (12,12) content-size 257.3125x17.46875 [BFC] children: inline
|
||||||
line 0 width: 6.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
line 0 width: 6.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
frag 0 from TextNode start: 0, length: 1, rect: [12,12 6.34375x17.46875]
|
frag 0 from TextNode start: 0, length: 1, rect: [12,12 6.34375x17.46875]
|
||||||
"1"
|
"1"
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
BlockContainer <div.grid-item.b> at (271.375,12) content-size 516.75x17.46875 [BFC] children: inline
|
BlockContainer <div.grid-item.b> at (271.3125,12) content-size 516.625x17.46875 [BFC] children: inline
|
||||||
line 0 width: 8.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
line 0 width: 8.8125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
frag 0 from TextNode start: 0, length: 1, rect: [271.375,12 8.8125x17.46875]
|
frag 0 from TextNode start: 0, length: 1, rect: [271.3125,12 8.8125x17.46875]
|
||||||
"2"
|
"2"
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
|
|
||||||
ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x602]
|
ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x602]
|
||||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x602]
|
PaintableWithLines (BlockContainer<HTML>) [0,0 800x602]
|
||||||
PaintableWithLines (BlockContainer<BODY>) [9,9 782x23.46875]
|
PaintableWithLines (BlockContainer<BODY>) [9,9 782x23.46875]
|
||||||
PaintableBox (Box<DIV>.grid-container) [10,10 780x21.46875] overflow: [11,11 778.125x19.46875]
|
PaintableBox (Box<DIV>.grid-container) [10,10 780x21.46875]
|
||||||
PaintableWithLines (BlockContainer<DIV>.grid-item.a) [11,11 259.375x19.46875]
|
PaintableWithLines (BlockContainer<DIV>.grid-item.a) [11,11 259.3125x19.46875]
|
||||||
TextPaintable (TextNode<#text>)
|
TextPaintable (TextNode<#text>)
|
||||||
PaintableWithLines (BlockContainer<DIV>.grid-item.b) [270.375,11 518.75x19.46875]
|
PaintableWithLines (BlockContainer<DIV>.grid-item.b) [270.3125,11 518.625x19.46875]
|
||||||
TextPaintable (TextNode<#text>)
|
TextPaintable (TextNode<#text>)
|
||||||
|
|
|
@ -120,7 +120,7 @@ int GridFormattingContext::count_of_repeated_auto_fill_or_fit_tracks(Vector<CSS:
|
||||||
sum_of_grid_track_sizes += min(resolve_definite_track_size(track_sizing_function.grid_size(), available_space), resolve_definite_track_size(track_sizing_function.grid_size(), available_space));
|
sum_of_grid_track_sizes += min(resolve_definite_track_size(track_sizing_function.grid_size(), available_space), resolve_definite_track_size(track_sizing_function.grid_size(), available_space));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max(1, static_cast<int>((get_free_space(available_space, GridDimension::Column).to_px_or_zero() / sum_of_grid_track_sizes).to_double()));
|
return max(1, (get_free_space(available_space, GridDimension::Column).to_px_or_zero() / sum_of_grid_track_sizes).to_int());
|
||||||
|
|
||||||
// For the purpose of finding the number of auto-repeated tracks in a standalone axis, the UA must
|
// For the purpose of finding the number of auto-repeated tracks in a standalone axis, the UA must
|
||||||
// floor the track size to a UA-specified value to avoid division by zero. It is suggested that this
|
// floor the track size to a UA-specified value to avoid division by zero. It is suggested that this
|
||||||
|
@ -1168,8 +1168,8 @@ void GridFormattingContext::expand_flexible_tracks(AvailableSpace const& availab
|
||||||
auto& tracks_and_gaps = dimension == GridDimension::Column ? m_grid_columns_and_gaps : m_grid_rows_and_gaps;
|
auto& tracks_and_gaps = dimension == GridDimension::Column ? m_grid_columns_and_gaps : m_grid_rows_and_gaps;
|
||||||
auto& tracks = dimension == GridDimension::Column ? m_grid_columns : m_grid_rows;
|
auto& tracks = dimension == GridDimension::Column ? m_grid_columns : m_grid_rows;
|
||||||
auto& available_size = dimension == GridDimension::Column ? available_space.width : available_space.height;
|
auto& available_size = dimension == GridDimension::Column ? available_space.width : available_space.height;
|
||||||
|
// FIXME: This should idealy take a Span, as that is more idomatic, but Span does not yet support holding references
|
||||||
auto find_the_size_of_an_fr = [&](Vector<GridTrack&> tracks, CSSPixels space_to_fill) -> CSSPixels {
|
auto find_the_size_of_an_fr = [&](Vector<GridTrack&> const& tracks, CSSPixels space_to_fill) -> CSSPixelFraction {
|
||||||
// https://www.w3.org/TR/css-grid-2/#algo-find-fr-size
|
// https://www.w3.org/TR/css-grid-2/#algo-find-fr-size
|
||||||
|
|
||||||
// 1. Let leftover space be the space to fill minus the base sizes of the non-flexible grid tracks.
|
// 1. Let leftover space be the space to fill minus the base sizes of the non-flexible grid tracks.
|
||||||
|
@ -1182,10 +1182,10 @@ void GridFormattingContext::expand_flexible_tracks(AvailableSpace const& availab
|
||||||
|
|
||||||
// 2. Let flex factor sum be the sum of the flex factors of the flexible tracks.
|
// 2. Let flex factor sum be the sum of the flex factors of the flexible tracks.
|
||||||
// If this value is less than 1, set it to 1 instead.
|
// If this value is less than 1, set it to 1 instead.
|
||||||
auto flex_factor_sum = 0;
|
CSSPixels flex_factor_sum = 0;
|
||||||
for (auto& track : tracks) {
|
for (auto& track : tracks) {
|
||||||
if (track.max_track_sizing_function.is_flexible_length())
|
if (track.max_track_sizing_function.is_flexible_length())
|
||||||
flex_factor_sum += track.max_track_sizing_function.flex_factor();
|
flex_factor_sum += CSSPixels::nearest_value_for(track.max_track_sizing_function.flex_factor());
|
||||||
}
|
}
|
||||||
if (flex_factor_sum < 1)
|
if (flex_factor_sum < 1)
|
||||||
flex_factor_sum = 1;
|
flex_factor_sum = 1;
|
||||||
|
@ -1201,12 +1201,12 @@ void GridFormattingContext::expand_flexible_tracks(AvailableSpace const& availab
|
||||||
};
|
};
|
||||||
|
|
||||||
// First, find the grid’s used flex fraction:
|
// First, find the grid’s used flex fraction:
|
||||||
auto flex_fraction = [&]() {
|
auto flex_fraction = [&]() -> CSSPixelFraction {
|
||||||
auto free_space = get_free_space(available_space, dimension);
|
auto free_space = get_free_space(available_space, dimension);
|
||||||
// If the free space is zero or if sizing the grid container under a min-content constraint:
|
// If the free space is zero or if sizing the grid container under a min-content constraint:
|
||||||
if ((free_space.is_definite() && free_space.to_px_or_zero() == 0) || available_size.is_min_content()) {
|
if ((free_space.is_definite() && free_space.to_px_or_zero() == 0) || available_size.is_min_content()) {
|
||||||
// The used flex fraction is zero.
|
// The used flex fraction is zero.
|
||||||
return CSSPixels(0);
|
return 0;
|
||||||
// Otherwise, if the free space is a definite length:
|
// Otherwise, if the free space is a definite length:
|
||||||
} else if (free_space.is_definite()) {
|
} else if (free_space.is_definite()) {
|
||||||
// The used flex fraction is the result of finding the size of an fr using all of the grid tracks and a space
|
// The used flex fraction is the result of finding the size of an fr using all of the grid tracks and a space
|
||||||
|
@ -1215,15 +1215,15 @@ void GridFormattingContext::expand_flexible_tracks(AvailableSpace const& availab
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, if the free space is an indefinite length:
|
// Otherwise, if the free space is an indefinite length:
|
||||||
// The used flex fraction is the maximum of:
|
// The used flex fraction is the maximum of:
|
||||||
CSSPixels result = 0;
|
CSSPixelFraction result = 0;
|
||||||
// For each flexible track, if the flexible track’s flex factor is greater than one, the result of dividing
|
// For each flexible track, if the flexible track’s flex factor is greater than one, the result of dividing
|
||||||
// the track’s base size by its flex factor; otherwise, the track’s base size.
|
// the track’s base size by its flex factor; otherwise, the track’s base size.
|
||||||
for (auto& track : tracks) {
|
for (auto& track : tracks) {
|
||||||
if (track.max_track_sizing_function.is_flexible_length()) {
|
if (track.max_track_sizing_function.is_flexible_length()) {
|
||||||
if (track.max_track_sizing_function.flex_factor() > 1) {
|
if (track.max_track_sizing_function.flex_factor() > 1) {
|
||||||
result = max(result, CSSPixels::nearest_value_for(track.base_size / track.max_track_sizing_function.flex_factor()));
|
result = max(result, track.base_size / CSSPixels::nearest_value_for(track.max_track_sizing_function.flex_factor()));
|
||||||
} else {
|
} else {
|
||||||
result = max(result, track.base_size);
|
result = max(result, track.base_size / 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1249,8 +1249,9 @@ void GridFormattingContext::expand_flexible_tracks(AvailableSpace const& availab
|
||||||
// For each flexible track, if the product of the used flex fraction and the track’s flex factor is greater than
|
// For each flexible track, if the product of the used flex fraction and the track’s flex factor is greater than
|
||||||
// the track’s base size, set its base size to that product.
|
// the track’s base size, set its base size to that product.
|
||||||
for (auto& track : tracks_and_gaps) {
|
for (auto& track : tracks_and_gaps) {
|
||||||
if (flex_fraction.scaled(track.max_track_sizing_function.flex_factor()) > track.base_size) {
|
auto scaled_fraction = CSSPixels::nearest_value_for(track.max_track_sizing_function.flex_factor()) * flex_fraction;
|
||||||
track.base_size = flex_fraction.scaled(track.max_track_sizing_function.flex_factor());
|
if (scaled_fraction > track.base_size) {
|
||||||
|
track.base_size = scaled_fraction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue