From e99a6fede48009fe0753b3fd1f54651a7690927a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 Jun 2023 15:19:25 +0200 Subject: [PATCH] LibWeb: Allow IFC to size inline-flex boxes midway through flex layout The part in FFC where we ask the parent formatting context to size the flex container midway through layout is really weird, but let's at least be consistently weird for BFC and IFC. Since IFC always works within its parent BFC, it can simply forward these requests to the BFC. This fixes an issue where inline-flex containers incorrectly had main axis margins subtracted from their content size. --- ...-with-main-axis-margin-on-flex-container.txt | 10 ++++++++++ ...with-main-axis-margin-on-flex-container.html | 17 +++++++++++++++++ .../LibWeb/Layout/InlineFormattingContext.cpp | 15 +++++++++++++++ .../LibWeb/Layout/InlineFormattingContext.h | 4 ++++ 4 files changed, 46 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/flex/inline-flex-with-main-axis-margin-on-flex-container.txt create mode 100644 Tests/LibWeb/Layout/input/flex/inline-flex-with-main-axis-margin-on-flex-container.html diff --git a/Tests/LibWeb/Layout/expected/flex/inline-flex-with-main-axis-margin-on-flex-container.txt b/Tests/LibWeb/Layout/expected/flex/inline-flex-with-main-axis-margin-on-flex-container.txt new file mode 100644 index 0000000000..1196b65b11 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/flex/inline-flex-with-main-axis-margin-on-flex-container.txt @@ -0,0 +1,10 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (1,1) content-size 500x37.46875 [BFC] children: inline + line 0 width: 272.40625, height: 37.46875, bottom: 37.46875, baseline: 15.53125 + frag 0 from Box start: 0, length: 0, rect: [10,10 162.40625x19.46875] + Box at (10,10) content-size 162.40625x19.46875 flex-container(row) [FFC] children: not-inline + BlockContainer
at (11,11) content-size 160.40625x17.46875 flex-item [BFC] children: inline + line 0 width: 160.40625, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 20, rect: [11,11 160.40625x17.46875] + "Immobilie inserieren" + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/flex/inline-flex-with-main-axis-margin-on-flex-container.html b/Tests/LibWeb/Layout/input/flex/inline-flex-with-main-axis-margin-on-flex-container.html new file mode 100644 index 0000000000..d1c9c670c2 --- /dev/null +++ b/Tests/LibWeb/Layout/input/flex/inline-flex-with-main-axis-margin-on-flex-container.html @@ -0,0 +1,17 @@ +
Immobilie inserieren \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 127c29cbb4..24b585d31a 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -348,4 +348,19 @@ bool InlineFormattingContext::can_fit_new_line_at_y(CSSPixels y) const return true; } +bool InlineFormattingContext::can_determine_size_of_child() const +{ + return parent().can_determine_size_of_child(); +} + +void InlineFormattingContext::determine_width_of_child(Box const& box, AvailableSpace const& available_space) +{ + return parent().determine_width_of_child(box, available_space); +} + +void InlineFormattingContext::determine_height_of_child(Box const& box, AvailableSpace const& available_space) +{ + return parent().determine_height_of_child(box, available_space); +} + } diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h index c795c345fd..c1e5c15a60 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h @@ -34,6 +34,10 @@ public: bool any_floats_intrude_at_y(CSSPixels y) const; bool can_fit_new_line_at_y(CSSPixels y) const; + virtual bool can_determine_size_of_child() const override; + virtual void determine_width_of_child(Box const&, AvailableSpace const&) override; + virtual void determine_height_of_child(Box const&, AvailableSpace const&) override; + private: void generate_line_boxes(LayoutMode); void apply_justification_to_fragments(CSS::TextJustify, LineBox&, bool is_last_line);