mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 02:35:09 +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:
parent
2b4eea5a50
commit
e971f5604c
7 changed files with 109 additions and 29 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue