mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +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:
parent
6d3a3f279a
commit
7bea0d501e
2 changed files with 22 additions and 19 deletions
|
@ -12,27 +12,31 @@ namespace Web::CSS {
|
||||||
Supports::Supports(NonnullOwnPtr<Condition>&& condition)
|
Supports::Supports(NonnullOwnPtr<Condition>&& condition)
|
||||||
: m_condition(move(condition))
|
: m_condition(move(condition))
|
||||||
{
|
{
|
||||||
auto result = m_condition->evaluate();
|
m_matches = m_condition->evaluate();
|
||||||
if (result == MatchResult::Unknown) {
|
|
||||||
dbgln("!!! Evaluation of CSS Supports returned 'Unknown'!");
|
|
||||||
}
|
|
||||||
m_matches = result == MatchResult::True;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MatchResult Supports::Condition::evaluate() const
|
bool Supports::Condition::evaluate() const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::Not:
|
case Type::Not:
|
||||||
return negate(children.first().evaluate());
|
return !children.first().evaluate();
|
||||||
case Type::And:
|
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:
|
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();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
MatchResult Supports::InParens::evaluate() const
|
bool Supports::InParens::evaluate() const
|
||||||
{
|
{
|
||||||
return value.visit(
|
return value.visit(
|
||||||
[&](NonnullOwnPtr<Condition> const& condition) {
|
[&](NonnullOwnPtr<Condition> const& condition) {
|
||||||
|
@ -41,17 +45,15 @@ MatchResult Supports::InParens::evaluate() const
|
||||||
[&](Feature const& feature) {
|
[&](Feature const& feature) {
|
||||||
return feature.evaluate();
|
return feature.evaluate();
|
||||||
},
|
},
|
||||||
[&](GeneralEnclosed const& general_enclosed) {
|
[&](GeneralEnclosed const&) {
|
||||||
return general_enclosed.evaluate();
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
MatchResult Supports::Feature::evaluate() const
|
bool Supports::Feature::evaluate() const
|
||||||
{
|
{
|
||||||
auto style_property = Parser({}, declaration).parse_as_declaration();
|
auto style_property = Parser({}, declaration).parse_as_declaration();
|
||||||
if (style_property.has_value())
|
return style_property.has_value();
|
||||||
return MatchResult::True;
|
|
||||||
return MatchResult::False;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,20 +16,21 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/css-conditional-3/#at-supports
|
||||||
class Supports final : public RefCounted<Supports> {
|
class Supports final : public RefCounted<Supports> {
|
||||||
friend class Parser;
|
friend class Parser;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Feature {
|
struct Feature {
|
||||||
String declaration;
|
String declaration;
|
||||||
MatchResult evaluate() const;
|
bool evaluate() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Condition;
|
struct Condition;
|
||||||
struct InParens {
|
struct InParens {
|
||||||
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
||||||
|
|
||||||
MatchResult evaluate() const;
|
bool evaluate() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Condition {
|
struct Condition {
|
||||||
|
@ -41,7 +42,7 @@ public:
|
||||||
Type type;
|
Type type;
|
||||||
Vector<InParens> children;
|
Vector<InParens> children;
|
||||||
|
|
||||||
MatchResult evaluate() const;
|
bool evaluate() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue