HTMLSelectElement.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
  4. * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <LibWeb/HTML/FormAssociatedElement.h>
  10. #include <LibWeb/HTML/HTMLElement.h>
  11. #include <LibWeb/HTML/HTMLOptionsCollection.h>
  12. namespace Web::HTML {
  13. class HTMLSelectElement final
  14. : public HTMLElement
  15. , public FormAssociatedElement {
  16. WEB_PLATFORM_OBJECT(HTMLSelectElement, HTMLElement);
  17. JS_DECLARE_ALLOCATOR(HTMLSelectElement);
  18. FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLSelectElement)
  19. public:
  20. virtual ~HTMLSelectElement() override;
  21. JS::GCPtr<HTMLOptionsCollection> const& options();
  22. size_t length();
  23. DOM::Element* item(size_t index);
  24. DOM::Element* named_item(FlyString const& name);
  25. WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
  26. int selected_index() const;
  27. void set_selected_index(int);
  28. bool is_open() const { return m_is_open; }
  29. void set_is_open(bool);
  30. Vector<JS::Handle<HTMLOptionElement>> list_of_options() const;
  31. // ^EventTarget
  32. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
  33. virtual bool is_focusable() const override { return true; }
  34. // ^FormAssociatedElement
  35. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  36. virtual bool is_listed() const override { return true; }
  37. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  38. virtual bool is_submittable() const override { return true; }
  39. // https://html.spec.whatwg.org/multipage/forms.html#category-reset
  40. virtual bool is_resettable() const override { return true; }
  41. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  42. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  43. // ^HTMLElement
  44. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  45. virtual bool is_labelable() const override { return true; }
  46. virtual void reset_algorithm() override;
  47. String const& type() const;
  48. virtual Optional<ARIA::Role> default_role() const override;
  49. private:
  50. HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
  51. virtual void initialize(JS::Realm&) override;
  52. virtual void visit_edges(Cell::Visitor&) override;
  53. // ^DOM::Element
  54. virtual i32 default_tab_index_value() const override;
  55. JS::GCPtr<HTMLOptionsCollection> m_options;
  56. bool m_is_open { false };
  57. };
  58. }