Line data Source code
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 : #include "nsWrapperCache.h"
8 :
9 : #include "mozilla/HoldDropJSObjects.h"
10 : #include "mozilla/dom/GamepadPoseBinding.h"
11 : #include "mozilla/dom/GamepadPose.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 0 : GamepadPose::GamepadPose(nsISupports* aParent, const GamepadPoseState& aState)
17 : : Pose(aParent),
18 0 : mPoseState(aState)
19 : {
20 0 : mozilla::HoldJSObjects(this);
21 0 : }
22 :
23 0 : GamepadPose::GamepadPose(nsISupports* aParent)
24 0 : : Pose(aParent)
25 : {
26 0 : mozilla::HoldJSObjects(this);
27 0 : mPoseState.Clear();
28 0 : }
29 :
30 0 : GamepadPose::~GamepadPose()
31 : {
32 0 : mozilla::DropJSObjects(this);
33 0 : }
34 :
35 : /* virtual */ JSObject*
36 0 : GamepadPose::WrapObject(JSContext* aJSContext, JS::Handle<JSObject*> aGivenProto)
37 : {
38 0 : return GamepadPoseBinding::Wrap(aJSContext, this, aGivenProto);
39 : }
40 :
41 : bool
42 0 : GamepadPose::HasOrientation() const
43 : {
44 0 : return bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position);
45 : }
46 :
47 : bool
48 0 : GamepadPose::HasPosition() const
49 : {
50 0 : return bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation);
51 : }
52 :
53 : void
54 0 : GamepadPose::GetPosition(JSContext* aJSContext,
55 : JS::MutableHandle<JSObject*> aRetval,
56 : ErrorResult& aRv)
57 : {
58 0 : SetFloat32Array(aJSContext, aRetval, mPosition,
59 0 : mPoseState.isPositionValid ? mPoseState.position : nullptr, 3,
60 0 : bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position), aRv);
61 0 : }
62 :
63 : void
64 0 : GamepadPose::GetLinearVelocity(JSContext* aJSContext,
65 : JS::MutableHandle<JSObject*> aRetval,
66 : ErrorResult& aRv)
67 : {
68 0 : SetFloat32Array(aJSContext, aRetval, mLinearVelocity,
69 0 : mPoseState.isPositionValid ? mPoseState.linearVelocity : nullptr, 3,
70 0 : bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position), aRv);
71 0 : }
72 :
73 : void
74 0 : GamepadPose::GetLinearAcceleration(JSContext* aJSContext,
75 : JS::MutableHandle<JSObject*> aRetval,
76 : ErrorResult& aRv)
77 : {
78 0 : SetFloat32Array(aJSContext, aRetval, mLinearAcceleration,
79 0 : mPoseState.isPositionValid ? mPoseState.linearAcceleration : nullptr, 3,
80 0 : bool(mPoseState.flags & GamepadCapabilityFlags::Cap_LinearAcceleration), aRv);
81 0 : }
82 :
83 : void
84 0 : GamepadPose::GetOrientation(JSContext* aJSContext,
85 : JS::MutableHandle<JSObject*> aRetval,
86 : ErrorResult& aRv)
87 : {
88 0 : SetFloat32Array(aJSContext, aRetval, mOrientation,
89 0 : mPoseState.isOrientationValid ? mPoseState.orientation : nullptr, 4,
90 0 : bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv);
91 0 : }
92 :
93 : void
94 0 : GamepadPose::GetAngularVelocity(JSContext* aJSContext,
95 : JS::MutableHandle<JSObject*> aRetval,
96 : ErrorResult& aRv)
97 : {
98 0 : SetFloat32Array(aJSContext, aRetval, mAngularVelocity,
99 0 : mPoseState.isOrientationValid ? mPoseState.angularVelocity : nullptr, 3,
100 0 : bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv);
101 0 : }
102 :
103 : void
104 0 : GamepadPose::GetAngularAcceleration(JSContext* aJSContext,
105 : JS::MutableHandle<JSObject*> aRetval,
106 : ErrorResult& aRv)
107 : {
108 0 : SetFloat32Array(aJSContext, aRetval, mAngularAcceleration,
109 0 : mPoseState.isOrientationValid ? mPoseState.angularAcceleration : nullptr, 3,
110 0 : bool(mPoseState.flags & GamepadCapabilityFlags::Cap_AngularAcceleration), aRv);
111 0 : }
112 :
113 : void
114 0 : GamepadPose::SetPoseState(const GamepadPoseState& aPose)
115 : {
116 0 : mPoseState = aPose;
117 0 : }
118 :
119 : const GamepadPoseState&
120 0 : GamepadPose::GetPoseState()
121 : {
122 0 : return mPoseState;
123 : }
124 :
125 : } // namespace dom
126 : } // namespace mozilla
|