/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Web::DOM { class ParentNode : public Node { public: template void for_each_child(F) const; template void for_each_child(F); RefPtr first_element_child(); RefPtr last_element_child(); u32 child_element_count() const; ExceptionOr> query_selector(StringView); ExceptionOr> query_selector_all(StringView); NonnullRefPtr children(); NonnullRefPtr get_elements_by_tag_name(FlyString const&); NonnullRefPtr get_elements_by_tag_name_ns(FlyString const&, FlyString const&); ExceptionOr prepend(Vector, String>> const& nodes); ExceptionOr append(Vector, String>> const& nodes); ExceptionOr replace_children(Vector, String>> const& nodes); protected: ParentNode(Document& document, NodeType type) : Node(document, type) { } }; 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); } }