Selector.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <AK/Vector.h>
  9. namespace Web::CSS {
  10. class Selector {
  11. public:
  12. struct SimpleSelector {
  13. enum class Type {
  14. Invalid,
  15. Universal,
  16. TagName,
  17. Id,
  18. Class,
  19. };
  20. Type type { Type::Invalid };
  21. enum class PseudoClass {
  22. None,
  23. Link,
  24. Visited,
  25. Hover,
  26. Focus,
  27. FirstChild,
  28. LastChild,
  29. OnlyChild,
  30. Empty,
  31. Root,
  32. FirstOfType,
  33. LastOfType,
  34. };
  35. PseudoClass pseudo_class { PseudoClass::None };
  36. enum class PseudoElement {
  37. None,
  38. Before,
  39. After,
  40. };
  41. PseudoElement pseudo_element { PseudoElement::None };
  42. FlyString value;
  43. enum class AttributeMatchType {
  44. None,
  45. HasAttribute,
  46. ExactValueMatch,
  47. Contains,
  48. StartsWith,
  49. };
  50. AttributeMatchType attribute_match_type { AttributeMatchType::None };
  51. FlyString attribute_name;
  52. String attribute_value;
  53. };
  54. struct ComplexSelector {
  55. enum class Relation {
  56. None,
  57. ImmediateChild,
  58. Descendant,
  59. AdjacentSibling,
  60. GeneralSibling,
  61. Column,
  62. };
  63. Relation relation { Relation::None };
  64. using CompoundSelector = Vector<SimpleSelector>;
  65. CompoundSelector compound_selector;
  66. };
  67. explicit Selector(Vector<ComplexSelector>&&);
  68. ~Selector();
  69. const Vector<ComplexSelector>& complex_selectors() const { return m_complex_selectors; }
  70. u32 specificity() const;
  71. private:
  72. Vector<ComplexSelector> m_complex_selectors;
  73. };
  74. }