mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibWeb: Expose ParentNode.{first,last}ElementChild
I needed these to write the event dispatcher test.
This commit is contained in:
parent
e8b3a65581
commit
c5e15d9282
Notes:
sideshowbarker
2024-07-19 01:18:42 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/c5e15d92823 Pull-request: https://github.com/SerenityOS/serenity/pull/4131 Reviewed-by: https://github.com/awesomekling
6 changed files with 41 additions and 1 deletions
|
@ -8,8 +8,12 @@ interface Document : Node {
|
|||
readonly attribute DOMString contentType;
|
||||
|
||||
Element? getElementById(DOMString id);
|
||||
Element? querySelector(DOMString selectors);
|
||||
ArrayFromVector getElementsByTagName(DOMString tagName);
|
||||
|
||||
readonly attribute Element? firstElementChild;
|
||||
readonly attribute Element? lastElementChild;
|
||||
|
||||
Element? querySelector(DOMString selectors);
|
||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
||||
|
||||
Element createElement(DOMString tagName);
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
interface DocumentFragment : Node {
|
||||
|
||||
Element? getElementById(DOMString id);
|
||||
|
||||
readonly attribute Element? firstElementChild;
|
||||
readonly attribute Element? lastElementChild;
|
||||
|
||||
Element? querySelector(DOMString selectors);
|
||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@ interface Element : Node {
|
|||
DOMString? getAttribute(DOMString qualifiedName);
|
||||
void setAttribute(DOMString qualifiedName, DOMString value);
|
||||
|
||||
readonly attribute Element? firstElementChild;
|
||||
readonly attribute Element? lastElementChild;
|
||||
|
||||
Element? querySelector(DOMString selectors);
|
||||
ArrayFromVector querySelectorAll(DOMString selectors);
|
||||
|
||||
|
|
|
@ -70,4 +70,14 @@ NonnullRefPtrVector<Element> ParentNode::query_selector_all(const StringView& se
|
|||
return elements;
|
||||
}
|
||||
|
||||
RefPtr<Element> ParentNode::first_element_child()
|
||||
{
|
||||
return first_child_of_type<Element>();
|
||||
}
|
||||
|
||||
RefPtr<Element> ParentNode::last_element_child()
|
||||
{
|
||||
return last_child_of_type<Element>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ public:
|
|||
template<typename F>
|
||||
void for_each_child(F);
|
||||
|
||||
RefPtr<Element> first_element_child();
|
||||
RefPtr<Element> last_element_child();
|
||||
|
||||
RefPtr<Element> query_selector(const StringView&);
|
||||
NonnullRefPtrVector<Element> query_selector_all(const StringView&);
|
||||
|
||||
|
|
|
@ -255,6 +255,12 @@ public:
|
|||
return const_cast<TreeNode*>(this)->template first_child_of_type<U>();
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
const U* last_child_of_type() const
|
||||
{
|
||||
return const_cast<TreeNode*>(this)->template last_child_of_type<U>();
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
U* first_child_of_type()
|
||||
{
|
||||
|
@ -265,6 +271,16 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
U* last_child_of_type()
|
||||
{
|
||||
for (auto* child = last_child(); child; child = child->previous_sibling()) {
|
||||
if (is<U>(*child))
|
||||
return &downcast<U>(*child);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
const U* first_ancestor_of_type() const
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue