diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-17 14:41:50 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-20 15:16:23 +0200 |
commit | 268b9c5d904e41ba901c9fce556a5be1d5fea228 (patch) | |
tree | 3162ca508db6480fef8729482dabb43c7eb5c4fe /Userland/Libraries/LibWeb/Layout/Node.h | |
parent | 83c5ff57d8dfaad4652cd94df834b08d6cdc3db3 (diff) | |
download | serenity-268b9c5d904e41ba901c9fce556a5be1d5fea228.zip |
LibWeb: Make the layout tree GC-allocated
This removes a set of complex reference cycles between DOM, layout tree
and browsing context.
It also makes lifetimes much easier to reason about, as the DOM and
layout trees are now free to keep each other alive.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/Node.h')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index e8ca0bfe1b..b3a044d3f8 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -31,7 +31,12 @@ enum class LayoutMode { IntrinsicSizing, }; -class Node : public TreeNode<Node> { +class Node + : public JS::Cell + , public TreeNode<Node> + , public Weakable<Node> { + JS_CELL(Node, JS::Cell); + public: virtual ~Node(); @@ -61,7 +66,6 @@ public: bool is_root_element() const; - String class_name() const; String debug_description() const; bool has_style() const { return m_has_style; } @@ -140,10 +144,12 @@ public: protected: Node(DOM::Document&, DOM::Node*); + virtual void visit_edges(Cell::Visitor&) override; + private: friend class NodeWithStyle; - JS::Handle<DOM::Node> m_dom_node; + JS::NonnullGCPtr<DOM::Node> m_dom_node; RefPtr<Painting::Paintable> m_paintable; size_t m_serial_id { 0 }; @@ -159,6 +165,8 @@ private: }; class NodeWithStyle : public Node { + JS_CELL(NodeWithStyle, Node); + public: virtual ~NodeWithStyle() override = default; @@ -171,7 +179,7 @@ public: Vector<CSS::BackgroundLayerData> const& background_layers() const { return computed_values().background_layers(); } const CSS::AbstractImageStyleValue* list_style_image() const { return m_list_style_image; } - NonnullRefPtr<NodeWithStyle> create_anonymous_wrapper() const; + JS::NonnullGCPtr<NodeWithStyle> create_anonymous_wrapper() const; protected: NodeWithStyle(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>); @@ -185,6 +193,8 @@ private: }; class NodeWithStyleAndBoxModelMetrics : public NodeWithStyle { + JS_CELL(NodeWithStyleAndBoxModelMetrics, NodeWithStyle); + public: BoxModelMetrics& box_model() { return m_box_model; } BoxModelMetrics const& box_model() const { return m_box_model; } |