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 GamepadTouch::GamepadTouch(nsISupports
* aParent
)
21 : mParent(aParent
), mPosition(nullptr), mSurfaceDimensions(nullptr) {
22 mozilla::HoldJSObjects(this);
23 mTouchState
= GamepadTouchState();
26 GamepadTouch::~GamepadTouch() { mozilla::DropJSObjects(this); }
28 /* virtual */ JSObject
* GamepadTouch::WrapObject(
29 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
30 return GamepadTouch_Binding::Wrap(aCx
, this, aGivenProto
);
33 void GamepadTouch::GetPosition(JSContext
* aCx
,
34 JS::MutableHandle
<JSObject
*> aRetval
,
36 mPosition
= Float32Array::Create(aCx
, this, mTouchState
.position
, aRv
);
41 aRetval
.set(mPosition
);
44 void GamepadTouch::GetSurfaceDimensions(JSContext
* aCx
,
45 JS::MutableHandle
<JSObject
*> aRetval
,
47 if (mTouchState
.isSurfaceDimensionsValid
) {
49 Uint32Array::Create(aCx
, this, mTouchState
.surfaceDimensions
, aRv
);
51 mSurfaceDimensions
= Uint32Array::Create(
52 aCx
, this, std::size(mTouchState
.surfaceDimensions
), aRv
);
55 if (!mSurfaceDimensions
) {
59 aRetval
.set(mSurfaceDimensions
);
62 void GamepadTouch::SetTouchState(const GamepadTouchState
& aTouch
) {
66 void GamepadTouch::Set(const GamepadTouch
* aOther
) {
68 mTouchState
= aOther
->mTouchState
;
71 } // namespace mozilla::dom