Title: [256215] trunk
Revision
256215
Author
[email protected]
Date
2020-02-10 14:38:22 -0800 (Mon, 10 Feb 2020)

Log Message

Standard gamepad mapping for GameControllerGamepads
https://bugs.webkit.org/show_bug.cgi?id=206033

Patch by James Howard <[email protected]> on 2020-02-10
Reviewed by Dean Jackson.
Source/WebCore:

Extend PlatformGamepad to add a field for the gamepad mapping.
The mapping defines the order and interpretation of the axes and
buttons vectors, and is passed along to users of the Gamepad
API[1].

Letting PlatformGamepad subclassers define their mapping is the
natural place for this functionality. The PlatformGamepad
already defines the order of the axes and buttons and
PlatformGamepad subclassers may know something about the
physical layout of the gamepad they represent.

This change modifies the GameControllerGamepad subclass of
PlatformGamepad to set the mapping to "standard" when a
GCExtendedGamepad is detected, and to bind the axes and buttons
appropriately. Previously, the buttons and axes were bound
arbitrarily, and in some cases incompletely. While that wasn't a
bug per se, because with the mapping set to the empty string an
implementation is free to provide any interpretation of the
gamepad elements it likes, it was certainly less useful than the
"standard" mapping.

[1] https://www.w3.org/TR/gamepad/#remapping

* Modules/gamepad/Gamepad.cpp:
(WebCore::Gamepad::Gamepad):
* platform/gamepad/PlatformGamepad.h:
(WebCore::PlatformGamepad::mapping const):
* platform/gamepad/cocoa/GameControllerGamepad.mm:
(WebCore::GameControllerGamepad::setupAsExtendedGamepad):
* testing/MockGamepad.cpp:
(WebCore::MockGamepad::MockGamepad):
(WebCore::MockGamepad::updateDetails):
* testing/MockGamepad.h:
* testing/MockGamepadProvider.cpp:
(WebCore::MockGamepadProvider::setMockGamepadDetails):
* testing/MockGamepadProvider.h:
* testing/js/WebCoreTestSupport.cpp:
(WebCoreTestSupport::setMockGamepadDetails):
* testing/js/WebCoreTestSupport.h:

Source/WebKit:

Make the mapping as provided by PlatformGamepad
available in UIGamepad, and pass it along to
GamepadData so it can be correctly reflected
in the Gamepad API.

* Shared/Gamepad/GamepadData.cpp:
(WebKit::GamepadData::GamepadData):
(WebKit::GamepadData::encode const):
(WebKit::GamepadData::decode):
* Shared/Gamepad/GamepadData.h:
(WebKit::GamepadData::mapping const):
* UIProcess/Gamepad/UIGamepad.cpp:
(WebKit::UIGamepad::UIGamepad):
(WebKit::UIGamepad::fullGamepadData const):
* UIProcess/Gamepad/UIGamepad.h:
* WebProcess/Gamepad/WebGamepad.cpp:
(WebKit::WebGamepad::WebGamepad):

Tools:

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setMockGamepadDetails):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

* gamepad/gamepad-polling-access-expected.txt:
* gamepad/gamepad-polling-access.html:
* gamepad/gamepad-timestamp.html:
* gamepad/gamepad-visibility-1.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (256214 => 256215)


--- trunk/LayoutTests/ChangeLog	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/LayoutTests/ChangeLog	2020-02-10 22:38:22 UTC (rev 256215)
@@ -1,3 +1,15 @@
+2020-02-10  James Howard  <[email protected]>
+
+        Standard gamepad mapping for GameControllerGamepads
+        https://bugs.webkit.org/show_bug.cgi?id=206033
+
+        Reviewed by Dean Jackson.
+
+        * gamepad/gamepad-polling-access-expected.txt:
+        * gamepad/gamepad-polling-access.html:
+        * gamepad/gamepad-timestamp.html:
+        * gamepad/gamepad-visibility-1.html:
+
 2020-02-10  Jason Lawrence  <[email protected]>
 
         [ Mac Debug wk2 ] imported/w3c/web-platform-tests/fetch/api/request/destination/fetch-destination-worker.https.html is flaky crashing.

Modified: trunk/LayoutTests/gamepad/gamepad-polling-access-expected.txt (256214 => 256215)


--- trunk/LayoutTests/gamepad/gamepad-polling-access-expected.txt	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/LayoutTests/gamepad/gamepad-polling-access-expected.txt	2020-02-10 22:38:22 UTC (rev 256215)
@@ -4,6 +4,7 @@
 [object Gamepad]
 Name: 0
 Index: 0
+Mapping: 
 Axes: 
 Buttons: 
 Connecting gamepad:
@@ -10,6 +11,7 @@
 [object Gamepad],[object Gamepad]
 Name: 1
 Index: 1
+Mapping: 
 Axes: 0
 Buttons: false-0 
 Connecting gamepad:
@@ -16,6 +18,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad]
 Name: 2
 Index: 2
+Mapping: 
 Axes: 0,0
 Buttons: false-0 false-0 
 Connecting gamepad:
@@ -22,6 +25,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 3
 Index: 3
