Bug 1352410 - Add a preference to enable or disable haptic feedback for gamepads; r?lenzak
MozReview-Commit-ID: 70FFdcd3n5q
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -636,47 +636,54 @@ GamepadManager::SetGamepadByEvent(const
return ret;
}
already_AddRefed<Promise>
GamepadManager::VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
double aIntensity, double aDuration,
nsIGlobalObject* aGlobal, ErrorResult& aRv)
{
+ const char* kGamepadHapticEnabledPref = "dom.gamepad.haptic_feedback.enabled";
RefPtr<Promise> promise = Promise::Create(aGlobal, aRv);
if (NS_WARN_IF(aRv.Failed())) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
-
- if (aControllerIdx >= VR_GAMEPAD_IDX_OFFSET) {
- if (gfx::VRManagerChild::IsCreated()) {
- const uint32_t index = aControllerIdx - VR_GAMEPAD_IDX_OFFSET;
- gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
- vm->AddPromise(mPromiseID, promise);
- vm->SendVibrateHaptic(index, aHapticIndex,
- aIntensity, aDuration,
- mPromiseID);
- }
- } else {
- for (const auto& channelChild: mChannelChildren) {
- channelChild->AddPromise(mPromiseID, promise);
- channelChild->SendVibrateHaptic(aControllerIdx, aHapticIndex,
- aIntensity, aDuration,
- mPromiseID);
+ if (Preferences::GetBool(kGamepadHapticEnabledPref)) {
+ if (aControllerIdx >= VR_GAMEPAD_IDX_OFFSET) {
+ if (gfx::VRManagerChild::IsCreated()) {
+ const uint32_t index = aControllerIdx - VR_GAMEPAD_IDX_OFFSET;
+ gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
+ vm->AddPromise(mPromiseID, promise);
+ vm->SendVibrateHaptic(index, aHapticIndex,
+ aIntensity, aDuration,
+ mPromiseID);
+ }
+ } else {
+ for (const auto& channelChild: mChannelChildren) {
+ channelChild->AddPromise(mPromiseID, promise);
+ channelChild->SendVibrateHaptic(aControllerIdx, aHapticIndex,
+ aIntensity, aDuration,
+ mPromiseID);
+ }
}
}
++mPromiseID;
return promise.forget();
}
void
GamepadManager::StopHaptics()
{
+ const char* kGamepadHapticEnabledPref = "dom.gamepad.haptic_feedback.enabled";
+ if (!Preferences::GetBool(kGamepadHapticEnabledPref)) {
+ return;
+ }
+
for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) {
const uint32_t gamepadIndex = iter.UserData()->HashKey();
if (gamepadIndex >= VR_GAMEPAD_IDX_OFFSET) {
if (gfx::VRManagerChild::IsCreated()) {
const uint32_t index = gamepadIndex - VR_GAMEPAD_IDX_OFFSET;
gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
vm->SendStopVibrateHaptic(index);
}
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -197,16 +197,17 @@ pref("dom.requestIdleCallback.enabled",
pref("dom.gamepad.enabled", true);
pref("dom.gamepad.test.enabled", false);
#ifdef RELEASE_OR_BETA
pref("dom.gamepad.non_standard_events.enabled", false);
#else
pref("dom.gamepad.non_standard_events.enabled", true);
#endif
pref("dom.gamepad.extensions.enabled", true);
+pref("dom.gamepad.haptic_feedback.enabled", true);
// If this is true, TextEventDispatcher dispatches keydown and keyup events
// even during composition (keypress events are never fired during composition
// even if this is true).
pref("dom.keyboardevent.dispatch_during_composition", false);
// Whether to run add-on code in different compartments from browser code. This
// causes a separate compartment for each (addon, global) combination, which may