Node.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <AK/Badge.h>
  3. #include <AK/RefPtr.h>
  4. #include <AK/String.h>
  5. #include <AK/Vector.h>
  6. #include <LibHTML/TreeNode.h>
  7. enum class NodeType : unsigned {
  8. INVALID = 0,
  9. ELEMENT_NODE = 1,
  10. TEXT_NODE = 3,
  11. DOCUMENT_NODE = 9,
  12. };
  13. class Document;
  14. class ParentNode;
  15. class LayoutNode;
  16. class StyleResolver;
  17. class StyleProperties;
  18. class Node : public TreeNode<Node> {
  19. public:
  20. virtual ~Node();
  21. NodeType type() const { return m_type; }
  22. bool is_element() const { return type() == NodeType::ELEMENT_NODE; }
  23. bool is_text() const { return type() == NodeType::TEXT_NODE; }
  24. bool is_document() const { return type() == NodeType::DOCUMENT_NODE; }
  25. bool is_parent_node() const { return is_element() || is_document(); }
  26. RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_properties) const;
  27. RefPtr<LayoutNode> create_layout_tree(const StyleResolver&, const StyleProperties* parent_properties) const;
  28. virtual String tag_name() const = 0;
  29. Document& document() { return m_document; }
  30. const Document& document() const { return m_document; }
  31. protected:
  32. Node(Document&, NodeType);
  33. Document& m_document;
  34. NodeType m_type { NodeType::INVALID };
  35. };