Bug 1313581 - Part 2: Support hand attribute in GamepadManager; r?lenzak800, kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Mon, 14 Nov 2016 17:30:31 +0800
changeset 448075 4524cbf3937e1fce07a070e287d2007ad339f29a
parent 448074 6cf2a0aa67f56eb438ba4f420a4fd53896fb6818
child 448076 12dd1dfa89746f77fd3bd4860372161f41252ef3
push id38254
push userbmo:dmu@mozilla.com
push dateFri, 09 Dec 2016 02:25:14 +0000
reviewerslenzak800, kip
bugs1313581
milestone53.0a1
Bug 1313581 - Part 2: Support hand attribute in GamepadManager; r?lenzak800, kip MozReview-Commit-ID: 4sIRuzH0HMl
dom/gamepad/GamepadManager.cpp
dom/gamepad/GamepadManager.h
dom/gamepad/GamepadPlatformService.cpp
dom/gamepad/GamepadServiceTest.cpp
--- 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;