Element.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <AK/String.h>
  3. #include <LibHTML/DOM/ParentNode.h>
  4. class Attribute {
  5. public:
  6. Attribute(const String& name, const String& value)
  7. : m_name(name)
  8. , m_value(value)
  9. {
  10. }
  11. const String& name() const { return m_name; }
  12. const String& value() const { return m_value; }
  13. void set_value(const String& value) { m_value = value; }
  14. private:
  15. String m_name;
  16. String m_value;
  17. };
  18. class Element : public ParentNode {
  19. public:
  20. Element(Document&, const String& tag_name);
  21. virtual ~Element() override;
  22. virtual String tag_name() const final { return m_tag_name; }
  23. String attribute(const String& name) const;
  24. void set_attribute(const String& name, const String& value);
  25. void set_attributes(Vector<Attribute>&&);
  26. template<typename Callback>
  27. void for_each_attribute(Callback callback) const
  28. {
  29. for (auto& attribute : m_attributes)
  30. callback(attribute.name(), attribute.value());
  31. }
  32. bool has_class(const StringView&) const;
  33. virtual void apply_presentational_hints(StyleProperties&) const {}
  34. virtual void parse_attribute(const String& name, const String& value);
  35. private:
  36. RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
  37. Attribute* find_attribute(const String& name);
  38. const Attribute* find_attribute(const String& name) const;
  39. String m_tag_name;
  40. Vector<Attribute> m_attributes;
  41. };
  42. template<>
  43. inline bool is<Element>(const Node& node)
  44. {
  45. return node.is_element();
  46. }