Skip to content

Commit acaceda

Browse files
Make track list control active
https://bugs.webkit.org/show_bug.cgi?id=101670 Reviewed by Eric Carlson. Source/WebCore: 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): LayoutTests: 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: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@135934 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 480e42f commit acaceda

16 files changed

+415
-18
lines changed

LayoutTests/ChangeLog

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2012-11-27 Dean Jackson <[email protected]>
2+
3+
Make track list control active
4+
https://bugs.webkit.org/show_bug.cgi?id=101670
5+
6+
Reviewed by Eric Carlson.
7+
8+
New test that exercises the track list menu, and how it can be used
9+
to enable specific tracks. Since this is only enabled for Mac, it is
10+
skipped on all other platforms.
11+
12+
Meanwhile, the existing test for a on/off captions button now
13+
does not work on Mac, so skip it there. I copied the functionality
14+
into the new test so we still have coverage.
15+
16+
* media/video-controls-captions-trackmenu-expected.txt: Added.
17+
* media/video-controls-captions-trackmenu.html: Added.
18+
* platform/chromium/TestExpectations:
19+
* platform/efl/TestExpectations:
20+
* platform/gtk/TestExpectations:
21+
* platform/mac/TestExpectations:
22+
* platform/qt/TestExpectations:
23+
* platform/win/TestExpectations:
24+
125
2012-11-27 Tony Chang <[email protected]>
226

