HTMLSelectElement.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <LibWeb/HTML/FormAssociatedElement.h>
  11. #include <LibWeb/HTML/HTMLElement.h>
  12. #include <LibWeb/HTML/HTMLOptionsCollection.h>
  13. #include <LibWeb/HTML/SelectItem.h>
  14. #include <LibWeb/WebIDL/Types.h>
  15. namespace Web::HTML {
  16. class HTMLSelectElement final
  17. : public HTMLElement
  18. , public FormAssociatedElement {
  19. WEB_PLATFORM_OBJECT(HTMLSelectElement, HTMLElement);
  20. JS_DECLARE_ALLOCATOR(HTMLSelectElement);
  21. FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLSelectElement)
  22. public:
  23. virtual ~HTMLSelectElement() override;
  24. virtual void adjust_computed_style(CSS::StyleProperties&) override;
  25. WebIDL::UnsignedLong size() const;
  26. WebIDL::ExceptionOr<void> set_size(WebIDL::UnsignedLong);
  27. JS::GCPtr<HTMLOptionsCollection> const& options();
  28. WebIDL::UnsignedLong length();
  29. WebIDL::ExceptionOr<void> set_length(WebIDL::UnsignedLong);
  30. HTMLOptionElement* item(WebIDL::UnsignedLong index);
  31. HTMLOptionElement* named_item(FlyString const& name);
  32. WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
  33. void remove();
  34. void remove(WebIDL::Long);
  35. JS::NonnullGCPtr<DOM::HTMLCollection> selected_options();
  36. WebIDL::Long selected_index() const;
  37. void set_selected_index(WebIDL::Long);
  38. virtual String value() const override;
  39. WebIDL::ExceptionOr<void> set_value(String const&);
  40. bool is_open() const { return m_is_open; }
  41. void set_is_open(bool);
  42. WebIDL::ExceptionOr<void> show_picker();
  43. Vector<JS::Handle<HTMLOptionElement>> list_of_options() const;
  44. // ^EventTarget
  45. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
  46. virtual bool is_focusable() const override { return true; }
  47. // ^FormAssociatedElement
  48. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  49. virtual bool is_listed() const override { return true; }
  50. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  51. virtual bool is_submittable() const override { return true; }
  52. // https://html.spec.whatwg.org/multipage/forms.html#category-reset
  53. virtual bool is_resettable() const override { return true; }
  54. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  55. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  56. // ^HTMLElement
  57. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  58. virtual bool is_labelable() const override { return true; }
  59. virtual void reset_algorithm() override;
  60. String const& type() const;
  61. virtual Optional<ARIA::Role> default_role() const override;
  62. virtual bool has_activation_behavior() const override;
  63. virtual void activation_behavior(DOM::Event const&) override;
  64. virtual void form_associated_element_was_inserted() override;
  65. virtual void form_associated_element_was_removed(DOM::Node*) override;
  66. void did_select_item(Optional<u32> const& id);
  67. void update_selectedness();
  68. private:
  69. HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
  70. virtual void initialize(JS::Realm&) override;
  71. virtual void visit_edges(Cell::Visitor&) override;
  72. // ^DOM::Element
  73. virtual i32 default_tab_index_value() const override;
  74. virtual void computed_css_values_changed() override;
  75. void show_the_picker_if_applicable();
  76. void create_shadow_tree_if_needed();
  77. void update_inner_text_element();
  78. void queue_input_and_change_events();
  79. JS::GCPtr<HTMLOptionsCollection> m_options;
  80. JS::GCPtr<DOM::HTMLCollection> m_selected_options;
  81. bool m_is_open { false };
  82. Vector<SelectItem> m_select_items;
  83. JS::GCPtr<DOM::Element> m_inner_text_element;
  84. JS::GCPtr<DOM::Element> m_chevron_icon_element;
  85. };
  86. }