mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 06:05:06 +00:00
LibHTML: Refactor to go from DOM -> styled tree -> layout tree.
Frame::layout() drives everything now, it takes the DOM contained in the frame and puts it through the tree transformations.
This commit is contained in:
parent
6e95b11395
commit
7eef69ad4b
20 changed files with 132 additions and 131 deletions
|
@ -1,3 +1,4 @@
|
|||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutDocument.h>
|
||||
|
@ -12,31 +13,9 @@ Document::~Document()
|
|||
{
|
||||
}
|
||||
|
||||
static void create_layout_tree_for_node(Node& node)
|
||||
StyleResolver& Document::style_resolver()
|
||||
{
|
||||
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));
|
||||
if (!m_style_resolver)
|
||||
m_style_resolver = make<StyleResolver>(*this);
|
||||
return *m_style_resolver;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue