Bug 1313581 - Part 2: Support hand attribute in GamepadManager; r?lenzak800, kip
MozReview-Commit-ID: 4sIRuzH0HMl
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -223,26 +223,28 @@ uint32_t GamepadManager::GetGamepadIndex
return newIndex;
}
void
GamepadManager::AddGamepad(uint32_t aIndex,
const nsAString& aId,
GamepadMappingType aMapping,
+ GamepadHand aHand,
GamepadServiceType aServiceType,
uint32_t aNumButtons,
uint32_t aNumAxes)
{
//TODO: bug 852258: get initial button/axis state
RefPtr<Gamepad> gamepad =
new Gamepad(nullptr,
aId,
0, // index is set by global window
aMapping,
+ aHand,
aNumButtons,
aNumAxes);
uint32_t newIndex = GetGamepadIndexWithServiceType(aIndex, aServiceType);
// We store the gamepad related to its index given by the parent process,
// and no duplicate index is allowed.
MOZ_ASSERT(!mGamepads.Get(newIndex, nullptr));
@@ -629,16 +631,17 @@ GamepadManager::SetWindowHasSeenGamepad(
void
GamepadManager::Update(const GamepadChangeEvent& aEvent)
{
if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) {
const GamepadAdded& a = aEvent.get_GamepadAdded();
AddGamepad(a.index(), a.id(),
static_cast<GamepadMappingType>(a.mapping()),
+ static_cast<GamepadHand>(a.hand()),
a.service_type(),
a.num_buttons(), a.num_axes());
return;
}
if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) {
const GamepadRemoved& a = aEvent.get_GamepadRemoved();
RemoveGamepad(a.index(), a.service_type());
return;
--- a/dom/gamepad/GamepadManager.h
+++ b/dom/gamepad/GamepadManager.h
@@ -46,17 +46,18 @@ class GamepadManager final : public nsIO
// Indicate that |aWindow| wants to receive gamepad events.
void AddListener(nsGlobalWindow* aWindow);
// Indicate that |aWindow| should no longer receive gamepad events.
void RemoveListener(nsGlobalWindow* aWindow);
// Add a gamepad to the list of known gamepads.
void AddGamepad(uint32_t aIndex, const nsAString& aID, GamepadMappingType aMapping,
- GamepadServiceType aServiceType, uint32_t aNumButtons, uint32_t aNumAxes);
+ GamepadHand aHand, GamepadServiceType aServiceType,
+ uint32_t aNumButtons, uint32_t aNumAxes);
// Remove the gamepad at |aIndex| from the list of known gamepads.
void RemoveGamepad(uint32_t aIndex, GamepadServiceType aServiceType);
// Update the state of |aButton| for the gamepad at |aIndex| for all
// windows that are listening and visible, and fire one of
// a gamepadbutton{up,down} event at them as well.
// aPressed is used for digital buttons, aValue is for analog buttons.
--- a/dom/gamepad/GamepadPlatformService.cpp
+++ b/dom/gamepad/GamepadPlatformService.cpp
@@ -90,17 +90,18 @@ GamepadPlatformService::AddGamepad(const
{
// This method is called by monitor thread populated in
// platform-dependent backends
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(!NS_IsMainThread());
uint32_t index = ++mGamepadIndex;
GamepadAdded a(NS_ConvertUTF8toUTF16(nsDependentCString(aID)), index,
- static_cast<uint32_t>(aMapping), GamepadServiceType::Standard, aNumButtons, aNumAxes);
+ static_cast<uint32_t>(aMapping), static_cast<uint32_t>(GamepadHand::_empty),
+ GamepadServiceType::Standard, aNumButtons, aNumAxes);
NotifyGamepadChange<GamepadAdded>(a);
return index;
}
void
GamepadPlatformService::RemoveGamepad(uint32_t aIndex)
{
// This method is called by monitor thread populated in
--- a/dom/gamepad/GamepadServiceTest.cpp
+++ b/dom/gamepad/GamepadServiceTest.cpp
@@ -118,17 +118,17 @@ GamepadServiceTest::AddGamepad(const nsA
uint32_t aNumAxes,
ErrorResult& aRv)
{
if (mShuttingDown) {
return nullptr;
}
GamepadAdded a(nsString(aID), 0,
- aMapping,
+ aMapping, static_cast<uint32_t>(GamepadHand::_empty),
GamepadServiceType::Standard,
aNumButtons, aNumAxes);
GamepadChangeEvent e(a);
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
RefPtr<Promise> p = Promise::Create(go, aRv);
if (aRv.Failed()) {
return nullptr;