summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstelar7 <dudedbz@gmail.com>2023-05-29 18:41:32 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-30 06:17:36 +0200
commit518679b0dd79cfbbd36ac5cdbe5e22d3b89c1e17 (patch)
tree17df50bf83ad78df4409424b660465270d561ff2
parent06593a81da7e7d5074ab0363d98e81aede645100 (diff)
downloadserenity-518679b0dd79cfbbd36ac5cdbe5e22d3b89c1e17.zip
LibWeb: Adjust change event timing for input elements
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp16
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLInputElement.h1
2 files changed, 12 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index c8344fcd3a..c9a1322b8d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -297,11 +297,6 @@ void HTMLInputElement::did_edit_text_node(Badge<BrowsingContext>)
input_event->set_bubbles(true);
input_event->set_composed(true);
dispatch_event(*input_event);
-
- // FIXME: This should only fire when the input is "committed", whatever that means.
- auto change_event = DOM::Event::create(realm(), HTML::EventNames::change).release_value_but_fixme_should_propagate_errors();
- change_event->set_bubbles(true);
- dispatch_event(change_event);
});
}
@@ -487,6 +482,17 @@ void HTMLInputElement::did_receive_focus()
browsing_context->set_cursor_position(DOM::Position { *m_text_node, 0 });
}
+void HTMLInputElement::did_lose_focus()
+{
+ // The change event fires when the value is committed, if that makes sense for the control,
+ // or else when the control loses focus
+ queue_an_element_task(HTML::Task::Source::UserInteraction, [this] {
+ auto change_event = DOM::Event::create(realm(), HTML::EventNames::change).release_value_but_fixme_should_propagate_errors();
+ change_event->set_bubbles(true);
+ dispatch_event(change_event);
+ });
+}
+
void HTMLInputElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
{
HTMLElement::parse_attribute(name, value);
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h
index 6f83d7ee15..0a020c9764 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h
@@ -140,6 +140,7 @@ private:
virtual bool is_html_input_element() const final { return true; }
// ^DOM::EventTarget
+ virtual void did_lose_focus() override;
virtual void did_receive_focus() override;
virtual void legacy_pre_activation_behavior() override;
virtual void legacy_cancelled_activation_behavior() override;