LiveNodeList.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 final : public NodeList {
  13. WEB_PLATFORM_OBJECT(LiveNodeList, NodeList);
  14. public:
  15. enum class Scope {
  16. Children,
  17. Descendants,
  18. };
  19. static WebIDL::ExceptionOr<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. private:
  25. LiveNodeList(JS::Realm&, Node& root, Scope, Function<bool(Node const&)> filter);
  26. virtual void visit_edges(Cell::Visitor&) override;
  27. JS::MarkedVector<Node*> collection() const;
  28. JS::NonnullGCPtr<Node> m_root;
  29. Function<bool(Node const&)> m_filter;
  30. Scope m_scope { Scope::Descendants };
  31. };
  32. }