Selector.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. };
  21. PseudoClass pseudo_class { PseudoClass::None };
  22. String value;
  23. enum class AttributeMatchType {
  24. None,
  25. HasAttribute,
  26. ExactValueMatch,
  27. };
  28. AttributeMatchType attribute_match_type { AttributeMatchType::None };
  29. String attribute_name;
  30. String attribute_value;
  31. };
  32. struct ComplexSelector {
  33. enum class Relation {
  34. None,
  35. ImmediateChild,
  36. Descendant,
  37. AdjacentSibling,
  38. GeneralSibling,
  39. };
  40. Relation relation { Relation::None };
  41. using CompoundSelector = Vector<SimpleSelector>;
  42. CompoundSelector compound_selector;
  43. };
  44. explicit Selector(Vector<ComplexSelector>&&);
  45. ~Selector();
  46. const Vector<ComplexSelector>& complex_selectors() const { return m_complex_selectors; }
  47. Specificity specificity() const;
  48. private:
  49. Vector<ComplexSelector> m_complex_selectors;
  50. };