Bug 1336002 - Part 2: Support button touched in GamepadManager; r?lenzak draft
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 07 Apr 2017 09:35:13 +0800
changeset 559527 9e56b7b89eed92f25a18b35de19a238a307499d2
parent 559526 23bfa984ac68cd2ecd5c1b0d3d1e33430886877c
child 559528 cf46dabee647aa03d6a68bc4e8e698a9c389f029
push id53123
push userbmo:dmu@mozilla.com
push dateMon, 10 Apr 2017 08:36:28 +0000
reviewerslenzak
bugs1336002
milestone55.0a1
Bug 1336002 - Part 2: Support button touched in GamepadManager; r?lenzak MozReview-Commit-ID: DcX988Obthp
dom/gamepad/GamepadManager.cpp
dom/gamepad/GamepadManager.h
dom/gamepad/GamepadPlatformService.cpp
dom/gamepad/GamepadPlatformService.h
dom/gamepad/GamepadServiceTest.cpp
dom/gamepad/GamepadServiceTest.h
dom/gamepad/ipc/GamepadEventTypes.ipdlh
dom/gamepad/ipc/GamepadTestChannelParent.cpp
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -264,30 +264,31 @@ GamepadManager::RemoveGamepad(uint32_t a
   }
   gamepad->SetConnected(false);
   NewConnectionEvent(newIndex, false);
   mGamepads.Remove(newIndex);
 }
 
 void
 GamepadManager::NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType,
-                               uint32_t aButton, bool aPressed, double aValue)
+                               uint32_t aButton, bool aPressed, bool aTouched,
+                               double aValue)
 {
   if (mShuttingDown) {
     return;
   }
 
   uint32_t newIndex = GetGamepadIndexWithServiceType(aIndex, aServiceType);
 
   RefPtr<Gamepad> gamepad = GetGamepad(newIndex);
   if (!gamepad) {
     return;
   }
 
-  gamepad->SetButton(aButton, aPressed, aValue);
+  gamepad->SetButton(aButton, aPressed, aTouched, aValue);
 
   // 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++) {
 
@@ -298,17 +299,17 @@ GamepadManager::NewButtonEvent(uint32_t 
         listeners[i]->GetOuterWindow()->IsBackground()) {
       continue;
     }
 
     bool firstTime = MaybeWindowHasSeenGamepad(listeners[i], newIndex);
 
     RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(newIndex);
     if (listenerGamepad) {
-      listenerGamepad->SetButton(aButton, aPressed, aValue);
+      listenerGamepad->SetButton(aButton, aPressed, aTouched, aValue);
       if (firstTime) {
         FireConnectionEvent(listeners[i], listenerGamepad, true);
       }
       if (mNonstandardEventsEnabled) {
         // Fire event
         FireButtonEvent(listeners[i], listenerGamepad, aButton, aValue);
       }
     }
@@ -645,17 +646,17 @@ GamepadManager::Update(const GamepadChan
   if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) {
     const GamepadRemoved& a = aEvent.get_GamepadRemoved();
     RemoveGamepad(a.index(), a.service_type());
     return;
   }
   if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
     const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
     NewButtonEvent(a.index(), a.service_type(), a.button(),
-                   a.pressed(), a.value());
+                   a.pressed(), a.touched(), a.value());
     return;
   }
   if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {
     const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation();
     NewAxisMoveEvent(a.index(), a.service_type(), a.axis(), a.value());
     return;
   }
   if (aEvent.type() == GamepadChangeEvent::TGamepadPoseInformation) {
--- a/dom/gamepad/GamepadManager.h
+++ b/dom/gamepad/GamepadManager.h
@@ -57,17 +57,17 @@ class GamepadManager final : public nsIO
   // 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.
   void NewButtonEvent(uint32_t aIndex, GamepadServiceType aServiceType, uint32_t aButton,
-                      bool aPressed, double aValue);
+                      bool aPressed, bool aTouched, double aValue);
 
   // Update the state of |aAxis| for the gamepad at |aIndex| for all
   // windows that are listening and visible, and fire a gamepadaxismove
   // event at them as well.
   void NewAxisMoveEvent(uint32_t aIndex, GamepadServiceType aServiceType,
                         uint32_t aAxis, double aValue);
 
   // Update the state of |aState| for the gamepad at |aIndex| for all
