From de44e0faf5101ad0b141a45964c5289d7b09fb1a Mon Sep 17 00:00:00 2001 From: Srikavin Ramkumar Date: Thu, 22 Dec 2022 19:33:37 -0500 Subject: LibWeb: Implement reset algorithm for HTMLInputElement --- .../Libraries/LibWeb/HTML/HTMLInputElement.cpp | 22 ++++++++++++++++++++++ Userland/Libraries/LibWeb/HTML/HTMLInputElement.h | 2 ++ 2 files changed, 24 insertions(+) (limited to 'Userland/Libraries/LibWeb/HTML') 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 -- cgit v1.2.3