LibWeb: Support x and y attributes on nested SVGs

This allows positioning a child SVG relative to its parent SVG.

Note: These have been implemented as CSS properties as in SVG 2, these
are geometry properties that can be used in CSS (see
https://www.w3.org/TR/SVG/geometry.html), but there is not much browser
support for this. It is nicer to implement than the ad-hoc SVG
attribute parsing though, so I feel it may make sense to port the rest
of the attributes specified here (which should fix some issues with
viewport relative sizes).
This commit is contained in:
MacDue 2024-01-28 17:48:59 +00:00 committed by Sam Atkins
parent 556679fedd
commit b10f58a1fe
Notes: sideshowbarker 2024-07-17 00:47:29 +09:00
8 changed files with 91 additions and 2 deletions

View file

@ -285,9 +285,11 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
return size.to_px(node, reference_value);
};
// FIXME: Support the x/y attributes to calculate the offset.
auto nested_viewport_x = descendant.computed_values().x().to_px(descendant, viewport_width);
auto nested_viewport_y = descendant.computed_values().y().to_px(descendant, viewport_height);
auto nested_viewport_width = resolve_dimension(descendant, descendant.computed_values().width(), viewport_width);
auto nested_viewport_height = resolve_dimension(descendant, descendant.computed_values().height(), viewport_height);
nested_viewport_state.set_content_offset({ nested_viewport_x, nested_viewport_y });
nested_viewport_state.set_content_width(nested_viewport_width);
nested_viewport_state.set_content_height(nested_viewport_height);
nested_context.run(static_cast<Box const&>(descendant), layout_mode, available_space);