diff options
author | Srikavin Ramkumar <srikavinramkumar@gmail.com> | 2022-12-22 19:33:37 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-03 18:09:40 +0100 |
commit | de44e0faf5101ad0b141a45964c5289d7b09fb1a (patch) | |
tree | 2ac4eb7aff3be43370c86ac1ab36c62ba8cf6779 /Userland/Libraries/LibWeb/HTML | |
parent | 6032d122c28ba0101de37d18961bc9678a0e224a (diff) | |
download | serenity-de44e0faf5101ad0b141a45964c5289d7b09fb1a.zip |
LibWeb: Implement reset algorithm for HTMLInputElement
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 22 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLInputElement.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index ba0c9a1c15..74946382bb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -736,6 +736,28 @@ DeprecatedString HTMLInputElement::value_sanitization_algorithm(DeprecatedString return value; } +// https://html.spec.whatwg.org/multipage/input.html#the-input-element:concept-form-reset-control +void HTMLInputElement::reset_algorithm() +{ + // The reset algorithm for input elements is to set the dirty value flag and dirty checkedness flag back to false, + m_dirty_value = false; + m_dirty_checkedness = false; + + // set the value of the element to the value of the value content attribute, if there is one, or the empty string otherwise, + m_value = has_attribute(AttributeNames::value) ? get_attribute(AttributeNames::value) : DeprecatedString::empty(); + + // set the checkedness of the element to true if the element has a checked content attribute and false if it does not, + m_checked = has_attribute(AttributeNames::checked); + + // empty the list of selected files, + m_selected_files = FileAPI::FileList::create(realm(), {}); + + // and then invoke the value sanitization algorithm, if the type attribute's current state defines one. + m_value = value_sanitization_algorithm(m_value); + if (m_text_node) + m_text_node->set_data(m_value); +} + void HTMLInputElement::form_associated_element_was_inserted() { create_shadow_tree_if_needed(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 7ee434f7b8..bda31d044e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -112,6 +112,8 @@ public: // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize virtual bool is_auto_capitalize_inheriting() const override { return true; } + virtual void reset_algorithm() override; + virtual void form_associated_element_was_inserted() override; // ^HTMLElement |