2020-08-01 03:05:43 +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) 2022, Andreas Kling <andreas@ladybird.org>
|
2020-08-01 03:05:43 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:05:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-07-19 19:35:33 -07:00
|
|
|
#include <LibWeb/Export.h>
|
2020-08-01 03:05:43 +01:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2025-07-19 19:35:33 -07:00
|
|
|
class WEB_API HTMLOptionElement final : public HTMLElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLOptionElement, HTMLElement);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLOptionElement);
|
2020-08-01 03:05:43 +01:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2020-08-01 03:05:43 +01:00
|
|
|
virtual ~HTMLOptionElement() override;
|
2022-03-20 16:13:23 +01:00
|
|
|
|
2022-03-20 16:13:58 +01:00
|
|
|
bool selected() const { return m_selected; }
|
|
|
|
|
void set_selected(bool);
|
2024-07-25 21:13:22 +04:00
|
|
|
void set_selected_internal(bool);
|
2024-11-14 00:05:38 +01:00
|
|
|
[[nodiscard]] u64 selectedness_update_index() const { return m_selectedness_update_index; }
|
2022-03-20 16:13:58 +01:00
|
|
|
|
2025-07-26 12:19:56 -04:00
|
|
|
Utf16String value() const;
|
2026-02-15 03:14:09 +00:00
|
|
|
virtual Utf16String form_value() const override { return value(); }
|
2025-10-31 12:30:47 +00:00
|
|
|
void set_value(Utf16String const&);
|
2022-04-12 13:29:16 -03:00
|
|
|
|
2025-07-28 09:46:06 -04:00
|
|
|
Utf16String text() const;
|
|
|
|
|
void set_text(Utf16String const&);
|
2022-04-12 13:29:16 -03:00
|
|
|
|
2024-11-15 11:14:28 +01:00
|
|
|
[[nodiscard]] String label() const;
|
|
|
|
|
void set_label(String const&);
|
|
|
|
|
|
2022-04-12 13:29:16 -03:00
|
|
|
int index() const;
|
|
|
|
|
|
2022-09-30 16:21:34 +01:00
|
|
|
bool disabled() const;
|
|
|
|
|
|
2025-01-26 19:13:17 +13:00
|
|
|
GC::Ptr<HTML::HTMLFormElement const> form() const;
|
2024-05-15 22:54:17 +01: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
|
|
|
|
2025-11-17 20:46:54 -08:00
|
|
|
GC::Ptr<HTMLSelectElement> nearest_select_element() { return m_cached_nearest_select_element; }
|
|
|
|
|
GC::Ptr<HTMLSelectElement const> nearest_select_element() const { return m_cached_nearest_select_element; }
|
2025-01-26 19:13:17 +13:00
|
|
|
|
2025-12-07 16:37:54 -08:00
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#the-option-element:clone-an-option-into-a-selectedcontent
|
|
|
|
|
WebIDL::ExceptionOr<void> maybe_clone_into_selectedcontent();
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#clone-an-option-into-a-selectedcontent
|
|
|
|
|
WebIDL::ExceptionOr<void> clone_into_selectedcontent(GC::Ref<HTMLSelectedContentElement>);
|
|
|
|
|
|
2022-03-20 16:13:23 +01:00
|
|
|
private:
|
2022-04-03 22:07:03 -03:00
|
|
|
friend class Bindings::OptionConstructor;
|
2022-03-20 16:13:58 +01:00
|
|
|
friend class HTMLSelectElement;
|
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
HTMLOptionElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
|
2025-12-15 17:30:06 -06:00
|
|
|
virtual bool is_html_option_element() const final { return true; }
|
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2025-11-17 20:46:54 -08:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2024-11-14 08:14:16 -05:00
|
|
|
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
2022-03-20 16:13:58 +01:00
|
|
|
|
2024-11-14 00:05:38 +01:00
|
|
|
virtual void inserted() override;
|
2025-01-23 17:37:18 +01:00
|
|
|
virtual void removed_from(Node* old_parent, Node& old_root) override;
|
2026-03-18 13:36:27 +01:00
|
|
|
virtual void children_changed(ChildrenChangedMetadata const&) override;
|
2024-11-14 00:05:38 +01:00
|
|
|
|
2022-03-20 16:13:58 +01:00
|
|
|
void ask_for_a_reset();
|
2025-01-10 19:35:03 +11:00
|
|
|
void update_selection_label();
|
2022-03-20 16:13:58 +01:00
|
|
|
|
2025-11-17 20:46:54 -08:00
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#update-an-option's-nearest-ancestor-select
|
|
|
|
|
void update_nearest_select_element();
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#option-element-nearest-ancestor-select
|
|
|
|
|
GC::Ptr<HTMLSelectElement> compute_nearest_select_element();
|
|
|
|
|
|
2022-03-20 16:13:23 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-selectedness
|
|
|
|
|
bool m_selected { false };
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-dirtiness
|
|
|
|
|
bool m_dirty { false };
|
2024-11-14 00:05:38 +01:00
|
|
|
|
|
|
|
|
u64 m_selectedness_update_index { 0 };
|
2025-11-17 20:46:54 -08:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#cached-nearest-ancestor-select-element
|
|
|
|
|
GC::Ptr<HTMLSelectElement> m_cached_nearest_select_element;
|
2020-08-01 03:05:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
2025-12-15 17:30:06 -06:00
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
inline bool Node::fast_is<HTML::HTMLOptionElement>() const { return is_html_option_element(); }
|
|
|
|
|
|
|
|
|
|
}
|