mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibWeb: Rough implementation of CSS namespace rule
This provides a rough implementation of the CSS @namespace rule. Currently we just support default namespaces, namespace prefixes are still to come.
This commit is contained in:
parent
3f7d97f098
commit
60e35f2a97
18 changed files with 266 additions and 3 deletions
|
@ -17,6 +17,7 @@
|
|||
#include <LibWeb/CSS/CSSKeyframeRule.h>
|
||||
#include <LibWeb/CSS/CSSKeyframesRule.h>
|
||||
#include <LibWeb/CSS/CSSMediaRule.h>
|
||||
#include <LibWeb/CSS/CSSNamespaceRule.h>
|
||||
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
||||
#include <LibWeb/CSS/CSSStyleRule.h>
|
||||
#include <LibWeb/CSS/CSSStyleSheet.h>
|
||||
|
@ -3241,6 +3242,37 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
|
|||
|
||||
return CSSKeyframesRule::create(m_context.realm(), name, move(keyframes)).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
if (rule->at_rule_name().equals_ignoring_ascii_case("namespace"sv)) {
|
||||
// https://drafts.csswg.org/css-namespaces/#syntax
|
||||
auto token_stream = TokenStream { rule->prelude() };
|
||||
token_stream.skip_whitespace();
|
||||
|
||||
auto token = token_stream.next_token();
|
||||
Optional<StringView> prefix = {};
|
||||
if (token.is(Token::Type::Ident)) {
|
||||
prefix = token.token().ident();
|
||||
token_stream.skip_whitespace();
|
||||
token = token_stream.next_token();
|
||||
}
|
||||
|
||||
DeprecatedString namespace_uri;
|
||||
if (token.is(Token::Type::String)) {
|
||||
namespace_uri = token.token().string();
|
||||
} else if (auto url = parse_url_function(token, AllowedDataUrlType::None); url.has_value()) {
|
||||
namespace_uri = url.value().to_deprecated_string();
|
||||
} else {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @namespace rule invalid; discarding.");
|
||||
return {};
|
||||
}
|
||||
|
||||
token_stream.skip_whitespace();
|
||||
if (token_stream.has_next_token()) {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @namespace rule invalid; discarding.");
|
||||
return {};
|
||||
}
|
||||
|
||||
return CSSNamespaceRule::create(m_context.realm(), prefix, namespace_uri).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
// FIXME: More at rules!
|
||||
dbgln_if(CSS_PARSER_DEBUG, "Unrecognized CSS at-rule: @{}", rule->at_rule_name());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue