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);