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:

    +
  1. Initialize |oldAxisValues:list| to be an empty [=list=]. +
  2. +
  3. [=list/For each=] |axis:double| of + |gamepad|.{{Gamepad/[[axes]]}}, [=list/append=] |axis| to + |oldAxisValues|. +
  4. +
  5. Initialize |oldButtonValues:list| to be an empty [=list=]. +
  6. +
  7. Initialize |oldButtonPressed:list| to be an empty [=list=]. +
  8. +
  9. [=list/For each=] |button:GamepadButton| of + |gamepad|.{{Gamepad/[[buttons]]}}: +
      +
    1. [=list/Append=] |button|.{{GamepadButton/value}} to + |oldButtonValues|. +
    2. +
    3. [=list/Append=] |button|.{{GamepadButton/pressed}} to + |oldButtonPressed|. +
    4. +
    +
  10. Let |now:DOMHighResTimeStamp| be the [=current high resolution time=].
  11. @@ -516,6 +570,99 @@

+
  • If |navigator|.{{Navigator/[[hasGamepadGesture]]}} is `false`, + abort these steps. +
  • +
  • [=list/For each=] |axisIndex:long| of [=the range=] from 0 to the + [=list/size=] of |gamepad|.{{Gamepad/axes}} − 1: +
      +
    1. If |oldAxisValues|[|axisIndex|] is not equal to + |gamepad|.{{Gamepad/[[axes]]}}[|axisIndex|], [=queue a task=] on + the [=gamepad task source=] to [=fire an event=] named + {{axischange}} at |gamepad| using {{GamepadAxisEvent}} with its + {{GamepadAxisEvent/gamepadIndex}} attribute initialized to + |gamepad|.{{Gamepad/index}}, its {{GamepadAxisEvent/axisIndex}} + attribute initialized to |axisIndex|, its + {{GamepadAxisEvent/axisSnapshot}} attribute initialized to + |newValue|, and its {{GamepadAxisEvent/gamepadTimestamp}} + attribute initialized to |now|. +
    2. +
    +
  • +
  • [=list/For each=] |buttonIndex:long| of [=the range=] from 0 to + the [=list/size=] of |gamepad|.{{Gamepad/buttons}} − 1: +
      +
    1. Let |button:GamepadButton| be + |gamepad|.{{Gamepad/[[buttons]]}}[|buttonIndex|]. +
    2. +
    3. If |oldButtonValue|[|buttonIndex|] is not equal to + |button|.{{GamepadButton/value}}: +
        +
      1. Let |buttonCopy| be a [=new=] {{GamepadButton}} instance + with its {{GamepadButton/value}} attribute initialized to + |button|.{{GamepadButton/value}}, its + {{GamepadButton/pressed}} attribute initialized to + |button|.{{GamepadButton/pressed}}, and its + {{GamepadButton/touched}} attribute initialized to + |button|.{{GamepadButton/touched}}. +
      2. +
      3. [=Queue a task=] on the [=gamepad task source=] to [=fire + an event=] named {{buttonchange}} 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|. +
      4. +
      +
    4. +
    5. If |oldButtonPressed|[|buttonIndex|] is not equal to + |button|.{{GamepadButton/pressed}}: +
        +
      1. Let |buttonCopy| be a [=new=] {{GamepadButton}} instance + with its {{GamepadButton/value}} attribute initialized to + |button|.{{GamepadButton/value}}, its + {{GamepadButton/pressed}} attribute initialized to + |button|.{{GamepadButton/pressed}}, and its + {{GamepadButton/touched}} attribute initialized to + |button|.{{GamepadButton/touched}}. +
      2. +
      3. +

        + 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|. +

        +
      4. +
      +
    6. +
    +
  • To map and normalize axes for |gamepad:Gamepad|, run the @@ -1207,6 +1354,173 @@

    +
    +

    + GamepadAxisEvent Interface +

    +
    +        [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;
    +        };
    +      
    +
    +
    + gamepadIndex attribute +
    +
    + The {{Gamepad/index}} attribute of the {{Gamepad}} associated with + this event. +
    +
    + axisIndex attribute +
    +
    + The index of the axis in the {{Gamepad/axes}} array. +
    +
    + axisSnapshot attribute +
    +
    + The axis value at the time when this event was created. +
    +
    + gamepadTimestamp attribute +
    +
    + The {{Gamepad/timestamp}} of the {{Gamepad}} associated with this + event at the time when the event was created. +
    +
    +
    +

    + GamepadAxisEventInit dictionary +

    +
    +        dictionary GamepadAxisEventInit : EventInit {
    +          required long gamepadIndex;
    +          required long axisIndex;
    +          required double axisSnapshot;
    +          required DOMHighResTimeStamp gamepadTimestamp;
    +        };
    +      
    +
    +
    + gamepadIndex member +
    +
    + The gamepad index for the event. +
    +
    + axisIndex member +
    +
    + The button index for the event. +
    +
    + axisSnapshot member +
    +
    + A copy of the current button state. +
    +
    + gamepadTimestamp member +
    +
    + The gamepad timestamp for the event. +
    +
    +
    +
    +
    +

    + GamepadButtonEvent Interface +

    +
    +        [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;
    +        };
    +      
    +
    +
    + gamepadIndex attribute +
    +
    + The {{Gamepad/index}} attribute of the {{Gamepad}} associated with + this event. +
    +
    + buttonIndex attribute +
    +
    + The index of the {{GamepadButton}} in the {{Gamepad/buttons}} array. +
    +
    + buttonSnapshot attribute +
    +
    + A copy of the {{GamepadButton}} at the time when this event was + created. +
    +
    + gamepadTimestamp attribute +
    +
    + The {{Gamepad/timestamp}} of the {{Gamepad}} associated with this + event at the time when the event was created. +
    +
    +
    +

    + GamepadButtonEventInit dictionary +

    +
    +        dictionary GamepadButtonEventInit : EventInit {
    +          required long gamepadIndex;
    +          required long buttonIndex;
    +          required GamepadButton buttonSnapshot;
    +          required DOMHighResTimeStamp gamepadTimestamp;
    +        };
    +      
    +
    +
    + gamepadIndex member +
    +
    + The gamepad index for the event. +
    +
    + buttonIndex member +
    +
    + The button index for the event. +
    +
    + buttonSnapshot member +
    +
    + A copy of the current button state. +
    +
    + gamepadTimestamp member +
    +
    + The gamepad timestamp for the event. +
    +
    +
    +

    Remapping @@ -1596,13 +1910,29 @@

    - Other events + The axischange, buttonchange, buttondown, and buttonup events

    - 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.