HTMLSelectElement.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. namespace Web::HTML {
  14. class HTMLSelectElement final
  15. : public HTMLElement
  16. , public FormAssociatedElement {
  17. WEB_PLATFORM_OBJECT(HTMLSelectElement, HTMLElement);
  18. JS_DECLARE_ALLOCATOR(HTMLSelectElement);
  19. FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLSelectElement)
  20. public:
  21. virtual ~HTMLSelectElement() override;
  22. virtual void adjust_computed_style(CSS::StyleProperties&) override;
  23. JS::GCPtr<HTMLOptionsCollection> const& options();
  24. size_t length();
  25. DOM::Element* item(size_t index);
  26. DOM::Element* named_item(FlyString const& name);
  27. WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
  28. int selected_index() const;
  29. void set_selected_index(int);
  30. virtual String value() const override;
  31. WebIDL::ExceptionOr<void> set_value(String const&);
  32. bool is_open() const { return m_is_open; }
  33. void set_is_open(bool);
  34. Vector<JS::Handle<HTMLOptionElement>> list_of_options() const;
  35. // ^EventTarget
  36. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
  37. virtual bool is_focusable() const override { return true; }
  38. // ^FormAssociatedElement
  39. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  40. virtual bool is_listed() const override { return true; }
  41. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  42. virtual bool is_submittable() const override { return true; }
  43. // https://html.spec.whatwg.org/multipage/forms.html#category-reset
  44. virtual bool is_resettable() const override { return true; }
  45. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  46. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  47. // ^HTMLElement
  48. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  49. virtual bool is_labelable() const override { return true; }
  50. virtual void reset_algorithm() override;
  51. String const& type() const;
  52. virtual Optional<ARIA::Role> default_role() const override;
  53. virtual bool has_activation_behavior() const override;
  54. virtual void activation_behavior(DOM::Event const&) override;
  55. virtual void form_associated_element_was_inserted() override;
  56. virtual void form_associated_element_was_removed(DOM::Node*) override;
  57. void did_select_value(Optional<String> value);
  58. private:
  59. HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
  60. virtual void initialize(JS::Realm&) override;
  61. virtual void visit_edges(Cell::Visitor&) override;
  62. // ^DOM::Element
  63. virtual i32 default_tab_index_value() const override;
  64. virtual void computed_css_values_changed() override;
  65. void create_shadow_tree_if_needed();
  66. void update_inner_text_element();
  67. JS::GCPtr<HTMLOptionsCollection> m_options;
  68. bool m_is_open { false };
  69. JS::GCPtr<DOM::Element> m_inner_text_element;
  70. JS::GCPtr<DOM::Element> m_chevron_icon_element;
  71. };
  72. }