HTMLOptionsCollection.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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<JS::Handle<HTMLOptionElement>, JS::Handle<HTMLOptGroupElement>>;
  13. using HTMLElementOrElementIndex = Variant<JS::Handle<HTMLElement>, i32>;
  14. class HTMLOptionsCollection final : public DOM::HTMLCollection {
  15. WEB_PLATFORM_OBJECT(HTMLOptionsCollection, DOM::HTMLCollection);
  16. JS_DECLARE_ALLOCATOR(HTMLOptionsCollection);
  17. public:
  18. [[nodiscard]] static JS::NonnullGCPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
  19. virtual ~HTMLOptionsCollection() override;
  20. WebIDL::ExceptionOr<void> set_length(WebIDL::UnsignedLong);
  21. WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
  22. void remove(WebIDL::Long);
  23. WebIDL::Long selected_index() const;
  24. void set_selected_index(WebIDL::Long);
  25. private:
  26. HTMLOptionsCollection(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
  27. virtual void initialize(JS::Realm&) override;
  28. };
  29. }