From 246c31ccf6cdc21e5959d7e75b73f4d8fb79fcc5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 17 Feb 2022 13:31:09 +0100 Subject: [PATCH] LibWeb: Make fire click events when clicked :^) This makes React react to checkboxes. Apparently they ignore the "change" event in favor of "click" on checkboxes. This is a compatibility hack for IE8. --- Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 8 ++++++++ Userland/Libraries/LibWeb/HTML/HTMLInputElement.h | 1 + Userland/Libraries/LibWeb/Layout/CheckBox.cpp | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 26769cd6525..abeece9e81b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -41,6 +41,14 @@ void HTMLInputElement::did_click_button(Badge) } } +void HTMLInputElement::did_click_checkbox(Badge) +{ + // FIXME: This should be a PointerEvent. + auto click_event = DOM::Event::create(EventNames::click); + click_event->set_bubbles(true); + dispatch_event(move(click_event)); +} + RefPtr HTMLInputElement::create_layout_node(NonnullRefPtr style) { if (type() == "hidden") diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 2a96aceb665..2b1302affb8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -43,6 +43,7 @@ public: bool enabled() const; void did_click_button(Badge); + void did_click_checkbox(Badge); void did_edit_text_node(Badge); diff --git a/Userland/Libraries/LibWeb/Layout/CheckBox.cpp b/Userland/Libraries/LibWeb/Layout/CheckBox.cpp index c1718998345..8d1a3da5894 100644 --- a/Userland/Libraries/LibWeb/Layout/CheckBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/CheckBox.cpp @@ -62,8 +62,10 @@ void CheckBox::handle_mouseup(Badge, const Gfx::IntPoint& position if (!is_inside_node_or_label) is_inside_node_or_label = Label::is_inside_associated_label(*this, position); - if (is_inside_node_or_label) + if (is_inside_node_or_label) { + dom_node().did_click_checkbox({}); dom_node().set_checked(!dom_node().checked(), HTML::HTMLInputElement::ChangeSource::User); + } m_being_pressed = false; m_tracking_mouse = false; @@ -103,6 +105,7 @@ void CheckBox::handle_associated_label_mouseup(Badge