[Mac] add "automatic" text track menu item

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

Reviewed by Jer Noble.

Source/WebCore: 

No new tests, existing tests updated.

* English.lproj/Localizable.strings: Add new track menu item.

* html/HTMLMediaElement.cpp: 
(WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_captionDisplayMode.
(WebCore::HTMLMediaElement::finishParsingChildren): LoadTextTrackResource -> ConfigureTextTracks.
(WebCore::HTMLMediaElement::scheduleDelayedAction): Ditto.
(WebCore::HTMLMediaElement::loadTimerFired): Ditto.
(WebCore::HTMLMediaElement::loadInternal): Ditto. Flag the caption menu as invalid so it will
    be rebuilt again.
(WebCore::HTMLMediaElement::mediaPlayerDidAddTrack): LoadTextTrackResource -> ConfigureTextTracks.
(WebCore::HTMLMediaElement::didAddTrack): Ditto.
(WebCore::HTMLMediaElement::configureTextTrackGroup): Deal with new track display modes.
(WebCore::HTMLMediaElement::HTMLMediaElement::hasClosedCaptions): Minor cleanup.
(WebCore::HTMLMediaElement::configureTextTrackGroup): Add some logging.
(WebCore::HTMLMediaElement::configureTextTracks): Call updateActiveTextTrackCues so cue display
    is updated.
(WebCore::HTMLMediaElement::captionPreferencesChanged): Deal with new track display modes.
(WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): Add some logging.
* html/HTMLMediaElement.h: Ditto.

* html/shadow/MediaControlElementTypes.cpp: Remove trackIndexAttributeName and trackListIndexForElement.
* html/shadow/MediaControlElementTypes.h: Ditto.

* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Don't use track index,
    everything we need is in the track<->element map now.
(WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Ditto. Always rebuild the 
    track list because clear the map each time the menu goes away because it refs every track.
(WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu): Don't set the track
    index attribute on the menu items, just use the map.
* html/shadow/MediaControlElements.h:

* html/shadow/MediaControlsApple.cpp:
(WebCore::MediaControlsApple::changedClosedCaptionsVisibility): resetTrackListMenu is gone.
(WebCore::MediaControlsApple::reset): Ditto.
(WebCore::MediaControlsApple::closedCaptionTracksChanged): Ditto.

* html/track/TextTrack.cpp:
(WebCore::TextTrack::captionMenuOffItem): New, static TextTrack used for the menu "Off" item.
(WebCore::TextTrack::captionMenuAutomaticItem): New, static TextTrack used for the menu "Automatic" item.
* html/track/TextTrack.h:

* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::shouldShowCaptions): Removed, we use captionDisplayMode instead.
(WebCore::CaptionUserPreferences::captionDisplayMode): New.
(WebCore::CaptionUserPreferences::setCaptionDisplayMode): New.
(WebCore::CaptionUserPreferences::setPreferredLanguage): Make the parameter a const reference.
(WebCore::CaptionUserPreferences::textTrackSelectionScore): Return 0 if the user doesn't want
    captions or subtitles.
(WebCore::CaptionUserPreferences::textTrackLanguageSelectionScore): Take language as a parameter
    instead of assuming that it is always the entire language list.
* page/CaptionUserPreferences.h:

* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::shouldShowCaptions): Removed, we use captionDisplayMode instead.
(WebCore::CaptionUserPreferencesMac::captionDisplayMode): New.
(WebCore::CaptionUserPreferencesMac::setCaptionDisplayMode): New.
(WebCore::CaptionUserPreferencesMac::setPreferredLanguage): Make the parameter a const reference.
(WebCore::CaptionUserPreferencesMac::textTrackSelectionScore): Deal with "Automatic" mode.
    captions or subtitles.
(WebCore::CaptionUserPreferences::textTrackLanguageSelectionScore): Take language as a parameter
    instead of assuming that it is always the entire language list.
(WebCore::CaptionUserPreferencesMac::sortedTrackListForMenu): Insert "Off" and "Automatic" items.

* platform/LocalizedStrings.cpp:
(WebCore::textTrackAutomaticMenuItemText): New.
* platform/LocalizedStrings.h:

* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::languageOfPrimaryAudioTrack): New.
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack): Return the language
    of the main audio track.

LayoutTests: 

* media/media-captions.html: Opportunistic fix - don't look at state until we get the 'canplaythrough'
    event because the media engine state may not have been processed until that time.
