@@ -225,14 +225,17 @@ void GamepadManager::AddGamepad(uint32_t aIndex, const nsAString& aId,
225225 GamepadMappingType aMapping, GamepadHand aHand,
226226 GamepadServiceType aServiceType,
227227 uint32_t aDisplayID, uint32_t aNumButtons,
228- uint32_t aNumAxes, uint32_t aNumHaptics) {
228+ uint32_t aNumAxes, uint32_t aNumHaptics,
229+ uint32_t aNumLightIndicator,
230+ uint32_t aNumTouchEvents) {
229231 uint32_t newIndex = GetGamepadIndexWithServiceType (aIndex, aServiceType);
230232
231233 // TODO: bug 852258: get initial button/axis state
232- RefPtr<Gamepad> gamepad = new Gamepad (nullptr , aId,
233- 0 , // index is set by global window
234- newIndex, aMapping, aHand, aDisplayID,
235- aNumButtons, aNumAxes, aNumHaptics);
234+ RefPtr<Gamepad> gamepad =
235+ new Gamepad (nullptr , aId,
236+ 0 , // index is set by global window
237+ newIndex, aMapping, aHand, aDisplayID, aNumButtons, aNumAxes,
238+ aNumHaptics, aNumLightIndicator, aNumTouchEvents);
236239
237240 // We store the gamepad related to its index given by the parent process,
238241 // and no duplicate index is allowed.
@@ -471,7 +474,8 @@ void GamepadManager::Update(const GamepadChangeEvent& aEvent) {
471474 const GamepadAdded& a = body.get_GamepadAdded ();
472475 AddGamepad (index, a.id (), static_cast <GamepadMappingType>(a.mapping ()),
473476 static_cast <GamepadHand>(a.hand ()), serviceType, a.display_id (),
474- a.num_buttons (), a.num_axes (), a.num_haptics ());
477+ a.num_buttons (), a.num_axes (), a.num_haptics (), a.num_lights (),
478+ a.num_touches ());
475479 return ;
476480 }
477481 if (body.type () == GamepadChangeEventBody::TGamepadRemoved) {
@@ -561,6 +565,25 @@ bool GamepadManager::SetGamepadByEvent(const GamepadChangeEvent& aEvent,
561565 gamepad->SetPose (a.pose_state ());
562566 break ;
563567 }
568+ case GamepadChangeEventBody::TGamepadLightIndicatorTypeInformation: {
569+ const GamepadLightIndicatorTypeInformation& a =
570+ body.get_GamepadLightIndicatorTypeInformation ();
571+ gamepad->SetLightIndicatorType (a.light (), a.type ());
572+ break ;
573+ }
574+ case GamepadChangeEventBody::TGamepadTouchInformation: {
575+ // Avoid GamepadTouch's touchId be accessed in cross-origin tracking.
576+ for (uint32_t i = 0 ; i < mListeners .Length (); i++) {
577+ RefPtr<Gamepad> listenerGamepad = mListeners [i]->GetGamepad (index);
578+ if (listenerGamepad && mListeners [i]->IsCurrentInnerWindow () &&
579+ !mListeners [i]->GetOuterWindow ()->IsBackground ()) {
580+ const GamepadTouchInformation& a =
581+ body.get_GamepadTouchInformation ();
582+ listenerGamepad->SetTouchEvent (a.index (), a.touch_state ());
583+ }
584+ }
585+ break ;
586+ }
564587 case GamepadChangeEventBody::TGamepadHandInformation: {
565588 const GamepadHandInformation& a = body.get_GamepadHandInformation ();
566589 gamepad->SetHand (a.hand ());
@@ -583,13 +606,12 @@ bool GamepadManager::SetGamepadByEvent(const GamepadChangeEvent& aEvent,
583606already_AddRefed<Promise> GamepadManager::VibrateHaptic (
584607 uint32_t aControllerIdx, uint32_t aHapticIndex, double aIntensity,
585608 double aDuration, nsIGlobalObject* aGlobal, ErrorResult& aRv) {
586- const char * kGamepadHapticEnabledPref = " dom.gamepad.haptic_feedback.enabled" ;
587609 RefPtr<Promise> promise = Promise::Create (aGlobal, aRv);
588610 if (NS_WARN_IF(aRv.Failed ())) {
589611 aRv.Throw (NS_ERROR_FAILURE);
590612 return nullptr ;
591613 }
592- if (Preferences::GetBool ( kGamepadHapticEnabledPref )) {
614+ if (StaticPrefs::dom_gamepad_haptic_feedback_enabled ( )) {
593615 if (aControllerIdx >= VR_GAMEPAD_IDX_OFFSET) {
594616 if (gfx::VRManagerChild::IsCreated ()) {
595617 const uint32_t index = aControllerIdx - VR_GAMEPAD_IDX_OFFSET;
@@ -612,8 +634,7 @@ already_AddRefed<Promise> GamepadManager::VibrateHaptic(
612634}
613635
614636void GamepadManager::StopHaptics () {
615- const char * kGamepadHapticEnabledPref = " dom.gamepad.haptic_feedback.enabled" ;
616- if (!Preferences::GetBool (kGamepadHapticEnabledPref )) {
637+ if (!StaticPrefs::dom_gamepad_haptic_feedback_enabled ()) {
617638 return ;
618639 }
619640
@@ -633,5 +654,32 @@ void GamepadManager::StopHaptics() {
633654 }
634655}
635656
657+ already_AddRefed<Promise> GamepadManager::SetLightIndicatorColor (
658+ uint32_t aControllerIdx, uint32_t aLightColorIndex, uint8_t aRed,
659+ uint8_t aGreen, uint8_t aBlue, nsIGlobalObject* aGlobal, ErrorResult& aRv) {
660+ RefPtr<Promise> promise = Promise::Create (aGlobal, aRv);
661+ if (NS_WARN_IF(aRv.Failed ())) {
662+ aRv.Throw (NS_ERROR_FAILURE);
663+ return nullptr ;
664+ }
665+ if (StaticPrefs::dom_gamepad_extensions_lightindicator ()) {
666+ for (auto iter = mGamepads .Iter (); !iter.Done (); iter.Next ()) {
667+ const uint32_t gamepadIndex = iter.UserData ()->HashKey ();
668+ if (gamepadIndex >= VR_GAMEPAD_IDX_OFFSET) {
669+ MOZ_ASSERT (false && " We don't support light indicator in VR." );
670+ } else {
671+ for (auto & channelChild : mChannelChildren ) {
672+ channelChild->AddPromise (mPromiseID , promise);
673+ channelChild->SendLightIndicatorColor (aControllerIdx,
674+ aLightColorIndex, aRed, aGreen,
675+ aBlue, mPromiseID );
676+ }
677+ }
678+ }
679+ }
680+
681+ ++mPromiseID ;
682+ return promise.forget ();
683+ }
636684} // namespace dom
637685} // namespace mozilla
0 commit comments