XRInputSource.h (2356B)
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_XRInputSource_h_ 8 #define mozilla_dom_XRInputSource_h_ 9 10 #include "gfxVR.h" 11 #include "mozilla/DOMEventTargetHelper.h" 12 #include "mozilla/dom/WebXRBinding.h" 13 14 namespace mozilla { 15 namespace gfx { 16 class VRDisplayClient; 17 } // namespace gfx 18 namespace dom { 19 class Gamepad; 20 class XRSpace; 21 class XRSession; 22 class XRNativeOrigin; 23 enum class XRHandedness : uint8_t; 24 enum class XRTargetRayMode : uint8_t; 25 26 class XRInputSource final : public nsWrapperCache { 27 public: 28 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(XRInputSource) 29 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(XRInputSource) 30 31 explicit XRInputSource(nsISupports* aParent); 32 33 // WebIDL Boilerplate 34 nsISupports* GetParentObject() const { return mParent; } 35 JSObject* WrapObject(JSContext* aCx, 36 JS::Handle<JSObject*> aGivenProto) override; 37 38 // WebIDL Members 39 XRHandedness Handedness(); 40 XRTargetRayMode TargetRayMode(); 41 XRSpace* TargetRaySpace(); 42 XRSpace* GetGripSpace(); 43 void GetProfiles(nsTArray<nsString>& aResult); 44 Gamepad* GetGamepad(); 45 void Setup(XRSession* aSession, uint32_t aIndex); 46 void SetGamepadIsConnected(bool aConnected, XRSession* aSession); 47 void Update(XRSession* aSession); 48 int32_t GetIndex(); 49 50 protected: 51 virtual ~XRInputSource(); 52 53 nsCOMPtr<nsISupports> mParent; 54 55 private: 56 enum class ActionState : uint8_t { 57 ActionState_Pressing = 0, 58 ActionState_Pressed = 1, 59 ActionState_Releasing = 2, 60 ActionState_Released = 3 61 }; 62 63 void CreateGripSpace(XRSession* aSession, 64 const gfx::VRControllerState& controllerState); 65 void DispatchEvent(const nsAString& aEvent, XRSession* aSession); 66 67 nsTArray<nsString> mProfiles; 68 XRHandedness mHandedness; 69 XRTargetRayMode mTargetRayMode; 70 71 RefPtr<XRSpace> mTargetRaySpace; 72 RefPtr<XRSpace> mGripSpace; 73 RefPtr<Gamepad> mGamepad; 74 int32_t mIndex; 75 ActionState mSelectAction; 76 ActionState mSqueezeAction; 77 }; 78 79 } // namespace dom 80 } // namespace mozilla 81 82 #endif // mozilla_dom_XRInputSource_h_