LibWeb: Give DOM::Node a direct pointer to its Paintable

Instead of going via the layout tree.
This commit is contained in:
Andreas Kling 2023-08-19 12:00:42 +02:00
parent 25375bf1d5
commit 3d7c880a42
3 changed files with 14 additions and 6 deletions

View file

@ -41,6 +41,7 @@
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Painting/Paintable.h>
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<Painting::Paintable> 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

View file

@ -187,6 +187,8 @@ public:
Painting::Paintable const* paintable() const;
Painting::Paintable* paintable();
void set_paintable(JS::GCPtr<Painting::Paintable>);
void set_layout_node(Badge<Layout::Node>, JS::NonnullGCPtr<Layout::Node>);
void detach_layout_node(Badge<Layout::TreeBuilder>);
@ -671,6 +673,7 @@ protected:
JS::GCPtr<Document> m_document;
JS::GCPtr<Layout::Node> m_layout_node;
JS::GCPtr<Painting::Paintable> m_paintable;
NodeType m_type { NodeType::INVALID };
bool m_needs_style_update { false };
bool m_child_needs_style_update { false };

View file

@ -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);
}