Produce "pen" Pointer Events if using a stylus (e.g. Apple Pencil)
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 02:03:45 +0000 (02:03 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 02:03:45 +0000 (02:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193945
<rdar://problem/47618922>

Reviewed by Antoine Quint.

Source/WebCore:

Calculate the pressure, tiltX and tiltY values for incoming
Pointer Events, which have values when the PlatformTouchEvent
originated from a stylus.

Test: pointerevents/ios/pointer-events-dispatch-on-stylus.html

* dom/PointerEvent.h: Default to "mouse".
* dom/ios/PointerEventIOS.cpp: Calculate the values.

LayoutTests:

Test for stylus -> "pen" Pointer Events.

* pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt: Added.
* pointerevents/ios/pointer-events-dispatch-on-stylus.html: Added.
* pointerevents/ios/pointer-events-dispatch-on-touch.html: Test for "touch" type.
* pointerevents/utils.js: Add a new helper for stylus event generation.
(prototype.assertMatchesEvents):
(const.ui.new.UIController.prototype.beginStylus):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240632 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt [new file with mode: 0644]
LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus.html [new file with mode: 0644]
LayoutTests/pointerevents/ios/pointer-events-dispatch-on-touch.html
LayoutTests/pointerevents/utils.js
Source/WebCore/ChangeLog
Source/WebCore/dom/PointerEvent.h
Source/WebCore/dom/ios/PointerEventIOS.cpp

index b580a7d..c38cf41 100644 (file)
@@ -1,3 +1,20 @@
+2019-01-28  Dean Jackson  <dino@apple.com>
+
+        Produce "pen" Pointer Events if using a stylus (e.g. Apple Pencil)
+        https://bugs.webkit.org/show_bug.cgi?id=193945
+        <rdar://problem/47618922>
+
+        Reviewed by Antoine Quint.
+
+        Test for stylus -> "pen" Pointer Events.
+
+        * pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt: Added.
+        * pointerevents/ios/pointer-events-dispatch-on-stylus.html: Added.
+        * pointerevents/ios/pointer-events-dispatch-on-touch.html: Test for "touch" type.
+        * pointerevents/utils.js: Add a new helper for stylus event generation.
+        (prototype.assertMatchesEvents):
+        (const.ui.new.UIController.prototype.beginStylus):
+
 2019-01-28  Daniel Bates  <dabates@apple.com>
 
         [iOS] Make Window virtual key code computation match Mac
diff --git a/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt b/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt
new file mode 100644 (file)
index 0000000..b213dd9
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Pointer events get dispatched in response to a stylus. 
+
diff --git a/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus.html b/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus.html
new file mode 100644 (file)
index 0000000..b601506
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset=utf-8>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../utils.js"></script>
+<script>
+
+'use strict';
+
+const fifteenDegrees = Math.PI / 12;
+const thirtyDegrees = Math.PI / 6;
+
+target_test((target, test) => {
+    target.addEventListener("pointerdown", event => {
+        assert_true(event instanceof PointerEvent);
+        assert_equals(event.type, "pointerdown");
+        assert_equals(event.clientX, 50);
+        assert_equals(event.clientY, 50);
+        assert_equals(event.pointerType, "pen");
+        assert_equals(event.pressure, 0.75);
+        assert_approx_equals(event.tiltX, 20, 1);
+        assert_approx_equals(event.tiltY, 75, 1);
+        test.done();
+    });
+    ui.beginStylus({ x: 50, y: 50, pressure: 0.75, azimuthAngle: fifteenDegrees, altitudeAngle: thirtyDegrees });
+}, "Pointer events get dispatched in response to a stylus.");
+
+</script>
+</body>
+</html>
\ No newline at end of file
index e11971d..5d4748c 100644 (file)
@@ -18,6 +18,7 @@ target_test((target, test) => {
         assert_equals(event.type, "pointerdown");
         assert_equals(event.clientX, 50);
         assert_equals(event.clientY, 50);
+        assert_equals(event.pointerType, "touch");
         test.done();
     });
     ui.beginTouches({ x: 50, y: 50 });
index 0487af7..c89f0c3 100644 (file)
@@ -34,7 +34,6 @@ function target_test(...args)
 
 class EventTracker
 {
-
     constructor(target, eventNames)
     {
         this.target = target;
@@ -71,7 +70,6 @@ class EventTracker
                 assert_equals(expectedEvent[property], actualEvent[property], `Property ${property} matches for event at index ${i}.`);
         }
     }
-
 }
 
 const ui = new (class UIController {
@@ -188,6 +186,14 @@ const ui = new (class UIController {
         }));
     }
 
+    beginStylus(options)
+    {
+        options.azimuthAngle = options.azimuthAngle || 0;
+        options.altitudeAngle = options.altitudeAngle || 0;
+        options.pressure = options.pressure || 0;
+        return this._run(`uiController.stylusDownAtPoint(${options.x}, ${options.y}, ${options.azimuthAngle}, ${options.altitudeAngle}, ${options.pressure})`);
+    }
+
     _runEvents(events)
     {
         return this._run(`uiController.sendEventStream('${JSON.stringify({ events })}')`);
index f43ca04..510cb09 100644 (file)
@@ -1,3 +1,20 @@
+2019-01-28  Dean Jackson  <dino@apple.com>
+
+        Produce "pen" Pointer Events if using a stylus (e.g. Apple Pencil)
+        https://bugs.webkit.org/show_bug.cgi?id=193945
+        <rdar://problem/47618922>
+
+        Reviewed by Antoine Quint.
+
+        Calculate the pressure, tiltX and tiltY values for incoming
+        Pointer Events, which have values when the PlatformTouchEvent
+        originated from a stylus.
+
+        Test: pointerevents/ios/pointer-events-dispatch-on-stylus.html
+
+        * dom/PointerEvent.h: Default to "mouse".
+        * dom/ios/PointerEventIOS.cpp: Calculate the values.
+
 2019-01-28  Timothy Hatcher  <timothy@apple.com>
 
         Make it easier for non-Apple ports to enable dark mode CSS support.
index 3932df9..bdaee5e 100644 (file)
@@ -47,7 +47,7 @@ public:
         long tiltX { 0 };
         long tiltY { 0 };
         long twist { 0 };
-        String pointerType;
+        String pointerType { "mouse"_s };
         bool isPrimary { false };
     };
 
@@ -97,7 +97,7 @@ private:
     long m_tiltX { 0 };
     long m_tiltY { 0 };
     long m_twist { 0 };
-    String m_pointerType;
+    String m_pointerType { "mouse"_s };
     bool m_isPrimary { false };
 };
 
index 92bb83e..2112ee8 100644 (file)
@@ -68,9 +68,17 @@ PointerEvent::PointerEvent(const AtomicString& type, const PlatformTouchEvent& e
     , m_pointerId(event.touchIdentifierAtIndex(index))
     , m_width(2 * event.radiusXAtIndex(index))
     , m_height(2 * event.radiusYAtIndex(index))
+    , m_pressure(event.forceAtIndex(index))
     , m_pointerType(event.touchTypeAtIndex(index) == PlatformTouchPoint::TouchType::Stylus ? "pen"_s : "touch"_s)
     , m_isPrimary(isPrimary)
 {
+    // See https://github.com/w3c/pointerevents/issues/274. We might expose the azimuth and altitude
+    // directly as well as the tilt.
+    double azimuthAngle = event.azimuthAngleAtIndex(index);
+    double altitudeAngle = event.altitudeAngleAtIndex(index);
+
+    m_tiltX = round(sin(azimuthAngle) * cos(altitudeAngle) * 90);
+    m_tiltY = round(cos(azimuthAngle) * cos(altitudeAngle) * 90);
 }
 
 } // namespace WebCore