2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-04-24 01:05:29 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_GamepadServiceTest_h_
|
|
|
|
#define mozilla_dom_GamepadServiceTest_h_
|
|
|
|
|
2016-11-03 23:55:36 +03:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2016-10-04 05:57:04 +03:00
|
|
|
#include "mozilla/dom/GamepadBinding.h"
|
2020-12-03 02:06:05 +03:00
|
|
|
#include "mozilla/dom/GamepadHandle.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2020-11-11 01:31:37 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2015-04-24 01:05:29 +03:00
|
|
|
|
2022-05-09 23:41:07 +03:00
|
|
|
namespace mozilla::dom {
|
2015-04-24 01:05:29 +03:00
|
|
|
|
2016-06-28 01:26:00 +03:00
|
|
|
class GamepadChangeEvent;
|
2016-06-28 01:25:00 +03:00
|
|
|
class GamepadManager;
|
2016-06-28 01:26:00 +03:00
|
|
|
class GamepadTestChannelChild;
|
|
|
|
class Promise;
|
2015-04-24 01:05:29 +03:00
|
|
|
|
|
|
|
// Service for testing purposes
|
2020-11-11 01:31:37 +03:00
|
|
|
class GamepadServiceTest final : public DOMEventTargetHelper,
|
|
|
|
public SupportsWeakPtr {
|
2015-04-24 01:05:29 +03:00
|
|
|
public:
|
2016-06-28 01:26:00 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GamepadServiceTest,
|
|
|
|
DOMEventTargetHelper)
|
2015-04-24 01:05:29 +03:00
|
|
|
|
2016-12-09 02:00:44 +03:00
|
|
|
GamepadMappingType NoMapping() const { return GamepadMappingType::_empty; }
|
|
|
|
GamepadMappingType StandardMapping() const {
|
|
|
|
return GamepadMappingType::Standard;
|
|
|
|
}
|
2017-02-02 10:00:51 +03:00
|
|
|
GamepadHand NoHand() const { return GamepadHand::_empty; }
|
|
|
|
GamepadHand LeftHand() const { return GamepadHand::Left; }
|
|
|
|
GamepadHand RightHand() const { return GamepadHand::Right; }
|
2015-04-24 01:05:29 +03:00
|
|
|
|
2021-06-22 11:45:59 +03:00
|
|
|
// IPC receiver
|
|
|
|
void ReplyGamepadHandle(uint32_t aPromiseId, const GamepadHandle& aHandle);
|
|
|
|
|
|
|
|
// Methods from GamepadServiceTest.webidl
|
2019-05-30 01:15:25 +03:00
|
|
|
already_AddRefed<Promise> AddGamepad(
|
|
|
|
const nsAString& aID, GamepadMappingType aMapping, GamepadHand aHand,
|
|
|
|
uint32_t aNumButtons, uint32_t aNumAxes, uint32_t aNumHaptics,
|
|
|
|
uint32_t aNumLightIndicator, uint32_t aNumTouchEvents, ErrorResult& aRv);
|
2020-11-11 01:31:37 +03:00
|
|
|
|
2021-06-22 11:45:59 +03:00
|
|
|
already_AddRefed<Promise> RemoveGamepad(uint32_t aHandleSlot,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise> NewButtonEvent(uint32_t aHandleSlot,
|
|
|
|
uint32_t aButton, bool aPressed,
|
|
|
|
bool aTouched, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise> NewButtonValueEvent(uint32_t aHandleSlot,
|
|
|
|
uint32_t aButton, bool aPressed,
|
|
|
|
bool aTouched, double aValue,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise> NewAxisMoveEvent(uint32_t aHandleSlot,
|
|
|
|
uint32_t aAxis, double aValue,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise> NewPoseMove(
|
|
|
|
uint32_t aHandleSlot, const Nullable<Float32Array>& aOrient,
|
|
|
|
const Nullable<Float32Array>& aPos,
|
|
|
|
const Nullable<Float32Array>& aAngVelocity,
|
|
|
|
const Nullable<Float32Array>& aAngAcceleration,
|
|
|
|
const Nullable<Float32Array>& aLinVelocity,
|
|
|
|
const Nullable<Float32Array>& aLinAcceleration, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<Promise> NewTouch(uint32_t aHandleSlot,
|
|
|
|
uint32_t aTouchArrayIndex,
|
|
|
|
uint32_t aTouchId, uint8_t aSurfaceId,
|
|
|
|
const Float32Array& aPos,
|
|
|
|
const Nullable<Float32Array>& aSurfDim,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-06-28 01:26:00 +03:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
static already_AddRefed<GamepadServiceTest> CreateTestService(
|
|
|
|
nsPIDOMWindowInner* aWindow);
|
|
|
|
nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
|
2022-06-05 23:54:59 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2015-04-24 01:05:29 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Hold a reference to the gamepad service so we don't have to worry about
|
|
|
|
// execution order in tests.
|
2016-06-28 01:25:00 +03:00
|
|
|
RefPtr<GamepadManager> mService;
|
2016-06-28 01:26:00 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
|
|
|
uint32_t mEventNumber;
|
|
|
|
bool mShuttingDown;
|
|
|
|
|
|
|
|
// IPDL Channel for us to send test events to GamepadPlatformService, it
|
|
|
|
// will only be used in this singleton class and deleted during the IPDL
|
|
|
|
// shutdown chain
|
2020-10-14 23:33:32 +03:00
|
|
|
RefPtr<GamepadTestChannelChild> mChild;
|
2020-12-03 02:06:05 +03:00
|
|
|
nsTArray<GamepadHandle> mGamepadHandles;
|
2016-06-28 01:26:00 +03:00
|
|
|
|
2020-11-11 01:31:37 +03:00
|
|
|
nsRefPtrHashtable<nsUint32HashKey, dom::Promise> mPromiseList;
|
|
|
|
|
2016-06-28 01:26:00 +03:00
|
|
|
explicit GamepadServiceTest(nsPIDOMWindowInner* aWindow);
|
|
|
|
~GamepadServiceTest();
|
|
|
|
void InitPBackgroundActor();
|
|
|
|
void DestroyPBackgroundActor();
|
2020-12-03 02:06:05 +03:00
|
|
|
|
|
|
|
uint32_t AddGamepadHandle(GamepadHandle aHandle);
|
|
|
|
void RemoveGamepadHandle(uint32_t aHandleSlot);
|
|
|
|
GamepadHandle GetHandleInSlot(uint32_t aHandleSlot) const;
|
2015-04-24 01:05:29 +03:00
|
|
|
};
|
|
|
|
|
2022-05-09 23:41:07 +03:00
|
|
|
} // namespace mozilla::dom
|
2015-04-24 01:05:29 +03:00
|
|
|
|
|
|
|
#endif
|