mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibWeb: Layout <svg> nested inside <svg>
This is far from perfect, but let's at least make an attempt at laying out <svg> when encountering it inside another <svg>. This makes https://awesomekling.substack.com actually load and render instead of asserting. :^)
This commit is contained in:
parent
ec5d5918c4
commit
ce5a939148
3 changed files with 29 additions and 3 deletions
10
Tests/LibWeb/Layout/expected/svg/svg-inside-svg.txt
Normal file
10
Tests/LibWeb/Layout/expected/svg/svg-inside-svg.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
|
BlockContainer <html> at (0,0) content-size 800x40 children: not-inline
|
||||||
|
BlockContainer <body> 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 <svg> at (8,8) content-size 24x24 children: inline
|
||||||
|
SVGGraphicsBox <g> children: inline
|
||||||
|
SVGSVGBox <svg> at (8,8) content-size 24x24 children: not-inline
|
||||||
|
SVGGeometryBox <rect> at (8,8) content-size 24x24 children: not-inline
|
||||||
|
TextNode <#text>
|
12
Tests/LibWeb/Layout/input/svg/svg-inside-svg.html
Normal file
12
Tests/LibWeb/Layout/input/svg/svg-inside-svg.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!doctype html><body><svg
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
><g><svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
><rect x="0" y="0" width="24" height="24"></svg></g>
|
||||||
|
</svg>
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
|
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
|
||||||
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
||||||
|
@ -10,6 +10,7 @@
|
||||||
#include <LibWeb/Layout/BlockFormattingContext.h>
|
#include <LibWeb/Layout/BlockFormattingContext.h>
|
||||||
#include <LibWeb/Layout/SVGFormattingContext.h>
|
#include <LibWeb/Layout/SVGFormattingContext.h>
|
||||||
#include <LibWeb/Layout/SVGGeometryBox.h>
|
#include <LibWeb/Layout/SVGGeometryBox.h>
|
||||||
|
#include <LibWeb/Layout/SVGSVGBox.h>
|
||||||
#include <LibWeb/SVG/SVGForeignObjectElement.h>
|
#include <LibWeb/SVG/SVGForeignObjectElement.h>
|
||||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ static ViewBoxTransform scale_and_align_viewbox_content(SVG::PreserveAspectRatio
|
||||||
return viewbox_transform;
|
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.
|
// 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;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
box.for_each_in_subtree_of_type<SVGBox>([&](SVGBox const& descendant) {
|
box.for_each_in_subtree_of_type<Box>([&](Box const& descendant) {
|
||||||
if (is<SVGGeometryBox>(descendant)) {
|
if (is<SVGGeometryBox>(descendant)) {
|
||||||
auto const& geometry_box = static_cast<SVGGeometryBox const&>(descendant);
|
auto const& geometry_box = static_cast<SVGGeometryBox const&>(descendant);
|
||||||
auto& geometry_box_state = m_state.get_mutable(geometry_box);
|
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_offset(path_bounding_box.top_left());
|
||||||
geometry_box_state.set_content_width(path_bounding_box.width());
|
geometry_box_state.set_content_width(path_bounding_box.width());
|
||||||
geometry_box_state.set_content_height(path_bounding_box.height());
|
geometry_box_state.set_content_height(path_bounding_box.height());
|
||||||
|
} else if (is<SVGSVGBox>(descendant)) {
|
||||||
|
SVGFormattingContext nested_context(m_state, descendant, this);
|
||||||
|
nested_context.run(descendant, layout_mode, available_space);
|
||||||
}
|
}
|
||||||
|
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue