New issue
Advanced search Search tips

Issue 856290 link

Starred by 4 users

Issue metadata

Status: Started
Owner:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Android , Windows , Chrome , Mac
Pri: 2
Type: Feature



Sign in to add a comment

Add non-standard gamepad button and axis events

Project Member Reported by mattreynolds@chromium.org, Jun 25 2018

Issue description

Gamepads generate events for connections and disconnections, but do not generate any events for button or axis inputs.

There is a proposal for adding button events for gamepadbuttondown and gamepadbuttonup, which are already implemented in Firefox behind a flag:

https://github.com/w3c/gamepad/pull/15

Firefox also implements a gamepadaxismove event behind the flag, but this event is not spec'ed in the proposal.

Chrome should implement gamepadbuttonup/down as proposed and should adopt Firefox's gamepadaxismove event. An additional gamepadbuttonchange event should also be added so applications can detect changes to analog button inputs that do not cause the .pressed attribute to change.
 

Comment 1 by a...@scirra.com, Jun 29 2018

It would be useful to also make sure these events count as user gestures, which would fix e.g. issue 454849. Currently anything that requires a user gesture, such as media playback, can't be activated by gamepad, because they don't fire events.
Hi ash@, gamepad input should start counting as a User Activation once chrome://flags/#user-activation-v2 is default-enabled. The new UA system doesn't require a live event tied to the gesture, and there's a change in Chrome 68 to allow gamepad button input to qualify as an activation under the new system.

Relevant CL:

https://chromiumdash.appspot.com/commit/6e6304736564c6cdb96b650facb133c34b9e2189

I'll make sure the new events can also trigger UA but hopefully UAv2 will be enabled by then.
Is there a way we can detect that gamepad input will allow user-gesture limited APIs in a cross-browser way, without having to resort to UA sniffing?
I think user agent sniffing is the best available option. We don't expose the presence of the capability, although for some features that require activation you should be able to detect the failure mode when activation is not present.
Project Member

Comment 5 by bugdroid1@chromium.org, Aug 2

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d3ea2db90eeae294a66afc6994f37ff38676c67e

commit d3ea2db90eeae294a66afc6994f37ff38676c67e
Author: Matt Reynolds <mattreynolds@google.com>
Date: Thu Aug 02 22:52:28 2018

Add a feature to enable gamepad button/axis events

This CL adds a command line switch and Feature entry for enabling
event listeners to listen for gamepad button and axis inputs.

Intent to implement thread:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/9cfRxXx5Cis

BUG=856290

Change-Id: I5323ff7692ffb235fc3759b1305216085ed6460c
Reviewed-on: https://chromium-review.googlesource.com/1139092
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580361}
[modify] https://crrev.com/d3ea2db90eeae294a66afc6994f37ff38676c67e/device/gamepad/public/cpp/gamepad_features.cc
[modify] https://crrev.com/d3ea2db90eeae294a66afc6994f37ff38676c67e/device/gamepad/public/cpp/gamepad_features.h
[modify] https://crrev.com/d3ea2db90eeae294a66afc6994f37ff38676c67e/device/gamepad/public/cpp/gamepad_switches.cc
[modify] https://crrev.com/d3ea2db90eeae294a66afc6994f37ff38676c67e/device/gamepad/public/cpp/gamepad_switches.h
[modify] https://crrev.com/d3ea2db90eeae294a66afc6994f37ff38676c67e/third_party/blink/renderer/platform/runtime_enabled_features.json5
[modify] https://crrev.com/d3ea2db90eeae294a66afc6994f37ff38676c67e/tools/metrics/histograms/enums.xml

Project Member

Comment 6 by bugdroid1@chromium.org, Aug 8

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/9d0e9866426d0bb126d54903b77dc99d6ea2855e

commit 9d0e9866426d0bb126d54903b77dc99d6ea2855e
Author: Matt Reynolds <mattreynolds@google.com>
Date: Wed Aug 08 00:57:15 2018

Communicate gamepad button/axis changes to blink

This CL extends the device::GamepadConsumer,
device::mojom::GamepadConsumer, and blink::WebGamepadListener interfaces
to allow gamepad button and axis events to be communicated from //device
to blink. These will be used to implement gamepad button and axis
events in javascript.

BUG=856290

Change-Id: I8ce83d5e4225e79c3b25c7d7ef65684e9ada404f
Reviewed-on: https://chromium-review.googlesource.com/1161492
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581421}
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/content/browser/renderer_host/pepper/pepper_gamepad_host.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_consumer.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_haptics_manager.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_haptics_manager.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_monitor.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_monitor.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_pad_state_provider.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_pad_state_provider.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_platform_data_fetcher_linux.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_provider.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_provider.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_service.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_service.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_service_unittest.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_test_helpers.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/gamepad_user_gesture.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/public/cpp/BUILD.gn
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/public/cpp/gamepad.cc
[add] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/public/cpp/gamepads.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/device/gamepad/public/mojom/gamepad.mojom
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/third_party/blink/public/platform/web_gamepad_listener.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/third_party/blink/renderer/modules/gamepad/gamepad_dispatcher.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/third_party/blink/renderer/modules/gamepad/gamepad_dispatcher.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/third_party/blink/renderer/modules/gamepad/gamepad_shared_memory_reader.cc
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/third_party/blink/renderer/modules/gamepad/gamepad_shared_memory_reader.h
[modify] https://crrev.com/9d0e9866426d0bb126d54903b77dc99d6ea2855e/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc

