Supports.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullOwnPtr.h>
  8. #include <AK/RefCounted.h>
  9. #include <AK/String.h>
  10. #include <AK/Variant.h>
  11. #include <AK/Vector.h>
  12. #include <LibWeb/CSS/GeneralEnclosed.h>
  13. #include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
  14. namespace Web::CSS {
  15. class Supports final : public RefCounted<Supports> {
  16. friend class Parser;
  17. public:
  18. struct Feature {
  19. String declaration;
  20. MatchResult evaluate() const;
  21. };
  22. struct Condition;
  23. struct InParens {
  24. Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
  25. MatchResult evaluate() const;
  26. };
  27. struct Condition {
  28. enum class Type {
  29. Not,
  30. And,
  31. Or,
  32. };
  33. Type type;
  34. Vector<InParens> children;
  35. MatchResult evaluate() const;
  36. };
  37. static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
  38. {
  39. return adopt_ref(*new Supports(move(condition)));
  40. }
  41. bool matches() const { return m_matches; }
  42. private:
  43. Supports(NonnullOwnPtr<Condition>&&);
  44. NonnullOwnPtr<Condition> m_condition;
  45. bool m_matches { false };
  46. };
  47. }