LibWeb: Move presentation attrs from SVGGraphicsElement to SVGElement

This matches how other browser behave and fixes a bunch of WPT tests.
This commit is contained in:
Andreas Kling 2025-04-24 19:48:58 +02:00 committed by Jelle Raaijmakers
parent fe6d8131ae
commit 10cff06a95
Notes: github-actions[bot] 2025-04-25 08:19:32 +00:00
11 changed files with 700 additions and 69 deletions

View file

@ -131,72 +131,6 @@ Gfx::AffineTransform SVGGraphicsElement::get_transform() const
return transform;
}
struct NamedPropertyID {
NamedPropertyID(CSS::PropertyID property_id)
: id(property_id)
, name(CSS::string_from_property_id(property_id))
{
}
CSS::PropertyID id;
StringView name;
};
static Array const attribute_style_properties {
// FIXME: The `fill` attribute and CSS `fill` property are not the same! But our support is limited enough that they are equivalent for now.
NamedPropertyID(CSS::PropertyID::Fill),
// FIXME: The `stroke` attribute and CSS `stroke` property are not the same! But our support is limited enough that they are equivalent for now.
NamedPropertyID(CSS::PropertyID::Stroke),
NamedPropertyID(CSS::PropertyID::StrokeDasharray),
NamedPropertyID(CSS::PropertyID::StrokeDashoffset),
NamedPropertyID(CSS::PropertyID::StrokeLinecap),
NamedPropertyID(CSS::PropertyID::StrokeLinejoin),
NamedPropertyID(CSS::PropertyID::StrokeMiterlimit),
NamedPropertyID(CSS::PropertyID::StrokeWidth),
NamedPropertyID(CSS::PropertyID::FillRule),
NamedPropertyID(CSS::PropertyID::FillOpacity),
NamedPropertyID(CSS::PropertyID::StrokeOpacity),
NamedPropertyID(CSS::PropertyID::Opacity),
NamedPropertyID(CSS::PropertyID::TextAnchor),
NamedPropertyID(CSS::PropertyID::FontSize),
NamedPropertyID(CSS::PropertyID::Mask),
NamedPropertyID(CSS::PropertyID::MaskType),
NamedPropertyID(CSS::PropertyID::ClipPath),
NamedPropertyID(CSS::PropertyID::ClipRule),
NamedPropertyID(CSS::PropertyID::Display),
};
bool SVGGraphicsElement::is_presentational_hint(FlyString const& name) const
{
if (Base::is_presentational_hint(name))
return true;
return any_of(attribute_style_properties, [&](auto& property) { return name.equals_ignoring_ascii_case(property.name); });
}
void SVGGraphicsElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
{
CSS::Parser::ParsingParams parsing_context { document(), CSS::Parser::ParsingMode::SVGPresentationAttribute };
for_each_attribute([&](auto& name, auto& value) {
for (auto property : attribute_style_properties) {
if (!name.equals_ignoring_ascii_case(property.name))
continue;
if (property.id == CSS::PropertyID::Mask) {
// Mask is a shorthand property in CSS, but parse_css_value does not take that into account. For now,
// just parse as 'mask-image' as anything else is currently not supported.
// FIXME: properly parse longhand 'mask' property
if (auto style_value = parse_css_value(parsing_context, value, CSS::PropertyID::MaskImage)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MaskImage, style_value.release_nonnull());
}
} else {
if (auto style_value = parse_css_value(parsing_context, value, property.id))
cascaded_properties->set_property_from_presentational_hint(property.id, style_value.release_nonnull());
}
break;
}
});
}
static FillRule to_svg_fill_rule(CSS::FillRule fill_rule)
{
switch (fill_rule) {