+Mapping: 
 Axes: 0,0,0
 Buttons: false-0 false-0 false-0 
 Connecting gamepad:
@@ -28,6 +32,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 4
 Index: 4
+Mapping: 
 Axes: 0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -34,6 +39,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 5
 Index: 5
+Mapping: 
 Axes: 0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -40,6 +46,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 6
 Index: 6
+Mapping: 
 Axes: 0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -46,6 +53,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 7
 Index: 7
+Mapping: 
 Axes: 0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -52,6 +60,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 8
 Index: 8
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -58,6 +67,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 9
 Index: 9
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -64,6 +74,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 10
 Index: 10
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -70,6 +81,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 11
 Index: 11
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -76,6 +88,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 12
 Index: 12
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -82,6 +95,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 13
 Index: 13
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -88,6 +102,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 14
 Index: 14
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -94,6 +109,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 15
 Index: 15
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0
 Connecting gamepad:
@@ -100,6 +116,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 16
 Index: 16
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -106,6 +123,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 17
 Index: 17
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -112,6 +130,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 18
 Index: 18
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Connecting gamepad:
@@ -118,6 +137,7 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 19
 Index: 19
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Verifying there are 20 connected gamepads in the set of all gamepads
@@ -124,82 +144,102 @@
 [object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad],[object Gamepad]
 Name: 0
 Index: 0
+Mapping: 
 Axes: 
 Buttons: 
 Name: 1
 Index: 1
+Mapping: 
 Axes: 0
 Buttons: false-0 
 Name: 2
 Index: 2
+Mapping: 
 Axes: 0,0
 Buttons: false-0 false-0 
 Name: 3
 Index: 3
+Mapping: 
 Axes: 0,0,0
 Buttons: false-0 false-0 false-0 
 Name: 4
 Index: 4
+Mapping: 
 Axes: 0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 
 Name: 5
 Index: 5
+Mapping: 
 Axes: 0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 
 Name: 6
 Index: 6
+Mapping: 
 Axes: 0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 7
 Index: 7
+Mapping: 
 Axes: 0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 8
 Index: 8
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 9
 Index: 9
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 10
 Index: 10
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 11
 Index: 11
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 12
 Index: 12
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 13
 Index: 13
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 14
 Index: 14
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 15
 Index: 15
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0
 Name: 16
 Index: 16
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 17
 Index: 17
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 18
 Index: 18
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Name: 19
 Index: 19
+Mapping: 
 Axes: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 Buttons: false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 false-0 
 Disconnecting gamepads in reverse order, making sure gamepads array remains as expected
@@ -248,6 +288,7 @@
 ,,,,,,,,,,[object Gamepad],,,,,,,,,
 Name: Awesome Joystick 5000
 Index: 10
+Mapping: standard
 Axes: 0.7,-0.9,1,-1
-Buttons: true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 
+Buttons: true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 true-1 
 

Modified: trunk/LayoutTests/gamepad/gamepad-polling-access.html (256214 => 256215)


