1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:47:44 +00:00

LibHTML: Start working on a simple HTML library.

I'd like to have rich text, and we might as well use HTML for that. :^)
This commit is contained in:
Andreas Kling 2019-06-15 18:55:47 +02:00
parent 01d1aee922
commit a67e823838
19 changed files with 329 additions and 0 deletions

41
LibHTML/Node.h Normal file
View file

@ -0,0 +1,41 @@
#pragma once
#include <AK/Retained.h>
#include <AK/Vector.h>
enum class NodeType : unsigned {
INVALID = 0,
ELEMENT_NODE = 1,
TEXT_NODE = 3,
DOCUMENT_NODE = 9,
};
class Node {
public:
virtual ~Node();
void retain();
void release();
int retain_count() const { return m_retain_count; }
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; }
void set_next_sibling(Node* node) { m_next_sibling = node; }
void set_previous_sibling(Node* node) { m_previous_sibling = node; }
protected:
explicit Node(NodeType);
int m_retain_count { 1 };
NodeType m_type { NodeType::INVALID };
Vector<Node*> m_children;
Node* m_next_sibling { nullptr };
Node* m_previous_sibling { nullptr };
};