2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-09-27 15:18:30 -03:00
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/DOM/Node.h>
|
2019-06-15 13:55:47 -03:00
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
namespace Web::DOM {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
class ParentNode : public Node {
|
|
|
|
|
public:
|
2020-09-18 04:49:51 -03:00
|
|
|
template<typename F>
|
|
|
|
|
void for_each_child(F) const;
|
|
|
|
|
template<typename F>
|
|
|
|
|
void for_each_child(F);
|
2019-06-15 13:55:47 -03:00
|
|
|
|
2020-11-21 15:49:09 -03:00
|
|
|
RefPtr<Element> first_element_child();
|
|
|
|
|
RefPtr<Element> last_element_child();
|
2021-04-11 13:13:10 -03:00
|
|
|
u32 child_element_count() const;
|
2020-11-21 15:49:09 -03:00
|
|
|
|
2021-09-11 17:54:26 -03:00
|
|
|
ExceptionOr<RefPtr<Element>> query_selector(StringView);
|
|
|
|
|
ExceptionOr<NonnullRefPtrVector<Element>> query_selector_all(StringView);
|
2020-08-17 15:14:30 -03:00
|
|
|
|
2021-09-13 19:01:17 -03:00
|
|
|
NonnullRefPtr<HTMLCollection> children();
|
|
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
protected:
|
2020-08-17 15:14:30 -03:00
|
|
|
ParentNode(Document& document, NodeType type)
|
2019-09-29 06:43:07 -03:00
|
|
|
: Node(document, type)
|
2019-06-15 13:55:47 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-15 17:49:44 -03:00
|
|
|
template<typename Callback>
|
|
|
|
|
inline void ParentNode::for_each_child(Callback callback) const
|
2019-06-15 13:55:47 -03:00
|
|
|
{
|
2019-06-15 17:49:44 -03:00
|
|
|
for (auto* node = first_child(); node; node = node->next_sibling())
|
|
|
|
|
callback(*node);
|
2019-06-15 13:55:47 -03:00
|
|
|
}
|
|
|
|
|
|
2019-06-15 17:49:44 -03:00
|
|
|
template<typename Callback>
|
|
|
|
|
inline void ParentNode::for_each_child(Callback callback)
|
|
|
|
|
{
|
|
|
|
|
for (auto* node = first_child(); node; node = node->next_sibling())
|
|
|
|
|
callback(*node);
|
|
|
|
|
}
|
2020-03-07 06:27:02 -03:00
|
|
|
|
|
|
|
|
}
|