--- trunk/LayoutTests/gamepad/gamepad-polling-access.html	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/LayoutTests/gamepad/gamepad-polling-access.html	2020-02-10 22:38:22 UTC (rev 256215)
@@ -36,6 +36,7 @@
 {
     log("Name: " + gp.id);
     log("Index: " + gp.index);
+    log("Mapping: " + gp.mapping);
     log("Axes: " + gp.axes);
     
     var buttonString = "";
@@ -53,7 +54,7 @@
     log("Initial gamepads length: " + navigator.getGamepads().length);
     log("Connecting 20 different gamepads");
     for (var i = 0; i < 20; ++i) {
-        testRunner.setMockGamepadDetails(i, i, i, i);
+        testRunner.setMockGamepadDetails(i, i, "", i, i);
         testRunner.connectMockGamepad(i);
         yield;
     }
@@ -73,12 +74,12 @@
 
     log("Checking non-zero'ed details for a gamepad");
 
-    testRunner.setMockGamepadDetails(10, "Awesome Joystick 5000", 4, 20);
+    testRunner.setMockGamepadDetails(10, "Awesome Joystick 5000", "standard", 4, 16);
     testRunner.setMockGamepadAxisValue(10, 0, 0.7);
     testRunner.setMockGamepadAxisValue(10, 1, -0.9);
     testRunner.setMockGamepadAxisValue(10, 2, 1.0);
     testRunner.setMockGamepadAxisValue(10, 3, -1.0);
-    for (var i = 0; i < 20; ++i)
+    for (var i = 0; i < 16; ++i)
         testRunner.setMockGamepadButtonValue(10, i, 1.0);
         
     testRunner.connectMockGamepad(10);

Modified: trunk/LayoutTests/gamepad/gamepad-timestamp.html (256214 => 256215)


--- trunk/LayoutTests/gamepad/gamepad-timestamp.html	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/LayoutTests/gamepad/gamepad-timestamp.html	2020-02-10 22:38:22 UTC (rev 256215)
@@ -72,13 +72,13 @@
 function runTest() {
     addEventListener("gamepadconnected", handleGamepadConnect);
 
-    testRunner.setMockGamepadDetails(0, "Test Joystick", 2, 2);
+    testRunner.setMockGamepadDetails(0, "Test Joystick", "", 2, 2);
     testRunner.setMockGamepadAxisValue(0, 0, 0.7);
     testRunner.setMockGamepadAxisValue(0, 1, -1.0);
     testRunner.setMockGamepadButtonValue(0, 0, 1.0);
     testRunner.setMockGamepadButtonValue(0, 1, 1.0);
     testRunner.connectMockGamepad(0);
-    testRunner.setMockGamepadDetails(1, "Test Joystick 2", 2, 2);
+    testRunner.setMockGamepadDetails(1, "Test Joystick 2", "", 2, 2);
     testRunner.setMockGamepadAxisValue(1, 0, 0.7);
     testRunner.setMockGamepadAxisValue(1, 1, -1.0);
     testRunner.setMockGamepadButtonValue(1, 0, 1.0);

Modified: trunk/LayoutTests/gamepad/gamepad-visibility-1.html (256214 => 256215)


--- trunk/LayoutTests/gamepad/gamepad-visibility-1.html	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/LayoutTests/gamepad/gamepad-visibility-1.html	2020-02-10 22:38:22 UTC (rev 256215)
@@ -41,7 +41,7 @@
 
     // Connecting the gamepad and changing axis values should *not* make it visible.
     // Only button presses should expose it.
-    testRunner.setMockGamepadDetails(0, "Test Joystick", 2, 2);
+    testRunner.setMockGamepadDetails(0, "Test Joystick", "", 2, 2);
     testRunner.connectMockGamepad(0);
     testRunner.setMockGamepadAxisValue(0, 0, 0.7);
     testRunner.setMockGamepadAxisValue(0, 1, -1.0);

Modified: trunk/Source/WTF/wtf/PlatformHave.h (256214 => 256215)


--- trunk/Source/WTF/wtf/PlatformHave.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -584,3 +584,11 @@
 #if PLATFORM(WATCHOS) || PLATFORM(APPLETV) || (PLATFORM(IOS_FAMILY) && !(defined __has_include && __has_include(<CoreFoundation/CFPriv.h>)))
 #define HAVE_NSPROGRESS_PUBLISHING_SPI 1
 #endif
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
+#define HAVE_GCEXTENDEDGAMEPAD_BUTTONS_OPTIONS_MENU 1
+#endif
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS_FAMILY))
+#define HAVE_GCEXTENDEDGAMEPAD_BUTTONS_THUMBSTICK 1
+#endif

Modified: trunk/Source/WebCore/ChangeLog (256214 => 256215)


--- trunk/Source/WebCore/ChangeLog	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/ChangeLog	2020-02-10 22:38:22 UTC (rev 256215)
@@ -1,3 +1,50 @@
+2020-02-10  James Howard  <[email protected]>
+
+        Standard gamepad mapping for GameControllerGamepads
+        https://bugs.webkit.org/show_bug.cgi?id=206033
+
+        Reviewed by Dean Jackson.
+
+        Extend PlatformGamepad to add a field for the gamepad mapping.
+        The mapping defines the order and interpretation of the axes and
+        buttons vectors, and is passed along to users of the Gamepad
+        API[1].
+
+        Letting PlatformGamepad subclassers define their mapping is the
+        natural place for this functionality. The PlatformGamepad
+        already defines the order of the axes and buttons and
+        PlatformGamepad subclassers may know something about the
+        physical layout of the gamepad they represent.
+
+        This change modifies the GameControllerGamepad subclass of
+        PlatformGamepad to set the mapping to "standard" when a
+        GCExtendedGamepad is detected, and to bind the axes and buttons
+        appropriately. Previously, the buttons and axes were bound
+        arbitrarily, and in some cases incompletely. While that wasn't a
+        bug per se, because with the mapping set to the empty string an
+        implementation is free to provide any interpretation of the
+        gamepad elements it likes, it was certainly less useful than the
+        "standard" mapping.
+
+        [1] https://www.w3.org/TR/gamepad/#remapping
+
+        * Modules/gamepad/Gamepad.cpp:
+        (WebCore::Gamepad::Gamepad):
+        * platform/gamepad/PlatformGamepad.h:
+        (WebCore::PlatformGamepad::mapping const):
+        * platform/gamepad/cocoa/GameControllerGamepad.mm:
+        (WebCore::GameControllerGamepad::setupAsExtendedGamepad):
+        * testing/MockGamepad.cpp:
+        (WebCore::MockGamepad::MockGamepad):
+        (WebCore::MockGamepad::updateDetails):
+        * testing/MockGamepad.h:
+        * testing/MockGamepadProvider.cpp:
+        (WebCore::MockGamepadProvider::setMockGamepadDetails):
+        * testing/MockGamepadProvider.h:
+        * testing/js/WebCoreTestSupport.cpp:
+        (WebCoreTestSupport::setMockGamepadDetails):
+        * testing/js/WebCoreTestSupport.h:
+
 2020-02-07  Ryosuke Niwa  <[email protected]>
 
         Don't update selection when calling setSelectionRange on a disconnected input element

Modified: trunk/Source/WebCore/Modules/gamepad/Gamepad.cpp (256214 => 256215)


--- trunk/Source/WebCore/Modules/gamepad/Gamepad.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/Modules/gamepad/Gamepad.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -39,6 +39,7 @@
     , m_index(platformGamepad.index())
     , m_connected(true)
     , m_timestamp(platformGamepad.lastUpdateTime())
+    , m_mapping(platformGamepad.mapping())
     , m_axes(platformGamepad.axisValues().size(), 0.0)
 {
     unsigned buttonCount = platformGamepad.buttonValues().size();

Modified: trunk/Source/WebCore/platform/gamepad/PlatformGamepad.h (256214 => 256215)


--- trunk/Source/WebCore/platform/gamepad/PlatformGamepad.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/platform/gamepad/PlatformGamepad.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -39,6 +39,7 @@
     virtual ~PlatformGamepad() = default;
 
     const String& id() const { return m_id; }
+    const String& mapping() const { return m_mapping; }
     unsigned index() const { return m_index; }
     MonotonicTime lastUpdateTime() const { return m_lastUpdateTime; }
     MonotonicTime connectTime() const { return m_connectTime; }
@@ -52,6 +53,7 @@
     }
 
     String m_id;
+    String m_mapping;
     unsigned m_index;
     MonotonicTime m_lastUpdateTime;
     MonotonicTime m_connectTime;

Modified: trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm (256214 => 256215)


--- trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/platform/gamepad/cocoa/GameControllerGamepad.mm	2020-02-10 22:38:22 UTC (rev 256215)
@@ -58,6 +58,7 @@
     ASSERT(m_extendedGamepad);
 
     m_id = makeString(String(m_gcController.get().vendorName), " Extended Gamepad"_s);
+    m_mapping = String("standard");
 
     m_extendedGamepad.get().valueChangedHandler = ^(GCExtendedGamepad *, GCControllerElement *) {
         m_lastUpdateTime = MonotonicTime::now();
@@ -65,83 +66,71 @@
         m_hadButtonPresses = false;
     };
 
-    m_buttonValues.resize(8);
-    m_buttonValues[0] = m_extendedGamepad.get().buttonA.value;
-    m_buttonValues[1] = m_extendedGamepad.get().buttonB.value;
-    m_buttonValues[2] = m_extendedGamepad.get().buttonX.value;
-    m_buttonValues[3] = m_extendedGamepad.get().buttonY.value;
-    m_buttonValues[4] = m_extendedGamepad.get().leftShoulder.value;
-    m_buttonValues[5] = m_extendedGamepad.get().rightShoulder.value;
-    m_buttonValues[6] = m_extendedGamepad.get().leftTrigger.value;
-    m_buttonValues[7] = m_extendedGamepad.get().rightTrigger.value;
+    m_buttonValues.resize(16);
 
-    m_axisValues.resize(6);
+    auto bindButton = ^(GCControllerButtonInput *button, size_t idx) {
+        m_buttonValues[idx] = button.value;
+        button.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
+            m_buttonValues[idx] = value;
+            if (pressed)
+                m_hadButtonPresses = true;
+        };
+    };
+
+    // Button Pad
+    bindButton(m_extendedGamepad.get().buttonA, 0);
+    bindButton(m_extendedGamepad.get().buttonB, 1);
+    bindButton(m_extendedGamepad.get().buttonX, 2);
+    bindButton(m_extendedGamepad.get().buttonY, 3);
+
+    // Shoulders, Triggers
+    bindButton(m_extendedGamepad.get().leftShoulder, 4);
+    bindButton(m_extendedGamepad.get().rightShoulder, 5);
+    bindButton(m_extendedGamepad.get().leftTrigger, 6);
+    bindButton(m_extendedGamepad.get().rightTrigger, 7);
+
+    // D Pad
+    bindButton(m_extendedGamepad.get().dpad.up, 12);
+    bindButton(m_extendedGamepad.get().dpad.down, 13);
+    bindButton(m_extendedGamepad.get().dpad.left, 14);
+    bindButton(m_extendedGamepad.get().dpad.right, 15);
+
+    // Select, Start
+#if HAVE(GCEXTENDEDGAMEPAD_BUTTONS_OPTIONS_MENU)
+    bindButton(m_extendedGamepad.get().buttonOptions, 8);
+    bindButton(m_extendedGamepad.get().buttonMenu, 9);
+#endif
+
+    // L3, R3
+#if HAVE(GCEXTENDEDGAMEPAD_BUTTONS_THUMBSTICK)
+    // Thumbstick buttons are only in macOS 10.14.1 / iOS 12.1
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability"
+    if ([m_extendedGamepad.get() respondsToSelector:@selector(leftThumbstickButton)]) {
+        bindButton(m_extendedGamepad.get().leftThumbstickButton, 10);
+        bindButton(m_extendedGamepad.get().rightThumbstickButton, 11);
+    }
+#pragma clang diagnostic pop
+#endif
+
+    m_axisValues.resize(4);
     m_axisValues[0] = m_extendedGamepad.get().leftThumbstick.xAxis.value;
-    m_axisValues[1] = m_extendedGamepad.get().leftThumbstick.yAxis.value;
+    m_axisValues[1] = -m_extendedGamepad.get().leftThumbstick.yAxis.value;
     m_axisValues[2] = m_extendedGamepad.get().rightThumbstick.xAxis.value;
-    m_axisValues[3] = m_extendedGamepad.get().rightThumbstick.yAxis.value;
-    m_axisValues[4] = m_extendedGamepad.get().dpad.xAxis.value;
-    m_axisValues[5] = m_extendedGamepad.get().dpad.yAxis.value;
+    m_axisValues[3] = -m_extendedGamepad.get().rightThumbstick.yAxis.value;
 
-    m_extendedGamepad.get().buttonA.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[0] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-    m_extendedGamepad.get().buttonB.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[1] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-    m_extendedGamepad.get().buttonX.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[2] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-    m_extendedGamepad.get().buttonY.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[3] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-    m_extendedGamepad.get().leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[4] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-    m_extendedGamepad.get().rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[5] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-    m_extendedGamepad.get().leftTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[6] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-    m_extendedGamepad.get().rightTrigger.valueChangedHandler = ^(GCControllerButtonInput *, float value, BOOL pressed) {
-        m_buttonValues[7] = value;
-        if (pressed)
-            m_hadButtonPresses = true;
-    };
-
     m_extendedGamepad.get().leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
         m_axisValues[0] = value;
     };
     m_extendedGamepad.get().leftThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
-        m_axisValues[1] = value;
+        m_axisValues[1] = -value;
     };
     m_extendedGamepad.get().rightThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
         m_axisValues[2] = value;
     };
     m_extendedGamepad.get().rightThumbstick.yAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
-        m_axisValues[3] = value;
+        m_axisValues[3] = -value;
     };
-    m_extendedGamepad.get().dpad.xAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
-        m_axisValues[4] = value;
-    };
-    m_extendedGamepad.get().dpad.yAxis.valueChangedHandler = ^(GCControllerAxisInput *, float value) {
-        m_axisValues[5] = value;
-    };
 }
 
 void GameControllerGamepad::setupAsGamepad()

Modified: trunk/Source/WebCore/testing/MockGamepad.cpp (256214 => 256215)


