1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 00:37:34 +00:00

LibWeb: Allow doing .to_color() on a StyleValue without a layout node

This will be needed to access the color of a stop from a SVG gradient
<stop> element (which does not participate in layout, so does not have
a layout node).
This commit is contained in:
MacDue 2023-04-19 18:31:00 +01:00 committed by Andreas Kling
parent 2013761feb
commit f099ee3d47
4 changed files with 12 additions and 7 deletions

View file

@ -84,15 +84,20 @@ bool IdentifierStyleValue::has_color() const
}
}
Color IdentifierStyleValue::to_color(Layout::NodeWithStyle const& node) const
Color IdentifierStyleValue::to_color(Optional<Layout::NodeWithStyle const&> node) const
{
if (id() == CSS::ValueID::Currentcolor) {
if (!node.has_style())
if (!node.has_value() || !node->has_style())
return Color::Black;
return node.computed_values().color();
return node->computed_values().color();
}
auto& document = node.document();
if (!node.has_value()) {
// FIXME: Can't resolve palette colors without layout node.
return Color::Black;
}
auto& document = node->document();
if (id() == CSS::ValueID::LibwebLink)
return document.link_color();