LiveNodeList.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Function.h>
  9. #include <LibWeb/DOM/NodeList.h>
  10. namespace Web::DOM {
  11. // FIXME: Just like HTMLCollection, LiveNodeList currently does no caching.
  12. class LiveNodeList : public NodeList {
  13. WEB_PLATFORM_OBJECT(LiveNodeList, NodeList);
  14. public:
  15. enum class Scope {
  16. Children,
  17. Descendants,
  18. };
  19. [[nodiscard]] static JS::NonnullGCPtr<NodeList> create(JS::Realm&, Node& root, Scope, Function<bool(Node const&)> filter);
  20. virtual ~LiveNodeList() override;
  21. virtual u32 length() const override;
  22. virtual Node const* item(u32 index) const override;
  23. virtual bool is_supported_property_index(u32) const override;
  24. protected:
  25. LiveNodeList(JS::Realm&, Node& root, Scope, Function<bool(Node const&)> filter);
  26. Node* first_matching(Function<bool(Node const&)> const& filter) const;
  27. private:
  28. virtual void visit_edges(Cell::Visitor&) override;
  29. JS::MarkedVector<Node*> collection() const;
  30. JS::NonnullGCPtr<Node> m_root;
  31. Function<bool(Node const&)> m_filter;
  32. Scope m_scope { Scope::Descendants };
  33. };
  34. }