LibWeb: Add SVG paint fallback color support to CSS parsing

This commit is contained in:
Tim Ledbetter
2026-02-17 15:48:31 +00:00
committed by Jelle Raaijmakers
parent f13a26d68e
commit 804287847a
Notes: github-actions[bot] 2026-02-27 16:16:30 +00:00
8 changed files with 52 additions and 11 deletions

View File

@@ -821,16 +821,24 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
computed_values.set_x(CSS::LengthPercentage::from_style_value(computed_style.property(CSS::PropertyID::X)));
computed_values.set_y(CSS::LengthPercentage::from_style_value(computed_style.property(CSS::PropertyID::Y)));
auto extract_paint_fallback_color = [&](CSS::URLStyleValue const& url_value) -> Optional<Color> {
if (auto const& fallback = url_value.paint_fallback()) {
if (fallback->has_color())
return fallback->to_color(color_resolution_context);
}
return {};
};
auto const& fill = computed_style.property(CSS::PropertyID::Fill);
if (fill.has_color())
computed_values.set_fill(fill.to_color(color_resolution_context).value());
else if (fill.is_url())
computed_values.set_fill(fill.as_url().url());
computed_values.set_fill(CSS::SVGPaint(fill.as_url().url(), extract_paint_fallback_color(fill.as_url())));
auto const& stroke = computed_style.property(CSS::PropertyID::Stroke);
if (stroke.has_color())
computed_values.set_stroke(stroke.to_color(color_resolution_context).value());
else if (stroke.is_url())
computed_values.set_stroke(stroke.as_url().url());
computed_values.set_stroke(CSS::SVGPaint(stroke.as_url().url(), extract_paint_fallback_color(stroke.as_url())));
computed_values.set_stop_color(computed_style.color_or_fallback(CSS::PropertyID::StopColor, color_resolution_context, CSS::InitialValues::stop_color()));