Allow ports specific text track menu

https://bugs.webkit.org/show_bug.cgi?id=112800

Reviewed by Dean Jackson.

Source/WebCore: 

No new tests, existing tests updated for changes.

* English.lproj/Localizable.strings: Add localizable strings for text track names.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): userPrefersCaptions -> shouldShowCaptions.
(WebCore::HTMLMediaElement::setSelectedTextTrack): toggleTrackAtIndex -> setSelectedTextTrack.
(WebCore::HTMLMediaElement::userPrefersCaptions): userPrefersCaptions -> shouldShowCaptions.
(WebCore::HTMLMediaElement::userIsInterestedInThisTrackKind): Get preferences from CaptionUserPreferences
    instead of from Settings.
(WebCore::HTMLMediaElement::setSelectedTextTrack): Renamed from toggleTrackAtIndex. Now takes
    a TextTrack* instead of an int.
(WebCore::HTMLMediaElement::captionPreferencesChanged): Don't force a recalculation unless 
    captions are enabled/disabled to avoid unnecessary thrash.
* html/HTMLMediaElement.h:

* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Use the menu to track
    map instead of just the track index.
(WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Build and configure the
    menu from the menu to track map.
(WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu): Start with a list
    of tracks already sorted according to platform specific rules. Build a menu to track map
    so tracks are retained while the menu is visible.
* html/shadow/MediaControlElements.h:

* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::textTrackPreferencesChanged): Call closedCaptionTracksChanged so the
    track menu will be rebuilt before it is shown again.

* html/track/InbandTextTrack.cpp:
(WebCore::InbandTextTrack::containsOnlyForcedSubtitles): New, passthrough to the private track.
(WebCore::InbandTextTrack::isMainProgramContent): Ditto.
(WebCore::InbandTextTrack::isEasyToRead): Ditto.
* html/track/InbandTextTrack.h:
* html/track/TextTrack.h:

* html/track/TextTrackList.cpp:
(WebCore::TextTrackList::contains): New.
* html/track/TextTrackList.h:

* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::CaptionUserPreferences): Pull in from .h ditto.
(WebCore::CaptionUserPreferences::~CaptionUserPreferences): Ditto.
(WebCore::CaptionUserPreferences::shouldShowCaptions): Renamed from userPrefersCaptions. 
(WebCore::CaptionUserPreferences::setShouldShowCaptions): New.
(WebCore::CaptionUserPreferences::userPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferences::userPrefersSubtitles): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersSubtitles): Ditto.
(WebCore::CaptionUserPreferences::userPrefersTextDescriptions): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersTextDescriptions): Ditto.
(WebCore::CaptionUserPreferences::displayNameForTrack): Ditto.
(WebCore::CaptionUserPreferences::sortedTrackListForMenu): Ditto.
* page/CaptionUserPreferences.h:

* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::shouldShowCaptions): Renamed from userPrefersCaptions. 
(WebCore::CaptionUserPreferencesMac::userPrefersCaptions): New.
(WebCore::CaptionUserPreferences::userPrefersSubtitles): Ditto.
(WebCore::trackDisplayName): Update logic used to build track title.
(WebCore::CaptionUserPreferencesMac::displayNameForTrack): Call trackDisplayName.
(WebCore::textTrackCompare): Text track title sort comparison function.
(WebCore::CaptionUserPreferencesMac::sortedTrackListForMenu): New. Sort the list of tracks
    according to title, language, and user preferences.

* platform/Language.cpp:
(WebCore::displayNameForLanguageLocale): Don't leak the CFLocale.
        
* platform/LocalizedStrings.cpp:
(WebCore::textTrackCountryAndLanguageMenuItemText): New.
(WebCore::textTrackLanguageMenuItemText): Ditto.
(WebCore::closedCaptionTrackMenuItemText): Ditto.
(WebCore::sdhTrackMenuItemText): Ditto.
(WebCore::easyReaderTrackMenuItemText): Ditto.
* platform/LocalizedStrings.h:

