LibWeb/SVG: Resolve fill URI reference values

This commit is contained in:
Tim Ledbetter 2025-08-20 20:31:56 +01:00 committed by Jelle Raaijmakers
commit 05432d7157
Notes: github-actions[bot] 2025-08-20 22:35:08 +00:00
6 changed files with 43 additions and 7 deletions

View file

@ -161,13 +161,19 @@ Optional<Gfx::Color> SVGGraphicsElement::fill_color() const
{
if (!layout_node())
return {};
// FIXME: In the working-draft spec, `fill` is intended to be a shorthand, with `fill-color`
// being what we actually want to use. But that's not final or widely supported yet.
return layout_node()->computed_values().fill().map([&](auto& paint) -> Gfx::Color {
if (!paint.is_color())
return Color::Black;
return paint.as_color();
});
auto paint = layout_node()->computed_values().fill();
if (!paint.has_value())
return {};
if (paint->is_url()) {
if (auto referenced_element = try_resolve_url_to<SVGGraphicsElement const>(paint->as_url()))
return referenced_element->fill_color();
return {};
}
return paint->as_color();
}
Optional<Gfx::Color> SVGGraphicsElement::stroke_color() const