LiveNodeList.h 904 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <AK/NonnullRefPtrVector.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. public:
  14. static NonnullRefPtr<NodeList> create(Node& root, Function<bool(Node const&)> filter)
  15. {
  16. return adopt_ref(*new LiveNodeList(root, move(filter)));
  17. }
  18. virtual u32 length() const override;
  19. virtual Node const* item(u32 index) const override;
  20. virtual bool is_supported_property_index(u32) const override;
  21. private:
  22. LiveNodeList(Node& root, Function<bool(Node const&)> filter);
  23. NonnullRefPtrVector<Node> collection() const;
  24. NonnullRefPtr<Node> m_root;
  25. Function<bool(Node const&)> m_filter;
  26. };
  27. }