mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibWeb: Handle fit-content in calculate_max_content_contribution in GFC
Fixes https://github.com/SerenityOS/serenity/issues/21569
This commit is contained in:
parent
04a4ffaa3d
commit
58f8068853
3 changed files with 41 additions and 3 deletions
25
Tests/LibWeb/Layout/expected/grid/item-fit-content-width.txt
Normal file
25
Tests/LibWeb/Layout/expected/grid/item-fit-content-width.txt
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
|
BlockContainer <html> at (0,0) content-size 800x33.46875 [BFC] children: not-inline
|
||||||
|
BlockContainer <body> at (8,8) content-size 784x17.46875 children: not-inline
|
||||||
|
Box <div.flex> at (8,8) content-size 784x17.46875 flex-container(row) [FFC] children: not-inline
|
||||||
|
Box <div.grid> at (8,8) content-size 67.4375x17.46875 flex-item [GFC] children: not-inline
|
||||||
|
BlockContainer <div.w-fit> at (8,8) content-size 31.25x17.46875 [BFC] children: inline
|
||||||
|
line 0 width: 31.25, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
|
frag 0 from TextNode start: 0, length: 4, rect: [8,8 31.25x17.46875]
|
||||||
|
"Col1"
|
||||||
|
TextNode <#text>
|
||||||
|
BlockContainer <div.w-fit> at (41.71875,8) content-size 33.71875x17.46875 [BFC] children: inline
|
||||||
|
line 0 width: 33.71875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
|
frag 0 from TextNode start: 0, length: 4, rect: [41.71875,8 33.71875x17.46875]
|
||||||
|
"Col2"
|
||||||
|
TextNode <#text>
|
||||||
|
|
||||||
|
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||||
|
PaintableWithLines (BlockContainer<HTML>) [0,0 800x33.46875]
|
||||||
|
PaintableWithLines (BlockContainer<BODY>) [8,8 784x17.46875]
|
||||||
|
PaintableBox (Box<DIV>.flex) [8,8 784x17.46875]
|
||||||
|
PaintableBox (Box<DIV>.grid) [8,8 67.4375x17.46875]
|
||||||
|
PaintableWithLines (BlockContainer<DIV>.w-fit) [8,8 31.25x17.46875]
|
||||||
|
TextPaintable (TextNode<#text>)
|
||||||
|
PaintableWithLines (BlockContainer<DIV>.w-fit) [41.71875,8 33.71875x17.46875]
|
||||||
|
TextPaintable (TextNode<#text>)
|
12
Tests/LibWeb/Layout/input/grid/item-fit-content-width.html
Normal file
12
Tests/LibWeb/Layout/input/grid/item-fit-content-width.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html><style type="text/css">
|
||||||
|
.flex {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
.w-fit {
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
</style><div class="flex"><div class="grid"><div class="w-fit">Col1</div><div class="w-fit">Col2</div>
|
|
@ -2196,11 +2196,12 @@ CSSPixels GridFormattingContext::calculate_max_content_contribution(GridItem con
|
||||||
return should_treat_height_as_auto(item.box, available_space_for_item);
|
return should_treat_height_as_auto(item.box, available_space_for_item);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (should_treat_preferred_size_as_auto) {
|
auto preferred_size = get_item_preferred_size(item, dimension);
|
||||||
return item.add_margin_box_sizes(calculate_max_content_size(item, dimension), dimension, m_state);
|
if (should_treat_preferred_size_as_auto || preferred_size.is_fit_content()) {
|
||||||
|
auto fit_content_size = dimension == GridDimension::Column ? calculate_fit_content_width(item.box, available_space_for_item) : calculate_fit_content_height(item.box, available_space_for_item);
|
||||||
|
return item.add_margin_box_sizes(fit_content_size, dimension, m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto preferred_size = get_item_preferred_size(item, dimension);
|
|
||||||
auto containing_block_size = containing_block_size_for_item(item, dimension);
|
auto containing_block_size = containing_block_size_for_item(item, dimension);
|
||||||
return item.add_margin_box_sizes(preferred_size.to_px(grid_container(), containing_block_size), dimension, m_state);
|
return item.add_margin_box_sizes(preferred_size.to_px(grid_container(), containing_block_size), dimension, m_state);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue