Pārlūkot izejas kodu

LibWeb: Make <input type=checkbox> 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.
Andreas Kling 3 gadi atpakaļ
vecāks
revīzija
246c31ccf6

+ 8 - 0
Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp

@@ -41,6 +41,14 @@ void HTMLInputElement::did_click_button(Badge<Layout::ButtonBox>)
     }
 }
 
+void HTMLInputElement::did_click_checkbox(Badge<Layout::CheckBox>)
+{
+    // 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<Layout::Node> HTMLInputElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
 {
     if (type() == "hidden")

+ 1 - 0
Userland/Libraries/LibWeb/HTML/HTMLInputElement.h

@@ -43,6 +43,7 @@ public:
     bool enabled() const;
 
     void did_click_button(Badge<Layout::ButtonBox>);
+    void did_click_checkbox(Badge<Layout::CheckBox>);
 
     void did_edit_text_node(Badge<BrowsingContext>);
 

+ 4 - 1
Userland/Libraries/LibWeb/Layout/CheckBox.cpp

@@ -62,8 +62,10 @@ void CheckBox::handle_mouseup(Badge<EventHandler>, 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<Label>)
     // NOTE: Changing the checked state of the DOM node may run arbitrary JS, which could disappear this node.
     NonnullRefPtr protect = *this;
 
+    dom_node().did_click_checkbox({});
     dom_node().set_checked(!dom_node().checked(), HTML::HTMLInputElement::ChangeSource::User);
     m_being_pressed = false;
 }