Bug 1945643 - Update to mozilla-nimbus-schemas 2025.1.1 r=chumphreys
[gecko.git] / dom / gamepad / GamepadTouch.cpp
blobc5cb81e43e567c9d6785ce4c209257129000118d
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),
17 (mPosition,
18 mSurfaceDimensions))
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,
35 ErrorResult& aRv) {
36 mPosition = Float32Array::Create(aCx, this, mTouchState.position, aRv);
37 if (aRv.Failed()) {
38 return;
41 aRetval.set(mPosition);
44 void GamepadTouch::GetSurfaceDimensions(JSContext* aCx,
45 JS::MutableHandle<JSObject*> aRetval,
46 ErrorResult& aRv) {
47 if (mTouchState.isSurfaceDimensionsValid) {
48 mSurfaceDimensions =
49 Uint32Array::Create(aCx, this, mTouchState.surfaceDimensions, aRv);
50 } else {
51 mSurfaceDimensions = Uint32Array::Create(
52 aCx, this, std::size(mTouchState.surfaceDimensions), aRv);
55 if (!mSurfaceDimensions) {
56 return;
59 aRetval.set(mSurfaceDimensions);
62 void GamepadTouch::SetTouchState(const GamepadTouchState& aTouch) {
63 mTouchState = aTouch;
66 void GamepadTouch::Set(const GamepadTouch* aOther) {
67 MOZ_ASSERT(aOther);
68 mTouchState = aOther->mTouchState;
71 } // namespace mozilla::dom