Skip to content

Commit

Permalink
LibWeb: Skip abspos boxes layout in intrinsic sizing mode
Browse files Browse the repository at this point in the history
Absolutely positioned boxes do not affect the size of the formatting
context box they belong to, so it's safe to skip their layout entirely
when calculating intrinsic size.

(cherry picked from commit 4eb16b144e20d615db2febaa42c78e89ecbc3e24)
  • Loading branch information
kalenikaliaksandr authored and nico committed Nov 24, 2024
1 parent 56bfc4f commit 4f9df88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ void BlockFormattingContext::parent_context_did_dimension_child_root_box()
box_state.set_content_x(float_containing_block_width - floating_box->offset_from_edge);
}

// We can also layout absolutely positioned boxes within this BFC.
for (auto& box : m_absolutely_positioned_boxes) {
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));
if (m_layout_mode == LayoutMode::Normal) {
// We can also layout absolutely positioned boxes within this BFC.
for (auto& box : m_absolutely_positioned_boxes) {
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));
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ void FlexFormattingContext::run(AvailableSpace const& available_space)

void FlexFormattingContext::parent_context_did_dimension_child_root_box()
{
if (m_layout_mode != LayoutMode::Normal)
return;

flex_container().for_each_child_of_type<Box>([&](Layout::Box& box) {
if (box.is_absolutely_positioned()) {
auto& cb_state = m_state.get(*box.containing_block());
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,9 @@ void GridFormattingContext::layout_absolutely_positioned_element(Box const& box,

void GridFormattingContext::parent_context_did_dimension_child_root_box()
{
if (m_layout_mode != LayoutMode::Normal)
return;

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());
Expand Down

0 comments on commit 4f9df88

Please sign in to comment.