mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 11:25:07 +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:
parent
3af59dfed1
commit
ffcbe8f0de
6 changed files with 86 additions and 16 deletions
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue