Skip to content
Permalink
Browse files
Apple.com/apple-events: Unable to enable subtitles on first watch of …
…the keynote

https://bugs.webkit.org/show_bug.cgi?id=247549
rdar://101785175

Reviewed by Eric Carlson.

Two interlocking bugs prevent captions from being visible if tracks are added after the video is
loaded: 1) `m_processingPreferenceChange` is set to `true` in
`markCaptionAndSubtitleTracksAsUnconfigured()` and is only set to `false` if at least one text
track is present and therefore `configureTextTrackGroup()` is called. 2) the MediaControlsHost is
not notified that the video element's videoBox has changed, as it's only notified during style
updates, and will not necessarily have a RenderVideo attached at that point.

Clear `m_processingPreferenceChange` unconditionally at the end of `configureTextTracks()`. And call
the MediaControlsHost's `updateCaptionDisplaySizes()` when the media element is resized.

* LayoutTests/media/track/video-track-add-visible-expected.txt: Added.
* LayoutTests/media/track/video-track-add-visible.html: Added.
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::configureTextTrackGroup):
(WebCore::HTMLMediaElement::layoutSizeChanged):
(WebCore::HTMLMediaElement::configureTextTracks):

Canonical link: https://commits.webkit.org/256408@main
  • Loading branch information
jernoble committed Nov 7, 2022
1 parent 68c7f6b commit 7ff585820d47faa4b1845617e6328c4d3d7c41ac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
@@ -0,0 +1,10 @@

RUN(video.src = findMediaFile("video", "../content/test"))
EVENT(canplay)
RUN(track = video.addTextTrack("subtitles"))
RUN(track.mode = "showing")
RUN(cue = new VTTCue(0, video.duration, "cue text"))
RUN(track.addCue(cue))
EXPECTED (internals.shadowRoot(video).querySelector(".media-controls-container").innerText == 'cue text') OK
END OF TEST

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<script src=../media-file.js></script>
<script src=../video-test.js></script>
<script>
window.addEventListener('load', async event => {
findMediaElement();
run('video.src = findMediaFile("video", "../content/test")');
await waitFor(video, 'canplay');
run('track = video.addTextTrack("subtitles")');
run('track.mode = "showing"');
run('cue = new VTTCue(0, video.duration, "cue text")');
run('track.addCue(cue)');
await testExpectedEventually('internals.shadowRoot(video).querySelector(".media-controls-container").innerText', 'cue text');
endTest();
});
</script>
</head>
<body>
<video muted></video>
</body>
</html>
@@ -4861,8 +4861,6 @@ void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group)
if (!webkitClosedCaptionsVisible() && closedCaptionsVisible() && displayMode == CaptionUserPreferences::AlwaysOn)
m_webkitLegacyClosedCaptionOverride = true;
}

m_processingPreferenceChange = false;
}

static JSC::JSValue controllerJSValue(JSC::JSGlobalObject& lexicalGlobalObject, JSDOMGlobalObject& globalObject, HTMLMediaElement& media)
@@ -4967,6 +4965,9 @@ void HTMLMediaElement::layoutSizeChanged()
auto task = [this] {
if (auto root = userAgentShadowRoot())
root->dispatchEvent(Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No));

if (m_mediaControlsHost)
m_mediaControlsHost->updateCaptionDisplaySizes();
};
queueTaskKeepingObjectAlive(*this, TaskSource::MediaElement, WTFMove(task));

@@ -5106,6 +5107,8 @@ void HTMLMediaElement::configureTextTracks()
if (otherTracks.tracks.size())
configureTextTrackGroup(otherTracks);

m_processingPreferenceChange = false;

updateCaptionContainer();
configureTextTrackDisplay();
}

0 comments on commit 7ff5858

Please sign in to comment.