michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_gamepad_Gamepad_h michael@0: #define mozilla_dom_gamepad_Gamepad_h michael@0: michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "mozilla/dom/GamepadButton.h" michael@0: #include michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: #include "nsWrapperCache.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: enum GamepadMappingType michael@0: { michael@0: NoMapping = 0, michael@0: StandardMapping = 1 michael@0: }; michael@0: michael@0: class Gamepad : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: Gamepad(nsISupports* aParent, michael@0: const nsAString& aID, uint32_t aIndex, michael@0: GamepadMappingType aMapping, michael@0: uint32_t aNumButtons, uint32_t aNumAxes); michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Gamepad) michael@0: michael@0: void SetConnected(bool aConnected); michael@0: void SetButton(uint32_t aButton, bool aPressed, double aValue); michael@0: void SetAxis(uint32_t aAxis, double aValue); michael@0: void SetIndex(uint32_t aIndex); michael@0: michael@0: // Make the state of this gamepad equivalent to other. michael@0: void SyncState(Gamepad* aOther); michael@0: michael@0: // Return a new Gamepad containing the same data as this object, michael@0: // parented to aParent. michael@0: already_AddRefed Clone(nsISupports* aParent); michael@0: michael@0: nsISupports* GetParentObject() const michael@0: { michael@0: return mParent; michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: void GetId(nsAString& aID) const michael@0: { michael@0: aID = mID; michael@0: } michael@0: michael@0: void GetMapping(nsAString& aMapping) const michael@0: { michael@0: if (mMapping == StandardMapping) { michael@0: aMapping = NS_LITERAL_STRING("standard"); michael@0: } else { michael@0: aMapping = NS_LITERAL_STRING(""); michael@0: } michael@0: } michael@0: michael@0: bool Connected() const michael@0: { michael@0: return mConnected; michael@0: } michael@0: michael@0: uint32_t Index() const michael@0: { michael@0: return mIndex; michael@0: } michael@0: michael@0: void GetButtons(nsTArray>& aButtons) const michael@0: { michael@0: aButtons = mButtons; michael@0: } michael@0: michael@0: void GetAxes(nsTArray& aAxes) const michael@0: { michael@0: aAxes = mAxes; michael@0: } michael@0: michael@0: private: michael@0: virtual ~Gamepad() {} michael@0: michael@0: protected: michael@0: nsCOMPtr mParent; michael@0: nsString mID; michael@0: uint32_t mIndex; michael@0: michael@0: // The mapping in use. michael@0: GamepadMappingType mMapping; michael@0: michael@0: // true if this gamepad is currently connected. michael@0: bool mConnected; michael@0: michael@0: // Current state of buttons, axes. michael@0: nsTArray> mButtons; michael@0: nsTArray mAxes; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_gamepad_Gamepad_h