Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Land stubs for Gamepad.vibrationActuator API
https://bugs.webkit.org/show_bug.cgi?id=250079

Reviewed by Brady Eidson.

Land stubs for Gamepad.vibrationActuator API:
- https://w3c.github.io/gamepad/extensions.html#gamepadhapticactuator-interface

* Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml:
* Source/WebCore/CMakeLists.txt:
* Source/WebCore/DerivedSources-input.xcfilelist:
* Source/WebCore/DerivedSources-output.xcfilelist:
* Source/WebCore/DerivedSources.make:
* Source/WebCore/Modules/gamepad/Gamepad.cpp:
(WebCore::Gamepad::Gamepad):
(WebCore::Gamepad::vibrationActuator):
* Source/WebCore/Modules/gamepad/Gamepad.h:
* Source/WebCore/Modules/gamepad/Gamepad.idl:
* Source/WebCore/Modules/gamepad/GamepadEffectParameters.h: Copied from Source/WebCore/Modules/gamepad/Gamepad.idl.
* Source/WebCore/Modules/gamepad/GamepadEffectParameters.idl: Copied from Source/WebCore/Modules/gamepad/Gamepad.idl.
* Source/WebCore/Modules/gamepad/GamepadHapticActuator.cpp: Copied from Source/WebCore/Modules/gamepad/Gamepad.idl.
(WebCore::GamepadHapticActuator::create):
(WebCore::GamepadHapticActuator::GamepadHapticActuator):
(WebCore::GamepadHapticActuator::canPlayEffectType const):
(WebCore::GamepadHapticActuator::playEffect):
(WebCore::GamepadHapticActuator::reset):
* Source/WebCore/Modules/gamepad/GamepadHapticActuator.h: Copied from Source/WebCore/Modules/gamepad/Gamepad.idl.
(WebCore::GamepadHapticActuator::type const):
* Source/WebCore/Modules/gamepad/GamepadHapticActuator.idl: Copied from Source/WebCore/Modules/gamepad/Gamepad.idl.
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/bindings/js/WebCoreBuiltinNames.h:

Canonical link: https://commits.webkit.org/258482@main
  • Loading branch information
cdumez committed Jan 5, 2023
1 parent 9cc33f1 commit 60f4fa7
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 12 deletions.
Expand Up @@ -3,17 +3,17 @@ PASS idl_test setup
PASS idl_test validation
PASS Partial interface Gamepad: original interface defined
PASS Partial interface Gamepad: member names are unique
FAIL GamepadHapticActuator interface: existence and properties of interface object assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface object length assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface object name assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: existence and properties of interface prototype object assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: attribute type assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: operation canPlayEffectType(GamepadHapticEffectType) assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: operation playEffect(GamepadHapticEffectType, optional GamepadEffectParameters) assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: operation pulse(double, double) assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
FAIL GamepadHapticActuator interface: operation reset() assert_own_property: self does not have own property "GamepadHapticActuator" expected property "GamepadHapticActuator" missing
PASS GamepadHapticActuator interface: existence and properties of interface object
PASS GamepadHapticActuator interface object length
PASS GamepadHapticActuator interface object name
PASS GamepadHapticActuator interface: existence and properties of interface prototype object
PASS GamepadHapticActuator interface: existence and properties of interface prototype object's "constructor" property
PASS GamepadHapticActuator interface: existence and properties of interface prototype object's @@unscopables property
PASS GamepadHapticActuator interface: attribute type
PASS GamepadHapticActuator interface: operation canPlayEffectType(GamepadHapticEffectType)
PASS GamepadHapticActuator interface: operation playEffect(GamepadHapticEffectType, optional GamepadEffectParameters)
FAIL GamepadHapticActuator interface: operation pulse(double, double) assert_own_property: interface prototype object missing non-static operation expected property "pulse" missing
PASS GamepadHapticActuator interface: operation reset()
FAIL GamepadPose interface: existence and properties of interface object assert_own_property: self does not have own property "GamepadPose" expected property "GamepadPose" missing
FAIL GamepadPose interface object length assert_own_property: self does not have own property "GamepadPose" expected property "GamepadPose" missing
FAIL GamepadPose interface object name assert_own_property: self does not have own property "GamepadPose" expected property "GamepadPose" missing
Expand Down Expand Up @@ -42,5 +42,5 @@ FAIL Gamepad interface: attribute hand assert_true: The prototype object must ha
FAIL Gamepad interface: attribute hapticActuators assert_true: The prototype object must have a property "hapticActuators" expected true got false
FAIL Gamepad interface: attribute pose assert_true: The prototype object must have a property "pose" expected true got false
FAIL Gamepad interface: attribute touchEvents assert_true: The prototype object must have a property "touchEvents" expected true got false
FAIL Gamepad interface: attribute vibrationActuator assert_true: The prototype object must have a property "vibrationActuator" expected true got false
PASS Gamepad interface: attribute vibrationActuator

13 changes: 13 additions & 0 deletions Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Expand Up @@ -2322,6 +2322,19 @@ GStreamerEnabled:
WebKit:
default: true

GamepadVibrationActuatorEnabled:
type: bool
status: testable
humanReadableName: "Gamepad.vibrationActuator support"
humanReadableDescription: "Support for Gamepad.vibrationActuator"
defaultValue:
WebKitLegacy:
default: false
WebKit:
default: false
WebCore:
default: false

GamepadsEnabled:
type: bool
status: embedder
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/CMakeLists.txt
Expand Up @@ -1516,7 +1516,9 @@ list(APPEND WebCore_IDL_INCLUDES
list(APPEND WebCore_NON_SVG_IDL_FILES
Modules/gamepad/Gamepad.idl
Modules/gamepad/GamepadButton.idl
Modules/gamepad/GamepadEffectParameters.idl
Modules/gamepad/GamepadEvent.idl
Modules/gamepad/GamepadHapticActuator.idl
Modules/gamepad/Navigator+Gamepad.idl
Modules/gamepad/WindowEventHandlers+Gamepad.idl
)
Expand All @@ -1526,6 +1528,7 @@ if (ENABLE_GAMEPAD)
Modules/gamepad/Gamepad.cpp
Modules/gamepad/GamepadButton.cpp
Modules/gamepad/GamepadEvent.cpp
Modules/gamepad/GamepadHapticActuator.cpp
Modules/gamepad/GamepadManager.cpp
Modules/gamepad/NavigatorGamepad.cpp

Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/DerivedSources-input.xcfilelist
Expand Up @@ -300,7 +300,9 @@ $(PROJECT_DIR)/Modules/filesystemaccess/FileSystemSyncAccessHandle.idl
$(PROJECT_DIR)/Modules/filesystemaccess/StorageManager+FileSystemAccess.idl
$(PROJECT_DIR)/Modules/gamepad/Gamepad.idl
$(PROJECT_DIR)/Modules/gamepad/GamepadButton.idl
$(PROJECT_DIR)/Modules/gamepad/GamepadEffectParameters.idl
$(PROJECT_DIR)/Modules/gamepad/GamepadEvent.idl
$(PROJECT_DIR)/Modules/gamepad/GamepadHapticActuator.idl
$(PROJECT_DIR)/Modules/gamepad/Navigator+Gamepad.idl
$(PROJECT_DIR)/Modules/gamepad/WindowEventHandlers+Gamepad.idl
$(PROJECT_DIR)/Modules/geolocation/Coordinates.idl
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/DerivedSources-output.xcfilelist
Expand Up @@ -1255,8 +1255,12 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepad.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepad.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadButton.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadButton.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadEffectParameters.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadEffectParameters.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadEvent.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadEvent.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadHapticActuator.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGamepadHapticActuator.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGenericTransformStream.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGenericTransformStream.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGeolocation.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/DerivedSources.make
Expand Up @@ -322,7 +322,9 @@ JS_BINDING_IDLS := \
$(WebCore)/Modules/filesystemaccess/StorageManager+FileSystemAccess.idl \
$(WebCore)/Modules/gamepad/Gamepad.idl \
$(WebCore)/Modules/gamepad/GamepadButton.idl \
$(WebCore)/Modules/gamepad/GamepadEffectParameters.idl \
$(WebCore)/Modules/gamepad/GamepadEvent.idl \
$(WebCore)/Modules/gamepad/GamepadHapticActuator.idl \
$(WebCore)/Modules/gamepad/Navigator+Gamepad.idl \
$(WebCore)/Modules/gamepad/WindowEventHandlers+Gamepad.idl \
$(WebCore)/Modules/geolocation/Geolocation.idl \
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/Modules/gamepad/Gamepad.cpp
Expand Up @@ -29,6 +29,7 @@
#if ENABLE(GAMEPAD)

#include "GamepadButton.h"
#include "GamepadHapticActuator.h"
#include "PlatformGamepad.h"
#include <wtf/text/WTFString.h>

Expand All @@ -41,6 +42,7 @@ Gamepad::Gamepad(const PlatformGamepad& platformGamepad)
, m_timestamp(platformGamepad.lastUpdateTime())
, m_mapping(platformGamepad.mapping())
, m_axes(platformGamepad.axisValues().size(), 0.0)
, m_vibrationActuator(GamepadHapticActuator::create())
{
unsigned buttonCount = platformGamepad.buttonValues().size();
m_buttons.reserveInitialCapacity(buttonCount);
Expand Down Expand Up @@ -70,6 +72,11 @@ void Gamepad::updateFromPlatformGamepad(const PlatformGamepad& platformGamepad)
m_timestamp = platformGamepad.lastUpdateTime();
}

GamepadHapticActuator& Gamepad::vibrationActuator()
{
return m_vibrationActuator.get();
}

} // namespace WebCore

