mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 12:55:46 +00:00
Bug 1356452 - Part 3: Support changing gamepad hand property in GamepadManager; r=Lenzak
MozReview-Commit-ID: KZx2qJqks6f --HG-- extra : rebase_source : f2d3d70f7394964b07bc45d4db1bfd6b56694e38
This commit is contained in:
parent
ba21000af3
commit
9e638e1eac
@ -451,6 +451,49 @@ GamepadManager::NewPoseEvent(uint32_t aIndex, GamepadServiceType aServiceType,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GamepadManager::NewHandChangeEvent(uint32_t aIndex, GamepadServiceType aServiceType,
|
||||
GamepadHand aHand)
|
||||
{
|
||||
if (mShuttingDown) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t newIndex = GetGamepadIndexWithServiceType(aIndex, aServiceType);
|
||||
|
||||
RefPtr<Gamepad> gamepad = GetGamepad(newIndex);
|
||||
if (!gamepad) {
|
||||
return;
|
||||
}
|
||||
gamepad->SetHand(aHand);
|
||||
|
||||
// Hold on to listeners in a separate array because firing events
|
||||
// can mutate the mListeners array.
|
||||
nsTArray<RefPtr<nsGlobalWindow>> listeners(mListeners);
|
||||
MOZ_ASSERT(!listeners.IsEmpty());
|
||||
|
||||
for (uint32_t i = 0; i < listeners.Length(); i++) {
|
||||
|
||||
MOZ_ASSERT(listeners[i]->IsInnerWindow());
|
||||
|
||||
// Only send events to non-background windows
|
||||
if (!listeners[i]->AsInner()->IsCurrentInnerWindow() ||
|
||||
listeners[i]->GetOuterWindow()->IsBackground()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool firstTime = MaybeWindowHasSeenGamepad(listeners[i], newIndex);
|
||||
|
||||
RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(newIndex);
|
||||
if (listenerGamepad) {
|
||||
listenerGamepad->SetHand(aHand);
|
||||
if (firstTime) {
|
||||
FireConnectionEvent(listeners[i], listenerGamepad, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GamepadManager::NewConnectionEvent(uint32_t aIndex, bool aConnected)
|
||||
{
|
||||
@ -664,6 +707,11 @@ GamepadManager::Update(const GamepadChangeEvent& aEvent)
|
||||
NewPoseEvent(a.index(), a.service_type(), a.pose_state());
|
||||
return;
|
||||
}
|
||||
if (aEvent.type() == GamepadChangeEvent::TGamepadHandInformation) {
|
||||
const GamepadHandInformation& a = aEvent.get_GamepadHandInformation();
|
||||
NewHandChangeEvent(a.index(), a.service_type(), a.hand());
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_CRASH("We shouldn't be here!");
|
||||
|
||||
|
@ -75,6 +75,11 @@ class GamepadManager final : public nsIObserver,
|
||||
void NewPoseEvent(uint32_t aIndex, GamepadServiceType aServiceType,
|
||||
const GamepadPoseState& aState);
|
||||
|
||||
// Update the hand of |aHand| for the gamepad at |aIndex| for all
|
||||
// windows that are listening and visible.
|
||||
void NewHandChangeEvent(uint32_t aIndex, GamepadServiceType aServiceType,
|
||||
GamepadHand aHand);
|
||||
|
||||
// Synchronize the state of |aGamepad| to match the gamepad stored at |aIndex|
|
||||
void SyncGamepadState(uint32_t aIndex, Gamepad* aGamepad);
|
||||
|
||||
|
@ -49,12 +49,19 @@ struct GamepadPoseInformation {
|
||||
GamepadPoseState pose_state;
|
||||
};
|
||||
|
||||
struct GamepadHandInformation {
|
||||
uint32_t index;
|
||||
GamepadServiceType service_type;
|
||||
GamepadHand hand;
|
||||
};
|
||||
|
||||
union GamepadChangeEvent {
|
||||
GamepadAdded;
|
||||
GamepadRemoved;
|
||||
GamepadAxisInformation;
|
||||
GamepadButtonInformation;
|
||||
GamepadPoseInformation;
|
||||
GamepadHandInformation;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user