LibWeb: Implement SVG opacity properties

This implements the stop-opacity, fill-opacity, and stroke-opacity
properties (in CSS). This replaces the existing more ad-hoc
fill-opacity attribute handling.
This commit is contained in:
MacDue 2023-05-19 20:35:39 +01:00 committed by Andreas Kling
parent 120e5b6b6f
commit 00cda96e2d
Notes: sideshowbarker 2024-07-16 21:51:02 +09:00
13 changed files with 141 additions and 29 deletions

View file

@ -31,11 +31,15 @@ void SVGStopElement::apply_presentational_hints(CSS::StyleProperties& style) con
{
CSS::Parser::ParsingContext parsing_context { document() };
for_each_attribute([&](auto& name, auto& value) {
CSS::Parser::ParsingContext parsing_context { document() };
if (name.equals_ignoring_ascii_case("stop-color"sv)) {
CSS::Parser::ParsingContext parsing_context { document() };
if (auto stop_color = parse_css_value(parsing_context, value, CSS::PropertyID::StopColor).release_value_but_fixme_should_propagate_errors()) {
style.set_property(CSS::PropertyID::StopColor, stop_color.release_nonnull());
}
} else if (name.equals_ignoring_ascii_case("stop-opacity"sv)) {
if (auto stop_opacity = parse_css_value(parsing_context, value, CSS::PropertyID::StopOpacity).release_value_but_fixme_should_propagate_errors()) {
style.set_property(CSS::PropertyID::StopOpacity, stop_opacity.release_nonnull());
}
}
});
}
@ -47,6 +51,13 @@ Gfx::Color SVGStopElement::stop_color() const
return Color::Black;
}
float SVGStopElement::stop_opacity() const
{
if (auto css_values = computed_css_values())
return css_values->stop_opacity();
return 1;
}
JS::NonnullGCPtr<SVGAnimatedNumber> SVGStopElement::offset() const
{
TODO();