Bug 1336002 - Part 1: Support button touched in the Gamepad API; r?qdot draft
authorDaosheng Mu <daoshengmu@gmail.com>
Thu, 06 Apr 2017 18:36:46 +0800
changeset 559526 23bfa984ac68cd2ecd5c1b0d3d1e33430886877c
parent 559365 45692c884fdd5136a64fb2f8a61a0c8183b69331
child 559527 9e56b7b89eed92f25a18b35de19a238a307499d2
push id53123
push userbmo:dmu@mozilla.com
push dateMon, 10 Apr 2017 08:36:28 +0000
reviewersqdot
bugs1336002
milestone55.0a1
Bug 1336002 - Part 1: Support button touched in the Gamepad API; r?qdot MozReview-Commit-ID: FVWo5bpuSkS
dom/gamepad/Gamepad.cpp
dom/gamepad/Gamepad.h
dom/gamepad/GamepadButton.h
dom/webidl/Gamepad.webidl
dom/webidl/GamepadServiceTest.webidl
--- a/dom/gamepad/Gamepad.cpp
+++ b/dom/gamepad/Gamepad.cpp
@@ -73,20 +73,22 @@ Gamepad::SetIndex(uint32_t aIndex)
 
 void
 Gamepad::SetConnected(bool aConnected)
 {
   mConnected = aConnected;
 }
 
 void
-Gamepad::SetButton(uint32_t aButton, bool aPressed, double aValue)
+Gamepad::SetButton(uint32_t aButton, bool aPressed,
+                   bool aTouched, double aValue)
 {
   MOZ_ASSERT(aButton < mButtons.Length());
   mButtons[aButton]->SetPressed(aPressed);
+  mButtons[aButton]->SetTouched(aTouched);
   mButtons[aButton]->SetValue(aValue);
   UpdateTimestamp();
 }
 
 void
 Gamepad::SetAxis(uint32_t aAxis, double aValue)
 {
   MOZ_ASSERT(aAxis < mAxes.Length());
@@ -111,16 +113,17 @@ Gamepad::SyncState(Gamepad* aOther)
   if (mButtons.Length() != aOther->mButtons.Length() ||
       mAxes.Length() != aOther->mAxes.Length()) {
     return;
   }
 
   mConnected = aOther->mConnected;
   for (uint32_t i = 0; i < mButtons.Length(); ++i) {
     mButtons[i]->SetPressed(aOther->mButtons[i]->Pressed());
+    mButtons[i]->SetTouched(aOther->mButtons[i]->Touched());
     mButtons[i]->SetValue(aOther->mButtons[i]->Value());
   }
 
   bool changed = false;
   for (uint32_t i = 0; i < mAxes.Length(); ++i) {
     changed = changed || (mAxes[i] != aOther->mAxes[i]);
     mAxes[i] = aOther->mAxes[i];
   }
--- a/dom/gamepad/Gamepad.h
+++ b/dom/gamepad/Gamepad.h
@@ -46,17 +46,18 @@ public:
           GamepadMappingType aMapping, GamepadHand aHand,
           uint32_t aNumButtons, uint32_t aNumAxes,
           uint32_t aNumHaptics);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Gamepad)
 
   void SetConnected(bool aConnected);
-  void SetButton(uint32_t aButton, bool aPressed, double aValue);
+  void SetButton(uint32_t aButton, bool aPressed,
+                 bool aTouched, double aValue);
   void SetAxis(uint32_t aAxis, double aValue);
   void SetIndex(uint32_t aIndex);
   void SetPose(const GamepadPoseState& aPose);
 
   // Make the state of this gamepad equivalent to other.
   void SyncState(Gamepad* aOther);
 
   // Return a new Gamepad containing the same data as this object,
--- a/dom/gamepad/GamepadButton.h
+++ b/dom/gamepad/GamepadButton.h
@@ -14,18 +14,19 @@
 namespace mozilla {
 namespace dom {
 
 class GamepadButton : public nsISupports,
                       public nsWrapperCache
 {
 public:
   explicit GamepadButton(nsISupports* aParent) : mParent(aParent),
+                                                 mValue(0),
                                                  mPressed(false),
-                                                 mValue(0)
+                                                 mTouched(false)
   {
   }
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(GamepadButton)
 
   nsISupports* GetParentObject() const
   {
@@ -34,36 +35,47 @@ public:
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void SetPressed(bool aPressed)
   {
     mPressed = aPressed;
   }
 
+  void SetTouched(bool aTouched)
+  {
+    mTouched = aTouched;
+  }
+
   void SetValue(double aValue)
   {
     mValue = aValue;
   }
 
   bool Pressed() const
   {
     return mPressed;
   }
 
+  bool Touched() const
+  {
+    return mTouched;
+  }
+
   double Value() const
   {
     return mValue;
   }
 
 private:
   virtual ~GamepadButton() {}
 
 protected:
   nsCOMPtr<nsISupports> mParent;
+  double mValue;
   bool mPressed;
-  double mValue;
+  bool mTouched;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_gamepad_GamepadButton_h
--- a/dom/webidl/Gamepad.webidl
+++ b/dom/webidl/Gamepad.webidl
@@ -6,16 +6,17 @@
  * The origin of this IDL file is
  * https://w3c.github.io/gamepad/
  * https://w3c.github.io/gamepad/extensions.html
  */
 
 [Pref="dom.gamepad.enabled"]
 interface GamepadButton {
   readonly    attribute boolean pressed;
+  readonly    attribute boolean touched;
   readonly    attribute double  value;
 };
 
 enum GamepadHand {
   "",
   "left",
   "right"
 };
--- a/dom/webidl/GamepadServiceTest.webidl
+++ b/dom/webidl/GamepadServiceTest.webidl
@@ -18,21 +18,23 @@ interface GamepadServiceTest
                                     unsigned long numButtons,
                                     unsigned long numAxes,
                                     unsigned long numHaptics);
 
   void removeGamepad(unsigned long index);
 
   void newButtonEvent(unsigned long index,
                       unsigned long button,
-                      boolean pressed);
+                      boolean pressed,
+                      boolean touched);
 
   void newButtonValueEvent(unsigned long index,
                            unsigned long button,
                            boolean pressed,
+                           boolean touched,
                            double value);
 
   void newAxisMoveEvent(unsigned long index,
                         unsigned long axis,
                         double value);
   void newPoseMove(unsigned long index,
                    Float32Array? orient,
                    Float32Array? pos,