From f4446cdf8c53b0d53cb51be3329b8e6b743e4b3b Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Tue, 20 Jun 2023 22:21:33 +0100 Subject: [PATCH] LibWeb: Resolve padding against 0 and not inf for indefinite width more In particular, in BFC: - Non-floating, non-replaced elements - Floating, non-replaced elements - Floating, replaced elements The first two regressed in https://github.com/SerenityOS/serenity/commit/1d76126abe9dd65251bd28a381350f70083b50f7 The third one seems to have been introduced by this regression, as it was seemingly copied from compute_width_for_floating_box in https://github.com/SerenityOS/serenity/commit/7f9ede07bcf287a2b16ff29c1ebbcf64c47a221f --- ...t-percentage-padding-against-indefinite-width.txt | 6 ++++++ ...t-percentage-padding-against-indefinite-width.txt | 6 ++++++ ...t-percentage-padding-against-indefinite-width.txt | 6 ++++++ ...-percentage-padding-against-indefinite-width.html | 11 +++++++++++ ...-percentage-padding-against-indefinite-width.html | 11 +++++++++++ ...-percentage-padding-against-indefinite-width.html | 10 ++++++++++ .../LibWeb/Layout/BlockFormattingContext.cpp | 12 ++++++------ 7 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/floating-non-replaced-element-percentage-padding-against-indefinite-width.txt create mode 100644 Tests/LibWeb/Layout/expected/floating-replaced-element-percentage-padding-against-indefinite-width.txt create mode 100644 Tests/LibWeb/Layout/expected/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.txt create mode 100644 Tests/LibWeb/Layout/input/floating-non-replaced-element-percentage-padding-against-indefinite-width.html create mode 100644 Tests/LibWeb/Layout/input/floating-replaced-element-percentage-padding-against-indefinite-width.html create mode 100644 Tests/LibWeb/Layout/input/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.html diff --git a/Tests/LibWeb/Layout/expected/floating-non-replaced-element-percentage-padding-against-indefinite-width.txt b/Tests/LibWeb/Layout/expected/floating-non-replaced-element-percentage-padding-against-indefinite-width.txt new file mode 100644 index 0000000000..635e10208b --- /dev/null +++ b/Tests/LibWeb/Layout/expected/floating-non-replaced-element-percentage-padding-against-indefinite-width.txt @@ -0,0 +1,6 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x16 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x0 children: not-inline + Box at (8,8) content-size 784x0 flex-container(row) [FFC] children: not-inline + BlockContainer
at (8,8) content-size 0x0 flex-item [BFC] children: not-inline + Box at (8,8) content-size 0x0 floating flex-container(row) [FFC] children: not-inline diff --git a/Tests/LibWeb/Layout/expected/floating-replaced-element-percentage-padding-against-indefinite-width.txt b/Tests/LibWeb/Layout/expected/floating-replaced-element-percentage-padding-against-indefinite-width.txt new file mode 100644 index 0000000000..ec1c60deba --- /dev/null +++ b/Tests/LibWeb/Layout/expected/floating-replaced-element-percentage-padding-against-indefinite-width.txt @@ -0,0 +1,6 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x80 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x64 children: not-inline + Box at (8,8) content-size 784x64 flex-container(row) [FFC] children: not-inline + BlockContainer
at (8,8) content-size 16x64 flex-item [BFC] children: not-inline + ImageBox at (24,24) content-size 16x32 floating flex-container(row) children: not-inline diff --git a/Tests/LibWeb/Layout/expected/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.txt b/Tests/LibWeb/Layout/expected/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.txt new file mode 100644 index 0000000000..086ad8ff9c --- /dev/null +++ b/Tests/LibWeb/Layout/expected/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.txt @@ -0,0 +1,6 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x16 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x0 children: not-inline + Box at (8,8) content-size 784x0 flex-container(row) [FFC] children: not-inline + BlockContainer
at (8,8) content-size 0x0 flex-item [BFC] children: not-inline + Box at (8,8) content-size 0x0 flex-container(row) [FFC] children: not-inline diff --git a/Tests/LibWeb/Layout/input/floating-non-replaced-element-percentage-padding-against-indefinite-width.html b/Tests/LibWeb/Layout/input/floating-non-replaced-element-percentage-padding-against-indefinite-width.html new file mode 100644 index 0000000000..3fbfa9e6e0 --- /dev/null +++ b/Tests/LibWeb/Layout/input/floating-non-replaced-element-percentage-padding-against-indefinite-width.html @@ -0,0 +1,11 @@ +
\ No newline at end of file diff --git a/Tests/LibWeb/Layout/input/floating-replaced-element-percentage-padding-against-indefinite-width.html b/Tests/LibWeb/Layout/input/floating-replaced-element-percentage-padding-against-indefinite-width.html new file mode 100644 index 0000000000..51e85b1309 --- /dev/null +++ b/Tests/LibWeb/Layout/input/floating-replaced-element-percentage-padding-against-indefinite-width.html @@ -0,0 +1,11 @@ +
\ No newline at end of file diff --git a/Tests/LibWeb/Layout/input/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.html b/Tests/LibWeb/Layout/input/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.html new file mode 100644 index 0000000000..09d30e48d9 --- /dev/null +++ b/Tests/LibWeb/Layout/input/non-floating-non-replaced-element-percentage-padding-against-indefinite-width.html @@ -0,0 +1,10 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 801e979c99..135c78698e 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -164,8 +164,8 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const& auto margin_left = CSS::Length::make_auto(); auto margin_right = CSS::Length::make_auto(); - auto const padding_left = computed_values.padding().left().to_px(box, width_of_containing_block); - auto const padding_right = computed_values.padding().right().to_px(box, width_of_containing_block); + auto const padding_left = computed_values.padding().left().resolved(box, width_of_containing_block_as_length_for_resolve).to_px(box); + auto const padding_right = computed_values.padding().right().resolved(box, width_of_containing_block_as_length_for_resolve).to_px(box); auto& box_state = m_state.get_mutable(box); box_state.border_left = computed_values.border_left().width; @@ -291,8 +291,8 @@ void BlockFormattingContext::compute_width_for_floating_box(Box const& box, Avai auto margin_left = computed_values.margin().left().resolved(box, width_of_containing_block_as_length_for_resolve); auto margin_right = computed_values.margin().right().resolved(box, width_of_containing_block_as_length_for_resolve); - auto const padding_left = computed_values.padding().left().to_px(box, width_of_containing_block); - auto const padding_right = computed_values.padding().right().to_px(box, width_of_containing_block); + auto const padding_left = computed_values.padding().left().resolved(box, width_of_containing_block_as_length_for_resolve).to_px(box); + auto const padding_right = computed_values.padding().right().resolved(box, width_of_containing_block_as_length_for_resolve).to_px(box); // If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'. if (margin_left.is_auto()) @@ -371,8 +371,8 @@ void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_n // non-replaced block-level elements are applied to determine the margins. auto margin_left = computed_values.margin().left().resolved(box, width_of_containing_block_as_length_for_resolve); auto margin_right = computed_values.margin().right().resolved(box, width_of_containing_block_as_length_for_resolve); - auto const padding_left = computed_values.padding().left().to_px(box, width_of_containing_block); - auto const padding_right = computed_values.padding().right().to_px(box, width_of_containing_block); + auto const padding_left = computed_values.padding().left().resolved(box, width_of_containing_block_as_length_for_resolve).to_px(box); + auto const padding_right = computed_values.padding().right().resolved(box, width_of_containing_block_as_length_for_resolve).to_px(box); // If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'. if (margin_left.is_auto())