LibWeb: Support positioning of abspos boxes inside grid container
- Out-of-flow items should not affect grid layout - "The static position of an absolutely-positioned child of a grid container is determined as if it were the sole grid item in a grid area whose edges coincide with the content edges of the grid container."
This commit is contained in:
parent
073eb46824
commit
568c486610
Notes:
sideshowbarker
2024-07-16 23:13:25 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/568c486610 Pull-request: https://github.com/SerenityOS/serenity/pull/20410 Issue: https://github.com/SerenityOS/serenity/issues/20260
4 changed files with 51 additions and 0 deletions
23
Tests/LibWeb/Layout/expected/grid/abspos-item.txt
Normal file
23
Tests/LibWeb/Layout/expected/grid/abspos-item.txt
Normal file
|
@ -0,0 +1,23 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x17.46875 children: not-inline
|
||||
Box <div.outer-grid> at (8,8) content-size 784x17.46875 [GFC] children: not-inline
|
||||
BlockContainer <div.inner-absolute-block> at (8,8) content-size 80.765625x17.46875 positioned [BFC] children: inline
|
||||
line 0 width: 80.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||
frag 0 from TextNode start: 0, length: 9, rect: [8,8 80.765625x17.46875]
|
||||
"some text"
|
||||
TextNode <#text>
|
||||
BlockContainer <div> at (8,8) content-size 784x17.46875 [BFC] children: inline
|
||||
line 0 width: 80.25, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||
frag 0 from TextNode start: 0, length: 9, rect: [8,8 80.25x17.46875]
|
||||
"more text"
|
||||
TextNode <#text>
|
||||
|
||||
PaintableWithLines (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x17.46875]
|
||||
PaintableBox (Box<DIV>.outer-grid) [8,8 784x17.46875]
|
||||
PaintableWithLines (BlockContainer<DIV>.inner-absolute-block) [8,8 80.765625x17.46875]
|
||||
TextPaintable (TextNode<#text>)
|
||||
PaintableWithLines (BlockContainer<DIV>) [8,8 784x17.46875]
|
||||
TextPaintable (TextNode<#text>)
|
10
Tests/LibWeb/Layout/input/grid/abspos-item.html
Normal file
10
Tests/LibWeb/Layout/input/grid/abspos-item.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<style>
|
||||
.outer-grid {
|
||||
display: grid;
|
||||
}
|
||||
.inner-absolute-block {
|
||||
display: block;
|
||||
position: absolute;
|
||||
}
|
||||
</style>
|
||||
<div class="outer-grid"><div class="inner-absolute-block">some text</div><div>more text</div></div>
|
|
@ -1317,6 +1317,10 @@ void GridFormattingContext::place_grid_items(AvailableSpace const& available_spa
|
|||
grid_container().for_each_child_of_type<Box>([&](Box& child_box) {
|
||||
if (can_skip_is_anonymous_text_run(child_box))
|
||||
return IterationDecision::Continue;
|
||||
|
||||
if (child_box.is_out_of_flow(*this))
|
||||
return IterationDecision::Continue;
|
||||
|
||||
m_boxes_to_place.append(child_box);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
@ -1780,6 +1784,18 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const
|
|||
}
|
||||
}
|
||||
|
||||
void GridFormattingContext::parent_context_did_dimension_child_root_box()
|
||||
{
|
||||
grid_container().for_each_child_of_type<Box>([&](Layout::Box& box) {
|
||||
if (box.is_absolutely_positioned()) {
|
||||
auto& cb_state = m_state.get(*box.containing_block());
|
||||
auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right);
|
||||
auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom);
|
||||
layout_absolutely_positioned_element(box, AvailableSpace(available_width, available_height));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void GridFormattingContext::determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space)
|
||||
{
|
||||
// https://www.w3.org/TR/css-grid-1/#intrinsic-sizes
|
||||
|
|
|
@ -223,6 +223,8 @@ private:
|
|||
void determine_grid_container_height();
|
||||
void determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space);
|
||||
|
||||
virtual void parent_context_did_dimension_child_root_box() override;
|
||||
|
||||
void resolve_grid_item_widths();
|
||||
void resolve_grid_item_heights();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue