Skip to content

Commit 443099f

Browse files
committed
On caption menu item doesn't enable text tracks
rdar://166158394 https://bugs.webkit.org/show_bug.cgi?id=304048 Reviewed by Eric Carlson. Make "On" behave similarly to "Auto", which is to enable the highest scoring text track available. Additionally, mark languages in the subtitle menu as checked when they will be enabled by the "On" menu item. Drive-by fix: Pass track and element parameters into CaptionUserPreferences by reference rather than by pointer value. Test: media/modern-media-controls/tracks-support/on-off-text-track.html * LayoutTests/media/modern-media-controls/resources/media-controls-utils.js: * LayoutTests/media/modern-media-controls/tracks-support/on-off-text-track-expected.txt: Added. * LayoutTests/media/modern-media-controls/tracks-support/on-off-text-track.html: Added. * Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp: (WebCore::MediaControlsHost::captionMenuOnItem): (WebCore::MediaControlsHost::showMediaControlsContextMenu): * Source/WebCore/Modules/mediacontrols/MediaControlsHost.h: * Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl: * Source/WebCore/html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::configureTextTrackGroup): (WebCore::HTMLMediaElement::setSelectedTextTrack): * Source/WebCore/page/CaptionUserPreferences.cpp: (WebCore::CaptionUserPreferences::textTrackSelectionScore const): (WebCore::CaptionUserPreferences::textTrackLanguageSelectionScore const): * Source/WebCore/page/CaptionUserPreferences.h: * Source/WebCore/testing/Internals.cpp: (WebCore::Internals::controlsHostForMediaElement): * Source/WebCore/testing/Internals.h: * Source/WebCore/testing/Internals.idl: Canonical link: https://commits.webkit.org/304462@main
1 parent 4d3c765 commit 443099f

22 files changed

+425
-74
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
RUN(video.src = findMediaFile("audio", "../../content/test"))
3+
EVENT(loadedmetadata)
4+
--
5+
Test basic menu structure:
6+
EXPECTED (contextMenu.length == '7') OK
7+
EXPECTED (contextMenu[0].title == 'Subtitles') OK
8+
EXPECTED (contextMenu[1].title == 'On') OK
9+
EXPECTED (contextMenu[2].title == 'Off') OK
10+
EXPECTED (contextMenu[3].title == 'undefined') OK
11+
EXPECTED (contextMenu[4].title == 'Languages') OK
12+
EXPECTED (contextMenu[4].children.length == '4') OK
13+
EXPECTED (contextMenu[4].children[0].title == 'English Captions') OK
14+
EXPECTED (contextMenu[4].children[1].title == 'French Captions') OK
15+
EXPECTED (contextMenu[4].children[2].title == 'German Captions') OK
16+
EXPECTED (contextMenu[4].children[3].title == 'Spanish Captions') OK
17+
EXPECTED (contextMenu[5].title == 'undefined') OK
18+
EXPECTED (contextMenu[6].title == 'Styles') OK
19+
--
20+
Test default menu selection states
21+
EXPECTED (contextMenu[1].checked == 'false') OK
22+
EXPECTED (contextMenu[2].checked == 'true') OK
23+
EXPECTED (contextMenu[4].children[0].checked == 'true') OK
24+
EXPECTED (contextMenu[4].children[1].checked == 'false') OK
25+
EXPECTED (contextMenu[4].children[2].checked == 'false') OK
26+
EXPECTED (contextMenu[4].children[3].checked == 'false') OK
27+
--
28+
Test On menu item behavior
29+
RUN(controlsHost.setSelectedTextTrack(onItem))
30+
EXPECTED (video.textTracks[0].mode == 'showing') OK
31+
EXPECTED (contextMenu[1].checked == 'true') OK
32+
EXPECTED (contextMenu[2].checked == 'false') OK
33+
EXPECTED (internals.captionDisplayMode == 'alwayson') OK
34+
--
35+
Test Off menu item behavior
36+
RUN(controlsHost.setSelectedTextTrack(offItem))
37+
EXPECTED (video.textTracks[0].mode == 'disabled') OK
38+
EXPECTED (contextMenu[1].checked == 'false') OK
39+
EXPECTED (contextMenu[2].checked == 'true') OK
40+
EXPECTED (internals.captionDisplayMode == 'forcedonly') OK
41+
--
42+
Test Language menu item behavior
43+
RUN(controlsHost.setSelectedTextTrack(video.textTracks[1]))
44+
EXPECTED (video.textTracks[1].mode == 'showing') OK
45+
EXPECTED (contextMenu[1].checked == 'true') OK
46+
EXPECTED (contextMenu[2].checked == 'false') OK
47+
EXPECTED (contextMenu[4].children[0].checked == 'false') OK
48+
EXPECTED (contextMenu[4].children[1].checked == 'true') OK
49+
EXPECTED (contextMenu[4].children[2].checked == 'false') OK
50+
EXPECTED (contextMenu[4].children[3].checked == 'false') OK
51+
EXPECTED (internals.captionDisplayMode == 'alwayson') OK
52+
END OF TEST
53+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!DOCTYPE html> <!-- webkit-test-runner [ CaptionDisplaySettingsEnabled=true ] -->
2+
<html>
3+
<head>
4+
<title>on-auto-text-track</title>
5+
<style>
6+
video { width: 600px; }
7+
</style>
8+
<script src="../resources/media-controls-utils.js"></script>
9+
<script src="../../video-test.js"></script>
10+
<script src="../../media-file.js"></script>
11+
<script>
12+
window.addEventListener('load', event => {
13+
runTest().then(endTest)//.catch(failTest)
14+
});
15+
16+
var shadowRoot;
17+
var controlsHost;
18+
var contextMenu;
19+
20+
window.internals.setCaptionDisplayMode('automatic');
21+
window.internals.settings.setShouldDisplayTrackKind('Captions', true);
22+
23+
function getContextMenuItems() {
24+
const options = { includeLanguages: true, includeSubtitles: true };
25+
return controlsHost.mediaControlsContextMenuItems(options)
26+
}
27+
28+
async function runTest() {
29+
findMediaElement();
30+
31+
run('video.src = findMediaFile("audio", "../../content/test")');
32+
await waitFor(video, 'loadedmetadata');
33+
34+
controlsHost = internals.controlsHostForMediaElement(video);
35+
contextMenu = getContextMenuItems();
36+
37+
consoleWrite('--');
38+
consoleWrite('Test basic menu structure:');
39+
testExpected('contextMenu.length', 7);
40+
testExpected('contextMenu[0].title', 'Subtitles');
41+
testExpected('contextMenu[1].title', 'On');
42+
testExpected('contextMenu[2].title', 'Off');
43+
testExpected('contextMenu[3].title', undefined);
44+
testExpected('contextMenu[4].title', 'Languages');
45+
testExpected('contextMenu[4].children.length', '4');
46+
testExpected('contextMenu[4].children[0].title', 'English Captions');
47+
testExpected('contextMenu[4].children[1].title', 'French Captions');
48+
testExpected('contextMenu[4].children[2].title', 'German Captions');
49+
testExpected('contextMenu[4].children[3].title', 'Spanish Captions');
50+
testExpected('contextMenu[5].title', undefined);
51+
testExpected('contextMenu[6].title', 'Styles');
52+
53+
consoleWrite('--');
54+
consoleWrite('Test default menu selection states');
55+
testExpected('contextMenu[1].checked', false);
56+
testExpected('contextMenu[2].checked', true);
57+
testExpected('contextMenu[4].children[0].checked', true);
58+
testExpected('contextMenu[4].children[1].checked', false);
59+
testExpected('contextMenu[4].children[2].checked', false);
60+
testExpected('contextMenu[4].children[3].checked', false);
61+
62+
consoleWrite('--');
63+
consoleWrite('Test On menu item behavior');
64+
65+
onItem = controlsHost.captionMenuOnItem;
66+
offItem = controlsHost.captionMenuOffItem;
67+
autoItem = controlsHost.captionMenuAutomaticItem;
68+
69+
run('controlsHost.setSelectedTextTrack(onItem)');
70+
await testExpectedEventually('video.textTracks[0].mode', 'showing', '==', 100);
71+
72+
contextMenu = getContextMenuItems();
73+
testExpected('contextMenu[1].checked', true);
74+
testExpected('contextMenu[2].checked', false);
75+
testExpected('internals.captionDisplayMode', 'alwayson');
76+
77+
consoleWrite('--');
78+
consoleWrite('Test Off menu item behavior');
79+
80+
run('controlsHost.setSelectedTextTrack(offItem)');
81+
await testExpectedEventually('video.textTracks[0].mode', 'disabled', '==', 100);
82+
83+
contextMenu = getContextMenuItems();
84+
testExpected('contextMenu[1].checked', false);
85+
testExpected('contextMenu[2].checked', true);
86+
testExpected('internals.captionDisplayMode', 'forcedonly');
87+
88+
consoleWrite('--');
89+
consoleWrite('Test Language menu item behavior');
90+
91+
run('controlsHost.setSelectedTextTrack(video.textTracks[1])');
92+
await testExpectedEventually('video.textTracks[1].mode', 'showing', '==', 100);
93+
94+
contextMenu = getContextMenuItems();
95+
testExpected('contextMenu[1].checked', true);
96+
testExpected('contextMenu[2].checked', false);
97+
testExpected('contextMenu[4].children[0].checked', false);
98+
testExpected('contextMenu[4].children[1].checked', true);
99+
testExpected('contextMenu[4].children[2].checked', false);
100+
testExpected('contextMenu[4].children[3].checked', false);
101+
testExpected('internals.captionDisplayMode', 'alwayson');
102+
}
103+
</script>
104+
</head>
105+
<body>
106+
<video controls muted playsinline disableremoteplayback preload="metadata">
107+
<track src="../../content/lorem-ipsum.vtt" kind="captions" srclang="en">
108+
<track src="../../content/lorem-ipsum.vtt" kind="captions" srclang="fr">
109+
<track src="../../content/lorem-ipsum.vtt" kind="captions" srclang="de">
110+
<track src="../../content/lorem-ipsum.vtt" kind="captions" srclang="es">
111+
</video>
112+
</body>
113+
</html>

LayoutTests/platform/glib/TestExpectations

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4850,6 +4850,7 @@ http/tests/performance/performance-resource-timing-redirection-cross-origin-medi
48504850
webkit.org/b/304053 imported/w3c/web-platform-tests/trusted-types/SharedWorker-eval.html [ Pass Crash ]
48514851

48524852
webkit.org/b/304054 webgl/1.0.x/conformance/textures/image_data/tex-2d-alpha-alpha-unsigned_byte.html [ Pass Crash ]
4853+
webkit.org/b/304180 media/modern-media-controls/tracks-support/on-off-text-track.html [ Failure ]
48534854

48544855
# End: Common failures between GTK and WPE.
48554856

Source/WebCore/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ set(WebCore_NON_SVG_IDL_FILES
490490
Modules/mediacapabilities/WorkerNavigator+MediaCapabilities.idl
491491

492492
Modules/mediacontrols/DOMWindow+MediaControls.idl
493+
Modules/mediacontrols/MediaControlsContextMenuItem.idl
493494
Modules/mediacontrols/MediaControlsHost.idl
494495
Modules/mediacontrols/MediaControlsUtils.idl
495496

Source/WebCore/DerivedSources-input.xcfilelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ $(PROJECT_DIR)/Modules/mediacapabilities/TransferFunction.idl
554554
$(PROJECT_DIR)/Modules/mediacapabilities/VideoConfiguration.idl
555555
$(PROJECT_DIR)/Modules/mediacapabilities/WorkerNavigator+MediaCapabilities.idl
556556
$(PROJECT_DIR)/Modules/mediacontrols/DOMWindow+MediaControls.idl
557+
$(PROJECT_DIR)/Modules/mediacontrols/MediaControlsContextMenuItem.idl
557558
$(PROJECT_DIR)/Modules/mediacontrols/MediaControlsHost.idl
558559
$(PROJECT_DIR)/Modules/mediacontrols/MediaControlsUtils.idl
559560
$(PROJECT_DIR)/Modules/mediarecorder/BlobEvent.idl

Source/WebCore/DerivedSources-output.xcfilelist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaConfiguration.cpp
18691869
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaConfiguration.h
18701870
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaController.cpp
18711871
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaController.h
1872+
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaControlsContextMenuItem.cpp
1873+
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaControlsContextMenuItem.h
18721874
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaControlsHost.cpp
18731875
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaControlsHost.h
18741876
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSMediaControlsUtils.cpp

Source/WebCore/DerivedSources.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ JS_BINDING_IDLS := \
415415
$(WebCore)/Modules/mediacapabilities/VideoConfiguration.idl \
416416
$(WebCore)/Modules/mediacapabilities/WorkerNavigator+MediaCapabilities.idl \
417417
$(WebCore)/Modules/mediacontrols/DOMWindow+MediaControls.idl \
418+
$(WebCore)/Modules/mediacontrols/MediaControlsContextMenuItem.idl \
418419
$(WebCore)/Modules/mediacontrols/MediaControlsHost.idl \
419420
$(WebCore)/Modules/mediacontrols/MediaControlsUtils.idl \
420421
$(WebCore)/Modules/mediarecorder/BlobEvent.idl \
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2025 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
[
27+
Conditional=MEDIA_CONTROLS_CONTEXT_MENUS,
28+
JSGenerateToJSObject,
29+
EnabledBySetting=MediaControlsContextMenusEnabled
30+
] dictionary MediaControlsContextMenuItem {
31+
unsigned long long id;
32+
DOMString title;
33+
DOMString icon;
34+
boolean checked;
35+
sequence<MediaControlsContextMenuItem> children;
36+
};

0 commit comments

Comments
 (0)