mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibWeb: Use smart pointers between DOM and Layout tree
DOM::Node now points to its LayoutNode with a WeakPtr. LayoutNode points to its DOM::Node and DOM::Document with RefPtrs. Layout trees come and go in response to various events, so the DOM tree already has to deal with that. The DOM should always live at least as long as the layout tree, so this patch enforces that assumption by making layout nodes keep their corresponding DOM objects alive. This may not be optimal, but it removes a lot of ambiguous raw pointer action which is not worth accomodating.
This commit is contained in:
parent
a316ca0e0d
commit
385d744989
Notes:
sideshowbarker
2024-07-19 01:48:06 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/385d7449896
3 changed files with 12 additions and 4 deletions
|
@ -217,4 +217,12 @@ void Node::removed_last_ref()
|
|||
delete this;
|
||||
}
|
||||
|
||||
void Node::set_layout_node(Badge<LayoutNode>, LayoutNode* layout_node) const
|
||||
{
|
||||
if (layout_node)
|
||||
m_layout_node = layout_node->make_weak_ptr();
|
||||
else
|
||||
m_layout_node = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>, LayoutNode* layout_node) const { m_layout_node = layout_node; }
|
||||
void set_layout_node(Badge<LayoutNode>, 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<LayoutNode> m_layout_node;
|
||||
NodeType m_type { NodeType::INVALID };
|
||||
bool m_needs_style_update { true };
|
||||
};
|
||||
|
|
|
@ -178,8 +178,8 @@ protected:
|
|||
private:
|
||||
friend class LayoutNodeWithStyle;
|
||||
|
||||
DOM::Document& m_document;
|
||||
DOM::Node* m_node { nullptr };
|
||||
NonnullRefPtr<DOM::Document> m_document;
|
||||
RefPtr<DOM::Node> m_node;
|
||||
|
||||
bool m_inline { false };
|
||||
bool m_has_style { false };
|
||||
|
|
Loading…
Add table
Reference in a new issue