Supports.h 1.3 KB

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