From 3d7c880a4265c4d3720849c69cee4feb41c3b818 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Aug 2023 12:00:42 +0200 Subject: [PATCH] LibWeb: Give DOM::Node a direct pointer to its Paintable Instead of going via the layout tree. --- Userland/Libraries/LibWeb/DOM/Node.cpp | 15 +++++++++------ Userland/Libraries/LibWeb/DOM/Node.h | 3 +++ Userland/Libraries/LibWeb/Layout/LayoutState.cpp | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index f5bd577185..8d37e5b9f6 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -41,6 +41,7 @@ #include #include #include +#include namespace Web::DOM { @@ -103,6 +104,7 @@ void Node::visit_edges(Cell::Visitor& visitor) visitor.visit(m_child_nodes); visitor.visit(m_layout_node); + visitor.visit(m_paintable); for (auto& registered_observer : m_registered_observer_list) visitor.visit(registered_observer); @@ -1438,18 +1440,19 @@ size_t Node::length() const return child_count(); } +void Node::set_paintable(JS::GCPtr paintable) +{ + m_paintable = paintable; +} + Painting::Paintable const* Node::paintable() const { - if (!layout_node()) - return nullptr; - return layout_node()->paintable(); + return m_paintable; } Painting::Paintable* Node::paintable() { - if (!layout_node()) - return nullptr; - return layout_node()->paintable(); + return m_paintable; } Painting::PaintableBox const* Node::paintable_box() const diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 2bb02f7211..6018284edc 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -187,6 +187,8 @@ public: Painting::Paintable const* paintable() const; Painting::Paintable* paintable(); + void set_paintable(JS::GCPtr); + void set_layout_node(Badge, JS::NonnullGCPtr); void detach_layout_node(Badge); @@ -671,6 +673,7 @@ protected: JS::GCPtr m_document; JS::GCPtr m_layout_node; + JS::GCPtr m_paintable; NodeType m_type { NodeType::INVALID }; bool m_needs_style_update { false }; bool m_child_needs_style_update { false }; diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index 015e1b2d73..083f19c802 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp @@ -209,6 +209,8 @@ static void build_paint_tree(Node& node, Painting::Paintable* parent_paintable = parent_paintable->append_child(paintable); } paintable.set_dom_node(node.dom_node()); + if (node.dom_node()) + node.dom_node()->set_paintable(&paintable); for (auto* child = node.first_child(); child; child = child->next_sibling()) { build_paint_tree(*child, &paintable); }