--- a/dom/gamepad/GamepadPlatformService.cpp
+++ b/dom/gamepad/GamepadPlatformService.cpp
@@ -112,37 +112,50 @@ GamepadPlatformService::RemoveGamepad(ui
   MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(!NS_IsMainThread());
   GamepadRemoved a(aIndex, GamepadServiceType::Standard);
   NotifyGamepadChange<GamepadRemoved>(a);
 }
 
 void
 GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
-                                       bool aPressed, double aValue)
+                                       bool aPressed, bool aTouched,
+                                       double aValue)
 {
   // This method is called by monitor thread populated in
   // platform-dependent backends
   MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(!NS_IsMainThread());
   GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
-                             aButton, aPressed, aValue);
+                             aButton, aValue, aPressed, aTouched);
   NotifyGamepadChange<GamepadButtonInformation>(a);
 }
 
 void
 GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
+                                       bool aPressed, bool aTouched)
+{
+  // This method is called by monitor thread populated in
+  // platform-dependent backends
+  MOZ_ASSERT(XRE_IsParentProcess());
+  MOZ_ASSERT(!NS_IsMainThread());
+  // When only a digital button is available the value will be synthesized.
+  NewButtonEvent(aIndex, aButton, aPressed, aTouched, aPressed ? 1.0L : 0.0L);
+}
+
+void
+GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
                                        bool aPressed)
 {
   // This method is called by monitor thread populated in
   // platform-dependent backends
   MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(!NS_IsMainThread());
   // When only a digital button is available the value will be synthesized.
-  NewButtonEvent(aIndex, aButton, aPressed, aPressed ? 1.0L : 0.0L);
+  NewButtonEvent(aIndex, aButton, aPressed, aPressed, aPressed ? 1.0L : 0.0L);
 }
 
 void
 GamepadPlatformService::NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis,
                                          double aValue)
 {
   // This method is called by monitor thread populated in
   // platform-dependent backends
--- a/dom/gamepad/GamepadPlatformService.h
+++ b/dom/gamepad/GamepadPlatformService.h
@@ -41,21 +41,25 @@ class GamepadPlatformService final
                       GamepadHand aHand, uint32_t aNumButtons,
                       uint32_t aNumAxes, uint32_t aNumHaptics);
   // Remove the gamepad at |aIndex| from the list of known gamepads.
   void RemoveGamepad(uint32_t aIndex);
 
   // 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.
+  // aPressed is used for digital buttons, aTouched is for detecting touched
+  // events, aValue is for analog buttons.
   void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed,
-                      double aValue);
+                      bool aTouched, double aValue);
   // When only a digital button is available the value will be synthesized.
   void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
+  // When only a digital button are available the value will be synthesized.
+  void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed,
+                      bool aTouched);
 
   // Update the state of |aAxis| for the gamepad at |aIndex| for all
   // windows that are listening and visible, and fire a gamepadaxismove
   // event at them as well.
   void NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue);
   // Update the state of |aState| for the gamepad at |aIndex| for all
   // windows that are listening and visible.
   void NewPoseEvent(uint32_t aIndex, const GamepadPoseState& aState);
