2021-10-08 11:40:19 -03:00
|
|
|
/*
|
2026-03-27 12:11:16 -03:00
|
|
|
* Copyright (c) 2021-2026, Sam Atkins <sam@ladybird.org>
|
2021-10-08 11:40:19 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-28 13:54:25 -03:00
|
|
|
#include <LibJS/Runtime/Realm.h>
|
2026-03-27 12:11:16 -03:00
|
|
|
#include <LibWeb/CSS/Serialize.h>
|
2021-10-08 11:40:19 -03:00
|
|
|
#include <LibWeb/CSS/Supports.h>
|
2025-12-04 09:23:20 -03:00
|
|
|
#include <LibWeb/Dump.h>
|
2021-10-08 11:40:19 -03:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2025-03-14 07:31:27 -03:00
|
|
|
Supports::Supports(NonnullOwnPtr<BooleanExpression>&& condition)
|
2021-10-08 11:40:19 -03:00
|
|
|
: m_condition(move(condition))
|
|
|
|
|
{
|
2026-05-08 10:50:13 -03:00
|
|
|
m_matches = m_condition->evaluate_to_boolean({});
|
2021-10-08 11:40:19 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-08 10:50:13 -03:00
|
|
|
MatchResult Supports::Declaration::evaluate(BooleanExpressionEvaluationContext const&) const
|
2022-02-19 14:22:05 -03:00
|
|
|
{
|
2025-03-14 07:31:27 -03:00
|
|
|
return as_match_result(m_matches);
|
2022-02-19 14:22:05 -03:00
|
|
|
}
|
|
|
|
|
|
2023-08-22 08:47:38 -03:00
|
|
|
String Supports::Declaration::to_string() const
|
2022-04-22 11:18:47 -03:00
|
|
|
{
|
2025-03-19 08:32:34 -03:00
|
|
|
return m_declaration;
|
2022-04-22 11:18:47 -03:00
|
|
|
}
|
|
|
|
|
|
2024-11-01 16:55:31 -03:00
|
|
|
void Supports::Declaration::dump(StringBuilder& builder, int indent_levels) const
|
|
|
|
|
{
|
|
|
|
|
indent(builder, indent_levels);
|
2025-03-14 07:31:27 -03:00
|
|
|
builder.appendff("Declaration: `{}`, matches={}\n", m_declaration, m_matches);
|
2024-11-01 16:55:31 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-08 10:50:13 -03:00
|
|
|
MatchResult Supports::Selector::evaluate(BooleanExpressionEvaluationContext const&) const
|
2024-11-01 16:55:31 -03:00
|
|
|
{
|
2025-03-14 07:31:27 -03:00
|
|
|
return as_match_result(m_matches);
|
2024-11-01 16:55:31 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-14 07:31:27 -03:00
|
|
|
String Supports::Selector::to_string() const
|
2024-11-01 16:55:31 -03:00
|
|
|
{
|
2025-03-14 07:31:27 -03:00
|
|
|
return MUST(String::formatted("selector({})", m_selector));
|
2024-11-01 16:55:31 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-14 07:31:27 -03:00
|
|
|
void Supports::Selector::dump(StringBuilder& builder, int indent_levels) const
|
2024-11-01 16:55:31 -03:00
|
|
|
{
|
2025-03-14 07:31:27 -03:00
|
|
|
indent(builder, indent_levels);
|
|
|
|
|
builder.appendff("Selector: `{}` matches={}\n", m_selector, m_matches);
|
2024-11-01 16:55:31 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-08 10:50:13 -03:00
|
|
|
MatchResult Supports::FontTech::evaluate(BooleanExpressionEvaluationContext const&) const
|
2025-03-14 08:36:15 -03:00
|
|
|
{
|
|
|
|
|
return as_match_result(m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String Supports::FontTech::to_string() const
|
|
|
|
|
{
|
|
|
|
|
return MUST(String::formatted("font-tech({})", m_tech));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Supports::FontTech::dump(StringBuilder& builder, int indent_levels) const
|
|
|
|
|
{
|
|
|
|
|
indent(builder, indent_levels);
|
|
|
|
|
builder.appendff("FontTech: `{}` matches={}\n", m_tech, m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-08 10:50:13 -03:00
|
|
|
MatchResult Supports::FontFormat::evaluate(BooleanExpressionEvaluationContext const&) const
|
2025-03-14 08:36:15 -03:00
|
|
|
{
|
|
|
|
|
return as_match_result(m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String Supports::FontFormat::to_string() const
|
|
|
|
|
{
|
|
|
|
|
return MUST(String::formatted("font-format({})", m_format));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Supports::FontFormat::dump(StringBuilder& builder, int indent_levels) const
|
|
|
|
|
{
|
|
|
|
|
indent(builder, indent_levels);
|
|
|
|
|
builder.appendff("FontFormat: `{}` matches={}\n", m_format, m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-08 10:50:13 -03:00
|
|
|
MatchResult Supports::Env::evaluate(BooleanExpressionEvaluationContext const&) const
|
2026-03-27 12:11:16 -03:00
|
|
|
{
|
|
|
|
|
return as_match_result(m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String Supports::Env::to_string() const
|
|
|
|
|
{
|
|
|
|
|
return MUST(String::formatted("font-format({})", serialize_an_identifier(m_variable_name)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Supports::Env::dump(StringBuilder& builder, int indent_levels) const
|
|
|
|
|
{
|
|
|
|
|
indent(builder, indent_levels);
|
|
|
|
|
builder.appendff("Env: `{}` matches={}\n", m_variable_name, m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-21 11:54:44 -03:00
|
|
|
MatchResult Supports::AtRule::evaluate(BooleanExpressionEvaluationContext const&) const
|
|
|
|
|
{
|
|
|
|
|
return as_match_result(m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String Supports::AtRule::to_string() const
|
|
|
|
|
{
|
|
|
|
|
StringBuilder builder;
|
|
|
|
|
builder.append("at-rule(@"sv);
|
|
|
|
|
serialize_an_identifier(builder, m_name);
|
|
|
|
|
builder.append(')');
|
|
|
|
|
return builder.to_string_without_validation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Supports::AtRule::dump(StringBuilder& builder, int indent_levels) const
|
|
|
|
|
{
|
|
|
|
|
indent(builder, indent_levels);
|
|
|
|
|
builder.appendff("AtRule: `@{}` matches={}\n", m_name, m_matches);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-14 07:31:27 -03:00
|
|
|
String Supports::to_string() const
|
2024-11-01 16:55:31 -03:00
|
|
|
{
|
2025-03-14 07:31:27 -03:00
|
|
|
return m_condition->to_string();
|
2024-11-01 16:55:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Supports::dump(StringBuilder& builder, int indent_levels) const
|
|
|
|
|
{
|
2025-12-04 09:23:20 -03:00
|
|
|
dump_indent(builder, indent_levels);
|
|
|
|
|
builder.appendff("Supports condition: (matches = {})\n", m_matches);
|
|
|
|
|
m_condition->dump(builder, indent_levels + 1);
|
2024-11-01 16:55:31 -03:00
|
|
|
}
|
|
|
|
|
|
2021-10-08 11:40:19 -03:00
|
|
|
}
|