2021-10-08 15:40:19 +01:00
|
|
|
/*
|
|
|
|
* 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))
|
|
|
|
{
|
2022-01-19 20:03:22 +00:00
|
|
|
m_matches = m_condition->evaluate();
|
2021-10-08 15:40:19 +01:00
|
|
|
}
|
|
|
|
|
2022-01-19 20:03:22 +00:00
|
|
|
bool Supports::Condition::evaluate() const
|
2021-10-08 15:40:19 +01:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case Type::Not:
|
2022-01-19 20:03:22 +00:00
|
|
|
return !children.first().evaluate();
|
2021-11-24 14:20:59 +00:00
|
|
|
case Type::And:
|
2022-01-19 20:03:22 +00:00
|
|
|
for (auto& child : children) {
|
|
|
|
if (!child.evaluate())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2021-11-24 14:20:59 +00:00
|
|
|
case Type::Or:
|
2022-01-19 20:03:22 +00:00
|
|
|
for (auto& child : children) {
|
|
|
|
if (child.evaluate())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2021-10-08 15:40:19 +01:00
|
|
|
}
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
2022-01-19 20:03:22 +00:00
|
|
|
bool Supports::InParens::evaluate() const
|
2021-10-08 15:40:19 +01:00
|
|
|
{
|
|
|
|
return value.visit(
|
2022-01-13 17:31:00 +03:30
|
|
|
[&](NonnullOwnPtr<Condition> const& condition) {
|
2021-10-08 15:40:19 +01:00
|
|
|
return condition->evaluate();
|
|
|
|
},
|
2022-01-13 17:31:00 +03:30
|
|
|
[&](Feature const& feature) {
|
2021-10-08 15:40:19 +01:00
|
|
|
return feature.evaluate();
|
|
|
|
},
|
2022-01-19 20:03:22 +00:00
|
|
|
[&](GeneralEnclosed const&) {
|
|
|
|
return false;
|
2021-10-08 15:40:19 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-19 20:03:22 +00:00
|
|
|
bool Supports::Feature::evaluate() const
|
2021-10-08 15:40:19 +01:00
|
|
|
{
|
2021-11-24 16:11:04 +00:00
|
|
|
auto style_property = Parser({}, declaration).parse_as_declaration();
|
2022-01-19 20:03:22 +00:00
|
|
|
return style_property.has_value();
|
2021-10-08 15:40:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|