<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[169725] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/169725">169725</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2014-06-09 15:56:41 -0700 (Mon, 09 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Automatic text track selection can select more than one track
https://bugs.webkit.org/show_bug.cgi?id=133590

Reviewed by Brent Fulgham.

Source/WebCore:
Test: media/video-trackmenu-selection.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::configureTextTrack): Consider the currently selected
    track, if any.

* page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu): Drive-by change
    to make sure no non-visible text tracks are included in the track menu.

LayoutTests:
* media/video-trackmenu-selection-expected.txt: Added.
* media/video-trackmenu-selection.html: Added.

* platform/efl/TestExpectations: New test skipped.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformeflTestExpectations">trunk/LayoutTests/platform/efl/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorepageCaptionUserPreferencesMediaAFcpp">trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsmediavideotrackmenuselectionexpectedtxt">trunk/LayoutTests/media/video-trackmenu-selection-expected.txt</a></li>
<li><a href="#trunkLayoutTestsmediavideotrackmenuselectionhtml">trunk/LayoutTests/media/video-trackmenu-selection.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (169724 => 169725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-06-09 22:30:48 UTC (rev 169724)
+++ trunk/LayoutTests/ChangeLog        2014-06-09 22:56:41 UTC (rev 169725)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-06-09  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        Automatic text track selection can select more than one track
+        https://bugs.webkit.org/show_bug.cgi?id=133590
+
+        Reviewed by Brent Fulgham.
+
+        * media/video-trackmenu-selection-expected.txt: Added.
+        * media/video-trackmenu-selection.html: Added.
+
+        * platform/efl/TestExpectations: New test skipped.
+
</ins><span class="cx"> 2014-05-21  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION: missing underline under CJK text
</span></span></pre></div>
<a id="trunkLayoutTestsmediavideotrackmenuselectionexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/video-trackmenu-selection-expected.txt (0 => 169725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/video-trackmenu-selection-expected.txt                                (rev 0)
+++ trunk/LayoutTests/media/video-trackmenu-selection-expected.txt        2014-06-09 22:56:41 UTC (rev 169725)
</span><span class="lines">@@ -0,0 +1,39 @@
</span><ins>+Test that we update the menu when the selected track changes.
+
+
+EVENT(canplaythrough)
+
+*** Set the user's preferred language to English, enable automatic caption selection.
+RUN(internals.setUserPreferredLanguages(['en']))
+RUN(internals.setCaptionDisplayMode('AlwaysOn'))
+
+** The preferred language is set to English, but the Spanish track should be enabled because it is available
+Track menu:
+0: &quot;Off&quot;
+1: &quot;Auto (Recommended)&quot;
+2: &quot;Spanish&quot;, checked
+EXPECTED (video.textTracks[0].mode == 'showing') OK
+
+*** Add a text track in the preferred language.
+RUN(track = document.createElement('track'))
+RUN(track.setAttribute('kind', 'captions'))
+RUN(track.src = 'data:text/vtt,WEBVTT%0A%0A00%3A00%3A00.000%20--%3E%2000%3A00%3A01.000%0ACaption%201%0A')
+RUN(track.setAttribute('srclang', 'en'))
+RUN(track.setAttribute('onload', 'trackLoaded()'))
+RUN(video.appendChild(track))
+
+EVENT(load)
+
+*** The new track should be selected because it is in the preferred language.
+EXPECTED (event.target.srclang == 'en') OK
+EXPECTED (event.target.readyState == '2') OK
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
+EXPECTED (video.textTracks[1].mode == 'showing') OK
+Track menu:
+0: &quot;Off&quot;
+1: &quot;Auto (Recommended)&quot;
+2: &quot;English&quot;, checked
+3: &quot;Spanish&quot;
+
+END OF TEST
+
</ins></span></pre></div>
<a id="trunkLayoutTestsmediavideotrackmenuselectionhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/media/video-trackmenu-selection.html (0 => 169725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/media/video-trackmenu-selection.html                                (rev 0)
+++ trunk/LayoutTests/media/video-trackmenu-selection.html        2014-06-09 22:56:41 UTC (rev 169725)
</span><span class="lines">@@ -0,0 +1,85 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+    &lt;head&gt;
+        &lt;title&gt;Selecting from a list of tracks&lt;/title&gt;
+        &lt;script src=&quot;media-controls.js&quot;&gt;&lt;/script&gt;
+        &lt;script src=&quot;media-file.js&quot;&gt;&lt;/script&gt;
+        &lt;script src=&quot;video-test.js&quot;&gt;&lt;/script&gt;
+        &lt;script src=&quot;trackmenu-test.js&quot;&gt;&lt;/script&gt;
+        &lt;script&gt;
+
+            function finishTest()
+            {
+                testExpected(&quot;video.textTracks[0].mode&quot;, &quot;disabled&quot;);
+                testExpected(&quot;video.textTracks[1].mode&quot;, &quot;showing&quot;);
+                listTrackMenu();
+
+                consoleWrite(&quot;&quot;);
+                endTest();
+            }
+
+            function trackLoaded()
+            {
+                consoleWrite(&quot;&lt;br&gt;EVENT(load)&quot;);
+
+                consoleWrite(&quot;&lt;br&gt;*** The new track should be selected because it is in the preferred language.&quot;);
+                testExpected(&quot;event.target.srclang&quot;, &quot;en&quot;);
+                testExpected(&quot;event.target.readyState&quot;, HTMLTrackElement.LOADED);
+
+                showMenu(finishTest);
+            }
+
+            function startTest()
+            {
+                trackListElement = getTrackListElement();
+                if (!trackListElement)
+                    return;
+
+                consoleWrite(&quot;&lt;br&gt;** The preferred language is set to English, but the Spanish track should be enabled because it is available&quot;);
+                listTrackMenu();
+                testExpected(&quot;video.textTracks[0].mode&quot;, &quot;showing&quot;);
+                clickCCButton();
+
+                consoleWrite(&quot;&lt;br&gt;*** Add a text track in the preferred language.&quot;);
+                run(&quot;track = document.createElement('track')&quot;);
+                run(&quot;track.setAttribute('kind', 'captions')&quot;);
+                uri = 'data:text/vtt,' + encodeURIComponent('WEBVTT\n\n00:00:00.000 --&gt; 00:00:01.000\nCaption 1\n');
+                run(&quot;track.src = '&quot; + uri + &quot;'&quot;);
+                run(&quot;track.setAttribute('srclang', 'en')&quot;);
+                run(&quot;track.setAttribute('onload', 'trackLoaded()')&quot;);
+                run(&quot;video.appendChild(track)&quot;);
+            }
+
+            function showMenu(nextFunction)
+            {
+                clickCCButton();
+                window.setTimeout(nextFunction, 100);
+            }
+
+            function canplaythrough()
+            {
+                consoleWrite(&quot;&lt;br&gt;*** Set the user's preferred language to English, enable automatic caption selection.&quot;);
+                run(&quot;internals.setUserPreferredLanguages(['en'])&quot;);
+                run(&quot;internals.setCaptionDisplayMode('AlwaysOn')&quot;);
+                window.setTimeout(function() { showMenu(startTest) }, 100);
+            }
+
+            function start()
+            {
+                findMediaElement();
+                video.src = findMediaFile('video', 'content/test');
+                setCaptionDisplayMode('Automatic');
+
+                waitForEvent('canplaythrough', canplaythrough);
+            }
+        &lt;/script&gt;
+    &lt;/head&gt;
+
+    &lt;body onload=&quot;start()&quot;&gt;
+        &lt;p&gt;Test that we update the menu when the selected track changes.&lt;/p&gt;
+        &lt;video width=&quot;500&quot; height=&quot;300&quot; controls&gt;
+            &lt;track kind=&quot;captions&quot; title=&quot;Commentary&quot; src=&quot;track/captions-webvtt/captions-fast.vtt&quot; srclang=&quot;es&quot;&gt;
+        &lt;/video&gt;
+    &lt;/body&gt;
+&lt;/html&gt;
+
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformeflTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/efl/TestExpectations (169724 => 169725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/efl/TestExpectations        2014-06-09 22:30:48 UTC (rev 169724)
+++ trunk/LayoutTests/platform/efl/TestExpectations        2014-06-09 22:56:41 UTC (rev 169725)
</span><span class="lines">@@ -1178,6 +1178,7 @@
</span><span class="cx"> webkit.org/b/101670 media/track/track-user-preferences.html [ Skip ]
</span><span class="cx"> webkit.org/b/101670 media/video-controls-captions-trackmenu-includes-enabled-track.html [ Skip ]
</span><span class="cx"> webkit.org/b/101670 media/video-controls-captions-trackmenu-only-captions-descriptions-and-subtitles.html [ Skip ]
</span><ins>+webkit.org/b/101670 media/video-trackmenu-selection.html [ Skip ]
</ins><span class="cx"> 
</span><span class="cx"> # Fails until we enable the Resource Timing API.
</span><span class="cx"> webkit.org/b/61138 http/tests/w3c/webperf/submission/Google/resource-timing [ Skip ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (169724 => 169725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-06-09 22:30:48 UTC (rev 169724)
+++ trunk/Source/WebCore/ChangeLog        2014-06-09 22:56:41 UTC (rev 169725)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2014-06-09  Eric Carlson  &lt;eric.carlson@apple.com&gt;
+
+        Automatic text track selection can select more than one track
+        https://bugs.webkit.org/show_bug.cgi?id=133590
+
+        Reviewed by Brent Fulgham.
+
+        Test: media/video-trackmenu-selection.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::configureTextTrack): Consider the currently selected
+            track, if any.
+
+        * page/CaptionUserPreferencesMediaAF.cpp:
+        (WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu): Drive-by change
+            to make sure no non-visible text tracks are included in the track menu.
+
</ins><span class="cx"> 2014-06-09  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] Hang when painting media before compositing mode activated
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (169724 => 169725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-06-09 22:30:48 UTC (rev 169724)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-06-09 22:56:41 UTC (rev 169725)
</span><span class="lines">@@ -3552,6 +3552,15 @@
</span><span class="cx">     RefPtr&lt;TextTrack&gt; forcedSubitleTrack;
</span><span class="cx">     int highestTrackScore = 0;
</span><span class="cx">     int highestForcedScore = 0;
</span><ins>+
+    // If there is a visible track, it has already been configured so it won't be considered in the loop below. We don't want to choose another
+    // track if it is less suitable, and we do want to disable it if another track is more suitable.
+    int alreadyVisibleTrackScore = 0;
+    if (group.visibleTrack &amp;&amp; captionPreferences) {
+        alreadyVisibleTrackScore = captionPreferences-&gt;textTrackSelectionScore(group.visibleTrack.get(), this);
+        currentlyEnabledTracks.append(group.visibleTrack);
+    }
+
</ins><span class="cx">     for (size_t i = 0; i &lt; group.tracks.size(); ++i) {
</span><span class="cx">         RefPtr&lt;TextTrack&gt; textTrack = group.tracks[i];
</span><span class="cx"> 
</span><span class="lines">@@ -3572,7 +3581,7 @@
</span><span class="cx">             // to believe is appropriate for the user, and there is no other text track in the media element's list of
</span><span class="cx">             // text tracks with a text track kind of chapters whose text track mode is showing
</span><span class="cx">             //    Let the text track mode be showing.
</span><del>-            if (trackScore &gt; highestTrackScore) {
</del><ins>+            if (trackScore &gt; highestTrackScore &amp;&amp; trackScore &gt; alreadyVisibleTrackScore) {
</ins><span class="cx">                 highestTrackScore = trackScore;
</span><span class="cx">                 trackToEnable = textTrack;
</span><span class="cx">             }
</span></span></pre></div>
<a id="trunkSourceWebCorepageCaptionUserPreferencesMediaAFcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (169724 => 169725)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp        2014-06-09 22:30:48 UTC (rev 169724)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp        2014-06-09 22:56:41 UTC (rev 169725)
</span><span class="lines">@@ -770,6 +770,10 @@
</span><span class="cx">         TextTrack* track = trackList-&gt;item(i);
</span><span class="cx">         String language = displayNameForLanguageLocale(track-&gt;language());
</span><span class="cx"> 
</span><ins>+        const AtomicString&amp; kind = track-&gt;kind();
+        if (kind != TextTrack::captionsKeyword() &amp;&amp; kind != TextTrack::descriptionsKeyword() &amp;&amp; kind != TextTrack::subtitlesKeyword())
+            continue;
+
</ins><span class="cx">         if (track-&gt;containsOnlyForcedSubtitles()) {
</span><span class="cx">             LOG(Media, &quot;CaptionUserPreferencesMac::sortedTrackListForMenu - skipping '%s' track with language '%s' because it contains only forced subtitles&quot;, track-&gt;kind().string().utf8().data(), language.utf8().data());
</span><span class="cx">             continue;
</span><span class="lines">@@ -824,6 +828,10 @@
</span><span class="cx">         TextTrack* track = trackList-&gt;item(i);
</span><span class="cx">         String language = displayNameForLanguageLocale(track-&gt;language());
</span><span class="cx"> 
</span><ins>+        const AtomicString&amp; kind = track-&gt;kind();
+        if (kind != TextTrack::captionsKeyword() &amp;&amp; kind != TextTrack::descriptionsKeyword() &amp;&amp; kind != TextTrack::subtitlesKeyword())
+            continue;
+
</ins><span class="cx">         // All candidates with no languge were added the first time through.
</span><span class="cx">         if (language.isEmpty())
</span><span class="cx">             continue;
</span></span></pre>
</div>
</div>

</body>
</html>