327
Unreviewed, updating TestExpectations after input slider change.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Test that we are able to trigger the list of captions, and select from the list.
2+
3+
EVENT(canplaythrough)
4+
*** Set the user language preference.
5+
RUN(internals.setUserPreferredLanguages(['en']))
6+
*** Click the CC button.
7+
*** Turning captions on
8+
Found tracklist menu and list of tracks OK
9+
Found four available tracks in menu OK
10+
EXPECTED (video.textTracks.length == '3') OK
11+
Track 0 should be disabled
12+
EXPECTED (video.textTracks[0].mode == 'disabled') OK
13+
Track 1 should be showing
14+
EXPECTED (video.textTracks[1].mode == 'showing') OK
15+
Track 2 should be disabled
16+
EXPECTED (video.textTracks[2].mode == 'disabled') OK
17+
EXPECTED (textTrackDisplayElement(video, 'display').innerText == 'Lorem') OK
18+
*** Click the CC button.
19+
*** Turning captions on
20+
Found tracklist menu and list of tracks OK
21+
Found four available tracks in menu OK
22+
EXPECTED (video.textTracks.length == '3') OK
23+
Track 0 should be disabled
24+
EXPECTED (video.textTracks[0].mode == 'disabled') OK
25+
Track 1 should be disabled
26+
EXPECTED (video.textTracks[1].mode == 'disabled') OK
27+
Track 2 should be disabled
28+
EXPECTED (video.textTracks[2].mode == 'disabled') OK
29+
No text track cue with display id '-webkit-media-text-track-display' is currently visible
30+
No text track cue with display id '-webkit-media-text-track-display' is currently visible
31+
END OF TEST
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Selecting from a list of tracks</title>
5+
<script src="media-controls.js"></script>
6+
<script src="media-file.js"></script>
7+
<script src="video-test.js"></script>
8+
<script>
9+
var captionsButtonCoordinates;
10+
11+
if (window.testRunner)
12+
testRunner.dumpAsText();
13+
14+
function clickCCButton()
15+
{
16+
consoleWrite("*** Click the CC button.");
17+
eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
18+
eventSender.mouseDown();
19+
eventSender.mouseUp();
20+
}
21+
22+
function startTest()
23+
{
24+
if (window.eventSender) {
25+
consoleWrite("*** Set the user language preference.");
26+
run("internals.setUserPreferredLanguages(['en'])");
27+
28+
try {
29+
captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggle-closed-captions-button");
30+
} catch (exception) {
31+
failTest(exception.description);
32+
return;
33+
}
34+
clickCCButton();
35+
window.setTimeout(turnCaptionsOn, 100);
36+
}
37+
}
38+
39+
function selectCaptionMenuItem(index, nextStep)
40+
{
41+
var trackListElement;
42+
try {
43+
trackListElement = mediaControlsElement(internals.shadowRoot(video).firstChild, "-webkit-media-controls-closed-captions-track-list");
44+
} catch (exception) {
45+
failTest(exception.description);
46+
return;
47+
}
48+
// Track list should have a <ul> with four <li> children (One of them is "Off").
49+
var trackList = trackListElement.querySelector("ul");
50+
if (!trackList) {
51+
failTest("Could not find a child ul element in track list menu");
52+
return;
53+
}
54+
logResult(true, "Found tracklist menu and list of tracks");
55+
var trackListItems = trackList.querySelectorAll("li");
56+
if (!trackListItems) {
57+
failTest("Could not find a child li elements in track list menu");
58+
return;
59+
}
60+
if (trackListItems.length != 4) {
61+
failTest("Expected 4 tracks in menu but found " + trackListItems.length);
62+
return;
63+
}
64+
logResult(true, "Found four available tracks in menu");
65+
// Click on the selected item
66+
var selectedTrackItem = trackListItems[index];
67+
var boundingRect = selectedTrackItem.getBoundingClientRect();
68+
var x = boundingRect.left + boundingRect.width / 2;
69+
var y = boundingRect.top + boundingRect.height / 2;
70+
eventSender.mouseMoveTo(x, y);
71+
eventSender.mouseDown();
72+
eventSender.mouseUp();
73+
window.setTimeout(nextStep, 100);
74+
}
75+
76+
function turnCaptionsOn()
77+
{
78+
consoleWrite("*** Turning captions on");
79+
// Click on the third item, which is the second track (Off is the first item in the menu)
80+
selectCaptionMenuItem(2, testCaptionsVisible);
81+
}
82+
83+
function testCaptionsVisible()
84+
{
85+
testExpected("video.textTracks.length", 3);
86+
consoleWrite("Track 0 should be disabled");
87+
testExpected("video.textTracks[0].mode", "disabled");
88+
consoleWrite("Track 1 should be showing");
89+
testExpected("video.textTracks[1].mode", "showing");
90+
consoleWrite("Track 2 should be disabled");
91+
testExpected("video.textTracks[2].mode", "disabled");
92+
testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
93+
clickCCButton();
94+
window.setTimeout(turnCaptionsOff, 100);
95+
}
96+
97+
function turnCaptionsOff()
98+
{
99+
consoleWrite("*** Turning captions on");
100+
// Click the Off button
101+
selectCaptionMenuItem(0, testCaptionsDisabled);
102+
}
103+
104+
function testCaptionsDisabled()
105+
{
106+
testExpected("video.textTracks.length", 3);
107+
consoleWrite("Track 0 should be disabled");
108+
testExpected("video.textTracks[0].mode", "disabled");
109+
consoleWrite("Track 1 should be disabled");
110+
testExpected("video.textTracks[1].mode", "disabled");
111+
consoleWrite("Track 2 should be disabled");
112+
testExpected("video.textTracks[2].mode", "disabled");
113+
testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
114+
testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
115+
endTest();
116+
}
117+
118+
function start()
119+
{
120+
findMediaElement();
121+
waitForEvent('canplaythrough', startTest);
122+
}
123+
</script>
124+
</head>
125+
126+
<body onload="start()">
127+
<p>Test that we are able to trigger the list of captions, and select from the list.</p>
128+
<video width="500" height="300" controls>
129+
<source src="content/test.mp4" type="video/mp4">
130+
<source src="content/test.ogv" type="video/ogg">
131+
<track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
132+
<track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
133+
<track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
134+
</video>
135+
</body>
136+
</html>
137+

LayoutTests/platform/chromium/TestExpectations

