Re: [w3c/gamepad] Add algorithms for getGamepads and events (#151)

@marcoscaceres approved this pull request.

Wowser! This is so much better! Nice one @nondebug! 

I'd be inclined for us to take this as is (with the suggestions) and we should just build on it. 


> +            <ol>
+              <li>Set |navigator|.{{Navigator/[[hasGamepadGesture]]}} to
+              `true`.
+              </li>
+              <li>[=list/For each=] |connectedGamepad:Gamepad?| of
+              |navigator|.{{Navigator/[[gamepads]]}}:
+                <ol>
+                  <li>If |connectedGamepad| is not equal to `null`:
+                    <ol>
+                      <li>Set |connectedGamepad|.{{Gamepad/[[exposed]]}} to
+                      `true`.
+                      </li>
+                      <li>Set |connectedGamepad|.{{Gamepad/[[timestamp]]}} to
+                      |now|.
+                      </li>
+                      <li>If |gamepad|'s [=relevant global object=] is a

I think here we should be able to just queue on gamepad task source instead of going through the global one. 

> +              <li>Set |navigator|.{{Navigator/[[hasGamepadGesture]]}} to
+              `true`.
+              </li>
+              <li>[=list/For each=] |connectedGamepad:Gamepad?| of
+              |navigator|.{{Navigator/[[gamepads]]}}:
+                <ol>
+                  <li>If |connectedGamepad| is not equal to `null`:
+                    <ol>
+                      <li>Set |connectedGamepad|.{{Gamepad/[[exposed]]}} to
+                      `true`.
+                      </li>
+                      <li>Set |connectedGamepad|.{{Gamepad/[[timestamp]]}} to
+                      |now|.
+                      </li>
+                      <li>If |gamepad|'s [=relevant global object=] is a
+                      {{Window}} object, [=queue a global task=] on |gamepad|'s

Here, we might want to also do the fully active check (as we are checking the {{Window}} is still there, per #149).... we can come back to this tho. 

> +                      {{GamepadEvent}} with its {{GamepadEvent/gamepad}}
+                      attribute initialized to |connectedGamepad|.
+                      </li>
+                    </ol>
+                  </li>
+                </ol>
+              </li>
+            </ol>
+          </li>
+        </ol>
+        <p>
+          To <dfn>map and normalize axes</dfn> for |gamepad:Gamepad|, run the
+          following steps:
+        </p>
+        <ol>
+          <li>Let |axisValues:list| be a [=list=] of `unsigned long` values

```suggestion
          <li>Let |axisValues:list| be a [=list=] of {{unsigned long}} values
```

> +              </li>
+              <li>Let |normalizedValue:double| be 2 (|logicalValue| −
+              |logicalMinimum|) / (|logicalMaximum| − |logicalMinimum|) − 1.
+              </li>
+              <li>Set |gamepad|.{{Gamepad/[[axes]]}}[|axisIndex|] to be
+              |normalizedValue|.
+              </li>
+            </ol>
+          </li>
+        </ol>
+        <p>
+          To <dfn>map and normalize buttons</dfn> for |gamepad:Gamepad|, run
+          the following steps:
+        </p>
+        <ol>
+          <li>Let |buttonValues:list| be a [=list=] of `unsigned long` values

```suggestion
          <li>Let |buttonValues:list| be a [=list=] of {{unsigned long}} values
```

> +          <li>[=list/Append=] `null` to |navigator|.{{Navigator/[[gamepads]]}}.
+          </li>
+          <li>Return the [=list/size=] of
+          |navigator|.{{Navigator/[[gamepads]]}} − 1.
+          </li>
+        </ol>
+        <p>
+          To <dfn data-lt="initializing axes">initialize axes</dfn> for
+          |gamepad:Gamepad|, run the following steps:
+        </p>
+        <ol>
+          <li>Let |inputCount:long| be the number of axis inputs exposed by the
+          device represented by |gamepad|.
+          </li>
+          <li>Set |gamepad|.{{Gamepad/[[axisMinimums]]}} to a [=list=] of
+          `unsigned long` values with [=list/size=] equal to |inputCount|

```suggestion
          {{unsigned long}} values with [=list/size=] equal to |inputCount|
```

Plus a few other ones... 

> +        <p>
+          User agents implementing this specification must provide a new DOM
+          event, named {{gamepadconnected}}. The corresponding event MUST be of
+          type {{GamepadEvent}} and, if [=allowed to use=] the `"gamepad"`
+          permission, MUST fire on the {{Window}} object. Registration for and
+          firing of the {{gamepadconnected}} event MUST follow the usual
+          behavior of DOM Events. [[DOM]]
+        </p>
+        <p>
+          A [=user agent=] MUST dispatch this event type to indicate the user
+          has connected a gamepad. If a gamepad was already connected when the
+          page was loaded, the {{gamepadconnected}} event SHOULD be dispatched
+          when the user presses a button or moves an axis.
+        </p>
+        <p>
+          A [=user agent=] MUST NOT dispatch this event type if the
+          [=environment settings object=] is a [=non-secure context=].
+        </p>

We don't need this stuff anymore 🎉... it's already above (including the secure context stuff... the API is not exposed in insecure contexts, so that can't ever happen). 

```suggestion
```



> @@ -275,43 +883,121 @@ <h2>
           readonly attribute double value;
         };
       </pre>
+      <p>
+        Instances of {{GamepadButton}} are created with the internal slots
+        described in the following table:
+      </p>
+      <table class="simple" dfn-for="GamepadButton">

```suggestion
      <table class="simple">
```

> +        <li>If the [=current settings object=]'s [=environment settings object
+        / responsible document=] is not [=allowed to use=] the `"gamepad"`
+        permission, then abort these steps.
+        </li>

I don't think we need the check here? 

```suggestion
```



>        </p>
     </section>
     <section>
       <h3 id="event-gamepaddisconnected">
         The <dfn class="event">gamepaddisconnected</dfn> event
       </h3>
+      <p>
+        When a gamepad becomes unavailable on the system, run the following
+        steps:
+      </p>
+      <ol>
+        <li>If the [=current settings object=]'s [=environment settings object
+        / responsible document=] is not [=allowed to use=] the `"gamepad"`
+        permission, then abort these steps.
+        </li>
+        <li>Let |gamepad:Gamepad| be the {{Gamepad}} representing the
+        unavailable device.
+        </li>
+        <li>Set |gamepad|.{{Gamepad/[[connected]]}} to `false`.

