Title: [240632] trunk
Revision
240632
Author
d...@apple.com
Date
2019-01-28 18:03:45 -0800 (Mon, 28 Jan 2019)

Log Message

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.

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):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (240631 => 240632)


--- trunk/LayoutTests/ChangeLog	2019-01-29 01:58:33 UTC (rev 240631)
+++ trunk/LayoutTests/ChangeLog	2019-01-29 02:03:45 UTC (rev 240632)
@@ -1,3 +1,20 @@
+2019-01-28  Dean Jackson  <d...@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  <daba...@apple.com>
 
         [iOS] Make Window virtual key code computation match Mac

Added: trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt (0 => 240632)


--- trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt	2019-01-29 02:03:45 UTC (rev 240632)
@@ -0,0 +1,3 @@
+
+PASS Pointer events get dispatched in response to a stylus. 
+
Property changes on: trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus-expected.txt
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/plain \ No newline at end of property

Copied: trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus.html (from rev 240631, trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-touch.html) (0 => 240632)


--- trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus.html	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-stylus.html	2019-01-29 02:03:45 UTC (rev 240632)
@@ -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=""
+<script src=""
+<script src=""
+<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

Modified: trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-touch.html (240631 => 240632)


--- trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-touch.html	2019-01-29 01:58:33 UTC (rev 240631)
+++ trunk/LayoutTests/pointerevents/ios/pointer-events-dispatch-on-touch.html	2019-01-29 02:03:45 UTC (rev 240632)
@@ -18,6 +18,7 @@
         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 });

Modified: trunk/LayoutTests/pointerevents/utils.js (240631 => 240632)


--- trunk/LayoutTests/pointerevents/utils.js	2019-01-29 01:58:33 UTC (rev 240631)
+++ trunk/LayoutTests/pointerevents/utils.js	2019-01-29 02:03:45 UTC (rev 240632)
@@ -34,7 +34,6 @@
 
 class EventTracker
 {
-
     constructor(target, eventNames)
     {
         this.target = target;
@@ -71,7 +70,6 @@
                 assert_equals(expectedEvent[property], actualEvent[property], `Property ${property} matches for event at index ${i}.`);
         }
     }
-
 }
 
 const ui = new (class UIController {
@@ -188,6 +186,14 @@
         }));
     }
 
+    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 })}')`);

Modified: trunk/Source/WebCore/ChangeLog (240631 => 240632)


--- trunk/Source/WebCore/ChangeLog	2019-01-29 01:58:33 UTC (rev 240631)
+++ trunk/Source/WebCore/ChangeLog	2019-01-29 02:03:45 UTC (rev 240632)
@@ -1,3 +1,20 @@
+2019-01-28  Dean Jackson  <d...@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  <timo...@apple.com>
 
         Make it easier for non-Apple ports to enable dark mode CSS support.

Modified: trunk/Source/WebCore/dom/PointerEvent.h (240631 => 240632)


--- trunk/Source/WebCore/dom/PointerEvent.h	2019-01-29 01:58:33 UTC (rev 240631)
+++ trunk/Source/WebCore/dom/PointerEvent.h	2019-01-29 02:03:45 UTC (rev 240632)
@@ -47,7 +47,7 @@
         long tiltX { 0 };
         long tiltY { 0 };
         long twist { 0 };
-        String pointerType;
+        String pointerType { "mouse"_s };
         bool isPrimary { false };
     };
 
@@ -97,7 +97,7 @@
     long m_tiltX { 0 };
     long m_tiltY { 0 };
     long m_twist { 0 };
-    String m_pointerType;
+    String m_pointerType { "mouse"_s };
     bool m_isPrimary { false };
 };
 

Modified: trunk/Source/WebCore/dom/ios/PointerEventIOS.cpp (240631 => 240632)


--- trunk/Source/WebCore/dom/ios/PointerEventIOS.cpp	2019-01-29 01:58:33 UTC (rev 240631)
+++ trunk/Source/WebCore/dom/ios/PointerEventIOS.cpp	2019-01-29 02:03:45 UTC (rev 240632)
@@ -68,9 +68,17 @@
     , 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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to