From b2c899af118e40e3786abde0825ba7f00cc5d248 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 20 May 2023 17:44:18 +0200 Subject: [PATCH] LibWeb: Make standalone SVG document roots the size of the viewport We have to special-case these, otherwise our normal CSS layout algorithm will see that some SVG roots have width/height assigned, and make those the used width/height. When used in an SVG-as-image context, the outermost viewport must be the authoritative root size. --- .../LibWeb/Layout/BlockFormattingContext.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 6da13110ee..c5492a9530 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -794,10 +795,19 @@ void BlockFormattingContext::layout_viewport(LayoutMode layout_mode, AvailableSp auto& viewport = verify_cast(root()); auto& viewport_state = m_state.get_mutable(viewport); - if (root().children_are_inline()) - layout_inline_children(root(), layout_mode, available_space); - else - layout_block_level_children(root(), layout_mode, available_space); + // NOTE: If we are laying out a standalone SVG document, we give it some special treatment: + // The root container gets the same size as the viewport, + // and we call directly into the SVG layout code from here. + if (root().first_child() && root().first_child()->is_svg_svg_box()) { + auto const& svg_root = verify_cast(*root().first_child()); + auto svg_formatting_context = create_independent_formatting_context_if_needed(m_state, svg_root); + svg_formatting_context->run(svg_root, layout_mode, available_space); + } else { + if (root().children_are_inline()) + layout_inline_children(root(), layout_mode, available_space); + else + layout_block_level_children(root(), layout_mode, available_space); + } CSSPixels bottom_edge = 0; CSSPixels right_edge = 0;