--- trunk/Source/WebCore/testing/MockGamepad.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/testing/MockGamepad.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -30,16 +30,17 @@
 
 namespace WebCore {
 
-MockGamepad::MockGamepad(unsigned index, const String& gamepadID, unsigned axisCount, unsigned buttonCount)
+MockGamepad::MockGamepad(unsigned index, const String& gamepadID, const String& mapping, unsigned axisCount, unsigned buttonCount)
     : PlatformGamepad(index)
 {
     m_connectTime = m_lastUpdateTime = MonotonicTime::now();
-    updateDetails(gamepadID, axisCount, buttonCount);
+    updateDetails(gamepadID, mapping, axisCount, buttonCount);
 }
 
-void MockGamepad::updateDetails(const String& gamepadID, unsigned axisCount, unsigned buttonCount)
+void MockGamepad::updateDetails(const String& gamepadID, const String& mapping, unsigned axisCount, unsigned buttonCount)
 {
     m_id = gamepadID;
+    m_mapping = mapping;
     m_axisValues = Vector<double>(axisCount, 0.0);
     m_buttonValues = Vector<double>(buttonCount, 0.0);
     m_lastUpdateTime = MonotonicTime::now();

Modified: trunk/Source/WebCore/testing/MockGamepad.h (256214 => 256215)


--- trunk/Source/WebCore/testing/MockGamepad.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/testing/MockGamepad.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -33,12 +33,12 @@
 
 class MockGamepad : public PlatformGamepad {
 public:
-    MockGamepad(unsigned index, const String& gamepadID, unsigned axisCount, unsigned buttonCount);
+    MockGamepad(unsigned index, const String& gamepadID, const String& mapping, unsigned axisCount, unsigned buttonCount);
 
     const Vector<double>& axisValues() const final { return m_axisValues; }
     const Vector<double>& buttonValues() const final { return m_buttonValues; }
 
-    void updateDetails(const String& gamepadID, unsigned axisCount, unsigned buttonCount);
+    void updateDetails(const String& gamepadID, const String& mapping, unsigned axisCount, unsigned buttonCount);
     bool setAxisValue(unsigned index, double value);
     bool setButtonValue(unsigned index, double value);
 

Modified: trunk/Source/WebCore/testing/MockGamepadProvider.cpp (256214 => 256215)


--- trunk/Source/WebCore/testing/MockGamepadProvider.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/testing/MockGamepadProvider.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -55,15 +55,15 @@
     m_clients.remove(&client);
 }
 
-void MockGamepadProvider::setMockGamepadDetails(unsigned index, const String& gamepadID, unsigned axisCount, unsigned buttonCount)
+void MockGamepadProvider::setMockGamepadDetails(unsigned index, const String& gamepadID, const String& mapping, unsigned axisCount, unsigned buttonCount)
 {
     if (index >= m_mockGamepadVector.size())
         m_mockGamepadVector.resize(index + 1);
 
     if (m_mockGamepadVector[index])
-        m_mockGamepadVector[index]->updateDetails(gamepadID, axisCount, buttonCount);
+        m_mockGamepadVector[index]->updateDetails(gamepadID, mapping, axisCount, buttonCount);
     else
-        m_mockGamepadVector[index] = makeUnique<MockGamepad>(index, gamepadID, axisCount, buttonCount);
+        m_mockGamepadVector[index] = makeUnique<MockGamepad>(index, gamepadID, mapping, axisCount, buttonCount);
 }
 
 bool MockGamepadProvider::connectMockGamepad(unsigned index)

Modified: trunk/Source/WebCore/testing/MockGamepadProvider.h (256214 => 256215)


--- trunk/Source/WebCore/testing/MockGamepadProvider.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/testing/MockGamepadProvider.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -44,7 +44,7 @@
     const Vector<PlatformGamepad*>& platformGamepads() final { return m_connectedGamepadVector; }
     bool isMockGamepadProvider() const final { return true; }
 
-    void setMockGamepadDetails(unsigned index, const String& gamepadID, unsigned axisCount, unsigned buttonCount);
+    void setMockGamepadDetails(unsigned index, const String& gamepadID, const String& mapping, unsigned axisCount, unsigned buttonCount);
     bool setMockGamepadAxisValue(unsigned index, unsigned axisIndex, double value);
     bool setMockGamepadButtonValue(unsigned index, unsigned buttonIndex, double value);
     bool connectMockGamepad(unsigned index);

Modified: trunk/Source/WebCore/testing/js/WebCoreTestSupport.cpp (256214 => 256215)


--- trunk/Source/WebCore/testing/js/WebCoreTestSupport.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/testing/js/WebCoreTestSupport.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -164,13 +164,14 @@
 #endif
 }
 
-void setMockGamepadDetails(unsigned gamepadIndex, const WTF::String& gamepadID, unsigned axisCount, unsigned buttonCount)
+void setMockGamepadDetails(unsigned gamepadIndex, const WTF::String& gamepadID, const WTF::String& mapping, unsigned axisCount, unsigned buttonCount)
 {
 #if ENABLE(GAMEPAD)
-    MockGamepadProvider::singleton().setMockGamepadDetails(gamepadIndex, gamepadID, axisCount, buttonCount);
+    MockGamepadProvider::singleton().setMockGamepadDetails(gamepadIndex, gamepadID, mapping, axisCount, buttonCount);
 #else
     UNUSED_PARAM(gamepadIndex);
     UNUSED_PARAM(gamepadID);
+    UNUSED_PARAM(mapping);
     UNUSED_PARAM(axisCount);
     UNUSED_PARAM(buttonCount);
 #endif

Modified: trunk/Source/WebCore/testing/js/WebCoreTestSupport.h (256214 => 256215)


--- trunk/Source/WebCore/testing/js/WebCoreTestSupport.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebCore/testing/js/WebCoreTestSupport.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -58,7 +58,7 @@
 void installMockGamepadProvider() TEST_SUPPORT_EXPORT;
 void connectMockGamepad(unsigned index) TEST_SUPPORT_EXPORT;
 void disconnectMockGamepad(unsigned index) TEST_SUPPORT_EXPORT;
-void setMockGamepadDetails(unsigned index, const WTF::String& gamepadID, unsigned axisCount, unsigned buttonCount) TEST_SUPPORT_EXPORT;
+void setMockGamepadDetails(unsigned index, const WTF::String& gamepadID, const WTF::String& mapping, unsigned axisCount, unsigned buttonCount) TEST_SUPPORT_EXPORT;
 void setMockGamepadAxisValue(unsigned index, unsigned axisIndex, double value) TEST_SUPPORT_EXPORT;
 void setMockGamepadButtonValue(unsigned index, unsigned buttonIndex, double value) TEST_SUPPORT_EXPORT;
 

Modified: trunk/Source/WebKit/ChangeLog (256214 => 256215)


--- trunk/Source/WebKit/ChangeLog	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebKit/ChangeLog	2020-02-10 22:38:22 UTC (rev 256215)
@@ -1,3 +1,28 @@
+2020-02-10  James Howard  <[email protected]>
+
+        Standard gamepad mapping for GameControllerGamepads
+        https://bugs.webkit.org/show_bug.cgi?id=206033
+
+        Reviewed by Dean Jackson.
+        
+        Make the mapping as provided by PlatformGamepad
+        available in UIGamepad, and pass it along to
+        GamepadData so it can be correctly reflected
+        in the Gamepad API.
+
+        * Shared/Gamepad/GamepadData.cpp:
+        (WebKit::GamepadData::GamepadData):
+        (WebKit::GamepadData::encode const):
+        (WebKit::GamepadData::decode):
+        * Shared/Gamepad/GamepadData.h:
+        (WebKit::GamepadData::mapping const):
+        * UIProcess/Gamepad/UIGamepad.cpp:
+        (WebKit::UIGamepad::UIGamepad):
+        (WebKit::UIGamepad::fullGamepadData const):
+        * UIProcess/Gamepad/UIGamepad.h:
+        * WebProcess/Gamepad/WebGamepad.cpp:
+        (WebKit::WebGamepad::WebGamepad):
+
 2020-02-10  Daniel Bates  <[email protected]>
 
         Disallow setting base URL to a data or _javascript_ URL

Modified: trunk/Source/WebKit/Shared/Gamepad/GamepadData.cpp (256214 => 256215)


--- trunk/Source/WebKit/Shared/Gamepad/GamepadData.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebKit/Shared/Gamepad/GamepadData.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -41,9 +41,10 @@
 {
 }
 
-GamepadData::GamepadData(unsigned index, const String& id, const Vector<double>& axisValues, const Vector<double>& buttonValues, MonotonicTime lastUpdateTime)
+GamepadData::GamepadData(unsigned index, const String& id, const String& mapping, const Vector<double>& axisValues, const Vector<double>& buttonValues, MonotonicTime lastUpdateTime)
     : m_index(index)
     , m_id(id)
+    , m_mapping(mapping)
     , m_axisValues(axisValues)
     , m_buttonValues(buttonValues)
     , m_lastUpdateTime(lastUpdateTime)
@@ -56,7 +57,7 @@
     if (m_isNull)
         return;
 
-    encoder << m_index << m_id << m_axisValues << m_buttonValues << m_lastUpdateTime;
+    encoder << m_index << m_id << m_mapping << m_axisValues << m_buttonValues << m_lastUpdateTime;
 }
 
 Optional<GamepadData> GamepadData::decode(IPC::Decoder& decoder)
@@ -74,6 +75,9 @@
     if (!decoder.decode(data.m_id))
         return WTF::nullopt;
 
+    if (!decoder.decode(data.m_mapping))
+        return WTF::nullopt;
+
     if (!decoder.decode(data.m_axisValues))
         return WTF::nullopt;
 

Modified: trunk/Source/WebKit/Shared/Gamepad/GamepadData.h (256214 => 256215)


--- trunk/Source/WebKit/Shared/Gamepad/GamepadData.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebKit/Shared/Gamepad/GamepadData.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -46,7 +46,7 @@
     }
 
     GamepadData(unsigned index, const Vector<double>& axisValues, const Vector<double>& buttonValues, MonotonicTime lastUpdateTime);
