HTMLSelectElement.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLSelectElement)
  18. public:
  19. virtual ~HTMLSelectElement() override;
  20. JS::GCPtr<HTMLOptionsCollection> const& options();
  21. size_t length();
  22. DOM::Element* item(size_t index);
  23. DOM::Element* named_item(FlyString const& name);
  24. WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
  25. int selected_index() const;
  26. void set_selected_index(int);
  27. bool is_open() const { return m_is_open; }
  28. void set_is_open(bool);
  29. Vector<JS::Handle<HTMLOptionElement>> list_of_options() const;
  30. // ^EventTarget
  31. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
  32. virtual bool is_focusable() const override { return true; }
  33. // ^FormAssociatedElement
  34. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  35. virtual bool is_listed() const override { return true; }
  36. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  37. virtual bool is_submittable() const override { return true; }
  38. // https://html.spec.whatwg.org/multipage/forms.html#category-reset
  39. virtual bool is_resettable() const override { return true; }
  40. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  41. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  42. // ^HTMLElement
  43. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  44. virtual bool is_labelable() const override { return true; }
  45. virtual void reset_algorithm() override;
  46. String const& type() const;
  47. virtual Optional<ARIA::Role> default_role() const override;
  48. private:
  49. HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
  50. virtual void initialize(JS::Realm&) override;
  51. virtual void visit_edges(Cell::Visitor&) override;
  52. // ^DOM::Element
  53. virtual i32 default_tab_index_value() const override;
  54. JS::GCPtr<HTMLOptionsCollection> m_options;
  55. bool m_is_open { false };
  56. };
  57. }