--- a/dom/gamepad/GamepadServiceTest.cpp
+++ b/dom/gamepad/GamepadServiceTest.cpp
@@ -163,47 +163,49 @@ GamepadServiceTest::RemoveGamepad(uint32
     PendingOperation op(id, e);
     mPendingOperations.AppendElement(op);
   }
 }
 
 void
 GamepadServiceTest::NewButtonEvent(uint32_t aIndex,
                                    uint32_t aButton,
+                                   bool aTouched,
                                    bool aPressed)
 {
   if (mShuttingDown) {
     return;
   }
 
   GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
-                             aButton, aPressed, aPressed ? 1.0 : 0);
+                             aButton, aPressed ? 1.0 : 0, aPressed, aTouched);
   GamepadChangeEvent e(a);
 
   uint32_t id = ++mEventNumber;
   if (mChild) {
     mChild->SendGamepadTestEvent(id, e);
   } else {
     PendingOperation op(id, e);
     mPendingOperations.AppendElement(op);
   }
 }
 
 void
 GamepadServiceTest::NewButtonValueEvent(uint32_t aIndex,
                                         uint32_t aButton,
                                         bool aPressed,
+                                        bool aTouched,
                                         double aValue)
 {
   if (mShuttingDown) {
     return;
   }
 
   GamepadButtonInformation a(aIndex, GamepadServiceType::Standard,
-                             aButton, aPressed, aValue);
+                             aButton, aValue, aPressed, aTouched);
   GamepadChangeEvent e(a);
 
   uint32_t id = ++mEventNumber;
   if (mChild) {
     mChild->SendGamepadTestEvent(id, e);
   } else {
     PendingOperation op(id, e);
     mPendingOperations.AppendElement(op);
--- a/dom/gamepad/GamepadServiceTest.h
+++ b/dom/gamepad/GamepadServiceTest.h
@@ -38,18 +38,19 @@ public:
   already_AddRefed<Promise> AddGamepad(const nsAString& aID,
                                        GamepadMappingType aMapping,
                                        GamepadHand aHand,
                                        uint32_t aNumButtons,
                                        uint32_t aNumAxes,
                                        uint32_t aNumHaptics,
                                        ErrorResult& aRv);
   void RemoveGamepad(uint32_t aIndex);
-  void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed);
-  void NewButtonValueEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, double aValue);
+  void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, bool aTouched);
+  void NewButtonValueEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, bool aTouched,
+                           double aValue);
   void NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue);
   void NewPoseMove(uint32_t aIndex,
                    const Nullable<Float32Array>& aOrient,
                    const Nullable<Float32Array>& aPos,
                    const Nullable<Float32Array>& aAngVelocity,
                    const Nullable<Float32Array>& aAngAcceleration,
                    const Nullable<Float32Array>& aLinVelocity,
                    const Nullable<Float32Array>& aLinAcceleration);
--- a/dom/gamepad/ipc/GamepadEventTypes.ipdlh
+++ b/dom/gamepad/ipc/GamepadEventTypes.ipdlh
@@ -33,18 +33,19 @@ struct GamepadAxisInformation {
   uint32_t axis;
   double value;
 };
 
 struct GamepadButtonInformation {
   uint32_t index;
   GamepadServiceType service_type;
   uint32_t button;
+  double value;
   bool pressed;
-  double value;
+  bool touched;
 };
 
 struct GamepadPoseInformation {
   uint32_t index;
   GamepadServiceType service_type;
   GamepadPoseState pose_state;
 };
 
--- a/dom/gamepad/ipc/GamepadTestChannelParent.cpp
+++ b/dom/gamepad/ipc/GamepadTestChannelParent.cpp
@@ -35,17 +35,18 @@ GamepadTestChannelParent::RecvGamepadTes
   }
   if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) {
     const GamepadRemoved& a = aEvent.get_GamepadRemoved();
     service->RemoveGamepad(a.index());
     return IPC_OK();
   }
   if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) {
     const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation();
-    service->NewButtonEvent(a.index(), a.button(), a.pressed(), a.value());
+    service->NewButtonEvent(a.index(), a.button(), a.pressed(), a.touched(),
+                            a.value());
     return IPC_OK();
   }
   if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) {
     const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation();
     service->NewAxisMoveEvent(a.index(), a.axis(), a.value());
     return IPC_OK();
   }
   if (aEvent.type() == GamepadChangeEvent::TGamepadPoseInformation) {