Serenity Operating System
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
9#pragma once
10
11#include <LibWeb/HTML/FormAssociatedElement.h>
12#include <LibWeb/HTML/HTMLElement.h>
13#include <LibWeb/HTML/HTMLOptionsCollection.h>
14
15namespace Web::HTML {
16
17class HTMLSelectElement final
18 : public HTMLElement
19 , public FormAssociatedElement {
20 WEB_PLATFORM_OBJECT(HTMLSelectElement, HTMLElement);
21 FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLSelectElement)
22
23public:
24 virtual ~HTMLSelectElement() override;
25
26 JS::GCPtr<HTMLOptionsCollection> const& options();
27
28 size_t length();
29 DOM::Element* item(size_t index);
30 DOM::Element* named_item(DeprecatedFlyString const& name);
31 WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
32
33 int selected_index() const;
34 void set_selected_index(int);
35
36 Vector<JS::Handle<HTMLOptionElement>> list_of_options() const;
37
38 // ^EventTarget
39 // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
40 virtual bool is_focusable() const override { return true; }
41
42 // ^FormAssociatedElement
43 // https://html.spec.whatwg.org/multipage/forms.html#category-listed
44 virtual bool is_listed() const override { return true; }
45
46 // https://html.spec.whatwg.org/multipage/forms.html#category-submit
47 virtual bool is_submittable() const override { return true; }
48
49 // https://html.spec.whatwg.org/multipage/forms.html#category-reset
50 virtual bool is_resettable() const override { return true; }
51
52 // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
53 virtual bool is_auto_capitalize_inheriting() const override { return true; }
54
55 // ^HTMLElement
56 // https://html.spec.whatwg.org/multipage/forms.html#category-label
57 virtual bool is_labelable() const override { return true; }
58
59 virtual void reset_algorithm() override;
60
61 DeprecatedString const& type() const;
62
63 virtual Optional<ARIA::Role> default_role() const override;
64
65private:
66 HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
67
68 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
69 virtual void visit_edges(Cell::Visitor&) override;
70
71 // ^DOM::Element
72 virtual i32 default_tab_index_value() const override;
73
74 JS::GCPtr<HTMLOptionsCollection> m_options;
75};
76
77}