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/. */
7 #include "mozilla/dom/GamepadTouch.h"
9 #include "mozilla/HoldDropJSObjects.h"
10 #include "mozilla/dom/GamepadManager.h"
11 #include "mozilla/dom/Promise.h"
12 #include "mozilla/dom/TypedArray.h"
14 namespace mozilla::dom
{
16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS(GamepadTouch
, (mParent
),
20 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(GamepadTouch
, AddRef
)
21 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(GamepadTouch
, Release
)
23 GamepadTouch::GamepadTouch(nsISupports
* aParent
)
24 : mParent(aParent
), mPosition(nullptr), mSurfaceDimensions(nullptr) {
25 mozilla::HoldJSObjects(this);
26 mTouchState
= GamepadTouchState();
29 GamepadTouch::~GamepadTouch() { mozilla::DropJSObjects(this); }
31 /* virtual */ JSObject
* GamepadTouch::WrapObject(
32 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
33 return GamepadTouch_Binding::Wrap(aCx
, this, aGivenProto
);
36 void GamepadTouch::GetPosition(JSContext
* aCx
,
37 JS::MutableHandle
<JSObject
*> aRetval
,
39 mPosition
= Float32Array::Create(aCx
, this, 2, mTouchState
.position
);
41 aRv
.NoteJSContextException(aCx
);
45 aRetval
.set(mPosition
);
48 void GamepadTouch::GetSurfaceDimensions(JSContext
* aCx
,
49 JS::MutableHandle
<JSObject
*> aRetval
,
51 mSurfaceDimensions
= Uint32Array::Create(aCx
, this, 2,
52 mTouchState
.isSurfaceDimensionsValid
53 ? mTouchState
.surfaceDimensions
56 if (!mSurfaceDimensions
) {
57 aRv
.NoteJSContextException(aCx
);
61 aRetval
.set(mSurfaceDimensions
);
64 void GamepadTouch::SetTouchState(const GamepadTouchState
& aTouch
) {
68 void GamepadTouch::Set(const GamepadTouch
* aOther
) {
70 mTouchState
= aOther
->mTouchState
;
73 } // namespace mozilla::dom