/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace Web::DOM { class ParentNode : public Node { WEB_PLATFORM_OBJECT(ParentNode, Node); public: template void for_each_child(F) const; template void for_each_child(F); JS::GCPtr first_element_child(); JS::GCPtr last_element_child(); u32 child_element_count() const; WebIDL::ExceptionOr> query_selector(StringView); WebIDL::ExceptionOr> query_selector_all(StringView); JS::NonnullGCPtr children(); JS::NonnullGCPtr get_elements_by_tag_name(DeprecatedFlyString const&); JS::NonnullGCPtr get_elements_by_tag_name_ns(DeprecatedFlyString const&, DeprecatedFlyString const&); WebIDL::ExceptionOr prepend(Vector, DeprecatedString>> const& nodes); WebIDL::ExceptionOr append(Vector, DeprecatedString>> const& nodes); WebIDL::ExceptionOr replace_children(Vector, DeprecatedString>> const& nodes); protected: ParentNode(JS::Realm& realm, Document& document, NodeType type) : Node(realm, document, type) { } ParentNode(Document& document, NodeType type) : Node(document, type) { } virtual void visit_edges(Cell::Visitor&) override; private: JS::GCPtr m_children; }; template<> inline bool Node::fast_is() const { return is_parent_node(); } template inline void ParentNode::for_each_child(Callback callback) const { for (auto* node = first_child(); node; node = node->next_sibling()) callback(*node); } template inline void ParentNode::for_each_child(Callback callback) { for (auto* node = first_child(); node; node = node->next_sibling()) callback(*node); } }