HTMLAllCollection.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <LibJS/Forward.h>
  9. #include <LibJS/Heap/GCPtr.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. JS_DECLARE_ALLOCATOR(HTMLAllCollection);
  17. public:
  18. enum class Scope {
  19. Children,
  20. Descendants,
  21. };
  22. [[nodiscard]] static JS::NonnullGCPtr<HTMLAllCollection> create(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter);
  23. virtual ~HTMLAllCollection() override;
  24. size_t length() const;
  25. Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> item(Optional<FlyString> const& name_or_index) const;
  26. Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> named_item(FlyString const& name) const;
  27. JS::MarkedVector<JS::NonnullGCPtr<DOM::Element>> collect_matching_elements() const;
  28. virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
  29. virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const override;
  30. virtual Vector<FlyString> supported_property_names() const override;
  31. virtual bool is_supported_property_index(u32) const override;
  32. protected:
  33. HTMLAllCollection(DOM::ParentNode& root, Scope, ESCAPING Function<bool(DOM::Element const&)> filter);
  34. virtual void initialize(JS::Realm&) override;
  35. virtual bool is_htmldda() const override { return true; }
  36. private:
  37. Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> get_the_all_named_elements(FlyString const& name) const;
  38. JS::GCPtr<DOM::Element> get_the_all_indexed_element(u32 index) const;
  39. Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> get_the_all_indexed_or_named_elements(JS::PropertyKey const& name_or_index) const;
  40. virtual void visit_edges(Cell::Visitor&) override;
  41. JS::NonnullGCPtr<DOM::ParentNode> m_root;
  42. Function<bool(DOM::Element const&)> m_filter;
  43. Scope m_scope { Scope::Descendants };
  44. };
  45. }