HTMLAllCollection.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <LibGC/Ptr.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibWeb/Bindings/PlatformObject.h>
  11. #include <LibWeb/DOM/HTMLCollection.h>
  12. #include <LibWeb/Forward.h>
  13. namespace Web::HTML {
  14. class HTMLAllCollection : public Bindings::PlatformObject {
  15. WEB_PLATFORM_OBJECT(HTMLAllCollection, Bindings::PlatformObject);
  16. GC_DECLARE_ALLOCATOR(HTMLAllCollection);
  17. public:
  18. enum class Scope {
  19. Children,
  20. Descendants,
  21. };
  22. [[nodiscard]] static GC::Ref<HTMLAllCollection> create(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter);
  23. virtual ~HTMLAllCollection() override;
  24. size_t length() const;
  25. Variant<GC::Ref<DOM::HTMLCollection>, GC::Ref<DOM::Element>, Empty> item(Optional<FlyString> const& name_or_index) const;
  26. Variant<GC::Ref<DOM::HTMLCollection>, GC::Ref<DOM::Element>, Empty> named_item(FlyString const& name) const;
  27. GC::RootVector<GC::Ref<DOM::Element>> collect_matching_elements() const;
  28. virtual Optional<JS::Value> item_value(size_t index) const override;
  29. virtual JS::Value named_item_value(FlyString const& name) const override;
  30. virtual Vector<FlyString> supported_property_names() const override;
  31. protected:
  32. HTMLAllCollection(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter);
  33. virtual void initialize(JS::Realm&) override;
  34. virtual bool is_htmldda() const override { return true; }
  35. private:
  36. Variant<GC::Ref<DOM::HTMLCollection>, GC::Ref<DOM::Element>, Empty> get_the_all_named_elements(FlyString const& name) const;
  37. GC::Ptr<DOM::Element> get_the_all_indexed_element(u32 index) const;
  38. Variant<GC::Ref<DOM::HTMLCollection>, GC::Ref<DOM::Element>, Empty> get_the_all_indexed_or_named_elements(JS::PropertyKey const& name_or_index) const;
  39. virtual void visit_edges(Cell::Visitor&) override;
  40. GC::Ref<DOM::ParentNode> m_root;
  41. Function<bool(DOM::Element const&)> m_filter;
  42. Scope m_scope { Scope::Descendants };
  43. };
  44. }