mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +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,18 +3,15 @@
|
|||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibHTML/Layout/LayoutStyle.h>
|
||||
#include <LibHTML/TreeNode.h>
|
||||
#include <SharedGraphics/Rect.h>
|
||||
|
||||
class Node;
|
||||
|
||||
class LayoutNode {
|
||||
class LayoutNode : public TreeNode<LayoutNode> {
|
||||
public:
|
||||
virtual ~LayoutNode();
|
||||
|
||||
void ref();
|
||||
void deref();
|
||||
int ref_count() const { return m_retain_count; }
|
||||
|
||||
const Rect& rect() const { return m_rect; }
|
||||
Rect& rect() { return m_rect; }
|
||||
void set_rect(const Rect& rect) { m_rect = rect; }
|
||||
|
@ -25,24 +22,6 @@ public:
|
|||
bool is_anonymous() const { return !m_node; }
|
||||
const Node* node() const { return m_node; }
|
||||
|
||||
const LayoutNode* parent_layout_node() const { return m_parent_node; }
|
||||
|
||||
LayoutNode* next_sibling() { return m_next_sibling; }
|
||||
LayoutNode* previous_sibling() { return m_previous_sibling; }
|
||||
LayoutNode* first_child() { return m_first_child; }
|
||||
LayoutNode* last_child() { return m_last_child; }
|
||||
const LayoutNode* next_sibling() const { return m_next_sibling; }
|
||||
const LayoutNode* previous_sibling() const { return m_previous_sibling; }
|
||||
const LayoutNode* first_child() const { return m_first_child; }
|
||||
const LayoutNode* last_child() const { return m_last_child; }
|
||||
|
||||
bool has_children() const { return m_first_child; }
|
||||
|
||||
void append_child(NonnullRefPtr<LayoutNode>);
|
||||
|
||||
void set_next_sibling(LayoutNode* node) { m_next_sibling = node; }
|
||||
void set_previous_sibling(LayoutNode* node) { m_previous_sibling = node; }
|
||||
|
||||
template<typename Callback>
|
||||
inline void for_each_child(Callback callback) const
|
||||
{
|
||||
|
@ -66,13 +45,8 @@ protected:
|
|||
explicit LayoutNode(const Node*);
|
||||
|
||||
private:
|
||||
int m_retain_count { 1 };
|
||||
const Node* m_node { nullptr };
|
||||
LayoutNode* m_parent_node { nullptr };
|
||||
LayoutNode* m_first_child { nullptr };
|
||||
LayoutNode* m_last_child { nullptr };
|
||||
LayoutNode* m_next_sibling { nullptr };
|
||||
LayoutNode* m_previous_sibling { nullptr };
|
||||
|
||||
LayoutStyle m_style;
|
||||
Rect m_rect;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue