Supports.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2021-2022, 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. // https://www.w3.org/TR/css-conditional-4/#at-supports
  16. class Supports final : public RefCounted<Supports> {
  17. friend class Parser;
  18. public:
  19. struct Declaration {
  20. String declaration;
  21. bool evaluate() const;
  22. };
  23. struct Selector {
  24. String selector;
  25. bool evaluate() const;
  26. };
  27. struct Feature {
  28. Variant<Declaration, Selector> value;
  29. bool evaluate() const;
  30. };
  31. struct Condition;
  32. struct InParens {
  33. Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
  34. bool evaluate() const;
  35. };
  36. struct Condition {
  37. enum class Type {
  38. Not,
  39. And,
  40. Or,
  41. };
  42. Type type;
  43. Vector<InParens> children;
  44. bool evaluate() const;
  45. };
  46. static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
  47. {
  48. return adopt_ref(*new Supports(move(condition)));
  49. }
  50. bool matches() const { return m_matches; }
  51. private:
  52. Supports(NonnullOwnPtr<Condition>&&);
  53. NonnullOwnPtr<Condition> m_condition;
  54. bool m_matches { false };
  55. };
  56. }