Element.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include <LibHTML/DOM/ParentNode.h>
  3. #include <AK/AKString.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. explicit Element(const String& tag_name);
  21. virtual ~Element() override;
  22. const String& tag_name() const { 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. virtual RetainPtr<LayoutNode> create_layout_node() override;
  33. private:
  34. Attribute* find_attribute(const String& name);
  35. const Attribute* find_attribute(const String& name) const;
  36. String m_tag_name;
  37. Vector<Attribute> m_attributes;
  38. };