HTMLSelectElement.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2021-2022, Andreas Kling <andreas@ladybird.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. GC_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. GC::Ptr<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. GC::Ref<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<GC::Root<HTMLOptionElement>> list_of_options() const;
  44. // ^EventTarget
  45. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
  46. // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area
  47. // https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled
  48. virtual bool is_focusable() const override;
  49. // ^FormAssociatedElement
  50. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  51. virtual bool is_listed() const override { return true; }
  52. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  53. virtual bool is_submittable() const override { return true; }
  54. // https://html.spec.whatwg.org/multipage/forms.html#category-reset
  55. virtual bool is_resettable() const override { return true; }
  56. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  57. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  58. // ^HTMLElement
  59. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  60. virtual bool is_labelable() const override { return true; }
  61. virtual void reset_algorithm() override;
  62. String const& type() const;
  63. virtual Optional<ARIA::Role> default_role() const override;
  64. virtual bool has_activation_behavior() const override;
  65. virtual void activation_behavior(DOM::Event const&) override;
  66. virtual void form_associated_element_was_inserted() override;
  67. virtual void form_associated_element_was_removed(DOM::Node*) override;
  68. void did_select_item(Optional<u32> const& id);
  69. void update_selectedness();
  70. private:
  71. HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
  72. virtual void initialize(JS::Realm&) override;
  73. virtual void visit_edges(Cell::Visitor&) override;
  74. // ^DOM::Element
  75. virtual i32 default_tab_index_value() const override;
  76. virtual void computed_css_values_changed() override;
  77. virtual void children_changed() override;
  78. void show_the_picker_if_applicable();
  79. void create_shadow_tree_if_needed();
  80. void update_inner_text_element();
  81. void queue_input_and_change_events();
  82. GC::Ptr<HTMLOptionsCollection> m_options;
  83. GC::Ptr<DOM::HTMLCollection> m_selected_options;
  84. bool m_is_open { false };
  85. Vector<SelectItem> m_select_items;
  86. GC::Ptr<DOM::Element> m_inner_text_element;
  87. GC::Ptr<DOM::Element> m_chevron_icon_element;
  88. };
  89. }