Skip to content

Commit cebb092

Browse files
committed
VibrationActuator should limit the duration of vibration effects
https://bugs.webkit.org/show_bug.cgi?id=250415 Reviewed by Brent Fulgham. VibrationActuator should limit the duration of vibration effects: - https://w3c.github.io/gamepad/extensions.html#gamepadeffectparameters-dictionary The specification recommends a maximum of 5 seconds. * Source/WebCore/Modules/gamepad/GamepadEffectParameters.h: * Source/WebCore/Modules/gamepad/GamepadHapticActuator.cpp: (WebCore::GamepadHapticActuator::playEffect): * Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEffect.mm: (WebCore::GameControllerHapticEffect::create): Canonical link: https://commits.webkit.org/258759@main
1 parent 4eaf82b commit cebb092

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Source/WebCore/Modules/gamepad/GamepadEffectParameters.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ struct GamepadEffectParameters {
3434
double startDelay = 0.0;
3535
double strongMagnitude = 0.0;
3636
double weakMagnitude = 0.0;
37+
38+
// A maximum duration of 5 seconds is recommended by the specification:
39+
// - https://w3c.github.io/gamepad/extensions.html#gamepadeffectparameters-dictionary
40+
static constexpr Seconds maximumDuration = 5_s;
3741
};
3842

3943
} // namespace WebCore

Source/WebCore/Modules/gamepad/GamepadHapticActuator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ void GamepadHapticActuator::playEffect(Document& document, EffectType effectType
8787
promise->reject(Exception { NotSupportedError, "This gamepad doesn't support playing such effect"_s });
8888
return;
8989
}
90+
91+
effectParameters.duration = std::min(effectParameters.duration, GamepadEffectParameters::maximumDuration.milliseconds());
92+
9093
m_playingEffectPromise = WTFMove(promise);
9194
GamepadProvider::singleton().playEffect(m_gamepad->index(), m_gamepad->id(), effectType, effectParameters, [this, protectedThis = Ref { *this }, document = Ref { document }, playingEffectPromise = m_playingEffectPromise](bool success) {
9295
if (m_playingEffectPromise != playingEffectPromise)

Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEffect.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
@{ CHHapticPatternKeyEvent: @{
4545
CHHapticPatternKeyEventType: CHHapticEventTypeHapticContinuous,
4646
CHHapticPatternKeyTime: [NSNumber numberWithDouble:std::max<double>(parameters.startDelay / 1000., 0)],
47-
CHHapticPatternKeyEventDuration: [NSNumber numberWithDouble:std::max<double>(parameters.duration / 1000., 0)],
47+
CHHapticPatternKeyEventDuration: [NSNumber numberWithDouble:std::clamp<double>(parameters.duration / 1000., 0, GamepadEffectParameters::maximumDuration.seconds())],
4848
CHHapticPatternKeyEventParameters: @[ @{
4949
CHHapticPatternKeyParameterID: CHHapticEventParameterIDHapticIntensity,
5050
CHHapticPatternKeyParameterValue: [NSNumber numberWithDouble:std::clamp<double>(intensity, 0, 1)],

0 commit comments

Comments
 (0)