diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-03-30 16:42:43 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-30 18:43:07 +0200 |
commit | 6a0adbefc76b064d843bc9eb779300bd788d8c2f (patch) | |
tree | 941b9eff4432712c84b9d99cb3aa7af916d8377a /Userland | |
parent | 75db8b1f86f993bc4d087c690efab3b3c29e48f1 (diff) | |
download | serenity-6a0adbefc76b064d843bc9eb779300bd788d8c2f.zip |
LibWeb: Tidy up StyleRule API
Constantly accessing private `m_foo` fields feels uncomfortable and
doesn't fit well with our code style.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/StyleRule.h | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp | 4 |
3 files changed, 16 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index ae42725eb3..aa4d2deb50 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1597,7 +1597,7 @@ NonnullRefPtr<StyleRule> Parser::consume_an_at_rule(TokenStream<T>& 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>(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<AK::URL> Parser::parse_url_function(StyleComponentValueRule const& comp RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> 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<AK::URL> url; for (auto& token : rule->prelude()) { @@ -2293,7 +2293,7 @@ RefPtr<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> 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<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> 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<CSSRule> Parser::convert_to_rule(NonnullRefPtr<StyleRule> 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 b1a255e8ac..9b1a5c7612 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<StyleComponentValueRule> const& prelude() const { return m_prelude; } RefPtr<StyleBlockRule const> 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<StyleComponentValueRule> m_prelude; RefPtr<StyleBlockRule> m_block; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp index 38f38ce539..8babc6dd93 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); |