diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index ac5b349429..a06a6e9e50 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -217,4 +217,12 @@ void Node::removed_last_ref() delete this; } +void Node::set_layout_node(Badge, LayoutNode* layout_node) const +{ + if (layout_node) + m_layout_node = layout_node->make_weak_ptr(); + else + m_layout_node = nullptr; +} + } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index df6e301647..9b2573c3fc 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -118,7 +118,7 @@ public: const LayoutNode* layout_node() const { return m_layout_node; } LayoutNode* layout_node() { return m_layout_node; } - void set_layout_node(Badge, LayoutNode* layout_node) const { m_layout_node = layout_node; } + void set_layout_node(Badge, LayoutNode*) const; virtual bool is_child_allowed(const Node&) const { return true; } @@ -138,7 +138,7 @@ protected: Node(Document&, NodeType); Document* m_document { nullptr }; - mutable LayoutNode* m_layout_node { nullptr }; + mutable WeakPtr m_layout_node; NodeType m_type { NodeType::INVALID }; bool m_needs_style_update { true }; }; diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index 1b72b5645b..8b955288af 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -178,8 +178,8 @@ protected: private: friend class LayoutNodeWithStyle; - DOM::Document& m_document; - DOM::Node* m_node { nullptr }; + NonnullRefPtr m_document; + RefPtr m_node; bool m_inline { false }; bool m_has_style { false };