2021-10-02 20:33:45 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2021-10-02 20:33:45 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <LibWeb/DOM/NodeList.h>
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
// FIXME: Just like HTMLCollection, LiveNodeList currently does no caching.
|
|
|
|
|
2023-08-20 13:22:41 +12:00
|
|
|
class LiveNodeList : public NodeList {
|
2022-09-01 16:30:26 +02:00
|
|
|
WEB_PLATFORM_OBJECT(LiveNodeList, NodeList);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(LiveNodeList);
|
2022-09-01 16:30:26 +02:00
|
|
|
|
2021-10-02 20:33:45 +01:00
|
|
|
public:
|
2023-05-23 12:28:16 +02:00
|
|
|
enum class Scope {
|
|
|
|
Children,
|
|
|
|
Descendants,
|
|
|
|
};
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<NodeList> create(JS::Realm&, Node const& root, Scope, ESCAPING Function<bool(Node const&)> filter);
|
2022-09-01 16:30:26 +02:00
|
|
|
virtual ~LiveNodeList() override;
|
2021-10-02 20:33:45 +01:00
|
|
|
|
|
|
|
virtual u32 length() const override;
|
|
|
|
virtual Node const* item(u32 index) const override;
|
|
|
|
|
2023-08-20 13:22:41 +12:00
|
|
|
protected:
|
2024-05-17 17:14:06 -07:00
|
|
|
LiveNodeList(JS::Realm&, Node const& root, Scope, ESCAPING Function<bool(Node const&)> filter);
|
2022-09-01 16:30:26 +02:00
|
|
|
|
2023-08-25 12:16:44 +12:00
|
|
|
Node* first_matching(Function<bool(Node const&)> const& filter) const;
|
|
|
|
|
2023-08-20 13:22:41 +12:00
|
|
|
private:
|
2022-09-01 16:30:26 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-10-02 20:33:45 +01:00
|
|
|
|
2024-12-26 14:32:52 +01:00
|
|
|
GC::RootVector<Node*> collection() const;
|
2021-10-02 20:33:45 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Node const> m_root;
|
2021-10-02 20:33:45 +01:00
|
|
|
Function<bool(Node const&)> m_filter;
|
2023-05-23 12:28:16 +02:00
|
|
|
Scope m_scope { Scope::Descendants };
|
2021-10-02 20:33:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|