1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-29 13:15:08 +00:00

LibHTML: Start building the style tree.

Walk the DOM and construct a parallel style tree that points back to the DOM
and has the relevant CSS property values hanging off of them.

The values are picked based on naive selector matching. There's no cascade
or specificity taken into account yet.
This commit is contained in:
Andreas Kling 2019-06-28 21:17:34 +02:00
parent 3af59dfed1
commit ffcbe8f0de
6 changed files with 86 additions and 16 deletions

View file

@ -1,4 +1,5 @@
#include <LibHTML/CSS/StyleSheet.h>
#include <LibHTML/CSS/StyledNode.h>
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/DOM/Text.h>
@ -67,6 +68,38 @@ void dump_tree(const LayoutNode& layout_node)
--indent;
}
void dump_tree(const StyledNode& styled_node)
{
static int indent = 0;
for (int i = 0; i < indent; ++i)
printf(" ");
String tag_name;
auto& node = *styled_node.node();
if (node.is_text())
tag_name = "#text";
else if (node.is_document())
tag_name = "#document";
else if (node.is_element())
tag_name = static_cast<const Element&>(node).tag_name();
else
tag_name = "???";
printf("%s", tag_name.characters());
printf("\n");
styled_node.for_each_property([&](auto& key, auto& value) {
for (int i = 0; i < indent; ++i)
printf(" ");
printf(" (%s: %s)\n", key.characters(), value.to_string().characters());
});
++indent;
styled_node.for_each_child([](auto& child) {
dump_tree(child);
});
--indent;
}
void dump_rule(const StyleRule& rule)
{
printf("Rule:\n");