mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1628919 - Emit XRInputSourceEvent selectend event If a controller is disconnected. r=kip
Differential Revision: https://phabricator.services.mozilla.com/D72248
This commit is contained in:
parent
903cd347ea
commit
7edcf8ac3b
@ -211,8 +211,21 @@ void XRInputSource::Setup(XRSession* aSession, uint32_t aIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
void XRInputSource::SetGamepadIsConnected(bool aConnected) {
|
||||
void XRInputSource::SetGamepadIsConnected(bool aConnected,
|
||||
XRSession* aSession) {
|
||||
mGamepad->SetConnected(aConnected);
|
||||
MOZ_ASSERT(aSession);
|
||||
|
||||
if (!aConnected) {
|
||||
if (mSelectAction != ActionState::ActionState_Released) {
|
||||
DispatchEvent(NS_LITERAL_STRING("selectend"), aSession);
|
||||
mSelectAction = ActionState::ActionState_Released;
|
||||
}
|
||||
if (mSqueezeAction != ActionState::ActionState_Released) {
|
||||
DispatchEvent(NS_LITERAL_STRING("squeezeend"), aSession);
|
||||
mSqueezeAction = ActionState::ActionState_Released;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XRInputSource::Update(XRSession* aSession) {
|
||||
@ -339,6 +352,9 @@ int32_t XRInputSource::GetIndex() { return mIndex; }
|
||||
|
||||
void XRInputSource::DispatchEvent(const nsAString& aEvent,
|
||||
XRSession* aSession) {
|
||||
if (!GetParentObject() || !aSession) {
|
||||
return;
|
||||
}
|
||||
// Create a XRFrame for its callbacks
|
||||
RefPtr<XRFrame> frame = new XRFrame(GetParentObject(), aSession);
|
||||
frame->StartInputSourceEvent();
|
||||
|
@ -44,7 +44,7 @@ class XRInputSource final : public nsWrapperCache {
|
||||
void GetProfiles(nsTArray<nsString>& aResult);
|
||||
Gamepad* GetGamepad();
|
||||
void Setup(XRSession* aSession, uint32_t aIndex);
|
||||
void SetGamepadIsConnected(bool aConnected);
|
||||
void SetGamepadIsConnected(bool aConnected, XRSession* aSession);
|
||||
void Update(XRSession* aSession);
|
||||
int32_t GetIndex();
|
||||
|
||||
|
@ -39,7 +39,8 @@ void XRInputSourceArray::Update(XRSession* aSession) {
|
||||
XRInputSourcesChangeEventInit addInit;
|
||||
nsTArray<RefPtr<XRInputSource>> removedInputs;
|
||||
for (int32_t i = 0; i < gfx::kVRControllerMaxCount; ++i) {
|
||||
const gfx::VRControllerState& controllerState = displayClient->GetDisplayInfo().mControllerState[i];
|
||||
const gfx::VRControllerState& controllerState =
|
||||
displayClient->GetDisplayInfo().mControllerState[i];
|
||||
if (controllerState.controllerName[0] == '\0') {
|
||||
// Checking if exising controllers need to be removed.
|
||||
for (auto& input : mInputSources) {
|
||||
@ -62,7 +63,7 @@ void XRInputSourceArray::Update(XRSession* aSession) {
|
||||
}
|
||||
// Checking if it is added before.
|
||||
if (!found &&
|
||||
(controllerState.numButtons > 0 || controllerState.numAxes > 0)) {
|
||||
(controllerState.numButtons > 0 || controllerState.numAxes > 0)) {
|
||||
inputSource = new XRInputSource(mParent);
|
||||
inputSource->Setup(aSession, i);
|
||||
mInputSources.AppendElement(inputSource);
|
||||
@ -80,8 +81,9 @@ void XRInputSourceArray::Update(XRSession* aSession) {
|
||||
|
||||
// Send `inputsourceschange` for new controllers.
|
||||
if (addInit.mAdded.Length()) {
|
||||
RefPtr<XRInputSourcesChangeEvent> event = XRInputSourcesChangeEvent::Constructor(aSession,
|
||||
NS_LITERAL_STRING("inputsourceschange"), addInit);
|
||||
RefPtr<XRInputSourcesChangeEvent> event =
|
||||
XRInputSourcesChangeEvent::Constructor(
|
||||
aSession, NS_LITERAL_STRING("inputsourceschange"), addInit);
|
||||
|
||||
event->SetTrusted(true);
|
||||
aSession->DispatchEvent(*event);
|
||||
@ -91,18 +93,20 @@ void XRInputSourceArray::Update(XRSession* aSession) {
|
||||
if (removedInputs.Length()) {
|
||||
DispatchInputSourceRemovedEvent(removedInputs, aSession);
|
||||
}
|
||||
for (auto& input: removedInputs) {
|
||||
for (auto& input : removedInputs) {
|
||||
mInputSources.RemoveElement(input);
|
||||
}
|
||||
}
|
||||
|
||||
void XRInputSourceArray::DispatchInputSourceRemovedEvent(
|
||||
const nsTArray<RefPtr<XRInputSource>>& aInputs, XRSession* aSession) {
|
||||
const nsTArray<RefPtr<XRInputSource>>& aInputs, XRSession* aSession) {
|
||||
if (!aSession) {
|
||||
return;
|
||||
}
|
||||
|
||||
XRInputSourcesChangeEventInit init;
|
||||
|
||||
for (auto& input: aInputs) {
|
||||
input->SetGamepadIsConnected(false);
|
||||
|
||||
for (const auto& input : aInputs) {
|
||||
input->SetGamepadIsConnected(false, aSession);
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = false;
|
||||
init.mSession = aSession;
|
||||
@ -110,8 +114,9 @@ void XRInputSourceArray::DispatchInputSourceRemovedEvent(
|
||||
}
|
||||
|
||||
if (init.mRemoved.Length()) {
|
||||
RefPtr<XRInputSourcesChangeEvent> event = XRInputSourcesChangeEvent::Constructor(aSession,
|
||||
NS_LITERAL_STRING("inputsourceschange"), init);
|
||||
RefPtr<XRInputSourcesChangeEvent> event =
|
||||
XRInputSourcesChangeEvent::Constructor(
|
||||
aSession, NS_LITERAL_STRING("inputsourceschange"), init);
|
||||
|
||||
event->SetTrusted(true);
|
||||
aSession->DispatchEvent(*event);
|
||||
|
Loading…
Reference in New Issue
Block a user