From 285a4165f39078db5d52645c2dc5d0861c4f38ac Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 6 Jun 2020 15:07:07 +0200 Subject: [PATCH] LibWeb: Add Node notifications for Document<=>Frame attach/detach Some DOM nodes will want to do stuff when we attach/detach from a Frame and this seems like a simple enough way to let them know. --- Libraries/LibWeb/DOM/Document.cpp | 10 +++++++++- Libraries/LibWeb/DOM/Node.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 529be4f88e..74e979c350 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -161,11 +161,19 @@ String Document::title() const void Document::attach_to_frame(Badge, Frame& frame) { m_frame = frame.make_weak_ptr(); + for_each_in_subtree([&](auto& node) { + node.document_did_attach_to_frame(frame); + return IterationDecision::Continue; + }); layout(); } -void Document::detach_from_frame(Badge, Frame&) +void Document::detach_from_frame(Badge, Frame& frame) { + for_each_in_subtree([&](auto& node) { + node.document_will_detach_from_frame(frame); + return IterationDecision::Continue; + }); m_layout_root = nullptr; m_frame = nullptr; } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 771a87f78d..ce1f9e23e0 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -128,6 +128,9 @@ public: bool is_link() const; + virtual void document_did_attach_to_frame(Frame&) {} + virtual void document_will_detach_from_frame(Frame&) {} + protected: Node(Document&, NodeType);