summaryrefslogtreecommitdiff
path: root/LibHTML/DOM/Node.h
blob: a021225f9edc0907d75a4a06256d093f687e2e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include <AK/Badge.h>
#include <AK/RetainPtr.h>
#include <AK/Vector.h>

enum class NodeType : unsigned {
    INVALID = 0,
    ELEMENT_NODE = 1,
    TEXT_NODE = 3,
    DOCUMENT_NODE = 9,
};

class LayoutNode;
class ParentNode;

class 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 RetainPtr<LayoutNode> create_layout_node();

    const LayoutNode* layout_node() const { return m_layout_node; }
    LayoutNode* layout_node() { return m_layout_node; }

    void set_layout_node(Retained<LayoutNode>);

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 };
    RetainPtr<LayoutNode> m_layout_node;
};