From caf74e7ed69c6f64fc2f770d03fe61bc60cdc08b Mon Sep 17 00:00:00 2001 From: Fernando Kiotheka Date: Thu, 10 Oct 2024 11:06:14 -0300 Subject: [PATCH] LibWeb: Implement activation behavior on input[type=reset] This fixes WPT html/semantics/forms/resetting-a-form/reset-form.html. I added a test based on the WPT test, but simpler. --- .../Text/expected/reset-input-element.txt | 13 +++++ .../Text/input/reset-input-element.html | 58 +++++++++++++++++++ .../LibWeb/HTML/HTMLInputElement.cpp | 15 +++++ 3 files changed, 86 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/reset-input-element.txt create mode 100644 Tests/LibWeb/Text/input/reset-input-element.html diff --git a/Tests/LibWeb/Text/expected/reset-input-element.txt b/Tests/LibWeb/Text/expected/reset-input-element.txt new file mode 100644 index 00000000000..baf8cfc78f1 --- /dev/null +++ b/Tests/LibWeb/Text/expected/reset-input-element.txt @@ -0,0 +1,13 @@ +abc + +true +false +true +false +abc +abc +1 +2 +false +true +true diff --git a/Tests/LibWeb/Text/input/reset-input-element.html b/Tests/LibWeb/Text/input/reset-input-element.html new file mode 100644 index 00000000000..56f912bc9b4 --- /dev/null +++ b/Tests/LibWeb/Text/input/reset-input-element.html @@ -0,0 +1,58 @@ + + +
+ + + + + + + + 5 + + + + + +
+ diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 352314f5505..ac7aef7aac5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -5,6 +5,7 @@ * Copyright (c) 2023-2024, Shannon Booth * Copyright (c) 2023, Bastiaan van der Plaat * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Fernando Kiotheka * * SPDX-License-Identifier: BSD-2-Clause */ @@ -406,6 +407,20 @@ WebIDL::ExceptionOr HTMLInputElement::run_input_activation_behavior(DOM::E // 4. Submit the element's form owner from the element with userInvolvement set to event's user navigation involvement. TRY(form->submit_form(*this, { .user_involvement = user_navigation_involvement(event) })); } + // https://html.spec.whatwg.org/multipage/input.html#reset-button-state-(type=reset) + else if (type_state() == TypeAttributeState::ResetButton) { + // 1. If the element does not have a form owner, then return. + auto* form = this->form(); + if (!form) + return {}; + + // 2. If the element's node document is not fully active, then return. + if (!document().is_fully_active()) + return {}; + + // 3. Reset the form owner from the element. + form->reset_form(); + } return {}; }