mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibWeb: Track all namespace rules in a CSSStyleSheet, and expose them
This commit is contained in:
parent
a8096d33ec
commit
4b7b726888
2 changed files with 16 additions and 1 deletions
|
@ -50,6 +50,8 @@ void CSSStyleSheet::visit_edges(Cell::Visitor& visitor)
|
||||||
visitor.visit(m_rules);
|
visitor.visit(m_rules);
|
||||||
visitor.visit(m_owner_css_rule);
|
visitor.visit(m_owner_css_rule);
|
||||||
visitor.visit(m_default_namespace_rule);
|
visitor.visit(m_default_namespace_rule);
|
||||||
|
for (auto& [key, namespace_rule] : m_namespace_rules)
|
||||||
|
visitor.visit(namespace_rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/cssom/#dom-cssstylesheet-insertrule
|
// https://www.w3.org/TR/cssom/#dom-cssstylesheet-insertrule
|
||||||
|
@ -150,8 +152,19 @@ Optional<StringView> CSSStyleSheet::default_namespace() const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<StringView> CSSStyleSheet::namespace_uri(StringView namespace_prefix) const
|
||||||
|
{
|
||||||
|
return m_namespace_rules.get(namespace_prefix)
|
||||||
|
.map([](JS::GCPtr<CSSNamespaceRule> namespace_) {
|
||||||
|
return namespace_->namespace_uri().view();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void CSSStyleSheet::recalculate_namespaces()
|
void CSSStyleSheet::recalculate_namespaces()
|
||||||
{
|
{
|
||||||
|
m_default_namespace_rule = nullptr;
|
||||||
|
m_namespace_rules.clear();
|
||||||
|
|
||||||
for (JS::NonnullGCPtr<CSSRule> rule : *m_rules) {
|
for (JS::NonnullGCPtr<CSSRule> rule : *m_rules) {
|
||||||
// "Any @namespace rules must follow all @charset and @import rules and precede all other
|
// "Any @namespace rules must follow all @charset and @import rules and precede all other
|
||||||
// non-ignored at-rules and style rules in a style sheet.
|
// non-ignored at-rules and style rules in a style sheet.
|
||||||
|
@ -174,7 +187,7 @@ void CSSStyleSheet::recalculate_namespaces()
|
||||||
if (!namespace_rule.namespace_uri().is_empty() && namespace_rule.prefix().is_empty())
|
if (!namespace_rule.namespace_uri().is_empty() && namespace_rule.prefix().is_empty())
|
||||||
m_default_namespace_rule = namespace_rule;
|
m_default_namespace_rule = namespace_rule;
|
||||||
|
|
||||||
// FIXME: Store qualified namespace rules.
|
m_namespace_rules.set(FlyString::from_deprecated_fly_string(namespace_rule.prefix()).release_value_but_fixme_should_propagate_errors(), namespace_rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
|
void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
|
||||||
|
|
||||||
Optional<StringView> default_namespace() const;
|
Optional<StringView> default_namespace() const;
|
||||||
|
Optional<StringView> namespace_uri(StringView namespace_prefix) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSSStyleSheet(JS::Realm&, CSSRuleList&, MediaList&, Optional<AK::URL> location);
|
CSSStyleSheet(JS::Realm&, CSSRuleList&, MediaList&, Optional<AK::URL> location);
|
||||||
|
@ -61,6 +62,7 @@ private:
|
||||||
|
|
||||||
JS::GCPtr<CSSRuleList> m_rules;
|
JS::GCPtr<CSSRuleList> m_rules;
|
||||||
JS::GCPtr<CSSNamespaceRule> m_default_namespace_rule;
|
JS::GCPtr<CSSNamespaceRule> m_default_namespace_rule;
|
||||||
|
HashMap<FlyString, JS::GCPtr<CSSNamespaceRule>> m_namespace_rules;
|
||||||
|
|
||||||
JS::GCPtr<StyleSheetList> m_style_sheet_list;
|
JS::GCPtr<StyleSheetList> m_style_sheet_list;
|
||||||
JS::GCPtr<CSSRule> m_owner_css_rule;
|
JS::GCPtr<CSSRule> m_owner_css_rule;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue