From 27b63feae5a214064372a6b24bd25f63923b4e85 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 26 Oct 2022 12:51:33 +0200 Subject: [PATCH] LibWeb: Always resolve horizontal padding and borders on block-level boxes We were neglecting to resolve the used horizontal padding and border properties on block-level boxes when treating their width as `auto` during intrinsic sizing. This led to padding and border not contributing to the intrinsic width of their containing block --- .../LibWeb/Layout/BlockFormattingContext.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index fd7fa26c44..34236a73dc 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -107,9 +107,6 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const& auto const& computed_values = box.computed_values(); - if (should_treat_width_as_auto(box, available_space) && available_space.width.is_intrinsic_sizing_constraint()) - return; - float width_of_containing_block = available_space.width.to_px(); auto width_of_containing_block_as_length_for_resolve = available_space.width.is_definite() ? CSS::Length::make_px(width_of_containing_block) : CSS::Length::make_px(0); @@ -117,8 +114,17 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const& auto margin_left = CSS::Length::make_auto(); auto margin_right = CSS::Length::make_auto(); - auto padding_left = computed_values.padding().left().resolved(box, width_of_containing_block_as_length_for_resolve).resolved(box); - auto padding_right = computed_values.padding().right().resolved(box, width_of_containing_block_as_length_for_resolve).resolved(box); + auto const padding_left = computed_values.padding().left().resolved(box, width_of_containing_block_as_length_for_resolve).resolved(box); + auto const padding_right = computed_values.padding().right().resolved(box, width_of_containing_block_as_length_for_resolve).resolved(box); + + auto& box_state = m_state.get_mutable(box); + box_state.border_left = computed_values.border_left().width; + box_state.border_right = computed_values.border_right().width; + box_state.padding_left = padding_left.to_px(box); + box_state.padding_right = padding_right.to_px(box); + + if (should_treat_width_as_auto(box, available_space) && available_space.width.is_intrinsic_sizing_constraint()) + return; auto try_compute_width = [&](auto const& a_width) { CSS::Length width = a_width; @@ -203,17 +209,11 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const& } } - auto& box_state = m_state.get_mutable(box); - if (!is(box) && !used_width.is_auto()) box_state.set_content_width(used_width.to_px(box)); box_state.margin_left = margin_left.to_px(box); box_state.margin_right = margin_right.to_px(box); - box_state.border_left = computed_values.border_left().width; - box_state.border_right = computed_values.border_right().width; - box_state.padding_left = padding_left.to_px(box); - box_state.padding_right = padding_right.to_px(box); } void BlockFormattingContext::compute_width_for_floating_box(Box const& box, AvailableSpace const& available_space)