#endif // ENABLE(GAMEPAD)
5 changes: 5 additions & 0 deletions Source/WebCore/Modules/gamepad/Gamepad.h
Expand Up @@ -35,6 +35,7 @@
namespace WebCore {

class GamepadButton;
class GamepadHapticActuator;
class PlatformGamepad;

class Gamepad: public RefCounted<Gamepad> {
Expand All @@ -57,6 +58,8 @@ class Gamepad: public RefCounted<Gamepad> {
void updateFromPlatformGamepad(const PlatformGamepad&);
void setConnected(bool connected) { m_connected = connected; }

GamepadHapticActuator& vibrationActuator();

private:
explicit Gamepad(const PlatformGamepad&);
String m_id;
Expand All @@ -67,6 +70,8 @@ class Gamepad: public RefCounted<Gamepad> {

Vector<double> m_axes;
Vector<Ref<GamepadButton>> m_buttons;

Ref<GamepadHapticActuator> m_vibrationActuator;
};

} // namespace WebCore
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/Modules/gamepad/Gamepad.idl
Expand Up @@ -35,5 +35,8 @@
readonly attribute DOMString mapping;
readonly attribute sequence<double> axes;
readonly attribute sequence<GamepadButton> buttons;

// Extension: https://w3c.github.io/gamepad/extensions.html#partial-gamepad-interface
[EnabledBySetting=GamepadVibrationActuatorEnabled] readonly attribute GamepadHapticActuator vibrationActuator;
};

41 changes: 41 additions & 0 deletions Source/WebCore/Modules/gamepad/GamepadEffectParameters.h
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(GAMEPAD)

namespace WebCore {

struct GamepadEffectParameters {
double duration = 0.0;
double startDelay = 0.0;
double strongMagnitude = 0.0;
double weakMagnitude = 0.0;
};

} // namespace WebCore

#endif // ENABLE(GAMEPAD)
34 changes: 34 additions & 0 deletions Source/WebCore/Modules/gamepad/GamepadEffectParameters.idl
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

[
Conditional=GAMEPAD,
EnabledBySetting=GamepadVibrationActuatorEnabled
] dictionary GamepadEffectParameters {
double duration = 0.0;
double startDelay = 0.0;
double strongMagnitude = 0.0;
double weakMagnitude = 0.0;
};
63 changes: 63 additions & 0 deletions Source/WebCore/Modules/gamepad/GamepadHapticActuator.cpp
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"

#if ENABLE(GAMEPAD)
#include "GamepadHapticActuator.h"

#include "GamepadEffectParameters.h"
#include "JSDOMPromiseDeferred.h"

namespace WebCore {

Ref<GamepadHapticActuator> GamepadHapticActuator::create()
{
return adoptRef(*new GamepadHapticActuator);
}

GamepadHapticActuator::GamepadHapticActuator()
: m_type { Type::Vibration }
{
}

bool GamepadHapticActuator::canPlayEffectType(EffectType) const
{
return false;
}

void GamepadHapticActuator::playEffect(EffectType, GamepadEffectParameters&&, Ref<DeferredPromise>&& promise)
{
promise->reject(Exception { NotSupportedError });
}

void GamepadHapticActuator::reset(Ref<DeferredPromise>&& promise)
{
promise->reject(Exception { NotSupportedError });
}

} // namespace WebCore

#endif // ENABLE(GAMEPAD)
59 changes: 59 additions & 0 deletions Source/WebCore/Modules/gamepad/GamepadHapticActuator.h
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(GAMEPAD)

#include <wtf/Forward.h>
#include <wtf/RefCounted.h>

namespace WebCore {

class DeferredPromise;
struct GamepadEffectParameters;

class GamepadHapticActuator : public RefCounted<GamepadHapticActuator> {
public:
static Ref<GamepadHapticActuator> create();

enum class Type : uint8_t { Vibration, DualRumble };
enum class EffectType : uint8_t { DualRumble };
enum class Result : uint8_t { Complete, Preempted };

Type type() const { return m_type; }
bool canPlayEffectType(EffectType) const;
void playEffect(EffectType, GamepadEffectParameters&&, Ref<DeferredPromise>&&);
void reset(Ref<DeferredPromise>&&);

private:
GamepadHapticActuator();

Type m_type;
};

} // namespace WebCore

#endif // ENABLE(GAMEPAD)

0 comments on commit 60f4fa7

Please sign in to comment.