mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb: Implement grid container intrinsic sizes calculation
When a width/height constraint is applied to GFC it should set its own width/height to the sum of track sizes according to the spec. Changes in layout tests are improvement over what we had before.
This commit is contained in:
parent
d0ce61bf13
commit
644e4f4c99
4 changed files with 34 additions and 6 deletions
|
@ -1,10 +1,10 @@
|
||||||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
BlockContainer <html> at (0,0) content-size 800x35.46875 [BFC] children: inline
|
BlockContainer <html> at (0,0) content-size 800x35.46875 [BFC] children: inline
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
BlockContainer <body> at (8,8) content-size 0x19.46875 floating [BFC] children: not-inline
|
BlockContainer <body> at (8,8) content-size 22x19.46875 floating [BFC] children: not-inline
|
||||||
BlockContainer <(anonymous)> at (8,8) content-size 0x0 children: inline
|
BlockContainer <(anonymous)> at (8,8) content-size 22x0 children: inline
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
Box <div.grid> at (8,8) content-size 0x19.46875 [GFC] children: not-inline
|
Box <div.grid> at (8,8) content-size 22x19.46875 [GFC] children: not-inline
|
||||||
BlockContainer <(anonymous)> [BFC] children: inline
|
BlockContainer <(anonymous)> [BFC] children: inline
|
||||||
TextNode <#text>
|
TextNode <#text>
|
||||||
BlockContainer <div.whee> at (9,9) content-size 18x17.46875 [BFC] children: inline
|
BlockContainer <div.whee> at (9,9) content-size 18x17.46875 [BFC] children: inline
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
BlockContainer <html> at (1,1) content-size 798x39.46875 [BFC] children: not-inline
|
BlockContainer <html> at (1,1) content-size 798x39.46875 [BFC] children: not-inline
|
||||||
BlockContainer <body> at (10,10) content-size 2x21.46875 floating [BFC] children: not-inline
|
BlockContainer <body> at (10,10) content-size 41.953125x21.46875 floating [BFC] children: not-inline
|
||||||
Box <div.grid> at (11,11) content-size 0x19.46875 [GFC] children: not-inline
|
Box <div.grid> at (11,11) content-size 39.953125x19.46875 [GFC] children: not-inline
|
||||||
BlockContainer <div.whee> at (12,12) content-size 35.953125x17.46875 [BFC] children: inline
|
BlockContainer <div.whee> at (12,12) content-size 37.953125x17.46875 [BFC] children: inline
|
||||||
line 0 width: 37.953125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
line 0 width: 37.953125, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
frag 0 from TextNode start: 0, length: 4, rect: [12,12 37.953125x17.46875]
|
frag 0 from TextNode start: 0, length: 4, rect: [12,12 37.953125x17.46875]
|
||||||
"whee"
|
"whee"
|
||||||
|
|
|
@ -1487,12 +1487,38 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
|
||||||
grid_item.box());
|
grid_item.box());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (available_space.height.is_intrinsic_sizing_constraint() || available_space.width.is_intrinsic_sizing_constraint())
|
||||||
|
determine_intrinsic_size_of_grid_container(available_space);
|
||||||
|
|
||||||
CSSPixels total_y = 0;
|
CSSPixels total_y = 0;
|
||||||
for (auto& grid_row : m_grid_rows)
|
for (auto& grid_row : m_grid_rows)
|
||||||
total_y += grid_row.full_vertical_size();
|
total_y += grid_row.full_vertical_size();
|
||||||
m_automatic_content_height = total_y;
|
m_automatic_content_height = total_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GridFormattingContext::determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space)
|
||||||
|
{
|
||||||
|
// https://www.w3.org/TR/css-grid-1/#intrinsic-sizes
|
||||||
|
// The max-content size (min-content size) of a grid container is the sum of the grid container’s track sizes
|
||||||
|
// (including gutters) in the appropriate axis, when the grid is sized under a max-content constraint (min-content constraint).
|
||||||
|
|
||||||
|
if (available_space.height.is_intrinsic_sizing_constraint()) {
|
||||||
|
CSSPixels grid_container_height = 0;
|
||||||
|
for (auto& track : m_grid_rows) {
|
||||||
|
grid_container_height += track.full_vertical_size();
|
||||||
|
}
|
||||||
|
m_state.get_mutable(grid_container()).set_content_height(grid_container_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (available_space.width.is_intrinsic_sizing_constraint()) {
|
||||||
|
CSSPixels grid_container_width = 0;
|
||||||
|
for (auto& track : m_grid_columns) {
|
||||||
|
grid_container_width += track.full_horizontal_size();
|
||||||
|
}
|
||||||
|
m_state.get_mutable(grid_container()).set_content_width(grid_container_width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CSSPixels GridFormattingContext::automatic_content_width() const
|
CSSPixels GridFormattingContext::automatic_content_width() const
|
||||||
{
|
{
|
||||||
return greatest_child_width(context_box());
|
return greatest_child_width(context_box());
|
||||||
|
|
|
@ -146,6 +146,8 @@ private:
|
||||||
Vector<GridItem> m_grid_items;
|
Vector<GridItem> m_grid_items;
|
||||||
Vector<JS::NonnullGCPtr<Box const>> m_boxes_to_place;
|
Vector<JS::NonnullGCPtr<Box const>> m_boxes_to_place;
|
||||||
|
|
||||||
|
void determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space);
|
||||||
|
|
||||||
AvailableSize get_free_space(AvailableSize const& available_size, Vector<TemporaryTrack> const& tracks) const;
|
AvailableSize get_free_space(AvailableSize const& available_size, Vector<TemporaryTrack> const& tracks) const;
|
||||||
|
|
||||||
int get_line_index_by_line_name(String const& line_name, CSS::GridTrackSizeList);
|
int get_line_index_by_line_name(String const& line_name, CSS::GridTrackSizeList);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue