浏览代码

LibWeb: Fire a pointer event on synthetic clicks

Shannon Booth 1 年之前
父节点
当前提交
db0519ddc1

+ 1 - 0
Tests/LibWeb/Text/expected/HTML/HTMLElement-click.txt

@@ -0,0 +1 @@
+  Event: PointerEvent

+ 15 - 0
Tests/LibWeb/Text/input/HTML/HTMLElement-click.html

@@ -0,0 +1,15 @@
+<script src="../include.js"></script>
+<button id="myButton"></button>
+<script>
+    asyncTest(done => {
+        function handleClick(event) {
+            println(`Event: ${event.constructor.name}`);
+            done();
+        }
+
+        let button = document.getElementById("myButton");
+
+        button.addEventListener("click", handleClick);
+        button.click();
+    });
+</script>

+ 2 - 3
Userland/Libraries/LibWeb/HTML/HTMLElement.cpp

@@ -381,8 +381,7 @@ bool HTMLElement::fire_a_synthetic_pointer_event(FlyString const& type, DOM::Ele
 {
     // 1. Let event be the result of creating an event using PointerEvent.
     // 2. Initialize event's type attribute to e.
-    // FIXME: Actually create a PointerEvent!
-    auto event = UIEvents::MouseEvent::create(realm(), type);
+    auto event = UIEvents::PointerEvent::create(realm(), type);
 
     // 3. Initialize event's bubbles and cancelable attributes to true.
     event->set_bubbles(true);
@@ -419,7 +418,7 @@ void HTMLElement::click()
     // 3. Set this element's click in progress flag.
     m_click_in_progress = true;
 
-    // FIXME: 4. Fire a synthetic pointer event named click at this element, with the not trusted flag set.
+    // 4. Fire a synthetic pointer event named click at this element, with the not trusted flag set.
     fire_a_synthetic_pointer_event(HTML::EventNames::click, *this, true);
 
     // 5. Unset this element's click in progress flag.