+3
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,9 @@ webkit.org/b/92570 [ Win Debug ] inspector/timeline/timeline-start-time.html [ F
37073707

37083708
webkit.org/b/94242 [ Android Debug ] media/track/track-cues-sorted-before-dispatch.html [ Crash Pass Timeout ]
37093709

3710+
# Chromium still has the CC toggle button, not the menu of tracks.
3711+
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
3712+
37103713
# Supposedly started failing between CR r140760 and CR r141216. The failures
37113714
# look like they involve antialiasing; the fact that the test clearly expects
37123715
# these pixels not to be antialiased means these shouldn't just be rebaselined

LayoutTests/platform/efl/TestExpectations

+3
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,9 @@ webkit.org/b/102367 fast/forms/zoomed-controls.html [ ImageOnlyFailure Missing ]
17041704

17051705
webkit.org/b/102493 fast/events/mouse-cursor.html [ Failure ]
17061706

1707+
# EFL still has the CC toggle button, not the menu of tracks.
1708+
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
1709+
17071710
# Fails until we enable the Resource Timing API.
17081711
webkit.org/b/61138 http/tests/w3c/webperf/submission/resource-timing [ Skip ]
17091712

LayoutTests/platform/gtk/TestExpectations

+3
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,9 @@ webkit.org/b/102993 media/video-no-audio.html [ Failure ]
13991399
webkit.org/b/102993 media/video-volume-slider.html [ Failure ]
14001400
webkit.org/b/102993 media/video-zoom-controls.html [ Failure ]
14011401

1402+
# GTK still has the CC toggle button, not the menu of tracks.
1403+
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
1404+
14021405
# Fix for https://bugs.webkit.org/show_bug.cgi?id=97192 introduces these regressions
14031406
webkit.org/b/102776 webkit.org/b/102993 media/media-document-audio-repaint.html [ Failure ]
14041407
webkit.org/b/102776 media/track/track-cue-container-rendering-position.html [ Failure ]

LayoutTests/platform/mac/TestExpectations

+3
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,9 @@ webkit.org/b/100142 css3/filters/effect-reference-hw.html [ Fail ]
12141214
webkit.org/b/100142 css3/filters/effect-reference-ordering-hw.html [ Fail ]
12151215
webkit.org/b/100142 css3/filters/effect-reference.html [ Fail ]
12161216

1217+
# Mac doesn't have a toggle for CC any more, it's based on a menu of choices.
1218+
webkit.org/b/101670 media/video-controls-captions.html [ Skip ]
1219+
12171220
# Overflowing LayoutUnits cause RenderGeometryMap assertions
12181221
webkit.org/b/67434 [ Debug ] fast/overflow/overflow-height-float-not-removed-crash.html [ Skip ]
12191222
webkit.org/b/67434 [ Debug ] fast/overflow/overflow-height-float-not-removed-crash2.html [ Skip ]

LayoutTests/platform/qt/TestExpectations

+3
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,9 @@ webkit.org/b/102993 fast/multicol/client-rects.html [ Failure ]
23822382
webkit.org/b/102993 fast/repaint/slider-thumb-drag-release.html [ Failure ]
23832383
webkit.org/b/102993 fast/repaint/slider-thumb-float.html [ Failure ]
23842384

2385+
# QT still has the CC toggle button, not the menu of tracks.
2386+
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
2387+
23852388
# New, but failing test
23862389
webkit.org/b/101035 fast/images/exif-orientation-image-document.html
23872390

LayoutTests/platform/win/TestExpectations

+3
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,9 @@ webkit.org/b/98666 webkit.org/b/102993 fast/multicol/client-rects.html [ Failure
23492349
webkit.org/b/98666 webkit.org/b/102993 fast/repaint/slider-thumb-drag-release.html [ Failure ]
23502350
webkit.org/b/98666 webkit.org/b/102993 fast/repaint/slider-thumb-float.html [ Failure ]
23512351

2352+
# Win doesn't support track menu
2353+
webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
2354+
23522355
#https://bugs.webkit.org/show_bug.cgi?id=98079
23532356
http/tests/security/cross-origin-local-storage-wk1.html
23542357

Source/WebCore/ChangeLog

+38
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
2012-11-27 Dean Jackson <[email protected]>
2+
3+
Make track list control active
4+
https://bugs.webkit.org/show_bug.cgi?id=101670
5+
6+
Reviewed by Eric Carlson.
7+
8+
Hook up the event handler for the captions menu so that it enables or
9+
disables tracks in the associated HTMLMediaElement.
10+
11+
Test: media/video-controls-captions-trackmenu.html
12+
13+
* html/HTMLMediaElement.cpp:
14+
(WebCore::HTMLMediaElement::toggleTrackAtIndex): New method to toggle the state of a track, by index.
15+
* html/HTMLMediaElement.h:
16+
(HTMLMediaElement): Ditto.
17+
(WebCore::HTMLMediaElement::textTracksOffIndex): Static method to return the "Off" value.
18+
* html/shadow/MediaControlElements.cpp:
19+
(WebCore::trackListIndexForElement): Helper function to take a track list <li> element and return the value of the custom attribute.
20+
(WebCore::MediaControlToggleClosedCaptionsButtonElement::updateDisplayType): Toggle the state of the button based on captions visibility.
21+
(WebCore::MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler): On Mac platforms show the captions menu. On other platforms, toggle captions.
22+
(WebCore::MediaControlClosedCaptionsTrackListElement::MediaControlClosedCaptionsTrackListElement): Now has a reference to the controls.
23+
(WebCore::MediaControlClosedCaptionsTrackListElement::create):
24+
(WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): When the user clicks on a track list item, look
25+
for the custom attribute that identifies the associated track, and then toggle that track.
26+
(WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Set a class on the track list elements so they can be
27+
styled by the injected CSS (with tick marks to represent visibility).
28+
(WebCore::MediaControlClosedCaptionsTrackListElement::resetTrackListMenu): When building the list of track menu items, add
29+
a custom HTML attribute to the element so that the corresponding track can be found in the event handler.
30+
* html/shadow/MediaControlElements.h:
31+
(MediaControlClosedCaptionsTrackListElement): Add a list of elements representing the track list.
32+
* html/shadow/MediaControlsApple.cpp:
33+
(WebCore::MediaControlsApple::createControls):
34+
(WebCore::MediaControlsApple::changedClosedCaptionsVisibility): Make sure to update the track menu.
35+
(WebCore::MediaControlsApple::reset):
36+
* html/shadow/MediaControlsApple.h:
37+
(MediaControlsApple):
38+
139
2012-11-27 Joshua Bell <[email protected]>
240

341
IndexedDB: Simplify transaction timers and event tracking

Source/WebCore/html/HTMLMediaElement.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -2998,6 +2998,22 @@ void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) const
29982998
}
29992999
}
30003000

