LiveNodeList.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. static WebIDL::ExceptionOr<JS::NonnullGCPtr<NodeList>> create(JS::Realm&, Node& root, Function<bool(Node const&)> filter);
  16. virtual ~LiveNodeList() override;
  17. virtual u32 length() const override;
  18. virtual Node const* item(u32 index) const override;
  19. virtual bool is_supported_property_index(u32) const override;
  20. private:
  21. LiveNodeList(JS::Realm&, Node& root, Function<bool(Node const&)> filter);
  22. virtual void visit_edges(Cell::Visitor&) override;
  23. JS::MarkedVector<Node*> collection() const;
  24. JS::NonnullGCPtr<Node> m_root;
  25. Function<bool(Node const&)> m_filter;
  26. };
  27. }