1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_dom_gamepad_GamepadButton_h
8 #define mozilla_dom_gamepad_GamepadButton_h
9 
10 #include <stdint.h>
11 #include "nsCOMPtr.h"
12 #include "nsWrapperCache.h"
13 
14 namespace mozilla {
15 namespace dom {
16 
17 class GamepadButton : public nsISupports, public nsWrapperCache {
18  public:
GamepadButton(nsISupports * aParent)19   explicit GamepadButton(nsISupports* aParent)
20       : mParent(aParent), mValue(0), mPressed(false), mTouched(false) {}
21 
22   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(GamepadButton)23   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(GamepadButton)
24 
25   nsISupports* GetParentObject() const { return mParent; }
26 
27   virtual JSObject* WrapObject(JSContext* aCx,
28                                JS::Handle<JSObject*> aGivenProto) override;
29 
SetPressed(bool aPressed)30   void SetPressed(bool aPressed) { mPressed = aPressed; }
31 
SetTouched(bool aTouched)32   void SetTouched(bool aTouched) { mTouched = aTouched; }
33 
SetValue(double aValue)34   void SetValue(double aValue) { mValue = aValue; }
35 
Pressed()36   bool Pressed() const { return mPressed; }
37 
Touched()38   bool Touched() const { return mTouched; }
39 
Value()40   double Value() const { return mValue; }
41 
42  private:
43   virtual ~GamepadButton() = default;
44 
45  protected:
46   nsCOMPtr<nsISupports> mParent;
47   double mValue;
48   bool mPressed;
49   bool mTouched;
50 };
51 
52 }  // namespace dom
53 }  // namespace mozilla
54 
55 #endif  // mozilla_dom_gamepad_GamepadButton_h
56