LibWeb: Make sure we run selectors for mixed-case tag names

Before this change, we would never apply CSS rules where the selector
had a mixed-case tag name. This happened because our rule caches would
key them on the lowercased tag name, but we didn't lowercase the tag
name when fetching things from the cache.

This uncovered the fact that the SVG2 spec has a bunch of style applied
to non-rendered elements in a way that doesn't match other browsers.
Instead of blindly following the spec, we now match other browsers.
This commit is contained in:
Andreas Kling 2025-07-07 15:18:22 +02:00 committed by Andreas Kling
parent 61df035612
commit b3fd939628
Notes: github-actions[bot] 2025-07-09 12:37:53 +00:00
5 changed files with 11 additions and 10 deletions

View file

@ -3280,7 +3280,7 @@ void RuleCache::for_each_matching_rules(DOM::Element const& element, Optional<Ps
return;
}
}
if (auto it = rules_by_tag_name.find(element.local_name()); it != rules_by_tag_name.end()) {
if (auto it = rules_by_tag_name.find(element.lowercased_local_name()); it != rules_by_tag_name.end()) {
if (callback(it->value) == IterationDecision::Break)
return;
}

View file

@ -117,6 +117,8 @@ public:
virtual FlyString node_name() const final { return html_uppercased_qualified_name(); }
FlyString const& local_name() const { return m_qualified_name.local_name(); }
FlyString const& lowercased_local_name() const { return m_qualified_name.lowercased_local_name(); }
// NOTE: This is for the JS bindings
FlyString const& tag_name() const { return html_uppercased_qualified_name(); }

View file

@ -56,6 +56,7 @@ QualifiedName::QualifiedName(FlyString const& local_name, Optional<FlyString> co
QualifiedName::Impl::Impl(FlyString const& a_local_name, Optional<FlyString> const& a_prefix, Optional<FlyString> const& a_namespace)
: local_name(a_local_name)
, lowercased_local_name(local_name.to_ascii_lowercase())
, prefix(a_prefix)
, namespace_(a_namespace)
{

View file

@ -21,6 +21,8 @@ public:
Optional<FlyString> const& prefix() const { return m_impl->prefix; }
Optional<FlyString> const& namespace_() const { return m_impl->namespace_; }
FlyString const& lowercased_local_name() const { return m_impl->lowercased_local_name; }
FlyString const& as_string() const { return m_impl->as_string; }
struct Impl : public RefCounted<Impl> {
@ -29,6 +31,7 @@ public:
void make_internal_string();
FlyString local_name;
FlyString lowercased_local_name;
Optional<FlyString> prefix;
Optional<FlyString> namespace_;
FlyString as_string;

View file

@ -14,14 +14,8 @@ svg:not(:root), image, marker, pattern, symbol { overflow: hidden; }
white-space-collapse: preserve-spaces;
}
/* FIXME: Allow setting the rest of these to `display: none`.
Currently that breaks <use> and <mask> and probably others. */
desc, title, metadata,
pattern, linearGradient, radialGradient,
script, style {
display: none !important;
}
/*
/* NOTE: These rules are in the SVG spec, but don't match how other engines behave.
So we simply comment them out for now.
defs,
clipPath, mask, marker,
desc, title, metadata,
@ -30,10 +24,11 @@ script, style,
symbol {
display: none !important;
}
*/
:host(use) > symbol {
display: inline !important;
}
*/
:link, :visited {
cursor: pointer;
}