mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibWeb: Implement ParentNode.children
Required by Web Platform Tests for the innerHTML/outerHTML tests.
This commit is contained in:
parent
8e0f3436a2
commit
e4d97add3d
6 changed files with 29 additions and 0 deletions
|
@ -64,6 +64,8 @@ interface Document : Node {
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
ArrayFromVector querySelectorAll(DOMString selectors);
|
||||||
|
|
||||||
|
[SameObject] readonly attribute HTMLCollection children;
|
||||||
|
|
||||||
// FIXME: These should all come from a GlobalEventHandlers mixin
|
// FIXME: These should all come from a GlobalEventHandlers mixin
|
||||||
attribute EventHandler onabort;
|
attribute EventHandler onabort;
|
||||||
attribute EventHandler onauxclick;
|
attribute EventHandler onauxclick;
|
||||||
|
|
|
@ -12,4 +12,6 @@ interface DocumentFragment : Node {
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
ArrayFromVector querySelectorAll(DOMString selectors);
|
||||||
|
|
||||||
|
[SameObject] readonly attribute HTMLCollection children;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,4 +31,6 @@ interface Element : Node {
|
||||||
|
|
||||||
Element? querySelector(DOMString selectors);
|
Element? querySelector(DOMString selectors);
|
||||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
ArrayFromVector querySelectorAll(DOMString selectors);
|
||||||
|
|
||||||
|
[SameObject] readonly attribute HTMLCollection children;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <LibWeb/CSS/Parser/Parser.h>
|
#include <LibWeb/CSS/Parser/Parser.h>
|
||||||
#include <LibWeb/CSS/SelectorEngine.h>
|
#include <LibWeb/CSS/SelectorEngine.h>
|
||||||
|
#include <LibWeb/DOM/HTMLCollection.h>
|
||||||
#include <LibWeb/DOM/ParentNode.h>
|
#include <LibWeb/DOM/ParentNode.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
|
|
||||||
|
@ -75,4 +76,15 @@ u32 ParentNode::child_element_count() const
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||||
|
NonnullRefPtr<HTMLCollection> ParentNode::children()
|
||||||
|
{
|
||||||
|
// The children getter steps are to return an HTMLCollection collection rooted at this matching only element children.
|
||||||
|
// FIXME: This should return the same HTMLCollection object every time,
|
||||||
|
// but that would cause a reference cycle since HTMLCollection refs the root.
|
||||||
|
return HTMLCollection::create(*this, [this](Element const& element) {
|
||||||
|
return is_parent_of(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ public:
|
||||||
ExceptionOr<RefPtr<Element>> query_selector(StringView);
|
ExceptionOr<RefPtr<Element>> query_selector(StringView);
|
||||||
ExceptionOr<NonnullRefPtrVector<Element>> query_selector_all(StringView);
|
ExceptionOr<NonnullRefPtrVector<Element>> query_selector_all(StringView);
|
||||||
|
|
||||||
|
NonnullRefPtr<HTMLCollection> children();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ParentNode(Document& document, NodeType type)
|
ParentNode(Document& document, NodeType type)
|
||||||
: Node(document, type)
|
: Node(document, type)
|
||||||
|
|
|
@ -398,6 +398,15 @@ public:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_parent_of(T const& other) const
|
||||||
|
{
|
||||||
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
|
if (&other == child)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
~TreeNode()
|
~TreeNode()
|
||||||
{
|
{
|
||||||
VERIFY(!m_parent);
|
VERIFY(!m_parent);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue