LibWeb: Use foreignObject's own size as available space inside it

This ensures that percentages resolve against the foreignObject's size
instead of the size of its containing block.

This makes user profile pictures clip correctly in the "Friends" view
of the Discord app.
This commit is contained in:
Andreas Kling 2025-07-11 17:32:13 +02:00 committed by Jelle Raaijmakers
commit 4e23882995
Notes: github-actions[bot] 2025-07-12 12:12:54 +00:00
2 changed files with 5 additions and 3 deletions

View file

@ -279,7 +279,6 @@ void SVGFormattingContext::layout_svg_element(Box const& child)
layout_nested_viewport(child);
} else if (is<SVG::SVGForeignObjectElement>(child.dom_node()) && is<BlockContainer>(child)) {
Layout::BlockFormattingContext bfc(m_state, m_layout_mode, static_cast<BlockContainer const&>(child), this);
bfc.run(*m_available_space);
auto& child_state = m_state.get_mutable(child);
CSSPixelRect rect {
{
@ -295,6 +294,9 @@ void SVGFormattingContext::layout_svg_element(Box const& child)
child_state.set_content_offset(transformed_rect.location());
child_state.set_content_width(transformed_rect.width());
child_state.set_content_height(transformed_rect.height());
bfc.run(AvailableSpace(AvailableSize::make_definite(child_state.content_width()), AvailableSize::make_definite(child_state.content_height())));
if (auto* mask_box = child.first_child_of_type<SVGMaskBox>())
layout_mask_or_clip(*mask_box);

View file

@ -5,7 +5,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
SVGForeignObjectBox <foreignObject> at (8,8) content-size 100x200 [BFC] children: not-inline
BlockContainer <(anonymous)> at (8,8) content-size 300x0 children: inline
BlockContainer <(anonymous)> at (8,8) content-size 100x0 children: inline
TextNode <#text>
BlockContainer <div.el> at (8,8) content-size 50x60 positioned [BFC] children: not-inline
TextNode <#text>
@ -19,7 +19,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<BODY>) [8,8 784x150]
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150] overflow: [8,8 300x200]
SVGForeignObjectPaintable (SVGForeignObjectBox<foreignObject>) [8,8 100x200]
PaintableWithLines (BlockContainer(anonymous)) [8,8 300x0]
PaintableWithLines (BlockContainer(anonymous)) [8,8 100x0]
PaintableWithLines (BlockContainer<DIV>.el) [8,8 50x60]
PaintableWithLines (BlockContainer(anonymous)) [8,158 784x0]