From 684f7cca9f9983cabd30749ee79a01d433ccedee Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Sep 2021 00:06:16 +0200 Subject: [PATCH] LibWeb: Implement very naive layout of within --- .../LibWeb/Layout/SVGFormattingContext.cpp | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index 4d09d8a947..992e95415b 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace Web::Layout { @@ -19,8 +20,27 @@ SVGFormattingContext::~SVGFormattingContext() { } -void SVGFormattingContext::run(Box&, LayoutMode) +void SVGFormattingContext::run(Box& box, LayoutMode) { + // FIXME: This formatting context is basically a total hack. + // It works by computing the united bounding box of all 's + // within an , and using that as the size of this box. + + Gfx::FloatRect total_bounding_box; + + box.for_each_in_subtree_of_type([&](auto& descendant) { + if (is(descendant)) { + auto& path_box = static_cast(descendant); + auto& path = path_box.dom_node().get_path(); + path_box.set_size(path.bounding_box().size()); + + total_bounding_box = total_bounding_box.united(path.bounding_box()); + } + + return IterationDecision::Continue; + }); + + box.set_size(total_bounding_box.size()); } }