
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
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
|
#include <LibWeb/CSS/Supports.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
Supports::Supports(NonnullOwnPtr<Condition>&& condition)
|
|
: m_condition(move(condition))
|
|
{
|
|
m_matches = m_condition->evaluate();
|
|
}
|
|
|
|
bool Supports::Condition::evaluate() const
|
|
{
|
|
switch (type) {
|
|
case Type::Not:
|
|
return !children.first().evaluate();
|
|
case Type::And:
|
|
for (auto& child : children) {
|
|
if (!child.evaluate())
|
|
return false;
|
|
}
|
|
return true;
|
|
case Type::Or:
|
|
for (auto& child : children) {
|
|
if (child.evaluate())
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
|
|
bool Supports::InParens::evaluate() const
|
|
{
|
|
return value.visit(
|
|
[&](NonnullOwnPtr<Condition> const& condition) {
|
|
return condition->evaluate();
|
|
},
|
|
[&](Feature const& feature) {
|
|
return feature.evaluate();
|
|
},
|
|
[&](GeneralEnclosed const&) {
|
|
return false;
|
|
});
|
|
}
|
|
|
|
bool Supports::Feature::evaluate() const
|
|
{
|
|
auto style_property = Parser({}, declaration).parse_as_declaration();
|
|
return style_property.has_value();
|
|
}
|
|
|
|
}
|