mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 09:27:35 +00:00
LibWeb: Use new GeneralEnclosed class in Supports
This commit is contained in:
parent
e760263728
commit
99e18f40fb
3 changed files with 11 additions and 55 deletions
|
@ -1083,7 +1083,7 @@ Optional<Supports::InParens> Parser::parse_supports_in_parens(TokenStream<StyleC
|
||||||
// `<general-enclosed>`
|
// `<general-enclosed>`
|
||||||
if (auto general_enclosed = parse_general_enclosed(tokens); general_enclosed.has_value()) {
|
if (auto general_enclosed = parse_general_enclosed(tokens); general_enclosed.has_value()) {
|
||||||
return Supports::InParens {
|
return Supports::InParens {
|
||||||
.value = Supports::GeneralEnclosed {}
|
.value = general_enclosed.release_value()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,42 +19,20 @@ Supports::Supports(NonnullOwnPtr<Condition>&& condition)
|
||||||
m_matches = result == MatchResult::True;
|
m_matches = result == MatchResult::True;
|
||||||
}
|
}
|
||||||
|
|
||||||
Supports::MatchResult Supports::Condition::evaluate() const
|
MatchResult Supports::Condition::evaluate() const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::Not:
|
case Type::Not:
|
||||||
return negate(children.first().evaluate());
|
return negate(children.first().evaluate());
|
||||||
case Type::And: {
|
case Type::And:
|
||||||
size_t true_results = 0;
|
return evaluate_and(children, [](auto& child) { return child.evaluate(); });
|
||||||
for (auto& child : children) {
|
case Type::Or:
|
||||||
auto child_match = child.evaluate();
|
return evaluate_or(children, [](auto& child) { return child.evaluate(); });
|
||||||
if (child_match == MatchResult::False)
|
|
||||||
return MatchResult::False;
|
|
||||||
if (child_match == MatchResult::True)
|
|
||||||
true_results++;
|
|
||||||
}
|
|
||||||
if (true_results == children.size())
|
|
||||||
return MatchResult::True;
|
|
||||||
return MatchResult::Unknown;
|
|
||||||
}
|
|
||||||
case Type::Or: {
|
|
||||||
size_t false_results = 0;
|
|
||||||
for (auto& child : children) {
|
|
||||||
auto child_match = child.evaluate();
|
|
||||||
if (child_match == MatchResult::True)
|
|
||||||
return MatchResult::True;
|
|
||||||
if (child_match == MatchResult::False)
|
|
||||||
false_results++;
|
|
||||||
}
|
|
||||||
if (false_results == children.size())
|
|
||||||
return MatchResult::False;
|
|
||||||
return MatchResult::Unknown;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Supports::MatchResult Supports::InParens::evaluate() const
|
MatchResult Supports::InParens::evaluate() const
|
||||||
{
|
{
|
||||||
return value.visit(
|
return value.visit(
|
||||||
[&](NonnullOwnPtr<Condition>& condition) {
|
[&](NonnullOwnPtr<Condition>& condition) {
|
||||||
|
@ -63,12 +41,12 @@ Supports::MatchResult Supports::InParens::evaluate() const
|
||||||
[&](Feature& feature) {
|
[&](Feature& feature) {
|
||||||
return feature.evaluate();
|
return feature.evaluate();
|
||||||
},
|
},
|
||||||
[&](GeneralEnclosed&) {
|
[&](GeneralEnclosed& general_enclosed) {
|
||||||
return MatchResult::Unknown;
|
return general_enclosed.evaluate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Supports::MatchResult Supports::Feature::evaluate() const
|
MatchResult Supports::Feature::evaluate() const
|
||||||
{
|
{
|
||||||
auto style_property = Parser({}, "").convert_to_style_property(declaration);
|
auto style_property = Parser({}, "").convert_to_style_property(declaration);
|
||||||
if (style_property.has_value())
|
if (style_property.has_value())
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Variant.h>
|
#include <AK/Variant.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibWeb/CSS/GeneralEnclosed.h>
|
||||||
#include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
|
#include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
@ -18,30 +19,7 @@ namespace Web::CSS {
|
||||||
class Supports final : public RefCounted<Supports> {
|
class Supports final : public RefCounted<Supports> {
|
||||||
friend class Parser;
|
friend class Parser;
|
||||||
|
|
||||||
private:
|
|
||||||
enum class MatchResult {
|
|
||||||
False,
|
|
||||||
True,
|
|
||||||
Unknown,
|
|
||||||
};
|
|
||||||
|
|
||||||
static MatchResult negate(MatchResult value)
|
|
||||||
{
|
|
||||||
switch (value) {
|
|
||||||
case MatchResult::False:
|
|
||||||
return MatchResult::True;
|
|
||||||
case MatchResult::True:
|
|
||||||
return MatchResult::False;
|
|
||||||
case MatchResult::Unknown:
|
|
||||||
return MatchResult::Unknown;
|
|
||||||
}
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct GeneralEnclosed {
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Feature {
|
struct Feature {
|
||||||
// FIXME: Using this internal parser class is a bit of a hack.
|
// FIXME: Using this internal parser class is a bit of a hack.
|
||||||
StyleDeclarationRule declaration;
|
StyleDeclarationRule declaration;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue