Selector.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <AK/String.h>
  3. #include <AK/Vector.h>
  4. #include <LibHTML/CSS/Specificity.h>
  5. class Selector {
  6. public:
  7. struct SimpleSelector {
  8. enum class Type {
  9. Invalid,
  10. Universal,
  11. TagName,
  12. Id,
  13. Class,
  14. };
  15. Type type { Type::Invalid };
  16. enum class PseudoClass {
  17. None,
  18. Link,
  19. Hover,
  20. FirstChild,
  21. LastChild,
  22. OnlyChild,
  23. Empty,
  24. };
  25. PseudoClass pseudo_class { PseudoClass::None };
  26. String value;
  27. enum class AttributeMatchType {
  28. None,
  29. HasAttribute,
  30. ExactValueMatch,
  31. };
  32. AttributeMatchType attribute_match_type { AttributeMatchType::None };
  33. String attribute_name;
  34. String attribute_value;
  35. };
  36. struct ComplexSelector {
  37. enum class Relation {
  38. None,
  39. ImmediateChild,
  40. Descendant,
  41. AdjacentSibling,
  42. GeneralSibling,
  43. };
  44. Relation relation { Relation::None };
  45. using CompoundSelector = Vector<SimpleSelector>;
  46. CompoundSelector compound_selector;
  47. };
  48. explicit Selector(Vector<ComplexSelector>&&);
  49. ~Selector();
  50. const Vector<ComplexSelector>& complex_selectors() const { return m_complex_selectors; }
  51. Specificity specificity() const;
  52. private:
  53. Vector<ComplexSelector> m_complex_selectors;
  54. };