/* * Copyright (c) 2021-2023, 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; JS::Handle realm; bool evaluate() const; ErrorOr to_string() const; }; struct Selector { String selector; JS::Handle realm; bool evaluate() const; ErrorOr to_string() const; }; struct Feature { Variant value; bool evaluate() const; ErrorOr to_string() const; }; struct Condition; struct InParens { Variant, Feature, GeneralEnclosed> value; bool evaluate() const; ErrorOr to_string() const; }; struct Condition { enum class Type { Not, And, Or, }; Type type; Vector children; bool evaluate() const; ErrorOr to_string() const; }; static NonnullRefPtr create(NonnullOwnPtr&& condition) { return adopt_ref(*new Supports(move(condition))); } bool matches() const { return m_matches; } ErrorOr 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, TRY(in_parens.to_string())); } };