Skip to content

Commit a64d182

Browse files
LibWeb: Use grid area as available size for abspos contained in GFC
Fixes incorrect percentage length resolution for abspos boxes contained by a grid.
1 parent 1d9c404 commit a64d182

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (1,1) content-size 798x120 [BFC] children: not-inline
3+
BlockContainer <body> at (10,10) content-size 780x102 children: not-inline
4+
Box <div.grid> at (11,11) content-size 200x100 positioned [GFC] children: not-inline
5+
BlockContainer <div.abspos-item> at (112,12) content-size 50x50 positioned [BFC] children: not-inline
6+
7+
ViewportPaintable (Viewport<#document>) [0,0 800x600]
8+
PaintableWithLines (BlockContainer<HTML>) [0,0 800x122]
9+
PaintableWithLines (BlockContainer<BODY>) [9,9 782x104]
10+
PaintableBox (Box<DIV>.grid) [10,10 202x102]
11+
PaintableWithLines (BlockContainer<DIV>.abspos-item) [111,11 52x52]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html><style>
2+
* {
3+
border: 1px solid black;
4+
}
5+
6+
.grid {
7+
display: grid;
8+
grid-template-columns: 100px 100px;
9+
grid-template-areas: "a b";
10+
position: relative;
11+
width: 200px;
12+
height: 100px;
13+
}
14+
15+
.abspos-item {
16+
position: absolute;
17+
top: 0;
18+
left: 0;
19+
width: 50%;
20+
height: 50%;
21+
grid-area: b;
22+
}
23+
</style><div class="grid"><div class="abspos-item"></div></div>

Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ void GridFormattingContext::run(AvailableSpace const& available_space)
18971897
m_state.get_mutable(grid_container()).set_grid_template_rows(CSS::GridTrackSizeListStyleValue::create(move(grid_track_rows)));
18981898
}
18991899

1900-
void GridFormattingContext::layout_absolutely_positioned_element(Box const& box, AvailableSpace const& available_space)
1900+
void GridFormattingContext::layout_absolutely_positioned_element(Box const& box)
19011901
{
19021902
auto& containing_block_state = m_state.get_mutable(*box.containing_block());
19031903
auto& box_state = m_state.get_mutable(box);
@@ -1913,6 +1913,8 @@ void GridFormattingContext::layout_absolutely_positioned_element(Box const& box,
19131913

19141914
GridItem item { box, row_start, row_span, column_start, column_span };
19151915

1916+
auto available_space = get_available_space_for_item(item);
1917+
19161918
// The border computed values are not changed by the compute_height & width calculations below.
19171919
// The spec only adjusts and computes sizes, insets and margins.
19181920
box_state.border_left = box.computed_values().border_left().width;
@@ -2015,12 +2017,9 @@ void GridFormattingContext::parent_context_did_dimension_child_root_box()
20152017
return IterationDecision::Continue;
20162018
});
20172019

2018-
for (auto& child : grid_container().contained_abspos_children()) {
2019-
auto& box = verify_cast<Box>(*child);
2020-
auto& cb_state = m_state.get(*box.containing_block());
2021-
auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right);
2022-
auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom);
2023-
layout_absolutely_positioned_element(box, AvailableSpace(available_width, available_height));
2020+
for (auto const& child : grid_container().contained_abspos_children()) {
2021+
auto const& box = verify_cast<Box>(*child);
2022+
layout_absolutely_positioned_element(box);
20242023
}
20252024
}
20262025

Userland/Libraries/LibWeb/Layout/GridFormattingContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class GridFormattingContext final : public FormattingContext {
238238
void determine_grid_container_height();
239239
void determine_intrinsic_size_of_grid_container(AvailableSpace const& available_space);
240240

241-
void layout_absolutely_positioned_element(Box const&, AvailableSpace const&);
241+
void layout_absolutely_positioned_element(Box const&);
242242
virtual void parent_context_did_dimension_child_root_box() override;
243243

244244
void resolve_grid_item_widths();

0 commit comments

Comments
 (0)