2022-04-12 11:14:12 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
2025-06-18 17:24:19 +01:00
|
|
|
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
2022-04-12 11:14:12 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
|
|
|
|
2022-04-12 12:13:10 +01:00
|
|
|
namespace Web::CSS::Parser {
|
2022-04-12 11:14:12 +01:00
|
|
|
|
|
|
|
ComponentValue::ComponentValue(Token token)
|
2025-06-18 17:24:19 +01:00
|
|
|
: m_value(move(token))
|
2022-04-12 11:14:12 +01:00
|
|
|
{
|
|
|
|
}
|
2024-10-11 11:17:10 +01:00
|
|
|
ComponentValue::ComponentValue(Function&& function)
|
2024-10-31 18:23:23 +01:00
|
|
|
: m_value(move(function))
|
2022-04-12 11:14:12 +01:00
|
|
|
{
|
|
|
|
}
|
2024-10-11 11:17:10 +01:00
|
|
|
ComponentValue::ComponentValue(SimpleBlock&& block)
|
2024-10-31 18:23:23 +01:00
|
|
|
: m_value(move(block))
|
2022-04-12 11:14:12 +01:00
|
|
|
{
|
|
|
|
}
|
2025-06-18 17:24:19 +01:00
|
|
|
ComponentValue::ComponentValue(GuaranteedInvalidValue&& invalid)
|
|
|
|
: m_value(move(invalid))
|
|
|
|
{
|
|
|
|
}
|
2022-04-12 11:14:12 +01:00
|
|
|
|
|
|
|
ComponentValue::~ComponentValue() = default;
|
|
|
|
|
2023-09-05 19:42:28 +01:00
|
|
|
bool ComponentValue::is_function(StringView name) const
|
|
|
|
{
|
2024-10-11 11:17:10 +01:00
|
|
|
return is_function() && function().name.equals_ignoring_ascii_case(name);
|
2023-09-05 19:42:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ComponentValue::is_ident(StringView ident) const
|
|
|
|
{
|
|
|
|
return is(Token::Type::Ident) && token().ident().equals_ignoring_ascii_case(ident);
|
|
|
|
}
|
|
|
|
|
2023-08-22 13:00:28 +01:00
|
|
|
String ComponentValue::to_string() const
|
2022-04-12 11:14:12 +01:00
|
|
|
{
|
2024-10-14 16:16:42 +01:00
|
|
|
return m_value.visit([](auto const& it) { return it.to_string(); });
|
2022-04-12 11:14:12 +01:00
|
|
|
}
|
|
|
|
|
2023-08-22 13:00:28 +01:00
|
|
|
String ComponentValue::to_debug_string() const
|
2022-04-12 11:14:12 +01:00
|
|
|
{
|
|
|
|
return m_value.visit(
|
2023-08-22 13:00:28 +01:00
|
|
|
[](Token const& token) {
|
|
|
|
return MUST(String::formatted("Token: {}", token.to_debug_string()));
|
2022-04-12 11:14:12 +01:00
|
|
|
},
|
2024-10-11 11:17:10 +01:00
|
|
|
[](SimpleBlock const& block) {
|
|
|
|
return MUST(String::formatted("Block: {}", block.to_string()));
|
2022-04-12 11:14:12 +01:00
|
|
|
},
|
2024-10-11 11:17:10 +01:00
|
|
|
[](Function const& function) {
|
|
|
|
return MUST(String::formatted("Function: {}", function.to_string()));
|
2025-06-18 17:24:19 +01:00
|
|
|
},
|
|
|
|
[](GuaranteedInvalidValue const&) {
|
|
|
|
return "Guaranteed-invalid value"_string;
|
2022-04-12 11:14:12 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-14 16:16:42 +01:00
|
|
|
String ComponentValue::original_source_text() const
|
|
|
|
{
|
|
|
|
return m_value.visit([](auto const& it) { return it.original_source_text(); });
|
|
|
|
}
|
|
|
|
|
2025-06-18 17:24:19 +01:00
|
|
|
bool ComponentValue::contains_guaranteed_invalid_value() const
|
|
|
|
{
|
|
|
|
return m_value.visit(
|
|
|
|
[](Token const&) {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
[](SimpleBlock const& block) {
|
|
|
|
return block.value
|
|
|
|
.first_matching([](auto const& it) { return it.contains_guaranteed_invalid_value(); })
|
|
|
|
.has_value();
|
|
|
|
},
|
|
|
|
[](Function const& function) {
|
|
|
|
return function.value
|
|
|
|
.first_matching([](auto const& it) { return it.contains_guaranteed_invalid_value(); })
|
|
|
|
.has_value();
|
|
|
|
},
|
|
|
|
[](GuaranteedInvalidValue const&) {
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-12 11:14:12 +01:00
|
|
|
}
|