LiveNodeList.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. JS_DECLARE_ALLOCATOR(LiveNodeList);
  15. public:
  16. enum class Scope {
  17. Children,
  18. Descendants,
  19. };
  20. [[nodiscard]] static JS::NonnullGCPtr<NodeList> create(JS::Realm&, Node const& root, Scope, Function<bool(Node const&)> filter);
  21. virtual ~LiveNodeList() override;
  22. virtual u32 length() const override;
  23. virtual Node const* item(u32 index) const override;
  24. virtual bool is_supported_property_index(u32) const override;
  25. protected:
  26. LiveNodeList(JS::Realm&, Node const& root, Scope, Function<bool(Node const&)> filter);
  27. Node* first_matching(Function<bool(Node const&)> const& filter) const;
  28. private:
  29. virtual void visit_edges(Cell::Visitor&) override;
  30. JS::MarkedVector<Node*> collection() const;
  31. JS::NonnullGCPtr<Node const> m_root;
  32. Function<bool(Node const&)> m_filter;
  33. Scope m_scope { Scope::Descendants };
  34. };
  35. }