mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 08:36:15 +00:00
LibHTML: Implement some very simple selector matching.
We walk the entire DOM and check all selectors against all elements. Only id, class and tag name are checked right now. There's no ancestor stack or compound selectors. All in good time :^)
This commit is contained in:
@@ -67,36 +67,41 @@ void dump_tree(const LayoutNode& layout_node)
|
||||
--indent;
|
||||
}
|
||||
|
||||
void dump_rule(const StyleRule& rule)
|
||||
{
|
||||
printf("Rule:\n");
|
||||
for (auto& selector : rule.selectors()) {
|
||||
printf(" Selector:\n");
|
||||
for (auto& component : selector.components()) {
|
||||
const char* type_description = "Unknown";
|
||||
switch (component.type) {
|
||||
case Selector::Component::Type::Invalid:
|
||||
type_description = "Invalid";
|
||||
break;
|
||||
case Selector::Component::Type::Id:
|
||||
type_description = "Id";
|
||||
break;
|
||||
case Selector::Component::Type::Class:
|
||||
type_description = "Class";
|
||||
break;
|
||||
case Selector::Component::Type::TagName:
|
||||
type_description = "TagName";
|
||||
break;
|
||||
}
|
||||
printf(" %s:%s\n", type_description, component.value.characters());
|
||||
}
|
||||
}
|
||||
printf(" Declarations:\n");
|
||||
for (auto& declaration : rule.declarations()) {
|
||||
printf(" '%s': '%s'\n", declaration.property_name().characters(), declaration.value().to_string().characters());
|
||||
}
|
||||
}
|
||||
|
||||
void dump_sheet(const StyleSheet& sheet)
|
||||
{
|
||||
printf("StyleSheet{%p}: %d rule(s)\n", &sheet, sheet.rules().size());
|
||||
|
||||
for (auto& rule : sheet.rules()) {
|
||||
printf("Rule:\n");
|
||||
for (auto& selector : rule.selectors()) {
|
||||
printf(" Selector:\n");
|
||||
for (auto& component : selector.components()) {
|
||||
const char* type_description = "Unknown";
|
||||
switch (component.type) {
|
||||
case Selector::Component::Type::Invalid:
|
||||
type_description = "Invalid";
|
||||
break;
|
||||
case Selector::Component::Type::Id:
|
||||
type_description = "Id";
|
||||
break;
|
||||
case Selector::Component::Type::Class:
|
||||
type_description = "Class";
|
||||
break;
|
||||
case Selector::Component::Type::TagName:
|
||||
type_description = "TagName";
|
||||
break;
|
||||
}
|
||||
printf(" %s:%s", type_description, component.value.characters());
|
||||
}
|
||||
}
|
||||
printf(" Declarations:\n");
|
||||
rule.for_each_declaration([](auto& declaration) {
|
||||
printf(" '%s': '%s'\n", declaration.property_name().characters(), declaration.value().to_string().characters());
|
||||
});
|
||||
dump_rule(rule);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user