3001+
void HTMLMediaElement::toggleTrackAtIndex(int index, bool exclusive)
3002+
{
3003+
TextTrackList* trackList = textTracks();
3004+
if (!trackList || !trackList->length())
3005+
return;
3006+
3007+
for (int i = 0, length = trackList->length(); i < length; ++i) {
3008+
TextTrack* track = trackList->item(i);
3009+
track->setShowingByDefault(false);
3010+
if (i == index)
3011+
track->setMode(TextTrack::showingKeyword());
3012+
else if (exclusive || index == HTMLMediaElement::textTracksOffIndex())
3013+
track->setMode(TextTrack::disabledKeyword());
3014+
}
3015+
}
3016+
30013017
void HTMLMediaElement::configureTextTracks()
30023018
{
30033019
TrackGroup captionAndSubtitleTracks(TrackGroup::CaptionsAndSubtitles);

Source/WebCore/html/HTMLMediaElement.h

+3
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, public Me
245245
void configureTextTracks();
246246
void configureTextTrackGroup(const TrackGroup&) const;
247247

248+
void toggleTrackAtIndex(int index, bool exclusive = true);
249+
static int textTracksOffIndex() { return -1; }
250+
248251
bool userPrefersCaptions() const;
249252
bool userIsInterestedInThisTrackKind(String) const;
250253
bool textTracksAreReady() const;

0 commit comments

Comments
 (0)