mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 05:48:26 +00:00
Bug 1538805 - Send GamepadAdded events to the later GamepadEventChannels. r=baku
Differential Revision: https://phabricator.services.mozilla.com/D74769
This commit is contained in:
parent
f94c9f4fbb
commit
433f122bcc
@ -416,9 +416,9 @@ bool GamepadManager::MaybeWindowHasSeenGamepad(nsGlobalWindowInner* aWindow,
|
||||
// This window hasn't seen this gamepad before, so
|
||||
// send a connection event first.
|
||||
SetWindowHasSeenGamepad(aWindow, aIndex);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GamepadManager::WindowHasSeenGamepad(nsGlobalWindowInner* aWindow,
|
||||
@ -531,7 +531,7 @@ bool GamepadManager::SetGamepadByEvent(const GamepadChangeEvent& aEvent,
|
||||
const uint32_t index =
|
||||
GetGamepadIndexWithServiceType(aEvent.index(), aEvent.service_type());
|
||||
if (aWindow) {
|
||||
firstTime = MaybeWindowHasSeenGamepad(aWindow, index);
|
||||
firstTime = !MaybeWindowHasSeenGamepad(aWindow, index);
|
||||
}
|
||||
|
||||
RefPtr<Gamepad> gamepad =
|
||||
|
@ -92,6 +92,7 @@ uint32_t GamepadPlatformService::AddGamepad(
|
||||
aHand, 0, aNumButtons, aNumAxes, aHaptics, aNumLightIndicator,
|
||||
aNumTouchEvents);
|
||||
|
||||
mGamepadAdded.emplace(index, a);
|
||||
NotifyGamepadChange<GamepadAdded>(index, a);
|
||||
return index;
|
||||
}
|
||||
@ -103,6 +104,7 @@ void GamepadPlatformService::RemoveGamepad(uint32_t aIndex) {
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
GamepadRemoved a;
|
||||
NotifyGamepadChange<GamepadRemoved>(aIndex, a);
|
||||
mGamepadAdded.erase(aIndex);
|
||||
}
|
||||
|
||||
void GamepadPlatformService::NewButtonEvent(uint32_t aIndex, uint32_t aButton,
|
||||
@ -207,6 +209,17 @@ void GamepadPlatformService::AddChannelParent(
|
||||
// We use mutex here to prevent race condition with monitor thread
|
||||
MutexAutoLock autoLock(mMutex);
|
||||
mChannelParents.AppendElement(aParent);
|
||||
|
||||
// For a new GamepadEventChannel, we have to send the exising GamepadAdded
|
||||
// to it to make it can have the same amount of gamepads with others.
|
||||
if (mChannelParents.Length() > 1) {
|
||||
for (const auto& evt : mGamepadAdded) {
|
||||
GamepadChangeEventBody body(evt.second);
|
||||
GamepadChangeEvent e(evt.first, GamepadServiceType::Standard, body);
|
||||
aParent->DispatchUpdateEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
FlushPendingEvents();
|
||||
}
|
||||
|
||||
@ -275,6 +288,7 @@ void GamepadPlatformService::MaybeShutdown() {
|
||||
if (isChannelParentEmpty) {
|
||||
kungFuDeathGrip = gGamepadPlatformServiceSingleton;
|
||||
gGamepadPlatformServiceSingleton = nullptr;
|
||||
mGamepadAdded.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "mozilla/dom/GamepadBinding.h"
|
||||
|
||||
#include <map>
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
|
||||
@ -115,6 +116,7 @@ class GamepadPlatformService final {
|
||||
// before GamepadEventChannel created, we need to buffer all events
|
||||
// until the channel is created if that happens.
|
||||
nsTArray<GamepadChangeEvent> mPendingEvents;
|
||||
std::map<uint32_t, GamepadAdded> mGamepadAdded;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
x
Reference in New Issue
Block a user