summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Dump.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-29 22:24:23 +0200
committerAndreas Kling <kling@serenityos.org>2020-03-30 11:35:39 +0200
commit0f7bcd4111bae9ae5e4e32c6c013511f89b255f6 (patch)
treedbe7de82c44bd2b6db4922647290f2339b41c684 /Libraries/LibWeb/Dump.cpp
parentc56acba75e9fcf6a511e92855f4f4e2221241835 (diff)
downloadserenity-0f7bcd4111bae9ae5e4e32c6c013511f89b255f6.zip
LibWeb: Add naive support for document.querySelectorAll()
This currently returns a JS::Array of elements matching a selector. The more correct behavior would be to return a static NodeList, but as we don't have NodeLists right now, that'll be a task for the future.
Diffstat (limited to 'Libraries/LibWeb/Dump.cpp')
-rw-r--r--Libraries/LibWeb/Dump.cpp125
1 files changed, 65 insertions, 60 deletions
diff --git a/Libraries/LibWeb/Dump.cpp b/Libraries/LibWeb/Dump.cpp
index 781d5f48eb..da3ad428a7 100644
--- a/Libraries/LibWeb/Dump.cpp
+++ b/Libraries/LibWeb/Dump.cpp
@@ -170,78 +170,83 @@ void dump_tree(const LayoutNode& layout_node)
--indent;
}
-void dump_rule(const StyleRule& rule)
+void dump_selector(const Selector& selector)
{
- dbgprintf("Rule:\n");
- for (auto& selector : rule.selectors()) {
- dbgprintf(" Selector:\n");
+ dbgprintf(" Selector:\n");
- for (auto& complex_selector : selector.complex_selectors()) {
- dbgprintf(" ");
+ for (auto& complex_selector : selector.complex_selectors()) {
+ dbgprintf(" ");
+
+ const char* relation_description = "";
+ switch (complex_selector.relation) {
+ case Selector::ComplexSelector::Relation::None:
+ break;
+ case Selector::ComplexSelector::Relation::ImmediateChild:
+ relation_description = "ImmediateChild";
+ break;
+ case Selector::ComplexSelector::Relation::Descendant:
+ relation_description = "Descendant";
+ break;
+ case Selector::ComplexSelector::Relation::AdjacentSibling:
+ relation_description = "AdjacentSibling";
+ break;
+ case Selector::ComplexSelector::Relation::GeneralSibling:
+ relation_description = "GeneralSibling";
+ break;
+ }
- const char* relation_description = "";
- switch (complex_selector.relation) {
- case Selector::ComplexSelector::Relation::None:
+ if (*relation_description)
+ dbgprintf("{%s} ", relation_description);
+
+ for (size_t i = 0; i < complex_selector.compound_selector.size(); ++i) {
+ auto& simple_selector = complex_selector.compound_selector[i];
+ const char* type_description = "Unknown";
+ switch (simple_selector.type) {
+ case Selector::SimpleSelector::Type::Invalid:
+ type_description = "Invalid";
break;
- case Selector::ComplexSelector::Relation::ImmediateChild:
- relation_description = "ImmediateChild";
+ case Selector::SimpleSelector::Type::Universal:
+ type_description = "Universal";
break;
- case Selector::ComplexSelector::Relation::Descendant:
- relation_description = "Descendant";
+ case Selector::SimpleSelector::Type::Id:
+ type_description = "Id";
break;
- case Selector::ComplexSelector::Relation::AdjacentSibling:
- relation_description = "AdjacentSibling";
+ case Selector::SimpleSelector::Type::Class:
+ type_description = "Class";
break;
- case Selector::ComplexSelector::Relation::GeneralSibling:
- relation_description = "GeneralSibling";
+ case Selector::SimpleSelector::Type::TagName:
+ type_description = "TagName";
+ break;
+ }
+ const char* attribute_match_type_description = "";
+ switch (simple_selector.attribute_match_type) {
+ case Selector::SimpleSelector::AttributeMatchType::None:
+ break;
+ case Selector::SimpleSelector::AttributeMatchType::HasAttribute:
+ attribute_match_type_description = "HasAttribute";
+ break;
+ case Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
+ attribute_match_type_description = "ExactValueMatch";
break;
}
- if (*relation_description)
- dbgprintf("{%s} ", relation_description);
-
- for (size_t i = 0; i < complex_selector.compound_selector.size(); ++i) {
- auto& simple_selector = complex_selector.compound_selector[i];
- const char* type_description = "Unknown";
- switch (simple_selector.type) {
- case Selector::SimpleSelector::Type::Invalid:
- type_description = "Invalid";
- break;
- case Selector::SimpleSelector::Type::Universal:
- type_description = "Universal";
- break;
- case Selector::SimpleSelector::Type::Id:
- type_description = "Id";
- break;
- case Selector::SimpleSelector::Type::Class:
- type_description = "Class";
- break;
- case Selector::SimpleSelector::Type::TagName:
- type_description = "TagName";
- break;
- }
- const char* attribute_match_type_description = "";
- switch (simple_selector.attribute_match_type) {
- case Selector::SimpleSelector::AttributeMatchType::None:
- break;
- case Selector::SimpleSelector::AttributeMatchType::HasAttribute:
- attribute_match_type_description = "HasAttribute";
- break;
- case Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
- attribute_match_type_description = "ExactValueMatch";
- break;
- }
-
- dbgprintf("%s:%s", type_description, simple_selector.value.characters());
- if (simple_selector.attribute_match_type != Selector::SimpleSelector::AttributeMatchType::None) {
- dbgprintf(" [%s, name='%s', value='%s']", attribute_match_type_description, simple_selector.attribute_name.characters(), simple_selector.attribute_value.characters());
- }
-
- if (i != complex_selector.compound_selector.size() - 1)
- dbgprintf(", ");
+ dbgprintf("%s:%s", type_description, simple_selector.value.characters());
+ if (simple_selector.attribute_match_type != Selector::SimpleSelector::AttributeMatchType::None) {
+ dbgprintf(" [%s, name='%s', value='%s']", attribute_match_type_description, simple_selector.attribute_name.characters(), simple_selector.attribute_value.characters());
}
- dbgprintf("\n");
+
+ if (i != complex_selector.compound_selector.size() - 1)
+ dbgprintf(", ");
}
+ dbgprintf("\n");
+ }
+}
+
+void dump_rule(const StyleRule& rule)
+{
+ dbgprintf("Rule:\n");
+ for (auto& selector : rule.selectors()) {
+ dump_selector(selector);
}
dbgprintf(" Declarations:\n");
for (auto& property : rule.declaration().properties()) {