1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:37:34 +00:00

LibWeb: Remove unknown value in @supports query logic

This is in line with this recent change to Conditional-3:

> Removed the “unknown” value in CSS feature queries’ boolean logic,
> defining unrecognized syntaxes as “false” instead.
> https://github.com/w3c/csswg-drafts/issues/6175
This commit is contained in:
Sam Atkins 2022-01-19 20:03:22 +00:00 committed by Linus Groh
parent 6d3a3f279a
commit 7bea0d501e
2 changed files with 22 additions and 19 deletions

View file

@ -12,27 +12,31 @@ namespace Web::CSS {
Supports::Supports(NonnullOwnPtr<Condition>&& condition)
: m_condition(move(condition))
{
auto result = m_condition->evaluate();
if (result == MatchResult::Unknown) {
dbgln("!!! Evaluation of CSS Supports returned 'Unknown'!");
}
m_matches = result == MatchResult::True;
m_matches = m_condition->evaluate();
}
MatchResult Supports::Condition::evaluate() const
bool Supports::Condition::evaluate() const
{
switch (type) {
case Type::Not:
return negate(children.first().evaluate());
return !children.first().evaluate();
case Type::And:
return evaluate_and(children, [](auto& child) { return child.evaluate(); });
for (auto& child : children) {
if (!child.evaluate())
return false;
}
return true;
case Type::Or:
return evaluate_or(children, [](auto& child) { return child.evaluate(); });
for (auto& child : children) {
if (child.evaluate())
return true;
}
return false;
}
VERIFY_NOT_REACHED();
}
MatchResult Supports::InParens::evaluate() const
bool Supports::InParens::evaluate() const
{
return value.visit(
[&](NonnullOwnPtr<Condition> const& condition) {
@ -41,17 +45,15 @@ MatchResult Supports::InParens::evaluate() const
[&](Feature const& feature) {
return feature.evaluate();
},
[&](GeneralEnclosed const& general_enclosed) {
return general_enclosed.evaluate();
[&](GeneralEnclosed const&) {
return false;
});
}
MatchResult Supports::Feature::evaluate() const
bool Supports::Feature::evaluate() const
{
auto style_property = Parser({}, declaration).parse_as_declaration();
if (style_property.has_value())
return MatchResult::True;
return MatchResult::False;
return style_property.has_value();
}
}

View file

@ -16,20 +16,21 @@
namespace Web::CSS {
// https://www.w3.org/TR/css-conditional-3/#at-supports
class Supports final : public RefCounted<Supports> {
friend class Parser;
public:
struct Feature {
String declaration;
MatchResult evaluate() const;
bool evaluate() const;
};
struct Condition;
struct InParens {
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
MatchResult evaluate() const;
bool evaluate() const;
};
struct Condition {
@ -41,7 +42,7 @@ public:
Type type;
Vector<InParens> children;
MatchResult evaluate() const;
bool evaluate() const;
};
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)