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);
|
2021-10-02 20:36:39 +01:00
|
|
|
ExceptionOr<NonnullRefPtr<NodeList>> query_selector_all(StringView);
|
2020-08-17 19:14:30 +01:00
|
|
|
|
2021-09-13 23:01:17 +01:00
|
|
|
NonnullRefPtr<HTMLCollection> children();
|
|
|
|
|
|
2021-09-22 18:06:19 +01:00
|
|
|
NonnullRefPtr<HTMLCollection> get_elements_by_tag_name(FlyString const&);
|
|
|
|
|
NonnullRefPtr<HTMLCollection> get_elements_by_tag_name_ns(FlyString const&, FlyString const&);
|
|
|
|
|
|
2022-01-29 20:23:48 +00:00
|
|
|
ExceptionOr<void> prepend(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
|
2022-01-29 20:45:17 +00:00
|
|
|
ExceptionOr<void> append(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
|
2022-01-29 21:01:09 +00:00
|
|
|
ExceptionOr<void> replace_children(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
|
2022-01-29 20:23:48 +00: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
|
|
|
|
|
|
|
|
}
|