зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1591620 - part1 : make 'MediaControlKeysEventListener' as a pure interface. r=chunmin
If the web extention also needs to implement its listener, they would definitely not need the current implementation in `KeyPressed()` for controlling media controller. Therefore, we should make `MediaControlKeysEventListener` as a pure interface and let inherited class to define their own `KeyPressed()`. Differential Revision: https://phabricator.services.mozilla.com/D50686 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f745bd76f9
Коммит
e4099c0683
|
@ -42,8 +42,7 @@ static const char* ToMediaControlKeysEventStr(MediaControlKeysEvent aKeyEvent) {
|
|||
ToMediaControlKeysEventStr(key), ##__VA_ARGS__)); \
|
||||
}
|
||||
|
||||
void MediaControlKeysEventListener::OnKeyPressed(
|
||||
MediaControlKeysEvent aKeyEvent) {
|
||||
void MediaControlKeysHandler::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
|
||||
LOG_KEY("OnKeyPressed '%s'", aKeyEvent);
|
||||
switch (aKeyEvent) {
|
||||
case MediaControlKeysEvent::ePlayPause: {
|
||||
|
|
|
@ -14,22 +14,31 @@ namespace dom {
|
|||
enum class MediaControlKeysEvent { ePlayPause, ePrev, eNext, eNone };
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* MediaControlKeysEventListener is a pure interface, which 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 MediaControlKeysEventListener {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaControlKeysEventListener);
|
||||
MediaControlKeysEventListener() = default;
|
||||
|
||||
virtual void OnKeyPressed(MediaControlKeysEvent aKeyEvent);
|
||||
virtual void OnKeyPressed(MediaControlKeysEvent aKeyEvent) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~MediaControlKeysEventListener() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* MediaControlKeysHandler is used to operate media controller by corresponding
|
||||
* received media control key events.
|
||||
*/
|
||||
class MediaControlKeysHandler final : public MediaControlKeysEventListener {
|
||||
public:
|
||||
void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override;
|
||||
};
|
||||
|
||||
/**
|
||||
* MediaControlKeysEventSource is a base class which is used to implement
|
||||
* transporting media control keys event to all its listeners when media keys
|
||||
|
|
|
@ -36,7 +36,7 @@ void MediaControlKeysManager::StartMonitoringControlKeys() {
|
|||
}
|
||||
CreateEventSource();
|
||||
if (mEventSource) {
|
||||
mEventSource->AddListener(new MediaControlKeysEventListener());
|
||||
mEventSource->AddListener(new MediaControlKeysHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ TEST(MediaControlKeysEvent, TestAddOrRemoveListener)
|
|||
ASSERT_TRUE(source->GetListenersNum() == 0);
|
||||
|
||||
RefPtr<MediaControlKeysEventListener> listener =
|
||||
new MediaControlKeysEventListener();
|
||||
new MediaControlKeysHandler();
|
||||
|
||||
source->AddListener(listener);
|
||||
ASSERT_TRUE(source->GetListenersNum() == 1);
|
||||
|
|
Загрузка…
Ссылка в новой задаче