* media/track/track-cue-container-rendering-position.html: Don't assume that a cue has been 
    rendered immediately when the 'canplaythrough' event comes through.
* media/track/track-cue-rendering-mode-changed.html: Ditto.
* media/track/track-in-band-expected.txt: Don't check if cues have loaded, it doesn't matter
    for this test.
* media/track/track-in-band.html: Ditto.
* media/track/track-user-preferences-expected.txt: Changed name of utility function from 
    menuIndexForLanguage to indexOfMenuItemBeginningWith.
* media/track/track-user-preferences.html: Move menuIndexForLanguage to trackmenu-test.js and
    change name to indexOfMenuItemBeginningWith. Clarify the message logged when a track loads
    but it should not.
* media/trackmenu-test.js: Move some functions here from track-user-preferences.html
(trackMenuList):
(indexOfMenuItemBeginningWith):
(selectCaptionMenuItem):
* media/video-controls-captions-trackmenu-sorted.html: Update for new menu item.
* media/video-controls-captions-trackmenu.html: Ditto.
* platform/mac/media/video-controls-captions-trackmenu-expected.txt: Ditto.
* platform/mac/media/video-controls-captions-trackmenu-sorted-expected.txt: Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 85dcc593
2013-04-04 Eric Carlson <eric.carlson@apple.com>
[Mac] add "automatic" text track menu item
https://bugs.webkit.org/show_bug.cgi?id=113822
Reviewed by Jer Noble.
* media/media-captions.html: Opportunistic fix - don't look at state until we get the 'canplaythrough'
event because the media engine state may not have been processed until that time.
* media/track/track-cue-container-rendering-position.html: Don't assume that a cue has been
rendered immediately when the 'canplaythrough' event comes through.
* media/track/track-cue-rendering-mode-changed.html: Ditto.
* media/track/track-in-band-expected.txt: Don't check if cues have loaded, it doesn't matter
for this test.
* media/track/track-in-band.html: Ditto.
* media/track/track-user-preferences-expected.txt: Changed name of utility function from
menuIndexForLanguage to indexOfMenuItemBeginningWith.
* media/track/track-user-preferences.html: Move menuIndexForLanguage to trackmenu-test.js and
change name to indexOfMenuItemBeginningWith. Clarify the message logged when a track loads
but it should not.
* media/trackmenu-test.js: Move some functions here from track-user-preferences.html
(trackMenuList):
(indexOfMenuItemBeginningWith):
(selectCaptionMenuItem):
* media/video-controls-captions-trackmenu-sorted.html: Update for new menu item.
* media/video-controls-captions-trackmenu.html: Ditto.
* platform/mac/media/video-controls-captions-trackmenu-expected.txt: Ditto.
* platform/mac/media/video-controls-captions-trackmenu-sorted-expected.txt: Ditto.
2013-04-04 Glenn Adams <glenn@skynav.com>
[EFL] Unreviewed gardening. Rebaseline after r147588. Remove overridden pixel results.
......@@ -74,7 +74,7 @@
waitForEvent("play");
waitForEvent("playing");
waitForEvent('loadedmetadata', canplaythrough);
waitForEvent('canplaythrough', canplaythrough);
consoleWrite("<b>Test before movie is open:</b>");
testExpected("mediaElement.webkitHasClosedCaptions", false);
......
......@@ -30,7 +30,7 @@
findMediaElement();
video.src = findMediaFile('video', '../content/test');
waitForEvent('canplaythrough', testPosition);
waitForEvent('canplaythrough', function () {setTimeout(testPosition, 100);});
}
</script>
......
......@@ -12,6 +12,31 @@
var testTrackArabic;
var testTrackEnglish;
var testCueDisplayBox;
var currentTest = 0;
function scheduleNextTest()
{
var test;
switch (++currentTest) {
case 1:
test = addTracks;
break;
case 2:
test = testCueActiveState;
break;
case 3:
test = testCueVisibility1;
break;
case 4:
test = testCueVisibility2;
break;
case 5:
endTest();
return;
}
window.setTimeout(test, 100);
}
function addTracks()
{
......@@ -31,6 +56,8 @@
consoleWrite("Set the mode of the 'English' track to hidden");
testTrackEnglish.mode = "hidden";
scheduleNextTest();
}
function testCueActiveState()
......@@ -42,9 +69,11 @@
testExpected("testTrackArabic.activeCues.length", 1);
testExpected("testTrackArabic.activeCues[0].text", "Arabic");
scheduleNextTest();
}
function testCueVisibility()
function testCueVisibility1()
{
consoleWrite("");
consoleWrite("** Only one cue should be visible **");
......@@ -56,6 +85,11 @@
consoleWrite("Set the mode of the 'English' track to showing");
testTrackEnglish.mode = "showing";
scheduleNextTest();
}
function testCueVisibility2()
{
consoleWrite("");
consoleWrite("** Both cues shold be visible. **");
testCueDisplayBox = textTrackDisplayElement(video, 'display', 0);
......@@ -63,13 +97,8 @@
testCueDisplayBox = textTrackDisplayElement(video, 'display', 1);
testExpected("testCueDisplayBox.innerText", "English");
}
function runTests() {
addTracks();
testCueActiveState();
testCueVisibility();
endTest();
scheduleNextTest();
}
function loaded()
......@@ -79,7 +108,7 @@
findMediaElement();
video.src = findMediaFile('video', '../content/test');
waitForEvent('canplaythrough', runTests);
waitForEvent('canplaythrough', scheduleNextTest);
}
</script>
......
......@@ -12,12 +12,8 @@ EVENT(canplaythrough)
EXPECTED (video.textTracks.length == '2') OK
RUN(inbandTrack1 = video.textTracks[0])
RUN(inbandTrack2 = video.textTracks[1])
EXPECTED (inbandTrack1.mode == 'disabled') OK
EXPECTED (inbandTrack1.cues == 'null') OK
EXPECTED (inbandTrack1.language == 'en') OK
EXPECTED (inbandTrack1.kind == 'subtitles') OK
EXPECTED (inbandTrack2.mode == 'disabled') OK
EXPECTED (inbandTrack2.cues == 'null') OK
EXPECTED (inbandTrack2.language == 'fr') OK
EXPECTED (inbandTrack2.kind == 'subtitles') OK
......
......@@ -29,12 +29,8 @@
testExpected("video.textTracks.length", 2);
run("inbandTrack1 = video.textTracks[0]");
run("inbandTrack2 = video.textTracks[1]");
testExpected("inbandTrack1.mode", "disabled");
testExpected("inbandTrack1.cues", null);
testExpected("inbandTrack1.language", "en");
testExpected("inbandTrack1.kind", "subtitles");
testExpected("inbandTrack2.mode", "disabled");
testExpected("inbandTrack2.cues", null);
testExpected("inbandTrack2.language", "fr");
testExpected("inbandTrack2.kind", "subtitles");
......
......@@ -18,9 +18,9 @@ EXPECTED (event.target.readyState == '2') OK
Test 3: select 'fr' track from menu
- show captions menu.
EXPECTED (trackMenuItems[menuIndexForLanguage('French')].className == '') OK
EXPECTED (trackMenuItems[menuIndexForLanguage('English')].className == '') OK
EXPECTED (trackMenuItems[menuIndexForLanguage('Norwegian')].className == 'selected') OK
EXPECTED (trackMenuItems[indexOfMenuItemBeginningWith('French')].className == '') OK
EXPECTED (trackMenuItems[indexOfMenuItemBeginningWith('English')].className == '') OK
EXPECTED (trackMenuItems[indexOfMenuItemBeginningWith('Norwegian')].className == 'selected') OK
- click on 'French' menu item.
EVENT(load)
EXPECTED (event.target.srclang == 'fr') OK
......
......@@ -23,59 +23,13 @@
timer = setTimeout(nextStep, 100);
}
function trackMenuList()
{
trackListElement = getTrackListElement();
if (!trackListElement)
return;
// Track list should have a <ul> with <li> children (One of them is "Off").
var trackList = trackListElement.querySelector("ul");
if (!trackList) {
failTest("Could not find a child ul element in track list menu");
return;
}
var trackListItems = trackList.querySelectorAll("li");
if (!trackListItems) {
failTest("Could not find child li elements in track list menu");
return;
}
return trackListItems;
}
function menuIndexForLanguage(language)
{
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;
var y = boundingRect.top + boundingRect.height / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
}
function trackLoaded()
{
consoleWrite("EVENT(load)");
if (expectedLanguage == "") {
failTest("'" + event.target.srclang + "' track loaded unexpectedly.");
return;
}
testExpected("event.target.srclang", expectedLanguage);
testExpected("event.target.readyState", HTMLTrackElement.LOADED);
......@@ -130,9 +84,9 @@
case 4:
trackMenuItems = trackMenuList();
testExpected("trackMenuItems[menuIndexForLanguage('French')].className", "");
testExpected("trackMenuItems[menuIndexForLanguage('English')].className", "");
testExpected("trackMenuItems[menuIndexForLanguage('Norwegian')].className", "selected");
testExpected("trackMenuItems[indexOfMenuItemBeginningWith('French')].className", "");
testExpected("trackMenuItems[indexOfMenuItemBeginningWith('English')].className", "");
testExpected("trackMenuItems[indexOfMenuItemBeginningWith('Norwegian')].className", "selected");
selectCaptionMenuItem("French");
expectedLanguage = 'fr';
......@@ -157,6 +111,7 @@
case 7:
selectCaptionMenuItem("Off");
expectedLanguage = '';
createTrackElements([ 'ru', 'jp', 'en']);
timer = setTimeout(nextStep, 100);
break;
......
......@@ -35,3 +35,54 @@ function getTrackListElement()
}
return trackListElement;
}
function trackMenuList()
{
trackListElement = getTrackListElement();
if (!trackListElement)
return;
// Track list should have a <ul> with <li> children.
var trackList = trackListElement.querySelector("ul");
if (!trackList) {
failTest("Could not find a child ul element in track list menu");
return;
}
var trackListItems = trackList.querySelectorAll("li");
if (!trackListItems) {
failTest("Could not find child li elements in track list menu");
return;
}
return trackListItems;
}
function indexOfMenuItemBeginningWith(title)
{
var trackMenuItems = trackMenuList();
for (i = 0; i < trackMenuItems.length; ++i) {
if (trackMenuItems[i].textContent.indexOf(title) == 0)
break;
}
return (i < trackMenuItems.length) ? i : -1;
}
function selectCaptionMenuItem(title)
{
var trackMenuItems = trackMenuList();
var index = indexOfMenuItemBeginningWith(title);
if (index < 0) {
failTest("Menu item " + title + " not found in track list menu.");
return;
}
consoleWrite("- click on '" + title + "' menu item.");
var selectedTrackItem = trackMenuItems[index];
var boundingRect = selectedTrackItem.getBoundingClientRect();
var x = boundingRect.left + boundingRect.width / 2;
var y = boundingRect.top + boundingRect.height / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
}
......@@ -41,14 +41,15 @@
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("trackMenuItems[1].textContent", "Automatic (English)");
testExpected("trackMenuItems[2].textContent", "u (English) SDH");
testExpected("trackMenuItems[3].textContent", "y (English-Australia) SDH");
testExpected("trackMenuItems[4].textContent", "v (English)");
testExpected("trackMenuItems[5].textContent", "x (English-Australia)");
testExpected("trackMenuItems[6].textContent", "w (Japanese) SDH");
testExpected("trackMenuItems[7].textContent", "z (Japanese)");
testExpected("video.textTracks.length", 6);
testExpected("trackMenuItems.length", 7);
testExpected("trackMenuItems.length", 8);
consoleWrite("<br><i>** Change preferred language to Japanese, change preference to subtitles<" + "/i>");
run("internals.setUserPreferredLanguages(['ja'])");
......@@ -61,11 +62,12 @@
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("trackMenuItems[1].textContent", "Automatic (Japanese)");
testExpected("trackMenuItems[2].textContent", "z (Japanese)");
testExpected("trackMenuItems[3].textContent", "v (English)");
testExpected("trackMenuItems[4].textContent", "x (English-Australia)");
testExpected("video.textTracks.length", 6);
testExpected("trackMenuItems.length", 4);
testExpected("trackMenuItems.length", 5);
consoleWrite("");
endTest();
......
......@@ -41,7 +41,7 @@
function testMenu()
{
trackListItems = trackMenuList();
var expectedItemCount = video.textTracks.length + 1;
var expectedItemCount = video.textTracks.length + 2;
consoleWrite("There should be " + expectedItemCount + " items in the menu.");
testExpected("trackListItems.length", expectedItemCount);
}
......@@ -63,8 +63,8 @@
function turnCaptionsOn()
{
consoleWrite("*** Turning captions on");
// Click on the second item, which is the second track (Off is the first item in the menu)
selectCaptionMenuItem(2, testCaptionsVisible);
// Click on the third item, which is the second track (Off is the first item, Automatic is second)
selectCaptionMenuItem(3, testCaptionsVisible);
}
function testCaptionsVisible()
......
......@@ -9,8 +9,8 @@ RUN(internals.setUserPreferredLanguages(['en']))
RUN(video.addTextTrack("captions", "Commentary", "ru"))
*** Turning captions on
There should be 5 items in the menu.
EXPECTED (trackListItems.length == '5') OK
There should be 6 items in the menu.
EXPECTED (trackListItems.length == '6') OK
EXPECTED (video.textTracks.length == '4') OK
Track 0 should be showing
EXPECTED (video.textTracks[0].mode == 'showing') OK
......@@ -25,8 +25,8 @@ EXPECTED (textTrackDisplayElement(video, 'display').innerText == 'Lorem') OK
*** Remove a track.
RUN(video.removeChild(document.querySelectorAll("track")[0]))
*** Turning captions off
There should be 4 items in the menu.
EXPECTED (trackListItems.length == '4') OK
There should be 5 items in the menu.
EXPECTED (trackListItems.length == '5') OK
EXPECTED (video.textTracks.length == '3') OK
Track 0 should be disabled
EXPECTED (video.textTracks[0].mode == 'disabled') OK
......
......@@ -8,25 +8,27 @@ RUN(internals.setUserPreferredLanguages(['en']))
** 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 (trackMenuItems[1].textContent == 'Automatic (English)') OK
EXPECTED (trackMenuItems[2].textContent == 'u (English) SDH') OK
EXPECTED (trackMenuItems[3].textContent == 'y (English-Australia) SDH') OK
EXPECTED (trackMenuItems[4].textContent == 'v (English)') OK
EXPECTED (trackMenuItems[5].textContent == 'x (English-Australia)') OK
EXPECTED (trackMenuItems[6].textContent == 'w (Japanese) SDH') OK
EXPECTED (trackMenuItems[7].textContent == 'z (Japanese)') OK
EXPECTED (video.textTracks.length == '6') OK
EXPECTED (trackMenuItems.length == '7') OK
EXPECTED (trackMenuItems.length == '8') 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 (trackMenuItems[1].textContent == 'Automatic (Japanese)') OK
EXPECTED (trackMenuItems[2].textContent == 'z (Japanese)') OK
EXPECTED (trackMenuItems[3].textContent == 'v (English)') OK
EXPECTED (trackMenuItems[4].textContent == 'x (English-Australia)') OK
EXPECTED (video.textTracks.length == '6') OK
EXPECTED (trackMenuItems.length == '4') OK
EXPECTED (trackMenuItems.length == '5') OK
END OF TEST
2013-04-04 Eric Carlson <eric.carlson@apple.com>
[Mac] add "automatic" text track menu item
https://bugs.webkit.org/show_bug.cgi?id=113822
Reviewed by Jer Noble.
No new tests, existing tests updated.
* English.lproj/Localizable.strings: Add new track menu item.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_captionDisplayMode.
(WebCore::HTMLMediaElement::finishParsingChildren): LoadTextTrackResource -> ConfigureTextTracks.
(WebCore::HTMLMediaElement::scheduleDelayedAction): Ditto.
(WebCore::HTMLMediaElement::loadTimerFired): Ditto.
(WebCore::HTMLMediaElement::loadInternal): Ditto. Flag the caption menu as invalid so it will
be rebuilt again.
(WebCore::HTMLMediaElement::mediaPlayerDidAddTrack): LoadTextTrackResource -> ConfigureTextTracks.
(WebCore::HTMLMediaElement::didAddTrack): Ditto.
(WebCore::HTMLMediaElement::configureTextTrackGroup): Deal with new track display modes.
(WebCore::HTMLMediaElement::HTMLMediaElement::hasClosedCaptions): Minor cleanup.
(WebCore::HTMLMediaElement::configureTextTrackGroup): Add some logging.
(WebCore::HTMLMediaElement::configureTextTracks): Call updateActiveTextTrackCues so cue display
is updated.
(WebCore::HTMLMediaElement::captionPreferencesChanged): Deal with new track display modes.
(WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): Add some logging.
* html/HTMLMediaElement.h: Ditto.
* html/shadow/MediaControlElementTypes.cpp: Remove trackIndexAttributeName and trackListIndexForElement.
* html/shadow/MediaControlElementTypes.h: Ditto.
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Don't use track index,
everything we need is in the track<->element map now.
(WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Ditto. Always rebuild the
track list because clear the map each time the menu goes away because it refs every track.
(WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu): Don't set the track
index attribute on the menu items, just use the map.
* html/shadow/MediaControlElements.h:
* html/shadow/MediaControlsApple.cpp:
(WebCore::MediaControlsApple::changedClosedCaptionsVisibility): resetTrackListMenu is gone.
(WebCore::MediaControlsApple::reset): Ditto.
(WebCore::MediaControlsApple::closedCaptionTracksChanged): Ditto.
* html/track/TextTrack.cpp:
(WebCore::TextTrack::captionMenuOffItem): New, static TextTrack used for the menu "Off" item.
(WebCore::TextTrack::captionMenuAutomaticItem): New, static TextTrack used for the menu "Automatic" item.
* html/track/TextTrack.h:
* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::shouldShowCaptions): Removed, we use captionDisplayMode instead.
(WebCore::CaptionUserPreferences::captionDisplayMode): New.
(WebCore::CaptionUserPreferences::setCaptionDisplayMode): New.
(WebCore::CaptionUserPreferences::setPreferredLanguage): Make the parameter a const reference.
(WebCore::CaptionUserPreferences::textTrackSelectionScore): Return 0 if the user doesn't want
captions or subtitles.
(WebCore::CaptionUserPreferences::textTrackLanguageSelectionScore): Take language as a parameter
instead of assuming that it is always the entire language list.
* page/CaptionUserPreferences.h:
* page/CaptionUserPreferencesMac.h:
* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::shouldShowCaptions): Removed, we use captionDisplayMode instead.
(WebCore::CaptionUserPreferencesMac::captionDisplayMode): New.
(WebCore::CaptionUserPreferencesMac::setCaptionDisplayMode): New.
(WebCore::CaptionUserPreferencesMac::setPreferredLanguage): Make the parameter a const reference.
(WebCore::CaptionUserPreferencesMac::textTrackSelectionScore): Deal with "Automatic" mode.
captions or subtitles.
(WebCore::CaptionUserPreferences::textTrackLanguageSelectionScore): Take language as a parameter
instead of assuming that it is always the entire language list.
(WebCore::CaptionUserPreferencesMac::sortedTrackListForMenu): Insert "Off" and "Automatic" items.
* platform/LocalizedStrings.cpp:
(WebCore::textTrackAutomaticMenuItemText): New.
* platform/LocalizedStrings.h:
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::languageOfPrimaryAudioTrack): New.
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack): Return the language
of the main audio track.
2013-04-04 Alexey Proskuryakov <ap@apple.com>
REGRESSION (r146580): Assertion using SecurityOrigin::create, URL string is not valid
B/* accessibility help text for media controller time value >= 1 day */
......
......@@ -295,6 +295,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
, m_haveVisibleTextTrack(false)
, m_processingPreferenceChange(false)
, m_lastTextTrackUpdateTime(-1)
, m_captionDisplayMode(CaptionUserPreferences::Automatic)
, m_textTracks(0)
, m_ignoreTrackDisplayUpdate(0)
#endif
......@@ -496,7 +497,7 @@ void HTMLMediaElement::finishParsingChildren()
for (Node* node = firstChild(); node; node = node->nextSibling()) {
if (node->hasTagName(trackTag)) {
scheduleDelayedAction(LoadTextTrackResource);
scheduleDelayedAction(ConfigureTextTracks);
break;
}
}
......@@ -610,8 +611,8 @@ void HTMLMediaElement::scheduleDelayedAction(DelayedActionType actionType)
}
#if ENABLE(VIDEO_TRACK)
if (RuntimeEnabledFeatures::webkitVideoTrackEnabled() && (actionType & LoadTextTrackResource))
m_pendingActionFlags |= LoadTextTrackResource;
if (RuntimeEnabledFeatures::webkitVideoTrackEnabled() && (actionType & ConfigureTextTracks))
m_pendingActionFlags |= ConfigureTextTracks;
#endif
#if USE(PLATFORM_TEXT_TRACK_MENU)
......@@ -619,8 +620,7 @@ void HTMLMediaElement::scheduleDelayedAction(DelayedActionType actionType)
m_pendingActionFlags |= TextTrackChangesNotification;
#endif
if (!m_loadTimer.isActive())
m_loadTimer.startOneShot(0);
m_loadTimer.startOneShot(0);
}
void HTMLMediaElement::scheduleNextSourceChild()
......@@ -646,7 +646,7 @@ void HTMLMediaElement::loadTimerFired(Timer<HTMLMediaElement>*)
RefPtr<HTMLMediaElement> protect(this); // loadNextSourceChild may fire 'beforeload', which can make arbitrary DOM mutations.
#if ENABLE(VIDEO_TRACK)
if (RuntimeEnabledFeatures::webkitVideoTrackEnabled() && (m_pendingActionFlags & LoadTextTrackResource))
if (RuntimeEnabledFeatures::webkitVideoTrackEnabled() && (m_pendingActionFlags & ConfigureTextTracks))
configureTextTracks();
#endif
......@@ -830,6 +830,9 @@ void HTMLMediaElement::loadInternal()
removeBehaviorRestriction(RequirePageConsentToLoadMediaRestriction);
#if ENABLE(VIDEO_TRACK)
if (hasMediaControls())
mediaControls()->changedClosedCaptionsVisibility();
// HTMLMediaElement::textTracksAreReady will need "... the text tracks whose mode was not in the
// disabled state when the element's resource selection algorithm last started".
if (RuntimeEnabledFeatures::webkitVideoTrackEnabled()) {
......@@ -2821,7 +2824,7 @@ void HTMLMediaElement::mediaPlayerDidAddTrack(PassRefPtr<InbandTextTrackPrivate>
// 7. Set the new text track's mode to the mode consistent with the user's preferences and the requirements of
// the relevant specification for the data.
// - This will happen in configureTextTracks()
scheduleDelayedAction(LoadTextTrackResource);
scheduleDelayedAction(ConfigureTextTracks);
// 8. Add the new text track to the media element's list of text tracks.
// 9. Fire an event with the name addtrack, that does not bubble and is not cancelable, and that uses the TrackEvent
......@@ -3023,7 +3026,7 @@ void HTMLMediaElement::didAddTrack(HTMLTrackElement* trackElement)
// Do not schedule the track loading until parsing finishes so we don't start before all tracks
// in the markup have been added.
if (!m_parsingInProgress)
scheduleDelayedAction(LoadTextTrackResource);
scheduleDelayedAction(ConfigureTextTracks);
if (hasMediaControls())
mediaControls()->closedCaptionTracksChanged();
......@@ -3063,20 +3066,12 @@ void HTMLMediaElement::didRemoveTrack(HTMLTrackElement* trackElement)
m_textTracksWhenResourceSelectionBegan.remove(index);
}
bool HTMLMediaElement::userPrefersCaptions() const
{
Page* page = document()->page();
if (!page)
return false;
CaptionUserPreferences* captionPreferences = page->group().captionPreferences();
return captionPreferences->userHasCaptionPreferences() && captionPreferences->shouldShowCaptions();
}
void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group)
{
ASSERT(group.tracks.size());
LOG(Media, "HTMLMediaElement::configureTextTrackGroup");
Page* page = document()->page();
CaptionUserPreferences* captionPreferences = page? page->group().captionPreferences() : 0;
......@@ -3147,23 +3142,39 @@ void HTMLMediaElement::setSelectedTextTrack(TextTrack* trackToSelect)
TextTrackList* trackList = textTracks();
if (!trackList || !trackList->length())
return;
if (trackToSelect && !trackList->contains(trackToSelect))
return;
for (int i = 0, length = trackList->length(); i < length; ++i) {
TextTrack* track = trackList->item(i);
if (!trackToSelect || track != trackToSelect)
track->setMode(TextTrack::disabledKeyword());
else
track->setMode(TextTrack::showingKeyword());
if (trackToSelect != TextTrack::captionMenuOffItem() && trackToSelect != TextTrack::captionMenuAutomaticItem()) {
if (!trackList->contains(trackToSelect))
return;
for (int i = 0, length = trackList->length(); i < length; ++i) {
TextTrack* track = trackList->item(i);
if (!trackToSelect || track != trackToSelect)
track->setMode(TextTrack::disabledKeyword());
else