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

LibHTML: Start fleshing out a basic layout tree.

This commit is contained in:
Andreas Kling 2019-06-15 22:49:44 +02:00
parent f8a86b5164
commit 8a0e21b22b
24 changed files with 338 additions and 18 deletions

View file

@ -1,4 +1,7 @@
#include <LibHTML/Document.h>
#include <LibHTML/Element.h>
#include <LibHTML/LayoutDocument.h>
#include <stdio.h>
Document::Document()
: ParentNode(NodeType::DOCUMENT_NODE)
@ -9,3 +12,31 @@ 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() && node.parent_node()->layout_node())
node.parent_node()->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);
}
RetainPtr<LayoutNode> Document::create_layout_node()
{
return adopt(*new LayoutDocument(*this));
}