/* * Copyright (c) 2021-2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::CSS { // https://www.w3.org/TR/css-conditional-4/#at-supports class Supports final : public RefCounted { friend class Parser::Parser; public: struct Declaration { String declaration; bool evaluate() const; String to_string() const; }; struct Selector { String selector; bool evaluate() const; String to_string() const; }; struct Feature { Variant value; bool evaluate() const; String to_string() const; }; struct Condition; struct InParens { Variant, Feature, GeneralEnclosed> value; bool evaluate() const; String to_string() const; }; struct Condition { enum class Type { Not, And, Or, }; Type type; Vector children; bool evaluate() const; String to_string() const; }; static NonnullRefPtr create(NonnullOwnPtr&& condition) { return adopt_ref(*new Supports(move(condition))); } bool matches() const { return m_matches; } String to_string() const; private: Supports(NonnullOwnPtr&&); NonnullOwnPtr m_condition; bool m_matches { false }; }; } template<> struct AK::Formatter : AK::Formatter { ErrorOr format(FormatBuilder& builder, Web::CSS::Supports::InParens const& in_parens) { return Formatter::format(builder, in_parens.to_string()); } };