I think this should be done in the steps of the task (right before the event is fired), no? Otherwise, it would update somewhat randomly. 

>        <p>
         User agents implementing this specification must provide a new DOM
-        event, named <code>gamepaddisconnected</code>. The corresponding event
-        MUST be of type <code>GamepadEvent</code> and, if <a>allowed to use</a>
-        the "`gamepad`" permission, MUST fire on the <code>window</code>
-        object. Registration for and firing of the
-        <code>gamepaddisconnected</code> event MUST follow the usual behavior
-        of DOM Events. [[DOM]]
+        event, named {{gamepaddisconnected}}. The corresponding event MUST be

I think they "allowed to use" checks should only happen when the developer tries to use the API. 

We can maybe have a global check that if the permission to use the API gets disabled, then just bring down everything... but that's probably overkill. 

> +        permission, MUST fire on the {{Window}} object. Registration for and
+        firing of the {{gamepaddisconnected}} event MUST follow the usual
+        behavior of DOM Events. [[DOM]]

Don't need this :) We are doing the right thing... 

```suggestion
        permission, MUST fire on the {{Window}} object.
```

> +        A [=user agent=] MUST NOT dispatch this event type if the [=environment
+        settings object=] is a [=non-secure context=].

Don't need this... can't register events in insecure contexts, so they will never fire in these contexts... 

```suggestion
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/gamepad/pull/151#pullrequestreview-701686307

Received on Thursday, 8 July 2021 06:55:26 UTC