-    GamepadData(unsigned index, const String& id, const Vector<double>& axisValues, const Vector<double>& buttonValues, MonotonicTime lastUpdateTime);
+    GamepadData(unsigned index, const String& id, const String& mapping, const Vector<double>& axisValues, const Vector<double>& buttonValues, MonotonicTime lastUpdateTime);
 
     void encode(IPC::Encoder&) const;
     static Optional<GamepadData> decode(IPC::Decoder&);
@@ -56,6 +56,7 @@
     MonotonicTime lastUpdateTime() const { return m_lastUpdateTime; }
     unsigned index() const { return m_index; }
     const String& id() const { return m_id; }
+    const String& mapping() const { return m_mapping; }
     const Vector<double>& axisValues() const { return m_axisValues; }
     const Vector<double>& buttonValues() const { return m_buttonValues; }
 
@@ -62,6 +63,7 @@
 private:
     unsigned m_index;
     String m_id;
+    String m_mapping;
     Vector<double> m_axisValues;
     Vector<double> m_buttonValues;
     MonotonicTime m_lastUpdateTime;

Modified: trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.cpp (256214 => 256215)


--- trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -37,6 +37,7 @@
 UIGamepad::UIGamepad(WebCore::PlatformGamepad& platformGamepad)
     : m_index(platformGamepad.index())
     , m_id(platformGamepad.id())
+    , m_mapping(platformGamepad.mapping())
     , m_lastUpdateTime(platformGamepad.lastUpdateTime())
 {
     m_axisValues.resize(platformGamepad.axisValues().size());
@@ -63,7 +64,7 @@
 
 GamepadData UIGamepad::fullGamepadData() const
 {
-    return { m_index, m_id, m_axisValues, m_buttonValues, m_lastUpdateTime };
+    return { m_index, m_id, m_mapping, m_axisValues, m_buttonValues, m_lastUpdateTime };
 }
 
 

Modified: trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.h (256214 => 256215)


--- trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebKit/UIProcess/Gamepad/UIGamepad.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -54,6 +54,7 @@
 private:
     unsigned m_index;
     String m_id;
+    String m_mapping;
     Vector<double> m_axisValues;
     Vector<double> m_buttonValues;
     MonotonicTime m_lastUpdateTime;

Modified: trunk/Source/WebKit/WebProcess/Gamepad/WebGamepad.cpp (256214 => 256215)


--- trunk/Source/WebKit/WebProcess/Gamepad/WebGamepad.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Source/WebKit/WebProcess/Gamepad/WebGamepad.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -40,6 +40,7 @@
     LOG(Gamepad, "Connecting WebGamepad %u", gamepadData.index());
 
     m_id = gamepadData.id();
+    m_mapping = gamepadData.mapping();
     m_axisValues.resize(gamepadData.axisValues().size());
     m_buttonValues.resize(gamepadData.buttonValues().size());
 

Modified: trunk/Tools/ChangeLog (256214 => 256215)


--- trunk/Tools/ChangeLog	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Tools/ChangeLog	2020-02-10 22:38:22 UTC (rev 256215)
@@ -1,3 +1,17 @@
+2020-02-10  James Howard  <[email protected]>
+
+        Standard gamepad mapping for GameControllerGamepads
+        https://bugs.webkit.org/show_bug.cgi?id=206033
+
+        Reviewed by Dean Jackson.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::setMockGamepadDetails):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2020-02-10  Aakash Jain  <[email protected]>
 
         [ews] Display flaky layout test names in build summary

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (256214 => 256215)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2020-02-10 22:38:22 UTC (rev 256215)
@@ -285,7 +285,7 @@
     void installCustomMenuAction(DOMString name, boolean dismissesAutomatically, object callback);
 
     // Gamepad
