From 71cfa705d1eab052e773e6a695c438bab87ec8b0 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 21 Aug 2024 12:19:37 +0100 Subject: [PATCH] LibWeb: Implement cloning steps for `HTMLInputElement` --- .../HTML/HTMLInputElement-cloning-steps.txt | 2 ++ .../HTML/HTMLInputElement-cloning-steps.html | 23 +++++++++++++++++++ .../LibWeb/HTML/HTMLInputElement.cpp | 12 ++++++++++ .../Libraries/LibWeb/HTML/HTMLInputElement.h | 2 ++ 4 files changed, 39 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/HTML/HTMLInputElement-cloning-steps.txt create mode 100644 Tests/LibWeb/Text/input/HTML/HTMLInputElement-cloning-steps.html diff --git a/Tests/LibWeb/Text/expected/HTML/HTMLInputElement-cloning-steps.txt b/Tests/LibWeb/Text/expected/HTML/HTMLInputElement-cloning-steps.txt new file mode 100644 index 00000000000..76ccc81241a --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/HTMLInputElement-cloning-steps.txt @@ -0,0 +1,2 @@ + Cloned checkbox checked: true +Cloned text input value: PASS diff --git a/Tests/LibWeb/Text/input/HTML/HTMLInputElement-cloning-steps.html b/Tests/LibWeb/Text/input/HTML/HTMLInputElement-cloning-steps.html new file mode 100644 index 00000000000..5c2da9fbe77 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/HTMLInputElement-cloning-steps.html @@ -0,0 +1,23 @@ + + +
+ + +
+ diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 62762cce04c..543cf533b0b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1446,6 +1446,18 @@ void HTMLInputElement::form_associated_element_was_removed(DOM::Node*) set_shadow_root(nullptr); } +// https://html.spec.whatwg.org/multipage/input.html#the-input-element%3Aconcept-node-clone-ext +WebIDL::ExceptionOr HTMLInputElement::cloned(DOM::Node& copy, bool) +{ + // The cloning steps for input elements must propagate the value, dirty value flag, checkedness, and dirty checkedness flag from the node being cloned to the copy. + auto& input_clone = verify_cast(copy); + input_clone.m_value = m_value; + input_clone.m_dirty_value = m_dirty_value; + input_clone.m_checked = m_checked; + input_clone.m_dirty_checkedness = m_dirty_checkedness; + return {}; +} + // https://html.spec.whatwg.org/multipage/input.html#radio-button-group static bool is_in_same_radio_button_group(HTML::HTMLInputElement const& a, HTML::HTMLInputElement const& b) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 88978e1a80b..f169b661b73 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -176,6 +176,8 @@ public: virtual void form_associated_element_was_removed(DOM::Node*) override; virtual void form_associated_element_attribute_changed(FlyString const&, Optional const&) override; + virtual WebIDL::ExceptionOr cloned(Node&, bool) override; + JS::NonnullGCPtr validity() const; // ^HTMLElement