mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +00:00
LibHTML: Add a simple TreeNode<T> template for making trees.
We'll be making a lot of trees here, so let's share code during bootstrap. Eventually some of these classes are gonna want custom trees but for now we can just fit them all into the same clothes.
This commit is contained in:
parent
e9b619c4aa
commit
8adae51b35
8 changed files with 68 additions and 109 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <AK/Badge.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibHTML/TreeNode.h>
|
||||
|
||||
enum class NodeType : unsigned {
|
||||
INVALID = 0,
|
||||
|
@ -14,33 +15,16 @@ enum class NodeType : unsigned {
|
|||
class LayoutNode;
|
||||
class ParentNode;
|
||||
|
||||
class Node {
|
||||
class Node : public TreeNode<Node> {
|
||||
public:
|
||||
virtual ~Node();
|
||||
|
||||
void ref();
|
||||
void deref();
|
||||
int ref_count() const { return m_retain_count; }
|
||||
|
||||
ParentNode* parent_node() { return m_parent_node; }
|
||||
const ParentNode* parent_node() const { return m_parent_node; }
|
||||
|
||||
void set_parent_node(Badge<ParentNode>, ParentNode* parent_node) { m_parent_node = parent_node; }
|
||||
|
||||
NodeType type() const { return m_type; }
|
||||
bool is_element() const { return type() == NodeType::ELEMENT_NODE; }
|
||||
bool is_text() const { return type() == NodeType::TEXT_NODE; }
|
||||
bool is_document() const { return type() == NodeType::DOCUMENT_NODE; }
|
||||
bool is_parent_node() const { return is_element() || is_document(); }
|
||||
|
||||
Node* next_sibling() { return m_next_sibling; }
|
||||
Node* previous_sibling() { return m_previous_sibling; }
|
||||
const Node* next_sibling() const { return m_next_sibling; }
|
||||
const Node* previous_sibling() const { return m_previous_sibling; }
|
||||
|
||||
void set_next_sibling(Node* node) { m_next_sibling = node; }
|
||||
void set_previous_sibling(Node* node) { m_previous_sibling = node; }
|
||||
|
||||
virtual RefPtr<LayoutNode> create_layout_node();
|
||||
|
||||
const LayoutNode* layout_node() const { return m_layout_node; }
|
||||
|
@ -51,10 +35,6 @@ public:
|
|||
protected:
|
||||
explicit Node(NodeType);
|
||||
|
||||
int m_retain_count { 1 };
|
||||
NodeType m_type { NodeType::INVALID };
|
||||
ParentNode* m_parent_node { nullptr };
|
||||
Node* m_next_sibling { nullptr };
|
||||
Node* m_previous_sibling { nullptr };
|
||||
RefPtr<LayoutNode> m_layout_node;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue