From 6d830e63353d11a828625152e3f0299faab8bf66 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 Oct 2022 18:20:34 +0200 Subject: [PATCH] LibWeb: Tie layout tree to a specific browsing context Now that both the layout tree and browsing context are GC-allocated, we can formalize their relationship a bit better by having layout nodes keep a NonnullGCPtr to the browsing context. This makes the previously-indirect link direct, removing an unpleasant "how do we know the browsing context is alive" question when accessing it from the layout tree. --- Userland/Libraries/LibWeb/Layout/Node.cpp | 8 ++++---- Userland/Libraries/LibWeb/Layout/Node.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 778e3cf4a9..f4ddba2d2f 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -20,6 +20,7 @@ namespace Web::Layout { Node::Node(DOM::Document& document, DOM::Node* node) : m_dom_node(node ? *node : document) + , m_browsing_context(*document.browsing_context()) , m_anonymous(node == nullptr) { m_serial_id = document.next_layout_node_serial_id({}); @@ -34,6 +35,7 @@ void Node::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_dom_node); + visitor.visit(m_browsing_context); TreeNode::visit_edges(visitor); } @@ -105,14 +107,12 @@ bool Node::establishes_stacking_context() const HTML::BrowsingContext const& Node::browsing_context() const { - VERIFY(document().browsing_context()); - return *document().browsing_context(); + return *m_browsing_context; } HTML::BrowsingContext& Node::browsing_context() { - VERIFY(document().browsing_context()); - return *document().browsing_context(); + return *m_browsing_context; } InitialContainingBlock const& Node::root() const diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index b3a044d3f8..240fe1b773 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -152,6 +152,8 @@ private: JS::NonnullGCPtr m_dom_node; RefPtr m_paintable; + JS::NonnullGCPtr m_browsing_context; + size_t m_serial_id { 0 }; bool m_anonymous { false };