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-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 {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(ParentNode, Node);
|
|
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
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
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
JS::GCPtr<Element> first_element_child();
|
|
|
|
|
JS::GCPtr<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
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
ExceptionOr<JS::GCPtr<Element>> query_selector(StringView);
|
2022-09-01 11:30:26 -03:00
|
|
|
ExceptionOr<JS::NonnullGCPtr<NodeList>> query_selector_all(StringView);
|
2020-08-17 15:14:30 -03:00
|
|
|
|
2022-09-01 15:50:16 -03:00
|
|
|
JS::NonnullGCPtr<HTMLCollection> children();
|
2021-09-13 19:01:17 -03:00
|
|
|
|
2022-09-01 15:50:16 -03:00
|
|
|
JS::NonnullGCPtr<HTMLCollection> get_elements_by_tag_name(FlyString const&);
|
|
|
|
|
JS::NonnullGCPtr<HTMLCollection> get_elements_by_tag_name_ns(FlyString const&, FlyString const&);
|
2021-09-22 14:06:19 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
ExceptionOr<void> prepend(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
|
|
|
|
|
ExceptionOr<void> append(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
|
|
|
|
|
ExceptionOr<void> replace_children(Vector<Variant<JS::Handle<Node>, String>> const& nodes);
|
2022-01-29 17:23:48 -03:00
|
|
|
|
2019-06-15 13:55:47 -03:00
|
|
|
protected:
|
2022-08-28 08:42:07 -03:00
|
|
|
ParentNode(JS::Realm& realm, Document& document, NodeType type)
|
|
|
|
|
: Node(realm, document, type)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
}
|
2022-09-17 19:42:33 -03:00
|
|
|
|
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
JS::GCPtr<HTMLCollection> m_children;
|
2019-06-15 13:55:47 -03:00
|
|
|
};
|
|
|
|
|
|
2022-03-14 10:40:42 -03:00
|
|
|
template<>
|
|
|
|
|
inline bool Node::fast_is<ParentNode>() const { return is_parent_node(); }
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|