зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1591608 - part1 : rename `MediaHardwareKeysXXX` to `MediaControlKeysXXX`. r=chunmin
The media control key events can come from either physical devices, such as a keyboard or a headset, or from virtual interface, such as SMTC-based visual controller on Windows or MPRIS-based visual controller on Linux. Therefore, we would be better to rename all those MediaHardwareKeysXXX to MediaControlKeysXXX in order to represent a generic concept. Differential Revision: https://phabricator.services.mozilla.com/D50681 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e4ec992ba0
Коммит
f2f6bb1b22
|
@ -59,7 +59,7 @@ class MediaControlService final : public nsIObserver {
|
|||
nsDataHashtable<nsUint64HashKey, RefPtr<MediaController>> mControllers;
|
||||
nsTArray<uint64_t> mControllerHistory;
|
||||
AudioFocusManager mAudioFocusManager;
|
||||
MediaHardwareKeysManager mHardwareKeysManager;
|
||||
MediaControlKeysManager mMediaControlKeysManager;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -15,7 +15,7 @@ extern mozilla::LazyLogModule gMediaControlLog;
|
|||
#undef LOG
|
||||
#define LOG(msg, ...) \
|
||||
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
|
||||
("MediaHardwareKeysEventListener=%p, " msg, this, ##__VA_ARGS__))
|
||||
("MediaControlKeysEventListener=%p, " msg, this, ##__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -38,11 +38,11 @@ static const char* ToMediaControlKeysEventStr(MediaControlKeysEvent aKeyEvent) {
|
|||
#define LOG_KEY(msg, key, ...) \
|
||||
if (MOZ_LOG_TEST(gMediaControlLog, mozilla::LogLevel::Debug)) { \
|
||||
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
|
||||
("MediaHardwareKeysEventListener=%p, " msg, this, \
|
||||
("MediaControlKeysEventListener=%p, " msg, this, \
|
||||
ToMediaControlKeysEventStr(key), ##__VA_ARGS__)); \
|
||||
}
|
||||
|
||||
void MediaHardwareKeysEventListener::OnKeyPressed(
|
||||
void MediaControlKeysEventListener::OnKeyPressed(
|
||||
MediaControlKeysEvent aKeyEvent) {
|
||||
LOG_KEY("OnKeyPressed '%s'", aKeyEvent);
|
||||
switch (aKeyEvent) {
|
||||
|
@ -71,25 +71,25 @@ void MediaHardwareKeysEventListener::OnKeyPressed(
|
|||
}
|
||||
}
|
||||
|
||||
void MediaHardwareKeysEventSource::AddListener(
|
||||
MediaHardwareKeysEventListener* aListener) {
|
||||
void MediaControlKeysEventSource::AddListener(
|
||||
MediaControlKeysEventListener* aListener) {
|
||||
MOZ_ASSERT(aListener);
|
||||
LOG("Add listener %p", aListener);
|
||||
mListeners.AppendElement(aListener);
|
||||
}
|
||||
|
||||
void MediaHardwareKeysEventSource::RemoveListener(
|
||||
MediaHardwareKeysEventListener* aListener) {
|
||||
void MediaControlKeysEventSource::RemoveListener(
|
||||
MediaControlKeysEventListener* aListener) {
|
||||
MOZ_ASSERT(aListener);
|
||||
LOG("Remove listener %p", aListener);
|
||||
mListeners.RemoveElement(aListener);
|
||||
}
|
||||
|
||||
size_t MediaHardwareKeysEventSource::GetListenersNum() const {
|
||||
size_t MediaControlKeysEventSource::GetListenersNum() const {
|
||||
return mListeners.Length();
|
||||
}
|
||||
|
||||
void MediaHardwareKeysEventSource::Close() { mListeners.Clear(); }
|
||||
void MediaControlKeysEventSource::Close() { mListeners.Clear(); }
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -14,41 +14,40 @@ namespace dom {
|
|||
enum class MediaControlKeysEvent { ePlayPause, ePrev, eNext, eNone };
|
||||
|
||||
/**
|
||||
* MediaHardwareKeysEventListener is used to monitor MediaControlKeysEvent, we
|
||||
* can add it onto the MediaHardwareKeysEventSource, and then everytime when
|
||||
* MediaControlKeysEventListener is used to monitor MediaControlKeysEvent, we
|
||||
* can add it onto the MediaControlKeysEventSource, and then everytime when
|
||||
* the media key events occur, `OnKeyPressed` will be called so that we can do
|
||||
* related handling.
|
||||
*/
|
||||
class MediaHardwareKeysEventListener {
|
||||
class MediaControlKeysEventListener {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaHardwareKeysEventListener);
|
||||
MediaHardwareKeysEventListener() = default;
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaControlKeysEventListener);
|
||||
MediaControlKeysEventListener() = default;
|
||||
|
||||
virtual void OnKeyPressed(MediaControlKeysEvent aKeyEvent);
|
||||
|
||||
protected:
|
||||
virtual ~MediaHardwareKeysEventListener() = default;
|
||||
virtual ~MediaControlKeysEventListener() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* MediaHardwareKeysEventSource is a base class which is used to implement
|
||||
* intercepting media hardware keys event per plaftform. When receiving media
|
||||
* key events, it would notify all listeners which have been added onto the
|
||||
* source.
|
||||
* MediaControlKeysEventSource is a base class which is used to implement
|
||||
* transporting media control keys event to all its listeners when media keys
|
||||
* event happens.
|
||||
*/
|
||||
class MediaHardwareKeysEventSource {
|
||||
class MediaControlKeysEventSource {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaHardwareKeysEventSource);
|
||||
MediaHardwareKeysEventSource() = default;
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaControlKeysEventSource);
|
||||
MediaControlKeysEventSource() = default;
|
||||
|
||||
virtual void AddListener(MediaHardwareKeysEventListener* aListener);
|
||||
virtual void RemoveListener(MediaHardwareKeysEventListener* aListener);
|
||||
virtual void AddListener(MediaControlKeysEventListener* aListener);
|
||||
virtual void RemoveListener(MediaControlKeysEventListener* aListener);
|
||||
size_t GetListenersNum() const;
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
virtual ~MediaHardwareKeysEventSource() = default;
|
||||
nsTArray<RefPtr<MediaHardwareKeysEventListener>> mListeners;
|
||||
virtual ~MediaControlKeysEventSource() = default;
|
||||
nsTArray<RefPtr<MediaControlKeysEventListener>> mListeners;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
|
||||
class MediaHardwareKeysEventSourceMac final
|
||||
: public MediaHardwareKeysEventSource {
|
||||
: public MediaControlKeysEventSource {
|
||||
public:
|
||||
MediaHardwareKeysEventSourceMac();
|
||||
~MediaHardwareKeysEventSourceMac();
|
||||
|
|
|
@ -16,38 +16,38 @@ extern mozilla::LazyLogModule gMediaControlLog;
|
|||
#undef LOG
|
||||
#define LOG(msg, ...) \
|
||||
MOZ_LOG(gMediaControlLog, LogLevel::Debug, \
|
||||
("MediaHardwareKeysManager=%p, " msg, this, ##__VA_ARGS__))
|
||||
("MediaControlKeysManager=%p, " msg, this, ##__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
MediaHardwareKeysManager::MediaHardwareKeysManager() {
|
||||
StartMonitoringHardwareKeys();
|
||||
MediaControlKeysManager::MediaControlKeysManager() {
|
||||
StartMonitoringControlKeys();
|
||||
}
|
||||
|
||||
MediaHardwareKeysManager::~MediaHardwareKeysManager() {
|
||||
StopMonitoringHardwareKeys();
|
||||
MediaControlKeysManager::~MediaControlKeysManager() {
|
||||
StopMonitoringControlKeys();
|
||||
}
|
||||
|
||||
void MediaHardwareKeysManager::StartMonitoringHardwareKeys() {
|
||||
LOG("StartMonitoringHardwareKeys");
|
||||
void MediaControlKeysManager::StartMonitoringControlKeys() {
|
||||
LOG("StartMonitoringControlKeys");
|
||||
if (!StaticPrefs::media_hardwaremediakeys_enabled()) {
|
||||
return;
|
||||
}
|
||||
CreateEventSource();
|
||||
if (mEventSource) {
|
||||
mEventSource->AddListener(new MediaHardwareKeysEventListener());
|
||||
mEventSource->AddListener(new MediaControlKeysEventListener());
|
||||
}
|
||||
}
|
||||
|
||||
void MediaHardwareKeysManager::CreateEventSource() {
|
||||
void MediaControlKeysManager::CreateEventSource() {
|
||||
#ifdef MOZ_APPLEMEDIA
|
||||
mEventSource = new MediaHardwareKeysEventSourceMac();
|
||||
#endif
|
||||
}
|
||||
|
||||
void MediaHardwareKeysManager::StopMonitoringHardwareKeys() {
|
||||
LOG("StopMonitoringHardwareKeys");
|
||||
void MediaControlKeysManager::StopMonitoringControlKeys() {
|
||||
LOG("StopMonitoringControlKeys");
|
||||
if (mEventSource) {
|
||||
mEventSource->Close();
|
||||
mEventSource = nullptr;
|
||||
|
|
|
@ -11,21 +11,21 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
|
||||
/**
|
||||
* MediaHardwareKeysManager is used to create a source to intercept platform
|
||||
* MediaControlKeysManager is used to create a source to intercept platform
|
||||
* level media keys event and assign a proper event listener to handle those
|
||||
* events.
|
||||
*/
|
||||
class MediaHardwareKeysManager final {
|
||||
class MediaControlKeysManager final {
|
||||
public:
|
||||
MediaHardwareKeysManager();
|
||||
~MediaHardwareKeysManager();
|
||||
MediaControlKeysManager();
|
||||
~MediaControlKeysManager();
|
||||
|
||||
void StartMonitoringHardwareKeys();
|
||||
void StopMonitoringHardwareKeys();
|
||||
void StartMonitoringControlKeys();
|
||||
void StopMonitoringControlKeys();
|
||||
|
||||
private:
|
||||
void CreateEventSource();
|
||||
RefPtr<MediaHardwareKeysEventSource> mEventSource;
|
||||
RefPtr<MediaControlKeysEventSource> mEventSource;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
TEST(MediaHardwareKeysEvent, TestAddOrRemoveListener)
|
||||
TEST(MediaControlKeysEvent, TestAddOrRemoveListener)
|
||||
{
|
||||
RefPtr<MediaHardwareKeysEventSource> source =
|
||||
new MediaHardwareKeysEventSource();
|
||||
RefPtr<MediaControlKeysEventSource> source =
|
||||
new MediaControlKeysEventSource();
|
||||
ASSERT_TRUE(source->GetListenersNum() == 0);
|
||||
|
||||
RefPtr<MediaHardwareKeysEventListener> listener =
|
||||
new MediaHardwareKeysEventListener();
|
||||
RefPtr<MediaControlKeysEventListener> listener =
|
||||
new MediaControlKeysEventListener();
|
||||
|
||||
source->AddListener(listener);
|
||||
ASSERT_TRUE(source->GetListenersNum() == 1);
|
||||
|
|
|
@ -15,7 +15,7 @@ using namespace mozilla::dom;
|
|||
|
||||
static const int kSystemDefinedEventMediaKeysSubtype = 8;
|
||||
|
||||
class MediaHardwareKeysEventListenerTest : public MediaHardwareKeysEventListener {
|
||||
class MediaHardwareKeysEventListenerTest : public MediaControlKeysEventListener {
|
||||
public:
|
||||
void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override { mReceivedEvent = aKeyEvent; }
|
||||
MediaControlKeysEvent GetResult() const { return mReceivedEvent; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче