mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 11:37:41 +00:00
LibWeb: Convert Node.childNodes to NodeList
This changes the old child_nodes implementation to children_as_vector so that can still be used in insert_before.
This commit is contained in:
parent
2f7fb1fe63
commit
6a7739c645
3 changed files with 15 additions and 5 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include <LibWeb/DOM/Event.h>
|
#include <LibWeb/DOM/Event.h>
|
||||||
#include <LibWeb/DOM/EventDispatcher.h>
|
#include <LibWeb/DOM/EventDispatcher.h>
|
||||||
#include <LibWeb/DOM/EventListener.h>
|
#include <LibWeb/DOM/EventListener.h>
|
||||||
|
#include <LibWeb/DOM/LiveNodeList.h>
|
||||||
#include <LibWeb/DOM/Node.h>
|
#include <LibWeb/DOM/Node.h>
|
||||||
#include <LibWeb/DOM/ProcessingInstruction.h>
|
#include <LibWeb/DOM/ProcessingInstruction.h>
|
||||||
#include <LibWeb/DOM/ShadowRoot.h>
|
#include <LibWeb/DOM/ShadowRoot.h>
|
||||||
|
@ -258,7 +259,7 @@ void Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool supp
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<Node> nodes;
|
NonnullRefPtrVector<Node> nodes;
|
||||||
if (is<DocumentFragment>(*node))
|
if (is<DocumentFragment>(*node))
|
||||||
nodes = verify_cast<DocumentFragment>(*node).child_nodes();
|
nodes = verify_cast<DocumentFragment>(*node).children_as_vector();
|
||||||
else
|
else
|
||||||
nodes.append(node);
|
nodes.append(node);
|
||||||
|
|
||||||
|
@ -591,7 +592,16 @@ ParentNode* Node::parent_or_shadow_host()
|
||||||
return verify_cast<ParentNode>(parent());
|
return verify_cast<ParentNode>(parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtrVector<Node> Node::child_nodes() const
|
NonnullRefPtr<NodeList> Node::child_nodes()
|
||||||
|
{
|
||||||
|
// FIXME: This should return the same LiveNodeList object every time,
|
||||||
|
// but that would cause a reference cycle since NodeList refs the root.
|
||||||
|
return LiveNodeList::create(*this, [this](auto& node) {
|
||||||
|
return is_parent_of(node);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
NonnullRefPtrVector<Node> Node::children_as_vector() const
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<Node> nodes;
|
NonnullRefPtrVector<Node> nodes;
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,8 @@ public:
|
||||||
|
|
||||||
// NOTE: This is intended for the JS bindings.
|
// NOTE: This is intended for the JS bindings.
|
||||||
bool has_child_nodes() const { return has_children(); }
|
bool has_child_nodes() const { return has_children(); }
|
||||||
NonnullRefPtrVector<Node> child_nodes() const;
|
NonnullRefPtr<NodeList> child_nodes();
|
||||||
|
NonnullRefPtrVector<Node> children_as_vector() const;
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node();
|
virtual RefPtr<Layout::Node> create_layout_node();
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@ interface Node : EventTarget {
|
||||||
readonly attribute DOMString nodeName;
|
readonly attribute DOMString nodeName;
|
||||||
|
|
||||||
boolean hasChildNodes();
|
boolean hasChildNodes();
|
||||||
// FIXME: This should be a NodeList
|
[SameObject] readonly attribute NodeList childNodes;
|
||||||
readonly attribute ArrayFromVector childNodes;
|
|
||||||
readonly attribute Node? firstChild;
|
readonly attribute Node? firstChild;
|
||||||
readonly attribute Node? lastChild;
|
readonly attribute Node? lastChild;
|
||||||
readonly attribute Node? previousSibling;
|
readonly attribute Node? previousSibling;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue