1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +00:00

LibWeb: Convert ParentNode.querySelectorAll to NodeList

This commit is contained in:
Luke Wilde 2021-10-02 20:36:39 +01:00 committed by Andreas Kling
parent 8d6db36cbb
commit 2f7fb1fe63
5 changed files with 8 additions and 7 deletions

View file

@ -8,6 +8,7 @@
#include <LibWeb/CSS/SelectorEngine.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/ParentNode.h>
#include <LibWeb/DOM/StaticNodeList.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Namespace.h>
@ -35,7 +36,7 @@ ExceptionOr<RefPtr<Element>> ParentNode::query_selector(StringView selector_text
return result;
}
ExceptionOr<NonnullRefPtrVector<Element>> ParentNode::query_selector_all(StringView selector_text)
ExceptionOr<NonnullRefPtr<NodeList>> ParentNode::query_selector_all(StringView selector_text)
{
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
if (!maybe_selectors.has_value())
@ -43,7 +44,7 @@ ExceptionOr<NonnullRefPtrVector<Element>> ParentNode::query_selector_all(StringV
auto selectors = maybe_selectors.value();
NonnullRefPtrVector<Element> elements;
NonnullRefPtrVector<Node> elements;
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
for (auto& selector : selectors) {
if (SelectorEngine::matches(selector, element)) {
@ -53,7 +54,7 @@ ExceptionOr<NonnullRefPtrVector<Element>> ParentNode::query_selector_all(StringV
return IterationDecision::Continue;
});
return elements;
return StaticNodeList::create(move(elements));
}
RefPtr<Element> ParentNode::first_element_child()