diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index c8c7a6ff4e..0df4a9f558 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp @@ -208,6 +208,7 @@ static void build_paint_tree(Node& node, Painting::Paintable* parent_paintable = } parent_paintable->append_child(paintable); } + paintable.set_dom_node(node.dom_node()); for (auto* child = node.first_child(); child; child = child->next_sibling()) { build_paint_tree(*child, &paintable); } diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp index c7a913e256..6da6ff15b1 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp @@ -14,11 +14,27 @@ namespace Web::Painting { void Paintable::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); + visitor.visit(m_dom_node); visitor.visit(m_layout_node); if (m_containing_block.has_value()) visitor.visit(m_containing_block.value()); } +void Paintable::set_dom_node(JS::GCPtr dom_node) +{ + m_dom_node = dom_node; +} + +JS::GCPtr Paintable::dom_node() +{ + return m_dom_node; +} + +JS::GCPtr Paintable::dom_node() const +{ + return m_dom_node; +} + Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge, CSSPixelPoint, unsigned, unsigned) { return DispatchEventOfSameName::Yes; diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h index ab1ceaddbd..81a7087ca0 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.h +++ b/Userland/Libraries/LibWeb/Painting/Paintable.h @@ -131,8 +131,9 @@ public: Layout::Node const& layout_node() const { return m_layout_node; } Layout::Node& layout_node() { return const_cast(*m_layout_node); } - DOM::Node* dom_node() { return layout_node().dom_node(); } - DOM::Node const* dom_node() const { return layout_node().dom_node(); } + [[nodiscard]] JS::GCPtr dom_node(); + [[nodiscard]] JS::GCPtr dom_node() const; + void set_dom_node(JS::GCPtr); auto const& computed_values() const { return m_layout_node->computed_values(); } @@ -164,6 +165,7 @@ protected: virtual void visit_edges(Cell::Visitor&) override; private: + JS::GCPtr m_dom_node; JS::NonnullGCPtr m_layout_node; Optional> mutable m_containing_block; };