From 6482c306f16b3a49b8fd10554847cc8f125fa0f3 Mon Sep 17 00:00:00 2001 From: MacDue Date: Mon, 10 Apr 2023 12:25:00 +0100 Subject: [PATCH] LibWeb: Parse and apply `fill-opacity` attribute to SVG paths This is needed to fix the rendering of the Street View directional controls (which have paths with various levels of opacity set by this attribute). --- Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp | 12 +++++++++++- Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.h | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp index 15ce9b3c016..fce7ca1aa4e 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp @@ -26,6 +26,14 @@ JS::ThrowCompletionOr SVGGraphicsElement::initialize(JS::Realm& realm) return {}; } +void SVGGraphicsElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) +{ + SVGElement::parse_attribute(name, value); + if (name == "fill-opacity"sv) { + m_fill_opacity = AttributeParser::parse_length(value); + } +} + void SVGGraphicsElement::apply_presentational_hints(CSS::StyleProperties& style) const { CSS::Parser::ParsingContext parsing_context { document() }; @@ -54,7 +62,9 @@ Optional SVGGraphicsElement::fill_color() const 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(); + return layout_node()->computed_values().fill().map([&](Gfx::Color color) { + return color.with_alpha(m_fill_opacity.value_or(1) * 255); + }); } Optional SVGGraphicsElement::stroke_color() const diff --git a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.h b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.h index e225a6526a4..7016f58943d 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.h @@ -20,7 +20,10 @@ class SVGGraphicsElement : public SVGElement { public: virtual void apply_presentational_hints(CSS::StyleProperties&) const override; + virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override; + Optional fill_color() const; + Gfx::Painter::WindingRule fill_rule() const; Optional stroke_color() const; Optional stroke_width() const; @@ -28,6 +31,8 @@ protected: SVGGraphicsElement(DOM::Document&, DOM::QualifiedName); virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; + + Optional m_fill_opacity = {}; }; }