mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
LibWeb: Convert ParentNode.querySelectorAll to NodeList
This commit is contained in:
parent
8d6db36cbb
commit
2f7fb1fe63
5 changed files with 8 additions and 7 deletions
|
@ -66,7 +66,7 @@ interface Document : Node {
|
||||||
readonly attribute unsigned long childElementCount;
|
readonly attribute unsigned long childElementCount;
|
||||||
|
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
[NewObject] NodeList querySelectorAll(DOMString selectors);
|
||||||
|
|
||||||
[SameObject] readonly attribute HTMLCollection children;
|
[SameObject] readonly attribute HTMLCollection children;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ interface DocumentFragment : Node {
|
||||||
readonly attribute unsigned long childElementCount;
|
readonly attribute unsigned long childElementCount;
|
||||||
|
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
[NewObject] NodeList querySelectorAll(DOMString selectors);
|
||||||
|
|
||||||
[SameObject] readonly attribute HTMLCollection children;
|
[SameObject] readonly attribute HTMLCollection children;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ interface Element : Node {
|
||||||
readonly attribute unsigned long childElementCount;
|
readonly attribute unsigned long childElementCount;
|
||||||
|
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
[NewObject] NodeList querySelectorAll(DOMString selectors);
|
||||||
|
|
||||||
[SameObject] readonly attribute HTMLCollection children;
|
[SameObject] readonly attribute HTMLCollection children;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <LibWeb/CSS/SelectorEngine.h>
|
#include <LibWeb/CSS/SelectorEngine.h>
|
||||||
#include <LibWeb/DOM/HTMLCollection.h>
|
#include <LibWeb/DOM/HTMLCollection.h>
|
||||||
#include <LibWeb/DOM/ParentNode.h>
|
#include <LibWeb/DOM/ParentNode.h>
|
||||||
|
#include <LibWeb/DOM/StaticNodeList.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
#include <LibWeb/Namespace.h>
|
#include <LibWeb/Namespace.h>
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ ExceptionOr<RefPtr<Element>> ParentNode::query_selector(StringView selector_text
|
||||||
return result;
|
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);
|
auto maybe_selectors = parse_selector(CSS::ParsingContext(*this), selector_text);
|
||||||
if (!maybe_selectors.has_value())
|
if (!maybe_selectors.has_value())
|
||||||
|
@ -43,7 +44,7 @@ ExceptionOr<NonnullRefPtrVector<Element>> ParentNode::query_selector_all(StringV
|
||||||
|
|
||||||
auto selectors = maybe_selectors.value();
|
auto selectors = maybe_selectors.value();
|
||||||
|
|
||||||
NonnullRefPtrVector<Element> elements;
|
NonnullRefPtrVector<Node> elements;
|
||||||
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
|
||||||
for (auto& selector : selectors) {
|
for (auto& selector : selectors) {
|
||||||
if (SelectorEngine::matches(selector, element)) {
|
if (SelectorEngine::matches(selector, element)) {
|
||||||
|
@ -53,7 +54,7 @@ ExceptionOr<NonnullRefPtrVector<Element>> ParentNode::query_selector_all(StringV
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
return elements;
|
return StaticNodeList::create(move(elements));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Element> ParentNode::first_element_child()
|
RefPtr<Element> ParentNode::first_element_child()
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
u32 child_element_count() const;
|
u32 child_element_count() const;
|
||||||
|
|
||||||
ExceptionOr<RefPtr<Element>> query_selector(StringView);
|
ExceptionOr<RefPtr<Element>> query_selector(StringView);
|
||||||
ExceptionOr<NonnullRefPtrVector<Element>> query_selector_all(StringView);
|
ExceptionOr<NonnullRefPtr<NodeList>> query_selector_all(StringView);
|
||||||
|
|
||||||
NonnullRefPtr<HTMLCollection> children();
|
NonnullRefPtr<HTMLCollection> children();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue