2019-06-15 19:55:47 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-06-15 23:49:44 +03:00
|
|
|
#include <AK/Badge.h>
|
2019-06-21 19:45:35 +03:00
|
|
|
#include <AK/RefPtr.h>
|
2019-09-28 23:59:16 +03:00
|
|
|
#include <AK/String.h>
|
2019-06-15 19:55:47 +03:00
|
|
|
#include <AK/Vector.h>
|
2019-06-25 20:46:01 +03:00
|
|
|
#include <LibHTML/TreeNode.h>
|
2019-06-15 19:55:47 +03:00
|
|
|
|
|
|
|
enum class NodeType : unsigned {
|
|
|
|
INVALID = 0,
|
|
|
|
ELEMENT_NODE = 1,
|
|
|
|
TEXT_NODE = 3,
|
|
|
|
DOCUMENT_NODE = 9,
|
|
|
|
};
|
|
|
|
|
2019-09-29 12:43:07 +03:00
|
|
|
class Document;
|
2019-09-29 13:24:36 +03:00
|
|
|
class HTMLElement;
|
2019-09-29 12:59:38 +03:00
|
|
|
class HTMLAnchorElement;
|
2019-06-15 23:49:44 +03:00
|
|
|
class ParentNode;
|
2019-09-25 12:17:29 +03:00
|
|
|
class LayoutNode;
|
|
|
|
class StyleResolver;
|
|
|
|
class StyleProperties;
|
2019-06-15 23:49:44 +03:00
|
|
|
|
2019-06-25 20:46:01 +03:00
|
|
|
class Node : public TreeNode<Node> {
|
2019-06-15 19:55:47 +03:00
|
|
|
public:
|
|
|
|
virtual ~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(); }
|
|
|
|
|
2019-09-25 12:17:29 +03:00
|
|
|
RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_properties) const;
|
|
|
|
RefPtr<LayoutNode> create_layout_tree(const StyleResolver&, const StyleProperties* parent_properties) const;
|
|
|
|
|
2019-09-28 23:59:16 +03:00
|
|
|
virtual String tag_name() const = 0;
|
|
|
|
|
2019-09-29 17:22:15 +03:00
|
|
|
virtual String text_content() const;
|
|
|
|
|
2019-09-29 12:43:07 +03:00
|
|
|
Document& document() { return m_document; }
|
|
|
|
const Document& document() const { return m_document; }
|
|
|
|
|
2019-09-29 12:59:38 +03:00
|
|
|
const HTMLAnchorElement* enclosing_link_element() const;
|
2019-09-29 13:24:36 +03:00
|
|
|
const HTMLElement* enclosing_html_element() const;
|
|
|
|
|
|
|
|
virtual bool is_html_element() const { return false; }
|
2019-09-29 12:59:38 +03:00
|
|
|
|
2019-09-29 17:24:57 +03:00
|
|
|
const Node* first_child_with_tag_name(const StringView& tag_name) const
|
|
|
|
{
|
|
|
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
|
|
|
if (child->tag_name() == tag_name)
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-09-29 18:40:39 +03:00
|
|
|
virtual void inserted_into(Node&) {}
|
|
|
|
virtual void removed_from(Node&) {}
|
|
|
|
|
2019-10-04 22:05:52 +03:00
|
|
|
const LayoutNode* layout_node() const { return m_layout_node; }
|
|
|
|
LayoutNode* layout_node() { return m_layout_node; }
|
|
|
|
|
|
|
|
void set_layout_node(Badge<LayoutNode>, LayoutNode* layout_node) const { m_layout_node = layout_node; }
|
|
|
|
|
2019-06-15 19:55:47 +03:00
|
|
|
protected:
|
2019-09-29 12:43:07 +03:00
|
|
|
Node(Document&, NodeType);
|
2019-06-15 19:55:47 +03:00
|
|
|
|
2019-09-29 12:43:07 +03:00
|
|
|
Document& m_document;
|
2019-10-04 22:05:52 +03:00
|
|
|
mutable LayoutNode* m_layout_node { nullptr };
|
2019-06-15 19:55:47 +03:00
|
|
|
NodeType m_type { NodeType::INVALID };
|
|
|
|
};
|