Bug 1640998 - part9 : use MediaControlKey to replace MediaControlKeysEvent r=chunmin,agi,geckoview-reviewers
This patch will - remove `MediaControlKeysEvent` and use `MediaControlKey` to replace it - rename names for all `MediaControlKey` related methods, functions, classes and descriptions The advantage of doing so are - remove the duplicated type so that we only need to maintain `MediaControlKey` Differential Revision: https://phabricator.services.mozilla.com/D78140
This commit is contained in:
@@ -380,7 +380,7 @@ class nsSourceErrorEventRunner : public nsMediaEvent {
|
||||
};
|
||||
|
||||
/**
|
||||
* We use MediaControlEventListener to listen MediaControlKeysEvent in order to
|
||||
* We use MediaControlKeyListener to listen to media control key in order to
|
||||
* play and pause media element when user press media control keys and update
|
||||
* media's playback and audible state to the media controller.
|
||||
*
|
||||
@@ -388,12 +388,12 @@ class nsSourceErrorEventRunner : public nsMediaEvent {
|
||||
* event. In addition, notifying any change to media controller MUST be done
|
||||
* after successfully calling `Start()`.
|
||||
*/
|
||||
class HTMLMediaElement::MediaControlEventListener final
|
||||
: public ContentControlKeyEventReceiver {
|
||||
class HTMLMediaElement::MediaControlKeyListener final
|
||||
: public ContentMediaControlKeyReceiver {
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(MediaControlEventListener, override)
|
||||
NS_INLINE_DECL_REFCOUNTING(MediaControlKeyListener, override)
|
||||
|
||||
MOZ_INIT_OUTSIDE_CTOR explicit MediaControlEventListener(
|
||||
MOZ_INIT_OUTSIDE_CTOR explicit MediaControlKeyListener(
|
||||
HTMLMediaElement* aElement)
|
||||
: mElement(aElement) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
@@ -495,14 +495,14 @@ class HTMLMediaElement::MediaControlEventListener final
|
||||
mIsPictureInPictureEnabled);
|
||||
}
|
||||
|
||||
void HandleEvent(MediaControlKeysEvent aEvent) override {
|
||||
void HandleMediaKey(MediaControlKey aKey) override {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(IsStarted());
|
||||
MEDIACONTROL_LOG("HandleEvent '%s'", ToMediaControlKeysEventStr(aEvent));
|
||||
if (aEvent == MediaControlKeysEvent::ePlay && Owner()->Paused()) {
|
||||
MEDIACONTROL_LOG("HandleEvent '%s'", ToMediaControlKeyStr(aKey));
|
||||
if (aKey == MediaControlKey::Play && Owner()->Paused()) {
|
||||
Owner()->Play();
|
||||
} else if ((aEvent == MediaControlKeysEvent::ePause ||
|
||||
aEvent == MediaControlKeysEvent::eStop) &&
|
||||
} else if ((aKey == MediaControlKey::Pause ||
|
||||
aKey == MediaControlKey::Stop) &&
|
||||
!Owner()->Paused()) {
|
||||
Owner()->Pause();
|
||||
}
|
||||
@@ -539,7 +539,7 @@ class HTMLMediaElement::MediaControlEventListener final
|
||||
}
|
||||
|
||||
private:
|
||||
~MediaControlEventListener() = default;
|
||||
~MediaControlKeyListener() = default;
|
||||
|
||||
// The media can be moved around different browsing contexts, so this context
|
||||
// might be different from the one that we used to initialize
|
||||
@@ -1952,9 +1952,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement,
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingPlayPromises)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSeekDOMPromise)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSetMediaKeysDOMPromise)
|
||||
if (tmp->mMediaControlEventListener) {
|
||||
tmp->StopListeningMediaControlEventIfNeeded();
|
||||
tmp->mMediaControlEventListener = nullptr;
|
||||
if (tmp->mMediaControlKeyListener) {
|
||||
tmp->StopListeningMediaControlKeyIfNeeded();
|
||||
tmp->mMediaControlKeyListener = nullptr;
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_PTR
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
@@ -4194,8 +4194,8 @@ HTMLMediaElement::~HTMLMediaElement() {
|
||||
mResumeDelayedPlaybackAgent = nullptr;
|
||||
}
|
||||
|
||||
StopListeningMediaControlEventIfNeeded();
|
||||
mMediaControlEventListener = nullptr;
|
||||
StopListeningMediaControlKeyIfNeeded();
|
||||
mMediaControlKeyListener = nullptr;
|
||||
|
||||
WakeLockRelease();
|
||||
ReportPlayedTimeAfterBlockedTelemetry();
|
||||
@@ -4395,7 +4395,7 @@ void HTMLMediaElement::PlayInternal(bool aHandlingUserInput) {
|
||||
UpdatePreloadAction();
|
||||
UpdateSrcMediaStreamPlaying();
|
||||
|
||||
StartListeningMediaControlEventIfNeeded();
|
||||
StartListeningMediaControlKeyIfNeeded();
|
||||
|
||||
// Once play() has been called in a user generated event handler,
|
||||
// it is allowed to autoplay. Note: we can reach here when not in
|
||||
@@ -4690,8 +4690,8 @@ nsresult HTMLMediaElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
||||
}
|
||||
|
||||
NotifyDecoderActivityChanges();
|
||||
if (mMediaControlEventListener) {
|
||||
mMediaControlEventListener->UpdateOwnerBrowsingContextIfNeeded();
|
||||
if (mMediaControlKeyListener) {
|
||||
mMediaControlKeyListener->UpdateOwnerBrowsingContextIfNeeded();
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -6136,7 +6136,7 @@ void HTMLMediaElement::CheckAutoplayDataReady() {
|
||||
UpdateSrcMediaStreamPlaying();
|
||||
UpdateAudioChannelPlayingState();
|
||||
|
||||
StartListeningMediaControlEventIfNeeded();
|
||||
StartListeningMediaControlKeyIfNeeded();
|
||||
|
||||
if (mDecoder) {
|
||||
SetPlayedOrSeeked(true);
|
||||
@@ -6471,7 +6471,7 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aSuspendElement) {
|
||||
mEventDeliveryPaused = true;
|
||||
// We won't want to resume media element from the bfcache.
|
||||
ClearResumeDelayedMediaPlaybackAgentIfNeeded();
|
||||
StopListeningMediaControlEventIfNeeded();
|
||||
StopListeningMediaControlKeyIfNeeded();
|
||||
} else {
|
||||
if (!mPaused) {
|
||||
mCurrentLoadPlayTime.Start();
|
||||
@@ -6497,9 +6497,8 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aSuspendElement) {
|
||||
}
|
||||
// If we stopped listening to the event when we suspended media element,
|
||||
// then we should restart to listen to the event if we haven't done so yet.
|
||||
if (mMediaControlEventListener &&
|
||||
!mMediaControlEventListener->IsStarted()) {
|
||||
StartListeningMediaControlEventIfNeeded();
|
||||
if (mMediaControlKeyListener && !mMediaControlKeyListener->IsStarted()) {
|
||||
StartListeningMediaControlKeyIfNeeded();
|
||||
}
|
||||
}
|
||||
if (StaticPrefs::media_testing_only_events()) {
|
||||
@@ -7348,8 +7347,8 @@ void HTMLMediaElement::NotifyAudioPlaybackChanged(
|
||||
if (mAudioChannelWrapper) {
|
||||
mAudioChannelWrapper->NotifyAudioPlaybackChanged(aReason);
|
||||
}
|
||||
if (mMediaControlEventListener && mMediaControlEventListener->IsStarted()) {
|
||||
mMediaControlEventListener->UpdateMediaAudibleState(IsAudible());
|
||||
if (mMediaControlKeyListener && mMediaControlKeyListener->IsStarted()) {
|
||||
mMediaControlKeyListener->UpdateMediaAudibleState(IsAudible());
|
||||
}
|
||||
// only request wake lock for audible media.
|
||||
UpdateWakeLock();
|
||||
@@ -7789,17 +7788,17 @@ void HTMLMediaElement::ClearResumeDelayedMediaPlaybackAgentIfNeeded() {
|
||||
}
|
||||
|
||||
void HTMLMediaElement::NotifyMediaControlPlaybackStateChanged() {
|
||||
if (!mMediaControlEventListener || !mMediaControlEventListener->IsStarted()) {
|
||||
if (!mMediaControlKeyListener || !mMediaControlKeyListener->IsStarted()) {
|
||||
return;
|
||||
}
|
||||
if (mPaused) {
|
||||
mMediaControlEventListener->NotifyMediaStoppedPlaying();
|
||||
mMediaControlKeyListener->NotifyMediaStoppedPlaying();
|
||||
} else {
|
||||
mMediaControlEventListener->NotifyMediaStartedPlaying();
|
||||
mMediaControlKeyListener->NotifyMediaStartedPlaying();
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() {
|
||||
void HTMLMediaElement::StartListeningMediaControlKeyIfNeeded() {
|
||||
if (mPaused) {
|
||||
MEDIACONTROL_LOG("Not listening because media is paused");
|
||||
return;
|
||||
@@ -7819,12 +7818,12 @@ void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() {
|
||||
// should clear the timer, which is used to stop listening to the event.
|
||||
ClearStopMediaControlTimerIfNeeded();
|
||||
|
||||
if (!mMediaControlEventListener) {
|
||||
mMediaControlEventListener = new MediaControlEventListener(this);
|
||||
if (!mMediaControlKeyListener) {
|
||||
mMediaControlKeyListener = new MediaControlKeyListener(this);
|
||||
}
|
||||
|
||||
if (mMediaControlEventListener->IsStarted() ||
|
||||
!mMediaControlEventListener->Start()) {
|
||||
if (mMediaControlKeyListener->IsStarted() ||
|
||||
!mMediaControlKeyListener->Start()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7837,17 +7836,17 @@ void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() {
|
||||
// `UpdateMediaAudibleState()` could only be used after we start the listener,
|
||||
// but the audible state update could happen before that. Therefore, we have
|
||||
// to manually update media's audible state as well.
|
||||
mMediaControlEventListener->UpdateMediaAudibleState(IsAudible());
|
||||
mMediaControlKeyListener->UpdateMediaAudibleState(IsAudible());
|
||||
|
||||
// Picture-in-Picture mode can be enabled before we start the listener so we
|
||||
// manually update the status here in case not to forgot to propagate that.
|
||||
mMediaControlEventListener->SetPictureInPictureModeEnabled(
|
||||
mMediaControlKeyListener->SetPictureInPictureModeEnabled(
|
||||
IsBeingUsedInPictureInPictureMode());
|
||||
}
|
||||
|
||||
void HTMLMediaElement::StopListeningMediaControlEventIfNeeded() {
|
||||
if (mMediaControlEventListener && mMediaControlEventListener->IsStarted()) {
|
||||
mMediaControlEventListener->Stop();
|
||||
void HTMLMediaElement::StopListeningMediaControlKeyIfNeeded() {
|
||||
if (mMediaControlKeyListener && mMediaControlKeyListener->IsStarted()) {
|
||||
mMediaControlKeyListener->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7858,16 +7857,16 @@ void HTMLMediaElement::StopMediaControlTimerCallback(nsITimer* aTimer,
|
||||
auto element = static_cast<HTMLMediaElement*>(aClosure);
|
||||
CONTROLLER_TIMER_LOG(element,
|
||||
"Runnning stop media control timmer callback function");
|
||||
element->StopListeningMediaControlEventIfNeeded();
|
||||
element->StopListeningMediaControlKeyIfNeeded();
|
||||
element->mStopMediaControlTimer = nullptr;
|
||||
}
|
||||
|
||||
void HTMLMediaElement::CreateStopMediaControlTimerIfNeeded() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
// We would create timer only when `mMediaControlEventListener` exists and has
|
||||
// We would create timer only when `mMediaControlKeyListener` exists and has
|
||||
// been started.
|
||||
if (mStopMediaControlTimer || !mMediaControlEventListener ||
|
||||
!mMediaControlEventListener->IsStarted()) {
|
||||
if (mStopMediaControlTimer || !mMediaControlKeyListener ||
|
||||
!mMediaControlKeyListener->IsStarted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7903,13 +7902,13 @@ void HTMLMediaElement::ClearStopMediaControlTimerIfNeeded() {
|
||||
|
||||
void HTMLMediaElement::UpdateMediaControlAfterPictureInPictureModeChanged() {
|
||||
// Hasn't started to connect with media control, no need to update anything.
|
||||
if (!mMediaControlEventListener || !mMediaControlEventListener->IsStarted()) {
|
||||
if (!mMediaControlKeyListener || !mMediaControlKeyListener->IsStarted()) {
|
||||
return;
|
||||
}
|
||||
if (IsBeingUsedInPictureInPictureMode()) {
|
||||
mMediaControlEventListener->SetPictureInPictureModeEnabled(true);
|
||||
mMediaControlKeyListener->SetPictureInPictureModeEnabled(true);
|
||||
} else {
|
||||
mMediaControlEventListener->SetPictureInPictureModeEnabled(false);
|
||||
mMediaControlKeyListener->SetPictureInPictureModeEnabled(false);
|
||||
CreateStopMediaControlTimerIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user