* platform/graphics/InbandTextTrackPrivate.h:
* platform/graphics/avfoundation/objc/InbandTextTrackPrivateAVFObjC.h:
* platform/graphics/avfoundation/objc/InbandTextTrackPrivateAVFObjC.mm:
(WebCore::InbandTextTrackPrivateAVFObjC::containsOnlyForcedSubtitles): New, return AVFoundation property.
(WebCore::InbandTextTrackPrivateAVFObjC::isMainProgramContent): Ditto.
(WebCore::InbandTextTrackPrivateAVFObjC::isEasyToRead): Ditto.

* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setShouldDisplayTrackKind): Set setting via CaptionUserPreferences
    instead of from Settings.
(WebCore::InternalSettings::shouldDisplayTrackKind): Get setting from CaptionUserPreferences
    instead of from Settings.

Source/WebKit: 

* WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in: Add new exports.
* win/WebKit.vcproj/WebKitExports.def.in: Ditto.

LayoutTests: 

* media/track/track-user-preferences-expected.txt:
* media/track/track-user-preferences.html:
* media/video-controls-captions-trackmenu-localized.html:
* media/video-controls-captions-trackmenu-sorted.html:
* media/video-controls-captions-trackmenu.html:
* platform/mac/media/video-controls-captions-trackmenu-expected.txt:
* platform/mac/media/video-controls-captions-trackmenu-localized-expected.txt:
* platform/mac/media/video-controls-captions-trackmenu-sorted-expected.txt:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@146380 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 50246a14
2013-03-20 Eric Carlson <eric.carlson@apple.com>
Allow ports specific text track menu
https://bugs.webkit.org/show_bug.cgi?id=112800
Reviewed by Dean Jackson.
* media/track/track-user-preferences-expected.txt:
* media/track/track-user-preferences.html:
* media/video-controls-captions-trackmenu-localized.html:
* media/video-controls-captions-trackmenu-sorted.html:
* media/video-controls-captions-trackmenu.html:
* platform/mac/media/video-controls-captions-trackmenu-expected.txt:
* platform/mac/media/video-controls-captions-trackmenu-localized-expected.txt:
* platform/mac/media/video-controls-captions-trackmenu-sorted-expected.txt:
2013-03-20 Julien Chaffraix <jchaffraix@webkit.org>
[CSS Grid Layout] Improper repainting when grid item change their position
......@@ -18,10 +18,10 @@ EXPECTED (event.target.readyState == '2') OK
Test 3: select 'fr' track from menu
- show captions menu.
EXPECTED (trackMenuItems[1].className == '') OK
EXPECTED (trackMenuItems[2].className == '') OK
EXPECTED (trackMenuItems[3].className == 'selected') OK
- click on menu item 2.
EXPECTED (trackMenuItems[menuIndexForLanguage('French')].className == '') OK
EXPECTED (trackMenuItems[menuIndexForLanguage('English')].className == '') OK
EXPECTED (trackMenuItems[menuIndexForLanguage('Norwegian')].className == 'selected') OK
- click on 'French' menu item.
EVENT(load)
EXPECTED (event.target.srclang == 'fr') OK
EXPECTED (event.target.readyState == '2') OK
......@@ -38,7 +38,7 @@ EXPECTED (video.textTracks[2].language == 'fr') OK
Test 5: turning captions off from menu disables caption selection
- show captions menu.
- click on menu item 0.
- click on 'Off' menu item.
- creating tracks for: [ru,jp,en].
EXPECTED (video.textTracks[0].mode == 'disabled') OK
EXPECTED (video.textTracks[1].mode == 'disabled') OK
......
......@@ -44,10 +44,26 @@
return trackListItems;
}
function selectCaptionMenuItem(index)
function menuIndexForLanguage(language)
{
consoleWrite("- click on menu item " + index + ".");
var trackMenuItems = trackMenuList();
for (i = 0; i < trackMenuItems.length; ++i) {
if (trackMenuItems[i].textContent.indexOf(language) >= 0)
break;
}
return (i < trackMenuItems.length) ? i : -1;
}
function selectCaptionMenuItem(language)
{
var trackMenuItems = trackMenuList();
var index = menuIndexForLanguage(language);
if (index < 0) {
failTest("Menu item " + language + " not found in track list menu.");
return;
}
consoleWrite("- click on '" + language + "' menu item.");
var selectedTrackItem = trackMenuItems[index];
var boundingRect = selectedTrackItem.getBoundingClientRect();
var x = boundingRect.left + boundingRect.width / 2;
......@@ -70,7 +86,7 @@
{
var track = document.createElement('track');
track.setAttribute('kind', "captions");
track.src = 'data:text/vtt,'+encodeURIComponent("WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nCaption 1\n");
track.src = 'data:text/vtt,' + encodeURIComponent("WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nCaption 1\n");
track.setAttribute('srclang', language);
track.setAttribute('onload', 'trackLoaded()');
if (isDefault) {
......@@ -108,20 +124,17 @@
break;
case 3:
// Clear the debug setting so it isn't considered in the track selection logic
internals.settings.setShouldDisplayTrackKind('Captions', false);
consoleWrite("<br>Test 3: select 'fr' track from menu");
showCaptionMenu();
break;
case 4:
trackMenuItems = trackMenuList();
testExpected("trackMenuItems[1].className", "");
testExpected("trackMenuItems[2].className", "");
testExpected("trackMenuItems[3].className", "selected");
testExpected("trackMenuItems[menuIndexForLanguage('French')].className", "");
testExpected("trackMenuItems[menuIndexForLanguage('English')].className", "");
testExpected("trackMenuItems[menuIndexForLanguage('Norwegian')].className", "selected");
selectCaptionMenuItem(2);
selectCaptionMenuItem("French");
expectedLanguage = 'fr';
break;
......@@ -143,7 +156,7 @@
break;
case 7:
selectCaptionMenuItem(0);
selectCaptionMenuItem("Off");
createTrackElements([ 'ru', 'jp', 'en']);
timer = setTimeout(nextStep, 100);
break;
......
......@@ -44,8 +44,8 @@
testExpected("item.textContent", "English CC");
item = captionsEntries[2];
consoleWrite("<br>Third item in captions menu should be labelled 'Unknown'");
testExpected("item.textContent", "Unknown");
consoleWrite("<br>Third item in captions menu should be labelled 'Unknown SDH'");
testExpected("item.textContent", "Unknown SDH");
item = captionsEntries[3];
consoleWrite("<br>Fourth item in captions menu should be labelled 'Unknown'");
......
......@@ -7,11 +7,16 @@
<script src="video-test.js"></script>
<script src="trackmenu-test.js"></script>
<script>
var test = 0;
if (window.testRunner)
testRunner.dumpAsText();
function testSortedMenu()
function textTrackMenuItems()
{
// Show and hide the menu to force a recalculation.
clickCCButton();
clickCCButton();
var trackListElement = getTrackListElement();
if (!trackListElement)
return;
......@@ -20,25 +25,54 @@
failTest("There should be a ul element in track list menu");
return;
}
var lastTrackLabel = null;
var trackListItems = trackListSection.querySelectorAll("li");
if (!trackListItems || trackListItems.length != 7) {
failTest("There should be seven li elements in the menu");
return;
}
for (var j = 0; j < trackListItems.length; j++) {
var item = trackListItems[j];
if (j == 0)
logResult(item.textContent == "Off", "First item should be labelled off");
else {
if (lastTrackLabel)
logResult(item.textContent > lastTrackLabel, lastTrackLabel + " comes before " + item.textContent);
else
logResult(true, item.textContent + " is the first real item in the list");
lastTrackLabel = item.textContent;
}
return trackListSection.querySelectorAll("li");
}
function testSortedMenu()
{
switch (test)
{
case 0:
consoleWrite("<br><i>** Test with preferred language set to English, track type set to captions<" + "/i>");
run("internals.settings.setShouldDisplayTrackKind('Captions', true)");
window.setTimeout(testSortedMenu, 0);
break;
case 1:
trackMenuItems = textTrackMenuItems();
testExpected("trackMenuItems[0].textContent", "Off");
testExpected("trackMenuItems[1].textContent", "u (English) SDH");
testExpected("trackMenuItems[2].textContent", "y (English-Australia) SDH");
testExpected("trackMenuItems[3].textContent", "v (English)");
testExpected("trackMenuItems[4].textContent", "x (English-Australia)");
testExpected("trackMenuItems[5].textContent", "w (Japanese) SDH");
testExpected("trackMenuItems[6].textContent", "z (Japanese)");
testExpected("video.textTracks.length", 6);
testExpected("trackMenuItems.length", 7);
consoleWrite("<br><i>** Change preferred language to Japanese, change preference to subtitles<" + "/i>");
run("internals.setUserPreferredLanguages(['ja'])");
run("internals.settings.setShouldDisplayTrackKind('Captions', false)");
run("internals.settings.setShouldDisplayTrackKind('Subtitles', true)");
window.setTimeout(testSortedMenu, 0);
break;
case 2:
trackMenuItems = textTrackMenuItems();
testExpected("trackMenuItems[0].textContent", "Off");
testExpected("trackMenuItems[1].textContent", "z (Japanese)");
testExpected("trackMenuItems[2].textContent", "v (English)");
testExpected("trackMenuItems[3].textContent", "x (English-Australia)");
testExpected("video.textTracks.length", 6);
testExpected("trackMenuItems.length", 4);
consoleWrite("");
endTest();
break;
}
endTest();
++test;
}
function start()
......@@ -51,14 +85,14 @@
</head>
<body onload="start()">
<p>Test that captions and subtitles are sorted in the menu.</p>
<p>Test that captions and subtitles are sorted in the menu according to user preferences.</p>
<video width="500" height="300" controls>
<track label="c" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
<track label="b" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
<track label="a" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
<track label="b" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
<track label="a" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
<track label="c" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
<track label="z" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
<track label="y" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
<track label="x" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
<track label="w" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
<track label="v" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
<track label="u" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
</video>
</body>
</html>
......
......@@ -15,6 +15,7 @@
consoleWrite("<br>*** Add another text track.");
run('video.addTextTrack("captions", "Commentary", "ru")');
window.setTimeout(turnCaptionsOn, 100);
consoleWrite("");
}
function trackMenuList()
......@@ -39,10 +40,10 @@
function testMenu()
{
var trackListItems = trackMenuList();
trackListItems = trackMenuList();
var expectedItemCount = video.textTracks.length + 1;
consoleWrite("There should be " + expectedItemCount + " items in the menu.");
testExpected(trackListItems.length, expectedItemCount);
testExpected("trackListItems.length", expectedItemCount);
}
function selectCaptionMenuItem(index, nextStep)
......@@ -62,7 +63,7 @@
function turnCaptionsOn()
{
consoleWrite("*** Turning captions on");
// Click on the third item, which is the second track (Off is the first item in the menu)
// Click on the second item, which is the second track (Off is the first item in the menu)
selectCaptionMenuItem(2, testCaptionsVisible);
}
......@@ -117,8 +118,8 @@
<body onload="start()">
<p>Test that we are able to trigger the list of captions, and select from the list.</p>
<video width="500" height="300" controls>
<track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="fr">
<track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
<track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
<track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
</video>
</body>
......
......@@ -7,9 +7,10 @@ RUN(internals.setUserPreferredLanguages(['en']))
*** Add another text track.
RUN(video.addTextTrack("captions", "Commentary", "ru"))
*** Turning captions on
There should be 5 items in the menu.
EXPECTED (5 == '5') OK
EXPECTED (trackListItems.length == '5') OK
EXPECTED (video.textTracks.length == '4') OK
Track 0 should be showing
EXPECTED (video.textTracks[0].mode == 'showing') OK
......@@ -25,7 +26,7 @@ EXPECTED (textTrackDisplayElement(video, 'display').innerText == 'Lorem') OK
RUN(video.removeChild(document.querySelectorAll("track")[0]))
*** Turning captions off
There should be 4 items in the menu.
EXPECTED (4 == '4') OK
EXPECTED (trackListItems.length == '4') OK
EXPECTED (video.textTracks.length == '3') OK
Track 0 should be disabled
EXPECTED (video.textTracks[0].mode == 'disabled') OK
......
......@@ -11,10 +11,10 @@ First item in captions menu should be labelled 'Off'
EXPECTED (item.textContent == 'Off') OK
Second item in captions menu should be labelled 'English CC'
EXPECTED (item.textContent == 'English CC'), OBSERVED 'Unknown' FAIL
EXPECTED (item.textContent == 'English CC'), OBSERVED 'Unknown SDH' FAIL
Third item in captions menu should be labelled 'Unknown'
EXPECTED (item.textContent == 'Unknown') OK
Third item in captions menu should be labelled 'Unknown SDH'
EXPECTED (item.textContent == 'Unknown SDH'), OBSERVED 'Unknown' FAIL
Fourth item in captions menu should be labelled 'Unknown'
TypeError: 'undefined' is not an object (evaluating 'item.textContent')
......
Test that captions and subtitles are sorted in the menu.
Test that captions and subtitles are sorted in the menu according to user preferences.
EVENT(canplaythrough)
*** Set the user language preference.
RUN(internals.setUserPreferredLanguages(['en']))
First item should be labelled off OK
a English (Australia) is the first real item in the list OK
a English (Australia) comes before a English SDH OK
a English SDH comes before b English (Australia) SDH OK
b English (Australia) SDH comes before b Japanese OK
b Japanese comes before c English OK
c English comes before c Japanese SDH OK
** Test with preferred language set to English, track type set to captions
RUN(internals.settings.setShouldDisplayTrackKind('Captions', true))
EXPECTED (trackMenuItems[0].textContent == 'Off') OK
EXPECTED (trackMenuItems[1].textContent == 'u (English) SDH') OK
EXPECTED (trackMenuItems[2].textContent == 'y (English-Australia) SDH') OK
EXPECTED (trackMenuItems[3].textContent == 'v (English)') OK
EXPECTED (trackMenuItems[4].textContent == 'x (English-Australia)') OK
EXPECTED (trackMenuItems[5].textContent == 'w (Japanese) SDH') OK
EXPECTED (trackMenuItems[6].textContent == 'z (Japanese)') OK
EXPECTED (video.textTracks.length == '6') OK
EXPECTED (trackMenuItems.length == '7') OK
** Change preferred language to Japanese, change preference to subtitles
RUN(internals.setUserPreferredLanguages(['ja']))
RUN(internals.settings.setShouldDisplayTrackKind('Captions', false))
RUN(internals.settings.setShouldDisplayTrackKind('Subtitles', true))
EXPECTED (trackMenuItems[0].textContent == 'Off') OK
EXPECTED (trackMenuItems[1].textContent == 'z (Japanese)') OK
EXPECTED (trackMenuItems[2].textContent == 'v (English)') OK
EXPECTED (trackMenuItems[3].textContent == 'x (English-Australia)') OK
EXPECTED (video.textTracks.length == '6') OK
EXPECTED (trackMenuItems.length == '4') OK
END OF TEST
2013-03-20 Eric Carlson <eric.carlson@apple.com>
Allow ports specific text track menu
https://bugs.webkit.org/show_bug.cgi?id=112800
Reviewed by Dean Jackson.
No new tests, existing tests updated for changes.
* English.lproj/Localizable.strings: Add localizable strings for text track names.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): userPrefersCaptions -> shouldShowCaptions.
(WebCore::HTMLMediaElement::setSelectedTextTrack): toggleTrackAtIndex -> setSelectedTextTrack.
(WebCore::HTMLMediaElement::userPrefersCaptions): userPrefersCaptions -> shouldShowCaptions.
(WebCore::HTMLMediaElement::userIsInterestedInThisTrackKind): Get preferences from CaptionUserPreferences
instead of from Settings.
(WebCore::HTMLMediaElement::setSelectedTextTrack): Renamed from toggleTrackAtIndex. Now takes
a TextTrack* instead of an int.
(WebCore::HTMLMediaElement::captionPreferencesChanged): Don't force a recalculation unless
captions are enabled/disabled to avoid unnecessary thrash.
* html/HTMLMediaElement.h:
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Use the menu to track
map instead of just the track index.
(WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Build and configure the
menu from the menu to track map.
(WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu): Start with a list
of tracks already sorted according to platform specific rules. Build a menu to track map
so tracks are retained while the menu is visible.
* html/shadow/MediaControlElements.h:
* html/shadow/MediaControls.cpp:
(WebCore::MediaControls::textTrackPreferencesChanged): Call closedCaptionTracksChanged so the
track menu will be rebuilt before it is shown again.
* html/track/InbandTextTrack.cpp:
(WebCore::InbandTextTrack::containsOnlyForcedSubtitles): New, passthrough to the private track.
(WebCore::InbandTextTrack::isMainProgramContent): Ditto.
(WebCore::InbandTextTrack::isEasyToRead): Ditto.
* html/track/InbandTextTrack.h:
* html/track/TextTrack.h:
* html/track/TextTrackList.cpp:
(WebCore::TextTrackList::contains): New.
* html/track/TextTrackList.h:
* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::CaptionUserPreferences): Pull in from .h ditto.
(WebCore::CaptionUserPreferences::~CaptionUserPreferences): Ditto.
(WebCore::CaptionUserPreferences::shouldShowCaptions): Renamed from userPrefersCaptions.
(WebCore::CaptionUserPreferences::setShouldShowCaptions): New.
(WebCore::CaptionUserPreferences::userPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferences::userPrefersSubtitles): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersSubtitles): Ditto.
(WebCore::CaptionUserPreferences::userPrefersTextDescriptions): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersTextDescriptions): Ditto.
(WebCore::CaptionUserPreferences::displayNameForTrack): Ditto.
(WebCore::CaptionUserPreferences::sortedTrackListForMenu): Ditto.
* page/CaptionUserPreferences.h:
* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::shouldShowCaptions): Renamed from userPrefersCaptions.
(WebCore::CaptionUserPreferencesMac::userPrefersCaptions): New.
(WebCore::CaptionUserPreferences::userPrefersSubtitles): Ditto.
(WebCore::trackDisplayName): Update logic used to build track title.
(WebCore::CaptionUserPreferencesMac::displayNameForTrack): Call trackDisplayName.
(WebCore::textTrackCompare): Text track title sort comparison function.
(WebCore::CaptionUserPreferencesMac::sortedTrackListForMenu): New. Sort the list of tracks
according to title, language, and user preferences.
* platform/Language.cpp:
(WebCore::displayNameForLanguageLocale): Don't leak the CFLocale.
* platform/LocalizedStrings.cpp:
(WebCore::textTrackCountryAndLanguageMenuItemText): New.
(WebCore::textTrackLanguageMenuItemText): Ditto.
(WebCore::closedCaptionTrackMenuItemText): Ditto.
(WebCore::sdhTrackMenuItemText): Ditto.
(WebCore::easyReaderTrackMenuItemText): Ditto.
* platform/LocalizedStrings.h:
* platform/graphics/InbandTextTrackPrivate.h:
* platform/graphics/avfoundation/objc/InbandTextTrackPrivateAVFObjC.h:
* platform/graphics/avfoundation/objc/InbandTextTrackPrivateAVFObjC.mm:
(WebCore::InbandTextTrackPrivateAVFObjC::containsOnlyForcedSubtitles): New, return AVFoundation property.
(WebCore::InbandTextTrackPrivateAVFObjC::isMainProgramContent): Ditto.
(WebCore::InbandTextTrackPrivateAVFObjC::isEasyToRead): Ditto.
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setShouldDisplayTrackKind): Set setting via CaptionUserPreferences
instead of from Settings.
(WebCore::InternalSettings::shouldDisplayTrackKind): Get setting from CaptionUserPreferences
instead of from Settings.
2013-03-20 Zan Dobersek <zdobersek@igalia.com>
[GTK] Clean up TemporaryLinkStubs.cpp
B/* accessibility help text for media controller time value >= 1 day */
......
......@@ -320,7 +320,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
if (document->page()) {
CaptionUserPreferences* captionPreferences = document->page()->group().captionPreferences();
if (captionPreferences->userHasCaptionPreferences())
m_disableCaptions = !captionPreferences->userPrefersCaptions();
m_disableCaptions = !captionPreferences->shouldShowCaptions();
}
#endif
}
......@@ -2862,7 +2862,7 @@ void HTMLMediaElement::setSelectedTextTrack(PassRefPtr<PlatformTextTrack> platfo
TrackDisplayUpdateScope scope(this);
if (!platformTrack) {
toggleTrackAtIndex(textTracksOffIndex(), true);
setSelectedTextTrack(0);
return;
}
......@@ -2877,7 +2877,7 @@ void HTMLMediaElement::setSelectedTextTrack(PassRefPtr<PlatformTextTrack> platfo
if (i == m_textTracks->length())
return;
toggleTrackAtIndex(i, true);
setSelectedTextTrack(textTrack);
}
Vector<RefPtr<PlatformTextTrack> > HTMLMediaElement::platformTextTracks()
......@@ -3076,7 +3076,7 @@ bool HTMLMediaElement::userPrefersCaptions() const
return false;
CaptionUserPreferences* captionPreferences = page->group().captionPreferences();
return captionPreferences->userHasCaptionPreferences() && captionPreferences->userPrefersCaptions();
return captionPreferences->userHasCaptionPreferences() && captionPreferences->shouldShowCaptions();
}
bool HTMLMediaElement::userIsInterestedInThisTrackKind(String kind) const
......@@ -3084,15 +3084,19 @@ bool HTMLMediaElement::userIsInterestedInThisTrackKind(String kind) const
if (m_disableCaptions)
return false;
Settings* settings = document()->settings();
Page* page = document()->page();
if (!page)
return false;
CaptionUserPreferences* captionPreferences = page->group().captionPreferences();
bool userPrefersCaptionsOrSubtitles = m_closedCaptionsVisible || userPrefersCaptions();
if (kind == TextTrack::subtitlesKeyword())
return (settings && settings->shouldDisplaySubtitles()) || userPrefersCaptionsOrSubtitles;
return captionPreferences->userPrefersSubtitles() || userPrefersCaptionsOrSubtitles;
if (kind == TextTrack::captionsKeyword())
return (settings && settings->shouldDisplayCaptions()) || userPrefersCaptionsOrSubtitles;
return captionPreferences->userPrefersCaptions() || userPrefersCaptionsOrSubtitles;
if (kind == TextTrack::descriptionsKeyword())
return settings && settings->shouldDisplayTextDescriptions();
return captionPreferences->userPrefersTextDescriptions() || userPrefersCaptionsOrSubtitles;
return false;
}
......@@ -3178,25 +3182,27 @@ void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group)
trackToEnable->setMode(TextTrack::showingKeyword());
}
void HTMLMediaElement::toggleTrackAtIndex(int index, bool exclusive)
void HTMLMediaElement::setSelectedTextTrack(TextTrack* trackToSelect)
{
TextTrackList* trackList = textTracks();
if (!trackList || !trackList->length())
return;
CaptionUserPreferences* captionPreferences = document()->page() ? document()->page()->group().captionPreferences() : 0;
if (captionPreferences)
captionPreferences->setUserPrefersCaptions(index != textTracksOffIndex());
if (trackToSelect && !trackList->contains(trackToSelect))
return;
for (int i = 0, length = trackList->length(); i < length; ++i) {
TextTrack* track = trackList->item(i);
if (i == index) {
track->setMode(TextTrack::showingKeyword());
if (captionPreferences && track->language().length())
captionPreferences->setPreferredLanguage(track->language());
}
else if (exclusive || index == HTMLMediaElement::textTracksOffIndex())
if (!trackToSelect || track != trackToSelect)
track->setMode(TextTrack::disabledKeyword());
else
track->setMode(TextTrack::showingKeyword());
}
CaptionUserPreferences* captionPreferences = document()->page() ? document()->page()->group().captionPreferences() : 0;
if (captionPreferences) {
captionPreferences->setShouldShowCaptions(trackToSelect);
if (trackToSelect && trackToSelect->language().length())
captionPreferences->setPreferredLanguage(trackToSelect->language());
}
}
......@@ -4520,11 +4526,15 @@ void HTMLMediaElement::captionPreferencesChanged()
if (!isVideo())
return;
m_processingPreferenceChange = true;
setClosedCaptionsVisible(userPrefersCaptions());
if (hasMediaControls())
mediaControls()->textTrackPreferencesChanged();
bool prefersCaptions = userPrefersCaptions();
if (m_disableCaptions == !prefersCaptions)
return;
m_processingPreferenceChange = true;
setClosedCaptionsVisible(prefersCaptions);
}
void HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured()
......
......@@ -267,7 +267,7 @@ public:
void configureTextTracks();
void configureTextTrackGroup(const TrackGroup&);
void toggleTrackAtIndex(int index, bool exclusive = true);
void setSelectedTextTrack(TextTrack*);
static int textTracksOffIndex() { return -1; }
static int textTracksIndexNotFound() { return -2; }
......
......@@ -755,6 +755,13 @@ void MediaControlClosedCaptionsTrackListElement::defaultEventHandler(Event* even
// Check if the event target has such a custom element and, if so,
// tell the HTMLMediaElement to enable that track.
RefPtr<TextTrack> textTrack;
MenuItemToTrackMap::iterator iter = m_menuToTrackMap.find(toElement(target));
if (iter != m_menuToTrackMap.end())
textTrack = iter->value;
m_menuToTrackMap.clear();
m_controls->toggleClosedCaptionTrackList();
int trackIndex = trackListIndexForElement(toElement(target));
if (trackIndex == HTMLMediaElement::textTracksIndexNotFound())
return;
......@@ -763,10 +770,11 @@ void MediaControlClosedCaptionsTrackListElement::defaultEventHandler(Event* even
if (!mediaElement)
return;
mediaElement->toggleTrackAtIndex(trackIndex);
if (textTrack)
mediaElement->setSelectedTextTrack(textTrack.get());
else if (trackIndex == HTMLMediaElement::textTracksOffIndex())
mediaElement->setSelectedTextTrack(0);
// We've selected a track to display, so we can now close the menu.
m_controls->toggleClosedCaptionTrackList();
updateDisplay();
}
......@@ -799,53 +807,37 @@ void MediaControlClosedCaptionsTrackListElement::updateDisplay()
if (m_trackListHasChanged)
rebuildTrackListMenu();
bool captionsVisible = mediaElement->closedCaptionsVisible();
for (unsigned i = 0, length = m_menuItems.size(); i < length; ++i) {
RefPtr<Element> trackItem = m_menuItems[i];
int trackIndex = trackListIndexForElement(trackItem.get());
if (trackIndex != HTMLMediaElement::textTracksIndexNotFound()) {
if (trackIndex == HTMLMediaElement::textTracksOffIndex()) {
if (captionsVisible)
trackItem->classList()->remove(selectedClassValue, ASSERT_NO_EXCEPTION);
else
trackItem->classList()->add(selectedClassValue, ASSERT_NO_EXCEPTION);
} else {
TextTrack* track = trackList->item(trackIndex);
if (!track)
continue;
if (track->mode() == TextTrack::showingKeyword())
trackItem->classList()->add(selectedClassValue, ASSERT_NO_EXCEPTION);
else
trackItem->classList()->remove(selectedClassValue, ASSERT_NO_EXCEPTION);
}
}
}
#endif
}
if (trackIndex == HTMLMediaElement::textTracksIndexNotFound())