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