diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index ae42725eb30..aa4d2deb502 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1597,7 +1597,7 @@ NonnullRefPtr Parser::consume_an_at_rule(TokenStream& tokens) // Create a new at-rule with its name set to the value of the current input token, its prelude initially set to an empty list, and its value initially set to nothing. auto rule = make_ref_counted(StyleRule::Type::At); - rule->m_name = ((Token)name_ident).at_keyword(); + rule->m_at_rule_name = ((Token)name_ident).at_keyword(); // Repeatedly consume the next input token: for (;;) { @@ -2260,17 +2260,17 @@ Optional Parser::parse_url_function(StyleComponentValueRule const& comp RefPtr Parser::convert_to_rule(NonnullRefPtr rule) { - if (rule->m_type == StyleRule::Type::At) { - if (has_ignored_vendor_prefix(rule->m_name)) { + if (rule->is_at_rule()) { + if (has_ignored_vendor_prefix(rule->at_rule_name())) { return {}; - } else if (rule->m_name.equals_ignoring_case("font-face"sv)) { + } else if (rule->at_rule_name().equals_ignoring_case("font-face"sv)) { if (rule->prelude().is_empty() || !rule->block()->is_curly()) { dbgln_if(CSS_PARSER_DEBUG, "@font-face rule is malformed."); return {}; } TokenStream tokens { rule->block()->values() }; return parse_font_face_rule(tokens); - } else if (rule->m_name.equals_ignoring_case("import"sv) && !rule->prelude().is_empty()) { + } else if (rule->at_rule_name().equals_ignoring_case("import"sv) && !rule->prelude().is_empty()) { Optional url; for (auto& token : rule->prelude()) { @@ -2293,7 +2293,7 @@ RefPtr Parser::convert_to_rule(NonnullRefPtr rule) else dbgln_if(CSS_PARSER_DEBUG, "Unable to parse url from @import rule"); - } else if (rule->m_name.equals_ignoring_case("media"sv)) { + } else if (rule->at_rule_name().equals_ignoring_case("media"sv)) { auto media_query_tokens = TokenStream { rule->prelude() }; auto media_query_list = parse_a_media_query_list(media_query_tokens); @@ -2310,7 +2310,7 @@ RefPtr Parser::convert_to_rule(NonnullRefPtr rule) return CSSMediaRule::create(MediaList::create(move(media_query_list)), move(child_rules)); - } else if (rule->m_name.equals_ignoring_case("supports"sv)) { + } else if (rule->at_rule_name().equals_ignoring_case("supports"sv)) { auto supports_tokens = TokenStream { rule->prelude() }; auto supports = parse_a_supports(supports_tokens); @@ -2335,13 +2335,13 @@ RefPtr Parser::convert_to_rule(NonnullRefPtr rule) return CSSSupportsRule::create(supports.release_nonnull(), move(child_rules)); } else { - dbgln_if(CSS_PARSER_DEBUG, "Unrecognized CSS at-rule: @{}", rule->m_name); + dbgln_if(CSS_PARSER_DEBUG, "Unrecognized CSS at-rule: @{}", rule->at_rule_name()); } // FIXME: More at rules! } else { - auto prelude_stream = TokenStream(rule->m_prelude); + auto prelude_stream = TokenStream(rule->prelude()); auto selectors = parse_a_selector_list(prelude_stream, SelectorType::Standalone); if (selectors.is_error()) { diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h b/Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h index b1a255e8ac4..9b1a5c7612a 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h @@ -26,14 +26,18 @@ public: StyleRule(Type); ~StyleRule(); + bool is_qualified_rule() const { return m_type == Type::Qualified; } + bool is_at_rule() const { return m_type == Type::At; } + Vector const& prelude() const { return m_prelude; } RefPtr block() const { return m_block; } + String const& at_rule_name() const { return m_at_rule_name; } String to_string() const; private: Type const m_type; - String m_name; // At-rules only + String m_at_rule_name; Vector m_prelude; RefPtr m_block; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp index 38f38ce5398..8babc6dd930 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp @@ -98,9 +98,9 @@ String StyleRule::to_string() const { StringBuilder builder; - if (m_type == Type::At) { + if (is_at_rule()) { builder.append("@"); - serialize_an_identifier(builder, m_name); + serialize_an_identifier(builder, m_at_rule_name); } append_with_to_string(builder, " ", m_prelude);