no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / gamepad / GamepadTouch.cpp
blob87be8e67015e31868706a460a2b6a324839094a2
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 aRv.NoteJSContextException(aCx);
57 return;
60 aRetval.set(mSurfaceDimensions);
63 void GamepadTouch::SetTouchState(const GamepadTouchState& aTouch) {
64 mTouchState = aTouch;
67 void GamepadTouch::Set(const GamepadTouch* aOther) {
68 MOZ_ASSERT(aOther);
69 mTouchState = aOther->mTouchState;
72 } // namespace mozilla::dom