mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 11:55:08 +00:00
LibHTML: Start fleshing out a basic layout tree.
This commit is contained in:
parent
f8a86b5164
commit
8a0e21b22b
24 changed files with 338 additions and 18 deletions
|
@ -1,10 +1,12 @@
|
|||
#include <LibHTML/Document.h>
|
||||
#include <LibHTML/Dump.h>
|
||||
#include <LibHTML/Element.h>
|
||||
#include <LibHTML/LayoutNode.h>
|
||||
#include <LibHTML/LayoutText.h>
|
||||
#include <LibHTML/Text.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void dump_tree(Node& node)
|
||||
void dump_tree(const Node& node)
|
||||
{
|
||||
static int indent = 0;
|
||||
for (int i = 0; i < indent; ++i)
|
||||
|
@ -12,19 +14,35 @@ void dump_tree(Node& node)
|
|||
if (node.is_document()) {
|
||||
printf("*Document*\n");
|
||||
} else if (node.is_element()) {
|
||||
printf("<%s", static_cast<Element&>(node).tag_name().characters());
|
||||
static_cast<Element&>(node).for_each_attribute([](auto& name, auto& value) {
|
||||
printf("<%s", static_cast<const Element&>(node).tag_name().characters());
|
||||
static_cast<const Element&>(node).for_each_attribute([](auto& name, auto& value) {
|
||||
printf(" %s=%s", name.characters(), value.characters());
|
||||
});
|
||||
printf(">\n");
|
||||
} else if (node.is_text()) {
|
||||
printf("\"%s\"\n", static_cast<Text&>(node).data().characters());
|
||||
printf("\"%s\"\n", static_cast<const Text&>(node).data().characters());
|
||||
}
|
||||
++indent;
|
||||
if (node.is_parent_node()) {
|
||||
static_cast<ParentNode&>(node).for_each_child([](Node& child) {
|
||||
static_cast<const ParentNode&>(node).for_each_child([](auto& child) {
|
||||
dump_tree(child);
|
||||
});
|
||||
}
|
||||
--indent;
|
||||
}
|
||||
|
||||
void dump_tree(const LayoutNode& node)
|
||||
{
|
||||
static int indent = 0;
|
||||
for (int i = 0; i < indent; ++i)
|
||||
printf(" ");
|
||||
printf("%s{%p}", node.class_name(), &node);
|
||||
if (node.is_text())
|
||||
printf(" \"%s\"", static_cast<const LayoutText&>(node).node().data().characters());
|
||||
printf("\n");
|
||||
++indent;
|
||||
node.for_each_child([](auto& child) {
|
||||
dump_tree(child);
|
||||
});
|
||||
--indent;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue