ParentNode.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtrVector.h>
  8. #include <LibWeb/DOM/Node.h>
  9. namespace Web::DOM {
  10. class ParentNode : public Node {
  11. public:
  12. template<typename F>
  13. void for_each_child(F) const;
  14. template<typename F>
  15. void for_each_child(F);
  16. RefPtr<Element> first_element_child();
  17. RefPtr<Element> last_element_child();
  18. u32 child_element_count() const;
  19. RefPtr<Element> query_selector(const StringView&);
  20. NonnullRefPtrVector<Element> query_selector_all(const StringView&);
  21. protected:
  22. ParentNode(Document& document, NodeType type)
  23. : Node(document, type)
  24. {
  25. }
  26. };
  27. template<typename Callback>
  28. inline void ParentNode::for_each_child(Callback callback) const
  29. {
  30. for (auto* node = first_child(); node; node = node->next_sibling())
  31. callback(*node);
  32. }
  33. template<typename Callback>
  34. inline void ParentNode::for_each_child(Callback callback)
  35. {
  36. for (auto* node = first_child(); node; node = node->next_sibling())
  37. callback(*node);
  38. }
  39. }