diff --git a/index.html b/index.html index 6820d0e..c1b3665 100644 --- a/index.html +++ b/index.html @@ -147,6 +147,11 @@
[Exposed=Window, SecureContext] interface Gamepad { + attribute EventHandler onbuttondown; + attribute EventHandler onbuttonup; + attribute EventHandler onbuttonchange; + attribute EventHandler onaxischange; + readonly attribute DOMString id; readonly attribute long index; readonly attribute boolean connected; @@ -304,6 +309,34 @@
+
- + onbuttondown attribute +
+- + {{Gamepad/onbuttondown}} is an [=event handler IDL attribute=] for + the {{buttondown}} event type. +
+- + onbuttonup attribute +
+- + {{Gamepad/onbuttonup}} is an [=event handler IDL attribute=] for the + {{buttonup}} event type. +
+- + onbuttonchange attribute +
+- + {{Gamepad/onbuttonchange}} is an [=event handler IDL attribute=] for + the {{buttonchange}} event type. +
+- + onaxischange attribute +
+- + {{Gamepad/onaxischange}} is an [=event handler IDL attribute=] for + the {{axischange}} event type. +
- id attribute
@@ -470,6 +503,27 @@following steps:
+
+- Initialize |oldAxisValues:list| to be an empty [=list=]. +
+- [=list/For each=] |axis:double| of + |gamepad|.{{Gamepad/[[axes]]}}, [=list/append=] |axis| to + |oldAxisValues|. +
+- Initialize |oldButtonValues:list| to be an empty [=list=]. +
+- Initialize |oldButtonPressed:list| to be an empty [=list=]. +
+- [=list/For each=] |button:GamepadButton| of + |gamepad|.{{Gamepad/[[buttons]]}}: +
+
+- [=list/Append=] |button|.{{GamepadButton/value}} to + |oldButtonValues|. +
+- [=list/Append=] |button|.{{GamepadButton/pressed}} to + |oldButtonPressed|. +
+- Let |now:DOMHighResTimeStamp| be the [=current high resolution time=].
@@ -516,6 +570,99 @@
+ If |button|.{{GamepadButton/pressed}} is `true`, [=queue + a task=] on the [=gamepad task source=] to [=fire an + event=] named {{buttondown}} at |gamepad| using + {{GamepadButtonEvent}} with its + {{GamepadButtonEvent/gamepadIndex}} attribute initialized + to |gamepad|.{{Gamepad/index}}, its + {{GamepadButtonEvent/buttonIndex}} attribute initialized + to |buttonIndex|, its + {{GamepadButtonEvent/buttonSnapshot}} attribute + initialized to |buttonCopy|, and its + {{GamepadButtonEvent/gamepadTimestamp}} attribute + initialized to |now|. +
++ Otherwise, [=queue a task=] on the [=gamepad task + source=] to [=fire an event=] named {{buttonup}} at + |gamepad| using {{GamepadButtonEvent}} with its + {{GamepadButtonEvent/gamepadIndex}} attribute initialized + to |gamepad|.{{Gamepad/index}}, its + {{GamepadButtonEvent/buttonIndex}} attribute initialized + to |buttonIndex|, its + {{GamepadButtonEvent/buttonSnapshot}} attribute + initialized to |buttonCopy|, and its + {{GamepadButtonEvent/gamepadTimestamp}} attribute + initialized to |now|. +
+To map and normalize axes for |gamepad:Gamepad|, run the @@ -1207,6 +1354,173 @@
+ [Exposed=Window, SecureContext] + + interface GamepadAxisEvent: Event { + constructor(DOMString type, GamepadAxisEventInit eventInitDict); + readonly attribute long gamepadIndex; + readonly attribute long axisIndex; + readonly attribute double axisSnapshot; + readonly attribute DOMHighResTimeStamp gamepadTimestamp; + }; ++
+ dictionary GamepadAxisEventInit : EventInit { + required long gamepadIndex; + required long axisIndex; + required double axisSnapshot; + required DOMHighResTimeStamp gamepadTimestamp; + }; ++
+ [Exposed=Window, SecureContext] + + interface GamepadButtonEvent: Event { + constructor(DOMString type, GamepadButtonEventInit eventInitDict); + readonly attribute long gamepadIndex; + readonly attribute long buttonIndex; + readonly attribute GamepadButton buttonSnapshot; + readonly attribute DOMHighResTimeStamp gamepadTimestamp; + }; ++
+ dictionary GamepadButtonEventInit : EventInit { + required long gamepadIndex; + required long buttonIndex; + required GamepadButton buttonSnapshot; + required DOMHighResTimeStamp gamepadTimestamp; + }; ++
- More discussion needed, on whether to include or exclude axis and - button changed events, and whether to roll them more together - (`"gamepadchanged"`?), separate somewhat (`"gamepadaxischanged"`?), or - separate by individual axis and button. + [=User agent=]s implementing this specification MUST provide new DOM + events named axischange, buttonchange, buttondown, and + buttonup. The corresponding event MUST be of + type {{GamepadAxisEvent}} for {{axischange}}, or {{GamepadButtonEvent}} + for {{buttonchange}}, {{buttondown}}, and {{buttonup}}. All events MUST + fire on the {{Gamepad}} object. +
++ When the [=user agent=] receives new button or axis input values from a + gamepad, the [=user agent=] MUST compare the current button and axis + values with the previous values and dispatch {{axischange}} and + {{buttonchange}} events for each axis and button with a changed value. + The [=user agent=] MUST also compare the current button pressed state + with the previous button pressed state and dispatch {{buttondown}} and + {{buttonup}} events. +
++ These events MUST NOT be dispatched before the [=user agent=] has + dispatched a {{gamepadconnected}} event for that gamepad.