diff --git a/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index cf666e61ffa..40ae393ce50 100644 --- a/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -281,9 +281,20 @@ void SVGFormattingContext::layout_svg_element(Box const& child) Layout::BlockFormattingContext bfc(m_state, m_layout_mode, static_cast(child), this); bfc.run(*m_available_space); auto& child_state = m_state.get_mutable(child); - child_state.set_content_offset(child_state.offset.translated(m_svg_offset)); - child_state.set_content_width(child.computed_values().width().to_px(child, m_available_space->width.to_px_or_zero())); - child_state.set_content_height(child.computed_values().height().to_px(child, m_available_space->height.to_px_or_zero())); + CSSPixelRect rect { + { + child.computed_values().x().to_px(child, m_available_space->width.to_px_or_zero()), + child.computed_values().y().to_px(child, m_available_space->height.to_px_or_zero()), + }, + { + child.computed_values().width().to_px(child, m_available_space->width.to_px_or_zero()), + child.computed_values().height().to_px(child, m_available_space->height.to_px_or_zero()), + } + }; + auto transformed_rect = m_current_viewbox_transform.map(rect.to_type()).to_type(); + child_state.set_content_offset(transformed_rect.location()); + child_state.set_content_width(transformed_rect.width()); + child_state.set_content_height(transformed_rect.height()); child.for_each_child_of_type([&](SVGMaskBox const& child) { layout_svg_element(child); return IterationDecision::Continue; diff --git a/Tests/LibWeb/Layout/expected/svg/foreignObject-simple.txt b/Tests/LibWeb/Layout/expected/svg/foreignObject-simple.txt new file mode 100644 index 00000000000..b1525f8f348 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/svg/foreignObject-simple.txt @@ -0,0 +1,20 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x64 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x48 children: not-inline + SVGSVGBox at (8,8) content-size 48x48 [SVG] children: not-inline + SVGForeignObjectBox at (8,8) content-size 30x30 [BFC] children: not-inline + BlockContainer
at (13,13) content-size 40x40 children: not-inline + BlockContainer <(anonymous)> at (8,56) content-size 784x0 children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x64] + PaintableWithLines (BlockContainer) [8,8 784x48] + SVGSVGPaintable (SVGSVGBox) [8,8 48x48] + SVGForeignObjectPaintable (SVGForeignObjectBox) [8,8 30x30] overflow: [8,8 50x50] + PaintableWithLines (BlockContainer
) [8,8 50x50] + PaintableWithLines (BlockContainer(anonymous)) [8,56 784x0] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x64] [children: 1] (z-index: auto) + SC for SVGForeignObjectBox [8,8 30x30] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/expected/svg/foreignObject-with-mask.txt b/Tests/LibWeb/Layout/expected/svg/foreignObject-with-mask.txt new file mode 100644 index 00000000000..64ed00693e7 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/svg/foreignObject-with-mask.txt @@ -0,0 +1,29 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x64 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x48 children: not-inline + SVGSVGBox at (8,8) content-size 48x48 [SVG] children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + TextNode <#text> + TextNode <#text> + SVGForeignObjectBox at (26,36) content-size 40x40 [BFC] children: not-inline + BlockContainer at (31,41) content-size 40x40 children: not-inline + SVGMaskBox at (16,16) content-size 48x48 children: inline + TextNode <#text> + SVGGraphicsBox at (16,16) content-size 48x48 children: not-inline + SVGGeometryBox at (16,16) content-size 48x48 children: not-inline + TextNode <#text> + BlockContainer <(anonymous)> at (8,56) content-size 784x0 children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x64] + PaintableWithLines (BlockContainer) [8,8 784x48] + SVGSVGPaintable (SVGSVGBox) [8,8 48x48] overflow: [8,8 58x68] + SVGForeignObjectPaintable (SVGForeignObjectBox) [26,36 40x40] overflow: [16,16 60x70] + PaintableWithLines (BlockContainer
.lmao) [26,36 50x50] + PaintableWithLines (BlockContainer(anonymous)) [8,56 784x0] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x64] [children: 1] (z-index: auto) + SC for SVGForeignObjectBox [26,36 40x40] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/input/svg/foreignObject-simple.html b/Tests/LibWeb/Layout/input/svg/foreignObject-simple.html new file mode 100644 index 00000000000..fae970fa917 --- /dev/null +++ b/Tests/LibWeb/Layout/input/svg/foreignObject-simple.html @@ -0,0 +1,13 @@ + +
diff --git a/Tests/LibWeb/Layout/input/svg/foreignObject-with-mask.html b/Tests/LibWeb/Layout/input/svg/foreignObject-with-mask.html new file mode 100644 index 00000000000..7de2640a3d8 --- /dev/null +++ b/Tests/LibWeb/Layout/input/svg/foreignObject-with-mask.html @@ -0,0 +1,24 @@ + + + + + + +