diff --git a/Userland/Libraries/LibWeb/CSS/Supports.cpp b/Userland/Libraries/LibWeb/CSS/Supports.cpp index 97e4d7d073..de220a5598 100644 --- a/Userland/Libraries/LibWeb/CSS/Supports.cpp +++ b/Userland/Libraries/LibWeb/CSS/Supports.cpp @@ -12,27 +12,31 @@ namespace Web::CSS { Supports::Supports(NonnullOwnPtr&& 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; + m_matches = m_condition->evaluate(); } -MatchResult Supports::Condition::evaluate() const +bool Supports::Condition::evaluate() const { switch (type) { case Type::Not: - return negate(children.first().evaluate()); + return !children.first().evaluate(); 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: - return evaluate_or(children, [](auto& child) { return child.evaluate(); }); + for (auto& child : children) { + if (child.evaluate()) + return true; + } + return false; } VERIFY_NOT_REACHED(); } -MatchResult Supports::InParens::evaluate() const +bool Supports::InParens::evaluate() const { return value.visit( [&](NonnullOwnPtr const& condition) { @@ -41,17 +45,15 @@ MatchResult Supports::InParens::evaluate() const [&](Feature const& feature) { return feature.evaluate(); }, - [&](GeneralEnclosed const& general_enclosed) { - return general_enclosed.evaluate(); + [&](GeneralEnclosed const&) { + return false; }); } -MatchResult Supports::Feature::evaluate() const +bool Supports::Feature::evaluate() const { auto style_property = Parser({}, declaration).parse_as_declaration(); - if (style_property.has_value()) - return MatchResult::True; - return MatchResult::False; + return style_property.has_value(); } } diff --git a/Userland/Libraries/LibWeb/CSS/Supports.h b/Userland/Libraries/LibWeb/CSS/Supports.h index bf7d671313..2494f0488b 100644 --- a/Userland/Libraries/LibWeb/CSS/Supports.h +++ b/Userland/Libraries/LibWeb/CSS/Supports.h @@ -16,20 +16,21 @@ namespace Web::CSS { +// https://www.w3.org/TR/css-conditional-3/#at-supports class Supports final : public RefCounted { friend class Parser; public: struct Feature { String declaration; - MatchResult evaluate() const; + bool evaluate() const; }; struct Condition; struct InParens { Variant, Feature, GeneralEnclosed> value; - MatchResult evaluate() const; + bool evaluate() const; }; struct Condition { @@ -41,7 +42,7 @@ public: Type type; Vector children; - MatchResult evaluate() const; + bool evaluate() const; }; static NonnullRefPtr create(NonnullOwnPtr&& condition)