Hey Matt,

Any updates on this feature?
Project Member

Comment 8 by bugdroid1@chromium.org, Nov 6

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/13341aa7f31720ed096a5446bb31fa65eb59bd4b

commit 13341aa7f31720ed096a5446bb31fa65eb59bd4b
Author: Matt Reynolds <mattreynolds@google.com>
Date: Tue Nov 06 22:50:58 2018

Add GamepadButtonEvent and GamepadAxisEvent

This CL defines the GamepadButtonEvent and GamepadAxisEvent types that
will be used to return button and axis events to event listeners.

BUG=856290

Change-Id: I52d4eb91f9e40fe86e45d498e8aa97ec341341d6
Reviewed-on: https://chromium-review.googlesource.com/c/1167976
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605863}
[modify] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt
[modify] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/bindings/modules/BUILD.gn
[modify] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/BUILD.gn
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_axis_event.cc
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_axis_event.h
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_axis_event.idl
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_axis_event_init.idl
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_button_event.cc
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_button_event.h
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_button_event.idl
[add] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_button_event_init.idl
[modify] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/gamepad/gamepad_event.h
[modify] https://crrev.com/13341aa7f31720ed096a5446bb31fa65eb59bd4b/third_party/blink/renderer/modules/modules_idl_files.gni

Project Member

Comment 9 by bugdroid1@chromium.org, Jan 18 (4 days ago)

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/99e2f5efae68e134de34848bdb982be82dd122de

commit 99e2f5efae68e134de34848bdb982be82dd122de
Author: Matt Reynolds <mattreynolds@google.com>
Date: Fri Jan 18 23:40:55 2019

Fire gamepad events synchronously

On receiving a signal that a gamepad has been connected or
disconnected, NavigatorGamepad will fetch a new sample of the
current gamepad state and compare it with the previous sample. If
any gamepads are newly found or lost, gamepad connection events are
queued and fired asynchronously by a task runner.

Allowing gamepad events to be queued in this way may cause events to
be delayed when there is more than one event per iteration of the task
runner loop. This is unlikely when only gamepad connection events are
handled in this way, but will become more likely with the addition of
gamepad button and axis events. To address this, this CL modifies the
event behavior so that events are fired synchronously when the
connection signal is received.

This CL also addresses some issues with gamepad timestamp behavior.
NavigatorGamepad must be able to detect whether any fields in the
Gamepad struct have been modified in order to know when to update
the underlying buffer. Timestamps are usually set by the gamepad data
fetcher to the time at which the data was received from the gamepad.
However, GamepadController (used in layout tests) does not update the
timestamp when setting gamepad state. To fix this, GamepadController
is modified to always update the timestamp whenever gamepad state is
changed.

The Gamepad spec also requires that the timestamp returned with the
gamepad state be no older than the timestamp of the first time gamepad
data was made available to the page. In some cases this was not true,
for instance if a gamepad was previously accessible by the page before
a refresh, it will automatically be "connected" after the page has
been refreshed. The timestamp for this gamepad may be earlier than
the first-available timestamp. To fix, earlier timestamps are
overwritten with the first-available timestamp.

BUG=856290

Change-Id: If0f96f68c48dc126d3238a9727634e18eb591882
Reviewed-on: https://chromium-review.googlesource.com/c/1171554
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#624355}
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/content/shell/test_runner/gamepad_controller.cc
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/device/gamepad/gamepad_standard_mappings.cc
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/device/gamepad/gamepad_standard_mappings.h
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/device/gamepad/public/cpp/gamepad.cc
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/device/gamepad/public/cpp/gamepad.h
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/device/gamepad/xbox_data_fetcher_mac.cc
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/BUILD.gn
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/BUILD.gn
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/gamepad.h
[add] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/gamepad_comparisons.cc
[add] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/gamepad_comparisons.h
[add] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/gamepad_comparisons_test.cc
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/gamepad_list.h
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/renderer/modules/gamepad/navigator_gamepad.h
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/web_tests/gamepad/gamepad-api.html
[add] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/web_tests/gamepad/gamepad-event-listeners.html
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/web_tests/gamepad/gamepad-polling-access.html
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/web_tests/gamepad/gamepad-vibration.html
[modify] https://crrev.com/99e2f5efae68e134de34848bdb982be82dd122de/third_party/blink/web_tests/gamepad/resources/gamepad-helpers.js

Sign in to add a comment