blob: 97e4d7d0736a523bcb242b3edf44f60162f6080e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*
* 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))
{
auto result = m_condition->evaluate();
if (result == MatchResult::Unknown) {
dbgln("!!! Evaluation of CSS Supports returned 'Unknown'!");
}
m_matches = result == MatchResult::True;
}
MatchResult Supports::Condition::evaluate() const
{
switch (type) {
case Type::Not:
return negate(children.first().evaluate());
case Type::And:
return evaluate_and(children, [](auto& child) { return child.evaluate(); });
case Type::Or:
return evaluate_or(children, [](auto& child) { return child.evaluate(); });
}
VERIFY_NOT_REACHED();
}
MatchResult Supports::InParens::evaluate() const
{
return value.visit(
[&](NonnullOwnPtr<Condition> const& condition) {
return condition->evaluate();
},
[&](Feature const& feature) {
return feature.evaluate();
},
[&](GeneralEnclosed const& general_enclosed) {
return general_enclosed.evaluate();
});
}
MatchResult Supports::Feature::evaluate() const
{
auto style_property = Parser({}, declaration).parse_as_declaration();
if (style_property.has_value())
return MatchResult::True;
return MatchResult::False;
}
}
|