mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
LibWeb: Implement HTMLOptionElement.selected
This commit is contained in:
parent
a606345576
commit
80ed2ab557
3 changed files with 52 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -15,4 +16,43 @@ HTMLOptionElement::HTMLOptionElement(DOM::Document& document, DOM::QualifiedName
|
|||
|
||||
HTMLOptionElement::~HTMLOptionElement() = default;
|
||||
|
||||
void HTMLOptionElement::parse_attribute(FlyString const& name, String const& value)
|
||||
{
|
||||
HTMLElement::parse_attribute(name, value);
|
||||
|
||||
if (name == HTML::AttributeNames::selected) {
|
||||
// Except where otherwise specified, when the element is created, its selectedness must be set to true
|
||||
// if the element has a selected attribute. Whenever an option element's selected attribute is added,
|
||||
// if its dirtiness is false, its selectedness must be set to true.
|
||||
if (!m_dirty)
|
||||
m_selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLOptionElement::did_remove_attribute(FlyString const& name)
|
||||
{
|
||||
HTMLElement::did_remove_attribute(name);
|
||||
|
||||
if (name == HTML::AttributeNames::selected) {
|
||||
// Whenever an option element's selected attribute is removed, if its dirtiness is false, its selectedness must be set to false.
|
||||
if (!m_dirty)
|
||||
m_selected = false;
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-selected
|
||||
void HTMLOptionElement::set_selected(bool selected)
|
||||
{
|
||||
// On setting, it must set the element's selectedness to the new value, set its dirtiness to true, and then cause the element to ask for a reset.
|
||||
m_selected = selected;
|
||||
m_dirty = true;
|
||||
ask_for_a_reset();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#ask-for-a-reset
|
||||
void HTMLOptionElement::ask_for_a_reset()
|
||||
{
|
||||
// FIXME: Implement this operation.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,17 @@ public:
|
|||
HTMLOptionElement(DOM::Document&, DOM::QualifiedName);
|
||||
virtual ~HTMLOptionElement() override;
|
||||
|
||||
bool selected() const { return m_selected; }
|
||||
void set_selected(bool);
|
||||
|
||||
private:
|
||||
friend class HTMLSelectElement;
|
||||
|
||||
void parse_attribute(FlyString const& name, String const& value) override;
|
||||
void did_remove_attribute(FlyString const& name) override;
|
||||
|
||||
void ask_for_a_reset();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-selectedness
|
||||
bool m_selected { false };
|
||||
|
||||
|
|
|
@ -5,4 +5,6 @@ interface HTMLOptionElement : HTMLElement {
|
|||
[Reflect] attribute boolean disabled;
|
||||
[Reflect=selected] attribute boolean defaultSelected;
|
||||
|
||||
attribute boolean selected;
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue