From e0b2ebcc7befc6147970e402683aac4dacb57862 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 12 Apr 2022 13:35:55 +0100 Subject: [PATCH] LibWeb: Move/rename StyleFunctionRule to Parser::Function --- Userland/Libraries/LibWeb/CMakeLists.txt | 2 +- .../LibWeb/CSS/Parser/ComponentValue.cpp | 8 ++--- .../LibWeb/CSS/Parser/ComponentValue.h | 10 +++--- .../{StyleFunctionRule.cpp => Function.cpp} | 12 +++---- .../Libraries/LibWeb/CSS/Parser/Function.h | 35 +++++++++++++++++++ .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 6 ++-- Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 4 +-- .../LibWeb/CSS/Parser/StyleFunctionRule.h | 35 ------------------- .../LibWeb/CSS/Parser/StyleRules.cpp | 2 +- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 2 +- Userland/Libraries/LibWeb/Forward.h | 1 + 11 files changed, 59 insertions(+), 58 deletions(-) rename Userland/Libraries/LibWeb/CSS/Parser/{StyleFunctionRule.cpp => Function.cpp} (61%) create mode 100644 Userland/Libraries/LibWeb/CSS/Parser/Function.h delete mode 100644 Userland/Libraries/LibWeb/CSS/Parser/StyleFunctionRule.h diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 020e4838de..c7f9d41310 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -45,8 +45,8 @@ set(SOURCES CSS/MediaQuery.cpp CSS/MediaQueryList.cpp CSS/Parser/ComponentValue.cpp + CSS/Parser/Function.cpp CSS/Parser/Parser.cpp - CSS/Parser/StyleFunctionRule.cpp CSS/Parser/StyleRules.cpp CSS/Parser/Token.cpp CSS/Parser/Tokenizer.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp index 58e80cc035..cd5463ebd4 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp @@ -6,8 +6,8 @@ */ #include +#include #include -#include namespace Web::CSS::Parser { @@ -15,7 +15,7 @@ ComponentValue::ComponentValue(Token token) : m_value(token) { } -ComponentValue::ComponentValue(NonnullRefPtr function) +ComponentValue::ComponentValue(NonnullRefPtr function) : m_value(function) { } @@ -31,7 +31,7 @@ String ComponentValue::to_string() const return m_value.visit( [](Token const& token) { return token.to_string(); }, [](NonnullRefPtr const& block) { return block->to_string(); }, - [](NonnullRefPtr const& function) { return function->to_string(); }); + [](NonnullRefPtr const& function) { return function->to_string(); }); } String ComponentValue::to_debug_string() const @@ -43,7 +43,7 @@ String ComponentValue::to_debug_string() const [](NonnullRefPtr const& block) { return String::formatted("Function: {}", block->to_string()); }, - [](NonnullRefPtr const& function) { + [](NonnullRefPtr const& function) { return String::formatted("Block: {}", function->to_string()); }); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h index 0c8a49544b..9ec4e146d0 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.h @@ -10,10 +10,10 @@ #include #include #include +#include namespace Web::CSS { class StyleBlockRule; -class StyleFunctionRule; } namespace Web::CSS::Parser { @@ -22,15 +22,15 @@ namespace Web::CSS::Parser { class ComponentValue { public: ComponentValue(Token); - explicit ComponentValue(NonnullRefPtr); + explicit ComponentValue(NonnullRefPtr); explicit ComponentValue(NonnullRefPtr); ~ComponentValue(); bool is_block() const { return m_value.has>(); } StyleBlockRule const& block() const { return m_value.get>(); } - bool is_function() const { return m_value.has>(); } - StyleFunctionRule const& function() const { return m_value.get>(); } + bool is_function() const { return m_value.has>(); } + Function const& function() const { return m_value.get>(); } bool is_token() const { return m_value.has(); } bool is(Token::Type type) const { return is_token() && token().is(type); } @@ -41,7 +41,7 @@ public: String to_debug_string() const; private: - Variant, NonnullRefPtr> m_value; + Variant, NonnullRefPtr> m_value; }; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleFunctionRule.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp similarity index 61% rename from Userland/Libraries/LibWeb/CSS/Parser/StyleFunctionRule.cpp rename to Userland/Libraries/LibWeb/CSS/Parser/Function.cpp index f3978fd437..5218d7b02a 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleFunctionRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp @@ -5,25 +5,25 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include -namespace Web::CSS { +namespace Web::CSS::Parser { -StyleFunctionRule::StyleFunctionRule(String name) +Function::Function(String name) : m_name(move(name)) { } -StyleFunctionRule::StyleFunctionRule(String name, Vector&& values) +Function::Function(String name, Vector&& values) : m_name(move(name)) , m_values(move(values)) { } -StyleFunctionRule::~StyleFunctionRule() = default; +Function::~Function() = default; -String StyleFunctionRule::to_string() const +String Function::to_string() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Function.h b/Userland/Libraries/LibWeb/CSS/Parser/Function.h new file mode 100644 index 0000000000..4ce7ed871f --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021-2022, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Web::CSS::Parser { + +class Function : public RefCounted { + friend class Parser; + +public: + explicit Function(String name); + Function(String name, Vector&& values); + ~Function(); + + String const& name() const { return m_name; } + Vector const& values() const { return m_values; } + + String to_string() const; + +private: + String m_name; + Vector m_values; +}; +} diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index f68c1e5478..d4402a462b 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -21,9 +21,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -1867,7 +1867,7 @@ NonnullRefPtr Parser::consume_a_simple_block(TokenStream& tok // 5.4.9. Consume a function // https://www.w3.org/TR/css-syntax-3/#consume-function template -NonnullRefPtr Parser::consume_a_function(TokenStream& tokens) +NonnullRefPtr Parser::consume_a_function(TokenStream& tokens) { // Note: This algorithm assumes that the current input token has already been checked to be a . auto name_ident = tokens.current_token(); @@ -1877,7 +1877,7 @@ NonnullRefPtr Parser::consume_a_function(TokenStream& toke // Create a function with its name equal to the value of the current input token // and with its value initially set to an empty list. - auto function = make_ref_counted(((Token)name_ident).function()); + auto function = make_ref_counted(((Token)name_ident).function()); // Repeatedly consume the next input token and process it as follows: for (;;) { diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 10d2b1b6bc..eedb78b8ee 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -19,8 +19,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -195,7 +195,7 @@ private: template NonnullRefPtr consume_a_simple_block(TokenStream&); template - NonnullRefPtr consume_a_function(TokenStream&); + NonnullRefPtr consume_a_function(TokenStream&); Optional parse_general_enclosed(TokenStream&); diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleFunctionRule.h b/Userland/Libraries/LibWeb/CSS/Parser/StyleFunctionRule.h deleted file mode 100644 index 239955b4cc..0000000000 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleFunctionRule.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021, Sam Atkins - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace Web::CSS { - -class StyleFunctionRule : public RefCounted { - friend class Parser::Parser; - -public: - explicit StyleFunctionRule(String name); - StyleFunctionRule(String name, Vector&& values); - ~StyleFunctionRule(); - - String const& name() const { return m_name; } - Vector const& values() const { return m_values; } - - String to_string() const; - -private: - String m_name; - Vector m_values; -}; -} diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp index b46001cc53..b14f857312 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp @@ -8,8 +8,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 8a0d4c857b..08f5d93c10 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -622,7 +622,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p Vector function_values; if (!expand_unresolved_values(element, property_name, dependencies, source_function.values(), function_values, 0)) return false; - NonnullRefPtr function = adopt_ref(*new StyleFunctionRule(source_function.name(), move(function_values))); + NonnullRefPtr function = adopt_ref(*new Parser::Function(source_function.name(), move(function_values))); dest.empend(function); continue; } diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index b06e1f78c2..a443f0e47e 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -100,6 +100,7 @@ enum class ValueID; namespace Web::CSS::Parser { class ComponentValue; +class Function; class Parser; }