HTMLOptionsCollection.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Variant.h>
  8. #include <LibWeb/DOM/HTMLCollection.h>
  9. #include <LibWeb/WebIDL/ExceptionOr.h>
  10. #include <LibWeb/WebIDL/Types.h>
  11. namespace Web::HTML {
  12. using HTMLOptionOrOptGroupElement = Variant<GC::Root<HTMLOptionElement>, GC::Root<HTMLOptGroupElement>>;
  13. using HTMLElementOrElementIndex = Variant<GC::Root<HTMLElement>, i32>;
  14. class HTMLOptionsCollection final : public DOM::HTMLCollection {
  15. WEB_PLATFORM_OBJECT(HTMLOptionsCollection, DOM::HTMLCollection);
  16. GC_DECLARE_ALLOCATOR(HTMLOptionsCollection);
  17. public:
  18. [[nodiscard]] static GC::Ref<HTMLOptionsCollection> create(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
  19. virtual ~HTMLOptionsCollection() override;
  20. WebIDL::ExceptionOr<void> set_value_of_indexed_property(u32, JS::Value) override;
  21. WebIDL::ExceptionOr<void> set_length(WebIDL::UnsignedLong);
  22. WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
  23. void remove(WebIDL::Long);
  24. WebIDL::Long selected_index() const;
  25. void set_selected_index(WebIDL::Long);
  26. private:
  27. HTMLOptionsCollection(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
  28. virtual void initialize(JS::Realm&) override;
  29. };
  30. }