mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:08:11 +00:00

We'll be making a lot of trees here, so let's share code during bootstrap. Eventually some of these classes are gonna want custom trees but for now we can just fit them all into the same clothes.
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include <LibHTML/DOM/Document.h>
|
|
#include <LibHTML/DOM/Element.h>
|
|
#include <LibHTML/Layout/LayoutDocument.h>
|
|
#include <stdio.h>
|
|
|
|
Document::Document()
|
|
: ParentNode(NodeType::DOCUMENT_NODE)
|
|
{
|
|
}
|
|
|
|
Document::~Document()
|
|
{
|
|
}
|
|
|
|
static void create_layout_tree_for_node(Node& node)
|
|
{
|
|
if (auto layout_node = node.create_layout_node()) {
|
|
node.set_layout_node(*layout_node);
|
|
#ifdef DEBUG_LAYOUT_TREE_BUILD
|
|
if (node.is_element()) {
|
|
printf("created layout node for <%s>, parent is %p, parent ln is %p\n", static_cast<const Element&>(node).tag_name().characters(), node.parent_node(), node.parent_node()->layout_node());
|
|
}
|
|
#endif
|
|
if (node.parent() && node.parent()->layout_node())
|
|
node.parent()->layout_node()->append_child(*layout_node);
|
|
}
|
|
if (node.is_parent_node()) {
|
|
static_cast<ParentNode&>(node).for_each_child([&](auto& child) {
|
|
create_layout_tree_for_node(child);
|
|
});
|
|
}
|
|
}
|
|
|
|
void Document::build_layout_tree()
|
|
{
|
|
create_layout_tree_for_node(*this);
|
|
}
|
|
|
|
RefPtr<LayoutNode> Document::create_layout_node()
|
|
{
|
|
return adopt(*new LayoutDocument(*this));
|
|
}
|