2020-08-01 03:07:00 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2021-2022, Andreas Kling <andreas@ladybird.org>
|
2022-03-01 21:03:30 +00:00
|
|
|
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
2023-12-07 15:53:49 +01:00
|
|
|
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
2020-08-01 03:07:00 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:07:00 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-04-20 22:52:55 +02:00
|
|
|
#include <LibWeb/HTML/FormAssociatedElement.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2022-03-16 13:08:12 +01:00
|
|
|
#include <LibWeb/HTML/HTMLOptionsCollection.h>
|
2024-04-03 19:19:08 +02:00
|
|
|
#include <LibWeb/HTML/SelectItem.h>
|
2024-04-08 21:34:19 +02:00
|
|
|
#include <LibWeb/WebIDL/Types.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2022-03-23 18:55:54 -04:00
|
|
|
class HTMLSelectElement final
|
|
|
|
: public HTMLElement
|
|
|
|
, public FormAssociatedElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLSelectElement, HTMLElement);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLSelectElement);
|
2022-03-23 18:55:54 -04:00
|
|
|
FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLSelectElement)
|
|
|
|
|
2020-08-01 03:07:00 +01:00
|
|
|
public:
|
|
|
|
virtual ~HTMLSelectElement() override;
|
2021-04-20 22:52:55 +02:00
|
|
|
|
2024-03-07 21:27:37 +01:00
|
|
|
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
2023-12-07 15:53:49 +01:00
|
|
|
|
2024-04-08 21:34:19 +02:00
|
|
|
WebIDL::UnsignedLong size() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_size(WebIDL::UnsignedLong);
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<HTMLOptionsCollection> const& options();
|
2022-03-16 13:08:12 +01:00
|
|
|
|
2024-04-08 21:50:35 +02:00
|
|
|
WebIDL::UnsignedLong length();
|
|
|
|
WebIDL::ExceptionOr<void> set_length(WebIDL::UnsignedLong);
|
2024-04-08 22:01:21 +02:00
|
|
|
HTMLOptionElement* item(WebIDL::UnsignedLong index);
|
|
|
|
HTMLOptionElement* named_item(FlyString const& name);
|
2022-09-25 17:03:42 +01:00
|
|
|
WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
|
2024-04-08 21:56:33 +02:00
|
|
|
void remove();
|
|
|
|
void remove(WebIDL::Long);
|
2022-03-21 20:03:37 -04:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<DOM::HTMLCollection> selected_options();
|
2024-04-08 21:58:39 +02:00
|
|
|
|
|
|
|
WebIDL::Long selected_index() const;
|
|
|
|
void set_selected_index(WebIDL::Long);
|
2022-03-20 16:13:23 +01:00
|
|
|
|
2023-12-07 15:53:49 +01:00
|
|
|
virtual String value() const override;
|
|
|
|
WebIDL::ExceptionOr<void> set_value(String const&);
|
|
|
|
|
2023-09-13 17:15:27 +01:00
|
|
|
bool is_open() const { return m_is_open; }
|
|
|
|
void set_is_open(bool);
|
|
|
|
|
2024-06-13 18:11:45 +02:00
|
|
|
WebIDL::ExceptionOr<void> show_picker();
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Root<HTMLOptionElement>> list_of_options() const;
|
2022-03-20 16:13:23 +01:00
|
|
|
|
2022-03-26 18:05:48 +00:00
|
|
|
// ^EventTarget
|
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element
|
2024-11-02 19:17:20 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#focusable-area
|
|
|
|
// https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled
|
|
|
|
virtual bool is_focusable() const override;
|
2022-03-26 18:05:48 +00:00
|
|
|
|
2022-03-01 21:03:30 +00:00
|
|
|
// ^FormAssociatedElement
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
|
|
|
virtual bool is_listed() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-submit
|
|
|
|
virtual bool is_submittable() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-reset
|
|
|
|
virtual bool is_resettable() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
|
|
|
|
virtual bool is_auto_capitalize_inheriting() const override { return true; }
|
|
|
|
|
|
|
|
// ^HTMLElement
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-label
|
|
|
|
virtual bool is_labelable() const override { return true; }
|
2022-03-16 13:08:12 +01:00
|
|
|
|
2022-12-22 19:51:46 -05:00
|
|
|
virtual void reset_algorithm() override;
|
|
|
|
|
2023-08-12 21:30:19 +12:00
|
|
|
String const& type() const;
|
2022-11-05 04:51:42 +00:00
|
|
|
|
2023-01-28 22:23:16 +00:00
|
|
|
virtual Optional<ARIA::Role> default_role() const override;
|
2022-11-28 17:58:13 -06:00
|
|
|
|
2023-12-07 15:53:49 +01:00
|
|
|
virtual bool has_activation_behavior() const override;
|
|
|
|
virtual void activation_behavior(DOM::Event const&) override;
|
|
|
|
|
|
|
|
virtual void form_associated_element_was_inserted() override;
|
|
|
|
virtual void form_associated_element_was_removed(DOM::Node*) override;
|
|
|
|
|
2024-04-03 19:19:08 +02:00
|
|
|
void did_select_item(Optional<u32> const& id);
|
2023-12-07 15:53:49 +01:00
|
|
|
|
2024-11-14 00:05:38 +01:00
|
|
|
void update_selectedness();
|
2024-07-25 21:13:22 +04:00
|
|
|
|
2022-03-16 13:08:12 +01:00
|
|
|
private:
|
2022-08-28 13:42:07 +02:00
|
|
|
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-09-01 20:50:16 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2022-11-05 03:58:14 +00:00
|
|
|
// ^DOM::Element
|
|
|
|
virtual i32 default_tab_index_value() const override;
|
|
|
|
|
2023-12-20 18:21:32 +01:00
|
|
|
virtual void computed_css_values_changed() override;
|
|
|
|
|
2024-11-14 00:05:38 +01:00
|
|
|
virtual void children_changed() override;
|
|
|
|
|
2024-06-13 18:11:45 +02:00
|
|
|
void show_the_picker_if_applicable();
|
|
|
|
|
2023-12-07 15:53:49 +01:00
|
|
|
void create_shadow_tree_if_needed();
|
|
|
|
void update_inner_text_element();
|
2024-04-03 19:19:08 +02:00
|
|
|
void queue_input_and_change_events();
|
2023-12-07 15:53:49 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<HTMLOptionsCollection> m_options;
|
|
|
|
GC::Ptr<DOM::HTMLCollection> m_selected_options;
|
2023-09-13 17:15:27 +01:00
|
|
|
bool m_is_open { false };
|
2024-04-03 19:19:08 +02:00
|
|
|
Vector<SelectItem> m_select_items;
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<DOM::Element> m_inner_text_element;
|
|
|
|
GC::Ptr<DOM::Element> m_chevron_icon_element;
|
2020-08-01 03:07:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|