2020-07-31 23:05:43 -03:00
|
|
|
/*
|
2021-04-28 17:46:44 -03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2020-07-31 23:05:43 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-31 23:05:43 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2020-07-31 23:05:43 -03:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API HTMLOptionElement final : public HTMLElement {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLOptionElement, HTMLElement);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLOptionElement);
|
2020-07-31 23:05:43 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
public:
|
2020-07-31 23:05:43 -03:00
|
|
|
virtual ~HTMLOptionElement() override;
|
2022-03-20 12:13:23 -03:00
|
|
|
|
2022-03-20 12:13:58 -03:00
|
|
|
bool selected() const { return m_selected; }
|
|
|
|
|
void set_selected(bool);
|
2024-07-25 14:13:22 -03:00
|
|
|
void set_selected_internal(bool);
|
2024-11-13 20:05:38 -03:00
|
|
|
[[nodiscard]] u64 selectedness_update_index() const { return m_selectedness_update_index; }
|
2022-03-20 12:13:58 -03:00
|
|
|
|
2025-07-26 13:19:56 -03:00
|
|
|
Utf16String value() const;
|
|
|
|
|
WebIDL::ExceptionOr<void> set_value(Utf16String const&);
|
2022-04-12 13:29:16 -03:00
|
|
|
|
2025-07-28 10:46:06 -03:00
|
|
|
Utf16String text() const;
|
|
|
|
|
void set_text(Utf16String const&);
|
2022-04-12 13:29:16 -03:00
|
|
|
|
2024-11-15 07:14:28 -03:00
|
|
|
[[nodiscard]] String label() const;
|
|
|
|
|
void set_label(String const&);
|
|
|
|
|
|
2022-04-12 13:29:16 -03:00
|
|
|
int index() const;
|
|
|
|
|
|
2022-09-30 12:21:34 -03:00
|
|
|
bool disabled() const;
|
|
|
|
|
|
2025-01-26 03:13:17 -03:00
|
|
|
GC::Ptr<HTML::HTMLFormElement const> form() const;
|
2024-05-15 18:54:17 -03:00
|
|
|
|
2023-01-28 19:23:16 -03:00
|
|
|
virtual Optional<ARIA::Role> default_role() const override;
|
2022-11-28 20:58:13 -03:00
|
|
|
|
2025-01-26 03:13:17 -03: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 12:13:23 -03:00
|
|
|
private:
|
2022-04-03 22:07:03 -03:00
|
|
|
friend class Bindings::OptionConstructor;
|
2022-03-20 12:13:58 -03:00
|
|
|
friend class HTMLSelectElement;
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
HTMLOptionElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2024-11-14 10:14:16 -03: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 12:13:58 -03:00
|
|
|
|
2024-11-13 20:05:38 -03:00
|
|
|
virtual void inserted() override;
|
2025-01-23 13:37:18 -03:00
|
|
|
virtual void removed_from(Node* old_parent, Node& old_root) override;
|
2025-01-26 09:16:33 -03:00
|
|
|
virtual void children_changed(ChildrenChangedMetadata const*) override;
|
2024-11-13 20:05:38 -03:00
|
|
|
|
2022-03-20 12:13:58 -03:00
|
|
|
void ask_for_a_reset();
|
2025-01-10 05:35:03 -03:00
|
|
|
void update_selection_label();
|
2022-03-20 12:13:58 -03:00
|
|
|
|
2022-03-20 12:13:23 -03: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-13 20:05:38 -03:00
|
|
|
|
|
|
|
|
u64 m_selectedness_update_index { 0 };
|
2020-07-31 23:05:43 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|