-    void setMockGamepadDetails(unsigned long index, DOMString id, unsigned long axisCount, unsigned long buttonCount);
+    void setMockGamepadDetails(unsigned long index, DOMString id, DOMString mapping, unsigned long axisCount, unsigned long buttonCount);
     void setMockGamepadAxisValue(unsigned long index, unsigned long axisIndex, double value);
     void setMockGamepadButtonValue(unsigned long index, unsigned long buttonIndex, double value);
     void connectMockGamepad(unsigned long index);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (256214 => 256215)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -2450,7 +2450,7 @@
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
 
-void TestRunner::setMockGamepadDetails(unsigned index, JSStringRef gamepadID, unsigned axisCount, unsigned buttonCount)
+void TestRunner::setMockGamepadDetails(unsigned index, JSStringRef gamepadID, JSStringRef mapping, unsigned axisCount, unsigned buttonCount)
 {
     Vector<WKRetainPtr<WKStringRef>> keys;
     Vector<WKRetainPtr<WKTypeRef>> values;
@@ -2458,6 +2458,9 @@
     keys.append(adoptWK(WKStringCreateWithUTF8CString("GamepadID")));
     values.append(toWK(gamepadID));
 
+    keys.append(adoptWK(WKStringCreateWithUTF8CString("Mapping")));
+    values.append(toWK(mapping));
+
     keys.append(adoptWK(WKStringCreateWithUTF8CString("GamepadIndex")));
     values.append(adoptWK(WKUInt64Create(index)));
 
@@ -2551,7 +2554,7 @@
 {
 }
 
-void TestRunner::setMockGamepadDetails(unsigned, JSStringRef, unsigned, unsigned)
+void TestRunner::setMockGamepadDetails(unsigned, JSStringRef, JSStringRef, unsigned, unsigned)
 {
 }
 

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (256214 => 256215)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2020-02-10 22:38:22 UTC (rev 256215)
@@ -375,7 +375,7 @@
     // Gamepads
     void connectMockGamepad(unsigned index);
     void disconnectMockGamepad(unsigned index);
-    void setMockGamepadDetails(unsigned index, JSStringRef gamepadID, unsigned axisCount, unsigned buttonCount);
+    void setMockGamepadDetails(unsigned index, JSStringRef gamepadID, JSStringRef mapping, unsigned axisCount, unsigned buttonCount);
     void setMockGamepadAxisValue(unsigned index, unsigned axisIndex, double value);
     void setMockGamepadButtonValue(unsigned index, unsigned buttonIndex, double value);
     

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (256214 => 256215)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2020-02-10 22:27:47 UTC (rev 256214)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2020-02-10 22:38:22 UTC (rev 256215)
@@ -1029,15 +1029,17 @@
         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
         WKRetainPtr<WKStringRef> gamepadIndexKey = adoptWK(WKStringCreateWithUTF8CString("GamepadIndex"));
         WKRetainPtr<WKStringRef> gamepadIDKey = adoptWK(WKStringCreateWithUTF8CString("GamepadID"));
+        WKRetainPtr<WKStringRef> mappingKey = adoptWK(WKStringCreateWithUTF8CString("Mapping"));
         WKRetainPtr<WKStringRef> axisCountKey = adoptWK(WKStringCreateWithUTF8CString("AxisCount"));
         WKRetainPtr<WKStringRef> buttonCountKey = adoptWK(WKStringCreateWithUTF8CString("ButtonCount"));
 
         WKUInt64Ref gamepadIndex = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIndexKey.get()));
         WKStringRef gamepadID = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, gamepadIDKey.get()));
+        WKStringRef mapping = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, mappingKey.get()));
         WKUInt64Ref axisCount = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, axisCountKey.get()));
         WKUInt64Ref buttonCount = static_cast<WKUInt64Ref>(WKDictionaryGetItemForKey(messageBodyDictionary, buttonCountKey.get()));
 
-        WebCoreTestSupport::setMockGamepadDetails(WKUInt64GetValue(gamepadIndex), toWTFString(gamepadID), WKUInt64GetValue(axisCount), WKUInt64GetValue(buttonCount));
+        WebCoreTestSupport::setMockGamepadDetails(WKUInt64GetValue(gamepadIndex), toWTFString(gamepadID), toWTFString(mapping), WKUInt64GetValue(axisCount), WKUInt64GetValue(buttonCount));
         return nullptr;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to