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;
|
|
|
|
WebIDL::ExceptionOr<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-01-26 19:13:17 +13:00
|
|
|
GC::Ptr<HTMLSelectElement> owner_select_element();
|
|
|
|
GC::Ptr<HTMLSelectElement const> owner_select_element() const { return const_cast<HTMLOptionElement&>(*this).owner_select_element(); }
|
|
|
|
|
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);
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) 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;
|
2025-01-27 01:16:33 +13: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
|
|
|
|
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 };
|
2020-08-01 03:05:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|