mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:47:46 +00:00
LibWeb: Move/rename StyleFunctionRule to Parser::Function
This commit is contained in:
parent
084780a0a2
commit
e0b2ebcc7b
11 changed files with 59 additions and 58 deletions
|
@ -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
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Parser/Function.h>
|
||||
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
|
||||
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
|
||||
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
|
@ -15,7 +15,7 @@ ComponentValue::ComponentValue(Token token)
|
|||
: m_value(token)
|
||||
{
|
||||
}
|
||||
ComponentValue::ComponentValue(NonnullRefPtr<StyleFunctionRule> function)
|
||||
ComponentValue::ComponentValue(NonnullRefPtr<Function> 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<StyleBlockRule> const& block) { return block->to_string(); },
|
||||
[](NonnullRefPtr<StyleFunctionRule> const& function) { return function->to_string(); });
|
||||
[](NonnullRefPtr<Function> const& function) { return function->to_string(); });
|
||||
}
|
||||
|
||||
String ComponentValue::to_debug_string() const
|
||||
|
@ -43,7 +43,7 @@ String ComponentValue::to_debug_string() const
|
|||
[](NonnullRefPtr<StyleBlockRule> const& block) {
|
||||
return String::formatted("Function: {}", block->to_string());
|
||||
},
|
||||
[](NonnullRefPtr<StyleFunctionRule> const& function) {
|
||||
[](NonnullRefPtr<Function> const& function) {
|
||||
return String::formatted("Block: {}", function->to_string());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <LibWeb/CSS/Parser/Token.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
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<StyleFunctionRule>);
|
||||
explicit ComponentValue(NonnullRefPtr<Function>);
|
||||
explicit ComponentValue(NonnullRefPtr<StyleBlockRule>);
|
||||
~ComponentValue();
|
||||
|
||||
bool is_block() const { return m_value.has<NonnullRefPtr<StyleBlockRule>>(); }
|
||||
StyleBlockRule const& block() const { return m_value.get<NonnullRefPtr<StyleBlockRule>>(); }
|
||||
|
||||
bool is_function() const { return m_value.has<NonnullRefPtr<StyleFunctionRule>>(); }
|
||||
StyleFunctionRule const& function() const { return m_value.get<NonnullRefPtr<StyleFunctionRule>>(); }
|
||||
bool is_function() const { return m_value.has<NonnullRefPtr<Function>>(); }
|
||||
Function const& function() const { return m_value.get<NonnullRefPtr<Function>>(); }
|
||||
|
||||
bool is_token() const { return m_value.has<Token>(); }
|
||||
bool is(Token::Type type) const { return is_token() && token().is(type); }
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
String to_debug_string() const;
|
||||
|
||||
private:
|
||||
Variant<Token, NonnullRefPtr<StyleFunctionRule>, NonnullRefPtr<StyleBlockRule>> m_value;
|
||||
Variant<Token, NonnullRefPtr<Function>, NonnullRefPtr<StyleBlockRule>> m_value;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,25 +5,25 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
|
||||
#include <LibWeb/CSS/Parser/Function.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
StyleFunctionRule::StyleFunctionRule(String name)
|
||||
Function::Function(String name)
|
||||
: m_name(move(name))
|
||||
{
|
||||
}
|
||||
|
||||
StyleFunctionRule::StyleFunctionRule(String name, Vector<Parser::ComponentValue>&& values)
|
||||
Function::Function(String name, Vector<ComponentValue>&& 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;
|
||||
|
35
Userland/Libraries/LibWeb/CSS/Parser/Function.h
Normal file
35
Userland/Libraries/LibWeb/CSS/Parser/Function.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
class Function : public RefCounted<Function> {
|
||||
friend class Parser;
|
||||
|
||||
public:
|
||||
explicit Function(String name);
|
||||
Function(String name, Vector<ComponentValue>&& values);
|
||||
~Function();
|
||||
|
||||
String const& name() const { return m_name; }
|
||||
Vector<ComponentValue> const& values() const { return m_values; }
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
String m_name;
|
||||
Vector<ComponentValue> m_values;
|
||||
};
|
||||
}
|
|
@ -21,9 +21,9 @@
|
|||
#include <LibWeb/CSS/CSSSupportsRule.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
|
||||
#include <LibWeb/CSS/Parser/Function.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
|
||||
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
|
||||
#include <LibWeb/CSS/Parser/StyleRule.h>
|
||||
#include <LibWeb/CSS/Selector.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
@ -1867,7 +1867,7 @@ NonnullRefPtr<StyleBlockRule> Parser::consume_a_simple_block(TokenStream<T>& tok
|
|||
// 5.4.9. Consume a function
|
||||
// https://www.w3.org/TR/css-syntax-3/#consume-function
|
||||
template<typename T>
|
||||
NonnullRefPtr<StyleFunctionRule> Parser::consume_a_function(TokenStream<T>& tokens)
|
||||
NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens)
|
||||
{
|
||||
// Note: This algorithm assumes that the current input token has already been checked to be a <function-token>.
|
||||
auto name_ident = tokens.current_token();
|
||||
|
@ -1877,7 +1877,7 @@ NonnullRefPtr<StyleFunctionRule> Parser::consume_a_function(TokenStream<T>& 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<StyleFunctionRule>(((Token)name_ident).function());
|
||||
auto function = make_ref_counted<Function>(((Token)name_ident).function());
|
||||
|
||||
// Repeatedly consume the next input token and process it as follows:
|
||||
for (;;) {
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Parser/Declaration.h>
|
||||
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
|
||||
#include <LibWeb/CSS/Parser/Function.h>
|
||||
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
|
||||
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
|
||||
#include <LibWeb/CSS/Parser/StyleRule.h>
|
||||
#include <LibWeb/CSS/Parser/Tokenizer.h>
|
||||
#include <LibWeb/CSS/Ratio.h>
|
||||
|
@ -195,7 +195,7 @@ private:
|
|||
template<typename T>
|
||||
NonnullRefPtr<StyleBlockRule> consume_a_simple_block(TokenStream<T>&);
|
||||
template<typename T>
|
||||
NonnullRefPtr<StyleFunctionRule> consume_a_function(TokenStream<T>&);
|
||||
NonnullRefPtr<Function> consume_a_function(TokenStream<T>&);
|
||||
|
||||
Optional<GeneralEnclosed> parse_general_enclosed(TokenStream<ComponentValue>&);
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class StyleFunctionRule : public RefCounted<StyleFunctionRule> {
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
explicit StyleFunctionRule(String name);
|
||||
StyleFunctionRule(String name, Vector<Parser::ComponentValue>&& values);
|
||||
~StyleFunctionRule();
|
||||
|
||||
String const& name() const { return m_name; }
|
||||
Vector<Parser::ComponentValue> const& values() const { return m_values; }
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
String m_name;
|
||||
Vector<Parser::ComponentValue> m_values;
|
||||
};
|
||||
}
|
|
@ -8,8 +8,8 @@
|
|||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Parser/Declaration.h>
|
||||
#include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
|
||||
#include <LibWeb/CSS/Parser/Function.h>
|
||||
#include <LibWeb/CSS/Parser/StyleBlockRule.h>
|
||||
#include <LibWeb/CSS/Parser/StyleFunctionRule.h>
|
||||
#include <LibWeb/CSS/Parser/StyleRule.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
|
||||
|
|
|
@ -622,7 +622,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
|
|||
Vector<Parser::ComponentValue> function_values;
|
||||
if (!expand_unresolved_values(element, property_name, dependencies, source_function.values(), function_values, 0))
|
||||
return false;
|
||||
NonnullRefPtr<StyleFunctionRule> function = adopt_ref(*new StyleFunctionRule(source_function.name(), move(function_values)));
|
||||
NonnullRefPtr<Parser::Function> function = adopt_ref(*new Parser::Function(source_function.name(), move(function_values)));
|
||||
dest.empend(function);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ enum class ValueID;
|
|||
|
||||
namespace Web::CSS::Parser {
|
||||
class ComponentValue;
|
||||
class Function;
|
||||
class Parser;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue