Diff
Modified: trunk/LayoutTests/ChangeLog (135933 => 135934)
--- trunk/LayoutTests/ChangeLog 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/LayoutTests/ChangeLog 2012-11-27 23:45:13 UTC (rev 135934)
@@ -1,3 +1,27 @@
+2012-11-27 Dean Jackson <[email protected]>
+
+ Make track list control active
+ https://bugs.webkit.org/show_bug.cgi?id=101670
+
+ Reviewed by Eric Carlson.
+
+ New test that exercises the track list menu, and how it can be used
+ to enable specific tracks. Since this is only enabled for Mac, it is
+ skipped on all other platforms.
+
+ Meanwhile, the existing test for a on/off captions button now
+ does not work on Mac, so skip it there. I copied the functionality
+ into the new test so we still have coverage.
+
+ * media/video-controls-captions-trackmenu-expected.txt: Added.
+ * media/video-controls-captions-trackmenu.html: Added.
+ * platform/chromium/TestExpectations:
+ * platform/efl/TestExpectations:
+ * platform/gtk/TestExpectations:
+ * platform/mac/TestExpectations:
+ * platform/qt/TestExpectations:
+ * platform/win/TestExpectations:
+
2012-11-27 Tony Chang <[email protected]>
Unreviewed, updating TestExpectations after input slider change.
Added: trunk/LayoutTests/media/video-controls-captions-trackmenu-expected.txt (0 => 135934)
--- trunk/LayoutTests/media/video-controls-captions-trackmenu-expected.txt (rev 0)
+++ trunk/LayoutTests/media/video-controls-captions-trackmenu-expected.txt 2012-11-27 23:45:13 UTC (rev 135934)
@@ -0,0 +1,32 @@
+Test that we are able to trigger the list of captions, and select from the list.
+
+EVENT(canplaythrough)
+*** Set the user language preference.
+RUN(internals.setUserPreferredLanguages(['en']))
+*** Click the CC button.
+*** Turning captions on
+Found tracklist menu and list of tracks OK
+Found four available tracks in menu OK
+EXPECTED (video.textTracks.length == '3') OK
+Track 0 should be disabled
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
+Track 1 should be showing
+EXPECTED (video.textTracks[1].mode == 'showing') OK
+Track 2 should be disabled
+EXPECTED (video.textTracks[2].mode == 'disabled') OK
+EXPECTED (textTrackDisplayElement(video, 'display').innerText == 'Lorem') OK
+*** Click the CC button.
+*** Turning captions on
+Found tracklist menu and list of tracks OK
+Found four available tracks in menu OK
+EXPECTED (video.textTracks.length == '3') OK
+Track 0 should be disabled
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
+Track 1 should be disabled
+EXPECTED (video.textTracks[1].mode == 'disabled') OK
+Track 2 should be disabled
+EXPECTED (video.textTracks[2].mode == 'disabled') OK
+No text track cue with display id '-webkit-media-text-track-display' is currently visible
+No text track cue with display id '-webkit-media-text-track-display' is currently visible
+END OF TEST
+
Property changes on: trunk/LayoutTests/media/video-controls-captions-trackmenu-expected.txt
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Added: trunk/LayoutTests/media/video-controls-captions-trackmenu.html (0 => 135934)
--- trunk/LayoutTests/media/video-controls-captions-trackmenu.html (rev 0)
+++ trunk/LayoutTests/media/video-controls-captions-trackmenu.html 2012-11-27 23:45:13 UTC (rev 135934)
@@ -0,0 +1,137 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Selecting from a list of tracks</title>
+ <script src=""
+ <script src=""
+ <script src=""
+ <script>
+ var captionsButtonCoordinates;
+
+ if (window.testRunner)
+ testRunner.dumpAsText();
+
+ function clickCCButton()
+ {
+ consoleWrite("*** Click the CC button.");
+ eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
+ eventSender.mouseDown();
+ eventSender.mouseUp();
+ }
+
+ function startTest()
+ {
+ if (window.eventSender) {
+ consoleWrite("*** Set the user language preference.");
+ run("internals.setUserPreferredLanguages(['en'])");
+
+ try {
+ captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggle-closed-captions-button");
+ } catch (exception) {
+ failTest(exception.description);
+ return;
+ }
+ clickCCButton();
+ window.setTimeout(turnCaptionsOn, 100);
+ }
+ }
+
+ function selectCaptionMenuItem(index, nextStep)
+ {
+ var trackListElement;
+ try {
+ trackListElement = mediaControlsElement(internals.shadowRoot(video).firstChild, "-webkit-media-controls-closed-captions-track-list");
+ } catch (exception) {
+ failTest(exception.description);
+ return;
+ }
+ // Track list should have a <ul> with four <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;
+ }
+ logResult(true, "Found tracklist menu and list of tracks");
+ var trackListItems = trackList.querySelectorAll("li");
+ if (!trackListItems) {
+ failTest("Could not find a child li elements in track list menu");
+ return;
+ }
+ if (trackListItems.length != 4) {
+ failTest("Expected 4 tracks in menu but found " + trackListItems.length);
+ return;
+ }
+ logResult(true, "Found four available tracks in menu");
+ // Click on the selected item
+ var selectedTrackItem = trackListItems[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();
+ window.setTimeout(nextStep, 100);
+ }
+
+ function turnCaptionsOn()
+ {
+ consoleWrite("*** Turning captions on");
+ // Click on the third item, which is the second track (Off is the first item in the menu)
+ selectCaptionMenuItem(2, testCaptionsVisible);
+ }
+
+ function testCaptionsVisible()
+ {
+ testExpected("video.textTracks.length", 3);
+ consoleWrite("Track 0 should be disabled");
+ testExpected("video.textTracks[0].mode", "disabled");
+ consoleWrite("Track 1 should be showing");
+ testExpected("video.textTracks[1].mode", "showing");
+ consoleWrite("Track 2 should be disabled");
+ testExpected("video.textTracks[2].mode", "disabled");
+ testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
+ clickCCButton();
+ window.setTimeout(turnCaptionsOff, 100);
+ }
+
+ function turnCaptionsOff()
+ {
+ consoleWrite("*** Turning captions on");
+ // Click the Off button
+ selectCaptionMenuItem(0, testCaptionsDisabled);
+ }
+
+ function testCaptionsDisabled()
+ {
+ testExpected("video.textTracks.length", 3);
+ consoleWrite("Track 0 should be disabled");
+ testExpected("video.textTracks[0].mode", "disabled");
+ consoleWrite("Track 1 should be disabled");
+ testExpected("video.textTracks[1].mode", "disabled");
+ consoleWrite("Track 2 should be disabled");
+ testExpected("video.textTracks[2].mode", "disabled");
+ testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
+ testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
+ endTest();
+ }
+
+ function start()
+ {
+ findMediaElement();
+ waitForEvent('canplaythrough', startTest);
+ }
+ </script>
+ </head>
+
+ <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>
+ <source src="" type="video/mp4">
+ <source src="" type="video/ogg">
+ <track kind="captions" src="" srclang="en">
+ <track kind="captions" src="" srclang="en-au">
+ <track kind="captions" src="" srclang="ja">
+ </video>
+ </body>
+</html>
+
Property changes on: trunk/LayoutTests/media/video-controls-captions-trackmenu.html
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Modified: trunk/LayoutTests/platform/chromium/TestExpectations (135933 => 135934)
--- trunk/LayoutTests/platform/chromium/TestExpectations 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/LayoutTests/platform/chromium/TestExpectations 2012-11-27 23:45:13 UTC (rev 135934)
@@ -3707,6 +3707,9 @@
webkit.org/b/94242 [ Android Debug ] media/track/track-cues-sorted-before-dispatch.html [ Crash Pass Timeout ]
+# Chromium still has the CC toggle button, not the menu of tracks.
+webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
+
# Supposedly started failing between CR r140760 and CR r141216. The failures
# look like they involve antialiasing; the fact that the test clearly expects
# these pixels not to be antialiased means these shouldn't just be rebaselined
Modified: trunk/LayoutTests/platform/efl/TestExpectations (135933 => 135934)
--- trunk/LayoutTests/platform/efl/TestExpectations 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/LayoutTests/platform/efl/TestExpectations 2012-11-27 23:45:13 UTC (rev 135934)
@@ -1704,6 +1704,9 @@
webkit.org/b/102493 fast/events/mouse-cursor.html [ Failure ]
+# EFL still has the CC toggle button, not the menu of tracks.
+webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
+
# Fails until we enable the Resource Timing API.
webkit.org/b/61138 http/tests/w3c/webperf/submission/resource-timing [ Skip ]
Modified: trunk/LayoutTests/platform/gtk/TestExpectations (135933 => 135934)
--- trunk/LayoutTests/platform/gtk/TestExpectations 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/LayoutTests/platform/gtk/TestExpectations 2012-11-27 23:45:13 UTC (rev 135934)
@@ -1399,6 +1399,9 @@
webkit.org/b/102993 media/video-volume-slider.html [ Failure ]
webkit.org/b/102993 media/video-zoom-controls.html [ Failure ]
+# GTK still has the CC toggle button, not the menu of tracks.
+webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
+
# Fix for https://bugs.webkit.org/show_bug.cgi?id=97192 introduces these regressions
webkit.org/b/102776 webkit.org/b/102993 media/media-document-audio-repaint.html [ Failure ]
webkit.org/b/102776 media/track/track-cue-container-rendering-position.html [ Failure ]
Modified: trunk/LayoutTests/platform/mac/TestExpectations (135933 => 135934)
--- trunk/LayoutTests/platform/mac/TestExpectations 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/LayoutTests/platform/mac/TestExpectations 2012-11-27 23:45:13 UTC (rev 135934)
@@ -1214,6 +1214,9 @@
webkit.org/b/100142 css3/filters/effect-reference-ordering-hw.html [ Fail ]
webkit.org/b/100142 css3/filters/effect-reference.html [ Fail ]
+# Mac doesn't have a toggle for CC any more, it's based on a menu of choices.
+webkit.org/b/101670 media/video-controls-captions.html [ Skip ]
+
# Overflowing LayoutUnits cause RenderGeometryMap assertions
webkit.org/b/67434 [ Debug ] fast/overflow/overflow-height-float-not-removed-crash.html [ Skip ]
webkit.org/b/67434 [ Debug ] fast/overflow/overflow-height-float-not-removed-crash2.html [ Skip ]
Modified: trunk/LayoutTests/platform/qt/TestExpectations (135933 => 135934)
--- trunk/LayoutTests/platform/qt/TestExpectations 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/LayoutTests/platform/qt/TestExpectations 2012-11-27 23:45:13 UTC (rev 135934)
@@ -2382,6 +2382,9 @@
webkit.org/b/102993 fast/repaint/slider-thumb-drag-release.html [ Failure ]
webkit.org/b/102993 fast/repaint/slider-thumb-float.html [ Failure ]
+# QT still has the CC toggle button, not the menu of tracks.
+webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
+
# New, but failing test
webkit.org/b/101035 fast/images/exif-orientation-image-document.html
Modified: trunk/LayoutTests/platform/win/TestExpectations (135933 => 135934)
--- trunk/LayoutTests/platform/win/TestExpectations 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/LayoutTests/platform/win/TestExpectations 2012-11-27 23:45:13 UTC (rev 135934)
@@ -2349,6 +2349,9 @@
webkit.org/b/98666 webkit.org/b/102993 fast/repaint/slider-thumb-drag-release.html [ Failure ]
webkit.org/b/98666 webkit.org/b/102993 fast/repaint/slider-thumb-float.html [ Failure ]
+# Win doesn't support track menu
+webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
+
#https://bugs.webkit.org/show_bug.cgi?id=98079
http/tests/security/cross-origin-local-storage-wk1.html
Modified: trunk/Source/WebCore/ChangeLog (135933 => 135934)
--- trunk/Source/WebCore/ChangeLog 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/Source/WebCore/ChangeLog 2012-11-27 23:45:13 UTC (rev 135934)
@@ -1,3 +1,41 @@
+2012-11-27 Dean Jackson <[email protected]>
+
+ Make track list control active
+ https://bugs.webkit.org/show_bug.cgi?id=101670
+
+ Reviewed by Eric Carlson.
+
+ Hook up the event handler for the captions menu so that it enables or
+ disables tracks in the associated HTMLMediaElement.
+
+ Test: media/video-controls-captions-trackmenu.html
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::toggleTrackAtIndex): New method to toggle the state of a track, by index.
+ * html/HTMLMediaElement.h:
+ (HTMLMediaElement): Ditto.
+ (WebCore::HTMLMediaElement::textTracksOffIndex): Static method to return the "Off" value.
+ * html/shadow/MediaControlElements.cpp:
+ (WebCore::trackListIndexForElement): Helper function to take a track list <li> element and return the value of the custom attribute.
+ (WebCore::MediaControlToggleClosedCaptionsButtonElement::updateDisplayType): Toggle the state of the button based on captions visibility.
+ (WebCore::MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler): On Mac platforms show the captions menu. On other platforms, toggle captions.
+ (WebCore::MediaControlClosedCaptionsTrackListElement::MediaControlClosedCaptionsTrackListElement): Now has a reference to the controls.
+ (WebCore::MediaControlClosedCaptionsTrackListElement::create):
+ (WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): When the user clicks on a track list item, look
+ for the custom attribute that identifies the associated track, and then toggle that track.
+ (WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Set a class on the track list elements so they can be
+ styled by the injected CSS (with tick marks to represent visibility).
+ (WebCore::MediaControlClosedCaptionsTrackListElement::resetTrackListMenu): When building the list of track menu items, add
+ a custom HTML attribute to the element so that the corresponding track can be found in the event handler.
+ * html/shadow/MediaControlElements.h:
+ (MediaControlClosedCaptionsTrackListElement): Add a list of elements representing the track list.
+ * html/shadow/MediaControlsApple.cpp:
+ (WebCore::MediaControlsApple::createControls):
+ (WebCore::MediaControlsApple::changedClosedCaptionsVisibility): Make sure to update the track menu.
+ (WebCore::MediaControlsApple::reset):
+ * html/shadow/MediaControlsApple.h:
+ (MediaControlsApple):
+
2012-11-27 Joshua Bell <[email protected]>
IndexedDB: Simplify transaction timers and event tracking
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (135933 => 135934)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2012-11-27 23:45:13 UTC (rev 135934)
@@ -2998,6 +2998,22 @@
}
}
+void HTMLMediaElement::toggleTrackAtIndex(int index, bool exclusive)
+{
+ TextTrackList* trackList = textTracks();
+ if (!trackList || !trackList->length())
+ return;
+
+ for (int i = 0, length = trackList->length(); i < length; ++i) {
+ TextTrack* track = trackList->item(i);
+ track->setShowingByDefault(false);
+ if (i == index)
+ track->setMode(TextTrack::showingKeyword());
+ else if (exclusive || index == HTMLMediaElement::textTracksOffIndex())
+ track->setMode(TextTrack::disabledKeyword());
+ }
+}
+
void HTMLMediaElement::configureTextTracks()
{
TrackGroup captionAndSubtitleTracks(TrackGroup::CaptionsAndSubtitles);
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (135933 => 135934)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2012-11-27 23:45:13 UTC (rev 135934)
@@ -245,6 +245,9 @@
void configureTextTracks();
void configureTextTrackGroup(const TrackGroup&) const;
+ void toggleTrackAtIndex(int index, bool exclusive = true);
+ static int textTracksOffIndex() { return -1; }
+
bool userPrefersCaptions() const;
bool userIsInterestedInThisTrackKind(String) const;
bool textTracksAreReady() const;
Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.cpp (135933 => 135934)
--- trunk/Source/WebCore/html/shadow/MediaControlElements.cpp 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.cpp 2012-11-27 23:45:13 UTC (rev 135934)
@@ -36,6 +36,7 @@
#include "CSSValueKeywords.h"
#include "DOMTokenList.h"
#include "EventNames.h"
+#include "EventTarget.h"
#include "FloatConversion.h"
#include "FloatPoint.h"
#include "Frame.h"
@@ -63,6 +64,7 @@
#include "StyleResolver.h"
#include "Text.h"
#if ENABLE(VIDEO_TRACK)
+#include "TextTrack.h"
#include "TextTrackList.h"
#endif
@@ -77,6 +79,11 @@
static const float cScanRepeatDelay = 1.5f;
static const float cScanMaximumRate = 8;
+#if ENABLE(VIDEO_TRACK)
+static const char* textTracksOffAttrValue = "-1"; // This must match HTMLMediaElement::textTracksOffIndex()
+static const int textTracksIndexNotFound = -2;
+#endif
+
HTMLMediaElement* toParentMediaElement(Node* node)
{
if (!node)
@@ -99,6 +106,26 @@
return static_cast<MediaControlElement*>(element)->displayType();
}
+#if ENABLE(VIDEO_TRACK)
+static const AtomicString& trackIndexAttributeName()
+{
+ DEFINE_STATIC_LOCAL(AtomicString, name, ("x-webkit-track-index", AtomicString::ConstructFromLiteral));
+ return name;
+}
+
+static int trackListIndexForElement(Element* element)
+{
+ const AtomicString trackIndexAttributeValue = element->getAttribute(trackIndexAttributeName());
+ if (trackIndexAttributeValue.isNull() || trackIndexAttributeValue.isEmpty())
+ return textTracksIndexNotFound;
+ bool ok;
+ int trackIndex = trackIndexAttributeValue.toInt(&ok);
+ if (!ok)
+ return textTracksIndexNotFound;
+ return trackIndex;
+}
+#endif
+
// ----------------------------
MediaControlElement::MediaControlElement(Document* document)
@@ -901,18 +928,25 @@
void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType()
{
- setDisplayType(mediaController()->closedCaptionsVisible() ? MediaHideClosedCaptionsButton : MediaShowClosedCaptionsButton);
+ bool captionsVisible = mediaController()->closedCaptionsVisible();
+ setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowClosedCaptionsButton);
+ setChecked(captionsVisible);
}
void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* event)
{
if (event->type() == eventNames().clickEvent) {
- // FIXME: This is now incorrectly doing two things at once: showing the list of captions and toggling display.
- // https://bugs.webkit.org/show_bug.cgi?id=101670
+ // FIXME: It's not great that the shared code is dictating behavior of platform-specific
+ // UI. Not all ports may want the closed captions button to toggle a list of tracks, so
+ // we have to use #if.
+ // https://bugs.webkit.org/show_bug.cgi?id=101877
+#if !PLATFORM(MAC)
mediaController()->setClosedCaptionsVisible(!mediaController()->closedCaptionsVisible());
setChecked(mediaController()->closedCaptionsVisible());
+ updateDisplayType();
+#else
m_controls->toggleClosedCaptionTrackList();
- updateDisplayType();
+#endif
event->setDefaultHandled();
}
@@ -927,22 +961,52 @@
// ----------------------------
-inline MediaControlClosedCaptionsTrackListElement::MediaControlClosedCaptionsTrackListElement(Document* document)
+inline MediaControlClosedCaptionsTrackListElement::MediaControlClosedCaptionsTrackListElement(Document* document, MediaControls* controls)
: MediaControlElement(document)
+ , m_controls(controls)
{
}
-PassRefPtr<MediaControlClosedCaptionsTrackListElement> MediaControlClosedCaptionsTrackListElement::create(Document* document)
+PassRefPtr<MediaControlClosedCaptionsTrackListElement> MediaControlClosedCaptionsTrackListElement::create(Document* document, MediaControls* controls)
{
- RefPtr<MediaControlClosedCaptionsTrackListElement> element = adoptRef(new MediaControlClosedCaptionsTrackListElement(document));
+ ASSERT(controls);
+ RefPtr<MediaControlClosedCaptionsTrackListElement> element = adoptRef(new MediaControlClosedCaptionsTrackListElement(document, controls));
return element.release();
}
void MediaControlClosedCaptionsTrackListElement::defaultEventHandler(Event* event)
{
- // FIXME: Hook this up to actual text tracks.
- // https://bugs.webkit.org/show_bug.cgi?id=101670
- UNUSED_PARAM(event);
+#if ENABLE(VIDEO_TRACK)
+ if (event->type() == eventNames().clickEvent) {
+ // FIXME: Add modifier key for exclusivity override.
+ // http://webkit.org/b/103361
+
+ Node* target = event->target()->toNode();
+ if (!target || !target->isElementNode())
+ return;
+
+ // When we created the elements in the track list, we gave them a custom
+ // attribute representing the index in the HTMLMediaElement's list of tracks.
+ // Check if the event target has such a custom element and, if so,
+ // tell the HTMLMediaElement to enable that track.
+
+ int trackIndex = trackListIndexForElement(toElement(target));
+ if (trackIndex == textTracksIndexNotFound)
+ return;
+
+ HTMLMediaElement* mediaElement = toParentMediaElement(this);
+ if (!mediaElement)
+ return;
+
+ mediaElement->toggleTrackAtIndex(trackIndex);
+
+ // We've selected a track to display, so we can now close the menu.
+ m_controls->toggleClosedCaptionTrackList();
+ updateDisplay();
+ }
+
+ MediaControlElement::defaultEventHandler(event);
+#endif
}
const AtomicString& MediaControlClosedCaptionsTrackListElement::shadowPseudoId() const
@@ -954,8 +1018,50 @@
void MediaControlClosedCaptionsTrackListElement::updateDisplay()
{
#if ENABLE(VIDEO_TRACK)
+ DEFINE_STATIC_LOCAL(AtomicString, selectedClassValue, ("selected", AtomicString::ConstructFromLiteral));
+
+ if (!mediaController()->hasClosedCaptions())
+ return;
+
+ HTMLMediaElement* mediaElement = toParentMediaElement(this);
+ if (!mediaElement)
+ return;
+
+ TextTrackList* trackList = mediaElement->textTracks();
+
+ if (!trackList || !trackList->length())
+ return;
+
+ bool captionsVisible = mediaElement->closedCaptionsVisible();
+ for (unsigned i = 0, length = menuItems.size(); i < length; ++i) {
+ RefPtr<Element> trackItem = menuItems[i];
+ int trackIndex = trackListIndexForElement(trackItem.get());
+ if (trackIndex != 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
+}
+
+void MediaControlClosedCaptionsTrackListElement::resetTrackListMenu()
+{
+#if ENABLE(VIDEO_TRACK)
// Remove any existing content.
removeChildren();
+ menuItems.clear();
if (!mediaController()->hasClosedCaptions())
return;
@@ -987,15 +1093,15 @@
trackItem = doc->createElement(liTag, ASSERT_NO_EXCEPTION);
trackItem->appendChild(doc->createTextNode("Off"));
- // FIXME: These lists are not yet live. Mark the Off entry as the selected one for now.
- trackItem->setAttribute(classAttr, "selected");
+ trackItem->setAttribute(trackIndexAttributeName(), textTracksOffAttrValue, ASSERT_NO_EXCEPTION);
captionsList->appendChild(trackItem);
+ menuItems.append(trackItem);
trackItem = doc->createElement(liTag, ASSERT_NO_EXCEPTION);
trackItem->appendChild(doc->createTextNode("Off"));
- // FIXME: These lists are not yet live. Mark the Off entry as the selected one for now.
- trackItem->setAttribute(classAttr, "selected");
+ trackItem->setAttribute(trackIndexAttributeName(), textTracksOffAttrValue, ASSERT_NO_EXCEPTION);
subtitlesList->appendChild(trackItem);
+ menuItems.append(trackItem);
bool hasCaptions = false;
bool hasSubtitles = false;
@@ -1003,6 +1109,13 @@
for (unsigned i = 0, length = trackList->length(); i < length; ++i) {
TextTrack* track = trackList->item(i);
trackItem = doc->createElement(liTag, ASSERT_NO_EXCEPTION);
+
+ // Add a custom attribute to the <li> element which will allow
+ // us to easily associate the user tapping here with the
+ // track. Since this list is rebuilt if the tracks change, we
+ // should always be in sync.
+ trackItem->setAttribute(trackIndexAttributeName(), String::number(i), ASSERT_NO_EXCEPTION);
+
AtomicString labelText = track->label();
if (labelText.isNull() || labelText.isEmpty())
labelText = displayNameForLanguageLocale(track->language());
@@ -1018,6 +1131,7 @@
subtitlesList->appendChild(trackItem);
}
trackItem->appendChild(doc->createTextNode(labelText));
+ menuItems.append(trackItem);
}
captionsSection->appendChild(captionsList);
@@ -1027,6 +1141,8 @@
appendChild(captionsSection);
if (hasSubtitles)
appendChild(subtitlesSection);
+
+ updateDisplay();
#endif
}
Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.h (135933 => 135934)
--- trunk/Source/WebCore/html/shadow/MediaControlElements.h 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.h 2012-11-27 23:45:13 UTC (rev 135934)
@@ -415,18 +415,23 @@
class MediaControlClosedCaptionsTrackListElement : public MediaControlElement {
public:
- static PassRefPtr<MediaControlClosedCaptionsTrackListElement> create(Document*);
+ static PassRefPtr<MediaControlClosedCaptionsTrackListElement> create(Document*, MediaControls*);
virtual void defaultEventHandler(Event*);
virtual bool willRespondToMouseClickEvents() OVERRIDE { return true; }
void updateDisplay();
+ void resetTrackListMenu();
private:
- MediaControlClosedCaptionsTrackListElement(Document*);
+ MediaControlClosedCaptionsTrackListElement(Document*, MediaControls*);
virtual MediaControlElementType displayType() const { return MediaClosedCaptionsTrackList; }
virtual const AtomicString& shadowPseudoId() const;
+
+ typedef Vector<RefPtr<Element> > TrackMenuItems;
+ TrackMenuItems menuItems;
+ MediaControls* m_controls;
};
// ----------------------------
Modified: trunk/Source/WebCore/html/shadow/MediaControlsApple.cpp (135933 => 135934)
--- trunk/Source/WebCore/html/shadow/MediaControlsApple.cpp 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/Source/WebCore/html/shadow/MediaControlsApple.cpp 2012-11-27 23:45:13 UTC (rev 135934)
@@ -149,7 +149,7 @@
if (document->page()->theme()->supportsClosedCaptioning()) {
RefPtr<MediaControlClosedCaptionsContainerElement> closedCaptionsContainer = MediaControlClosedCaptionsContainerElement::create(document);
- RefPtr<MediaControlClosedCaptionsTrackListElement> closedCaptionsTrackList = MediaControlClosedCaptionsTrackListElement::create(document);
+ RefPtr<MediaControlClosedCaptionsTrackListElement> closedCaptionsTrackList = MediaControlClosedCaptionsTrackListElement::create(document, controls.get());
controls->m_closedCaptionsTrackList = closedCaptionsTrackList.get();
closedCaptionsContainer->appendChild(closedCaptionsTrackList.release(), ec, true);
if (ec)
@@ -289,6 +289,13 @@
m_closedCaptionsContainer->hide();
}
+void MediaControlsApple::changedClosedCaptionsVisibility()
+{
+ MediaControls::changedClosedCaptionsVisibility();
+ if (m_closedCaptionsTrackList)
+ m_closedCaptionsTrackList->updateDisplay();
+}
+
void MediaControlsApple::reset()
{
Page* page = document()->page();
@@ -323,7 +330,7 @@
if (m_mediaController->hasClosedCaptions()) {
m_toggleClosedCaptionsButton->show();
if (m_closedCaptionsTrackList)
- m_closedCaptionsTrackList->updateDisplay();
+ m_closedCaptionsTrackList->resetTrackListMenu();
} else
m_toggleClosedCaptionsButton->hide();
}
Modified: trunk/Source/WebCore/html/shadow/MediaControlsApple.h (135933 => 135934)
--- trunk/Source/WebCore/html/shadow/MediaControlsApple.h 2012-11-27 23:39:19 UTC (rev 135933)
+++ trunk/Source/WebCore/html/shadow/MediaControlsApple.h 2012-11-27 23:45:13 UTC (rev 135934)
@@ -58,6 +58,7 @@
virtual void updateCurrentTimeDisplay() OVERRIDE;
virtual void updateStatusDisplay() OVERRIDE;
+ virtual void changedClosedCaptionsVisibility() OVERRIDE;
void toggleClosedCaptionTrackList();
private: