Bug 1795723 - Unified extensions UI should support High Contrast Mode. r=ayeddi,deskt...
[gecko.git] / dom / gamepad / GamepadTouch.cpp
blobd2fe0de2c04f37400ba5814de79b12dd43e9370a
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 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,
38 ErrorResult& aRv) {
39 mPosition = Float32Array::Create(aCx, this, 2, mTouchState.position);
40 if (!mPosition) {
41 aRv.NoteJSContextException(aCx);
42 return;
45 aRetval.set(mPosition);
48 void GamepadTouch::GetSurfaceDimensions(JSContext* aCx,
49 JS::MutableHandle<JSObject*> aRetval,
50 ErrorResult& aRv) {
51 mSurfaceDimensions = Uint32Array::Create(aCx, this, 2,
52 mTouchState.isSurfaceDimensionsValid
53 ? mTouchState.surfaceDimensions
54 : nullptr);
56 if (!mSurfaceDimensions) {
57 aRv.NoteJSContextException(aCx);
58 return;
61 aRetval.set(mSurfaceDimensions);
64 void GamepadTouch::SetTouchState(const GamepadTouchState& aTouch) {
65 mTouchState = aTouch;
68 void GamepadTouch::Set(const GamepadTouch* aOther) {
69 MOZ_ASSERT(aOther);
70 mTouchState = aOther->mTouchState;
73 } // namespace mozilla::dom