LibWeb: Send InputEvent with right .inputType on insert and delete

Applies to `<input>` and `<textarea>`. Editing commands in
`contenteditable` already sent the right events and input types.

Fixes #7668
This commit is contained in:
Jelle Raaijmakers 2026-01-29 09:54:27 +01:00 committed by Jelle Raaijmakers
parent c9108a2ad5
commit e05503dbcb
Notes: github-actions[bot] 2026-02-06 10:55:26 +00:00
12 changed files with 133 additions and 58 deletions

View file

@ -4,7 +4,7 @@
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
* Copyright (c) 2023-2026, Shannon Booth <shannon@serenityos.org>
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
* Copyright (c) 2024-2026, Jelle Raaijmakers <jelle@ladybird.org>
* Copyright (c) 2024, Fernando Kiotheka <fer@k6a.dev>
* Copyright (c) 2025, Felipe Muñoz Mazur <felipe.munoz.mazur@protonmail.com>
* Copyright (c) 2025, Glenn Skrzypczak <glenn.skrzypczak@gmail.com>
@ -35,7 +35,6 @@
#include <LibWeb/HTML/DecodedImageData.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/HTMLDataListElement.h>
#include <LibWeb/HTML/HTMLDivElement.h>
#include <LibWeb/HTML/HTMLFormElement.h>
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/Numbers.h>
@ -45,7 +44,6 @@
#include <LibWeb/HTML/SharedResourceRequest.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/CheckBox.h>
#include <LibWeb/Layout/ImageBox.h>
@ -57,6 +55,7 @@
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Selection/Selection.h>
#include <LibWeb/UIEvents/EventNames.h>
#include <LibWeb/UIEvents/InputEvent.h>
#include <LibWeb/UIEvents/MouseEvent.h>
#include <LibWeb/WebIDL/DOMException.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -548,7 +547,7 @@ WebIDL::ExceptionOr<void> HTMLInputElement::run_input_activation_behavior(DOM::E
return {};
}
void HTMLInputElement::did_edit_text_node()
void HTMLInputElement::did_edit_text_node(FlyString const& input_type)
{
// An input element's dirty value flag must be set to true whenever the user interacts with the control in a way that changes the value.
auto old_value = move(m_value);
@ -562,7 +561,7 @@ void HTMLInputElement::did_edit_text_node()
update_placeholder_visibility();
user_interaction_did_change_input_value();
user_interaction_did_change_input_value(input_type);
}
void HTMLInputElement::did_pick_color(Optional<Color> picked_color, ColorPickerUpdateState state)
@ -1406,18 +1405,21 @@ void HTMLInputElement::create_range_input_shadow_tree()
add_event_listener_without_options(UIEvents::EventNames::mousedown, DOM::IDLEventListener::create(realm(), mousedown_callback));
}
void HTMLInputElement::user_interaction_did_change_input_value()
void HTMLInputElement::user_interaction_did_change_input_value(FlyString const& input_type)
{
// https://html.spec.whatwg.org/multipage/input.html#common-input-element-events
// For input elements without a defined input activation behavior, but to which these events apply,
// and for which the user interface involves both interactive manipulation and an explicit commit action,
// then when the user changes the element's value, the user agent must queue an element task on the user interaction task source
// given the input element to fire an event named input at the input element, with the bubbles and composed attributes initialized to true
queue_an_element_task(HTML::Task::Source::UserInteraction, [this] {
queue_an_element_task(HTML::Task::Source::UserInteraction, [this, input_type] {
// https://w3c.github.io/uievents/#event-type-input
// FIXME: If a string was added to this input, this input event's .data should be set to it.
auto input_event = DOM::Event::create(realm(), HTML::EventNames::input);
input_event->set_bubbles(true);
input_event->set_composed(true);
UIEvents::InputEventInit input_event_init;
input_event_init.bubbles = true;
input_event_init.composed = true;
input_event_init.input_type = input_type;
auto input_event = UIEvents::InputEvent::create_from_platform_event(realm(), HTML::EventNames::input, input_event_init);
dispatch_event(*input_event);
});
// and any time the user commits the change, the user agent must queue an element task on the user interaction task source given the input