From ce5a9391482b054ba231e6e10de75f1de3287893 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 18 Apr 2023 19:32:00 +0200 Subject: [PATCH] LibWeb: Layout nested inside This is far from perfect, but let's at least make an attempt at laying out when encountering it inside another . This makes https://awesomekling.substack.com actually load and render instead of asserting. :^) --- Tests/LibWeb/Layout/expected/svg/svg-inside-svg.txt | 10 ++++++++++ Tests/LibWeb/Layout/input/svg/svg-inside-svg.html | 12 ++++++++++++ .../Libraries/LibWeb/Layout/SVGFormattingContext.cpp | 10 +++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/svg/svg-inside-svg.txt create mode 100644 Tests/LibWeb/Layout/input/svg/svg-inside-svg.html diff --git a/Tests/LibWeb/Layout/expected/svg/svg-inside-svg.txt b/Tests/LibWeb/Layout/expected/svg/svg-inside-svg.txt new file mode 100644 index 0000000000..b8b8734e33 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/svg/svg-inside-svg.txt @@ -0,0 +1,10 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x40 children: not-inline + BlockContainer at (8,8) content-size 784x24 children: inline + line 0 width: 24, height: 24, bottom: 24, baseline: 24 + frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 24x24] + SVGSVGBox at (8,8) content-size 24x24 children: inline + SVGGraphicsBox children: inline + SVGSVGBox at (8,8) content-size 24x24 children: not-inline + SVGGeometryBox at (8,8) content-size 24x24 children: not-inline + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/svg/svg-inside-svg.html b/Tests/LibWeb/Layout/input/svg/svg-inside-svg.html new file mode 100644 index 0000000000..03ead1fa2e --- /dev/null +++ b/Tests/LibWeb/Layout/input/svg/svg-inside-svg.html @@ -0,0 +1,12 @@ + + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index 7e7bd1991e..90f2361643 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021-2023, Andreas Kling * Copyright (c) 2022, Sam Atkins * Copyright (c) 2022, Tobias Christiansen * Copyright (c) 2023, MacDue @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -128,7 +129,7 @@ static ViewBoxTransform scale_and_align_viewbox_content(SVG::PreserveAspectRatio return viewbox_transform; } -void SVGFormattingContext::run(Box const& box, LayoutMode, [[maybe_unused]] AvailableSpace const& available_space) +void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, AvailableSpace const& available_space) { // FIXME: This a bunch of this thing is an ad-hoc hack. @@ -148,7 +149,7 @@ void SVGFormattingContext::run(Box const& box, LayoutMode, [[maybe_unused]] Avai return IterationDecision::Continue; }); - box.for_each_in_subtree_of_type([&](SVGBox const& descendant) { + box.for_each_in_subtree_of_type([&](Box const& descendant) { if (is(descendant)) { auto const& geometry_box = static_cast(descendant); auto& geometry_box_state = m_state.get_mutable(geometry_box); @@ -184,6 +185,9 @@ void SVGFormattingContext::run(Box const& box, LayoutMode, [[maybe_unused]] Avai geometry_box_state.set_content_offset(path_bounding_box.top_left()); geometry_box_state.set_content_width(path_bounding_box.width()); geometry_box_state.set_content_height(path_bounding_box.height()); + } else if (is(descendant)) { + SVGFormattingContext nested_context(m_state, descendant, this); + nested_context.run(descendant, layout_mode, available_space); } return IterationDecision::Continue;