Bug 1375816 - Part 1: Add displayId attribute in Gamepad; r=qdot
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 14 Jul 2017 16:53:03 +0800
changeset 418206 7e194151d3691e523b1ba9d7a02e71915f06b1f9
parent 418205 380ad1bfb187a075e540ffaf07e2c104d6c00a13
child 418207 a77053bac9a9c22662f84c692e7697f0b81a23ff
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1375816
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1375816 - Part 1: Add displayId attribute in Gamepad; r=qdot MozReview-Commit-ID: 7nrOrKRemGY
dom/gamepad/Gamepad.cpp
dom/gamepad/Gamepad.h
dom/webidl/Gamepad.webidl
--- a/dom/gamepad/Gamepad.cpp
+++ b/dom/gamepad/Gamepad.cpp
@@ -36,22 +36,23 @@ Gamepad::UpdateTimestamp()
   }
 }
 
 Gamepad::Gamepad(nsISupports* aParent,
                  const nsAString& aID, uint32_t aIndex,
                  uint32_t aHashKey,
                  GamepadMappingType aMapping,
                  GamepadHand aHand,
-                 uint32_t aNumButtons, uint32_t aNumAxes,
-                 uint32_t aNumHaptics)
+                 uint32_t aDisplayID, uint32_t aNumButtons,
+                 uint32_t aNumAxes, uint32_t aNumHaptics)
   : mParent(aParent),
     mID(aID),
     mIndex(aIndex),
     mHashKey(aHashKey),
+    mDisplayId(aDisplayID),
     mMapping(aMapping),
     mHand(aHand),
     mConnected(true),
     mButtons(aNumButtons),
     mAxes(aNumAxes),
     mTimestamp(0)
 {
   for (unsigned i = 0; i < aNumButtons; i++) {
@@ -150,17 +151,17 @@ Gamepad::SyncState(Gamepad* aOther)
   UpdateTimestamp();
 }
 
 already_AddRefed<Gamepad>
 Gamepad::Clone(nsISupports* aParent)
 {
   RefPtr<Gamepad> out =
     new Gamepad(aParent, mID, mIndex, mHashKey, mMapping,
-                mHand, mButtons.Length(), mAxes.Length(),
+                mHand, mDisplayId, mButtons.Length(), mAxes.Length(),
                 mHapticActuators.Length());
   out->SyncState(this);
   return out.forget();
 }
 
 /* virtual */ JSObject*
 Gamepad::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
--- a/dom/gamepad/Gamepad.h
+++ b/dom/gamepad/Gamepad.h
@@ -39,18 +39,18 @@ const int kRightStickYAxis = 3;
 class Gamepad final : public nsISupports,
                       public nsWrapperCache
 {
 public:
   Gamepad(nsISupports* aParent,
           const nsAString& aID, uint32_t aIndex,
           uint32_t aHashKey,
           GamepadMappingType aMapping, GamepadHand aHand,
-          uint32_t aNumButtons, uint32_t aNumAxes,
-          uint32_t aNumHaptics);
+          uint32_t aDisplayID, 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,
                  bool aTouched, double aValue);
   void SetAxis(uint32_t aAxis, double aValue);
@@ -82,16 +82,21 @@ public:
      return mTimestamp;
   }
 
   GamepadMappingType Mapping()
   {
     return mMapping;
   }
 
+  uint32_t DisplayId() const
+  {
+    return mDisplayId;
+  }
+
   GamepadHand Hand()
   {
     return mHand;
   }
 
   bool Connected() const
   {
     return mConnected;
@@ -132,17 +137,17 @@ private:
   void UpdateTimestamp();
 
 protected:
   nsCOMPtr<nsISupports> mParent;
   nsString mID;
   uint32_t mIndex;
   // the gamepad hash key in GamepadManager
   uint32_t mHashKey;
-
+  uint32_t mDisplayId;
   // The mapping in use.
   GamepadMappingType mMapping;
   GamepadHand mHand;
 
   // true if this gamepad is currently connected.
   bool mConnected;
 
   // Current state of buttons, axes.
--- a/dom/webidl/Gamepad.webidl
+++ b/dom/webidl/Gamepad.webidl
@@ -1,16 +1,17 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
  * https://w3c.github.io/gamepad/
  * https://w3c.github.io/gamepad/extensions.html
+ * https://w3c.github.io/webvr/spec/1.1/#interface-gamepad
  */
 
 [Pref="dom.gamepad.enabled"]
 interface GamepadButton {
   readonly    attribute boolean pressed;
   readonly    attribute boolean touched;
   readonly    attribute double  value;
 };
@@ -48,16 +49,23 @@ interface Gamepad {
   /**
    * The hand in use for this device. The empty string
    * indicates that unknown, both hands, or not applicable
    */
   [Pref="dom.gamepad.extensions.enabled"]
   readonly attribute GamepadHand hand;
 
   /**
+   * The displayId in use for as an association point in the VRDisplay API
+   * to identify which VRDisplay that the gamepad is associated with.
+   */
+  [Pref="dom.vr.enabled"]
+  readonly attribute unsigned long displayId;
+
+  /**
    * true if this gamepad is currently connected to the system.
    */
   readonly attribute boolean connected;
 
   /**
    * The current state of all buttons on the device, an
    * array of GamepadButton.
    */