/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLAllCollection.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Function.h> |
10 | | #include <LibJS/Forward.h> |
11 | | #include <LibJS/Heap/GCPtr.h> |
12 | | #include <LibWeb/Bindings/PlatformObject.h> |
13 | | #include <LibWeb/DOM/HTMLCollection.h> |
14 | | #include <LibWeb/Forward.h> |
15 | | |
16 | | namespace Web::HTML { |
17 | | |
18 | | class HTMLAllCollection : public Bindings::PlatformObject { |
19 | | WEB_PLATFORM_OBJECT(HTMLAllCollection, Bindings::PlatformObject); |
20 | | JS_DECLARE_ALLOCATOR(HTMLAllCollection); |
21 | | |
22 | | public: |
23 | | enum class Scope { |
24 | | Children, |
25 | | Descendants, |
26 | | }; |
27 | | [[nodiscard]] static JS::NonnullGCPtr<HTMLAllCollection> create(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter); |
28 | | |
29 | | virtual ~HTMLAllCollection() override; |
30 | | |
31 | | size_t length() const; |
32 | | Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> item(Optional<FlyString> const& name_or_index) const; |
33 | | Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> named_item(FlyString const& name) const; |
34 | | |
35 | | JS::MarkedVector<JS::NonnullGCPtr<DOM::Element>> collect_matching_elements() const; |
36 | | |
37 | | virtual Optional<JS::Value> item_value(size_t index) const override; |
38 | | virtual JS::Value named_item_value(FlyString const& name) const override; |
39 | | virtual Vector<FlyString> supported_property_names() const override; |
40 | | |
41 | | protected: |
42 | | HTMLAllCollection(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter); |
43 | | |
44 | | virtual void initialize(JS::Realm&) override; |
45 | | |
46 | 0 | virtual bool is_htmldda() const override { return true; } |
47 | | |
48 | | private: |
49 | | Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> get_the_all_named_elements(FlyString const& name) const; |
50 | | JS::GCPtr<DOM::Element> get_the_all_indexed_element(u32 index) const; |
51 | | Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> get_the_all_indexed_or_named_elements(JS::PropertyKey const& name_or_index) const; |
52 | | |
53 | | virtual void visit_edges(Cell::Visitor&) override; |
54 | | |
55 | | JS::NonnullGCPtr<DOM::ParentNode> m_root; |
56 | | Function<bool(DOM::Element const&)> m_filter; |
57 | | Scope m_scope { Scope::Descendants }; |
58 | | }; |
59 | | |
60 | | } |