| Differences between
and this patch
- a/Source/WebCore/ChangeLog +61 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2012-08-23  Anna Cavender  <annacc@chromium.org>
2
3
        Create a toggle button for closed captions.
4
        https://bugs.webkit.org/show_bug.cgi?id=94395
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        This patch will create a button that toggles any captions or subtitles on or off.
9
10
        Test: media/video-controls-captions.html
11
12
        * css/mediaControlsChromium.css:
13
        (audio::-webkit-media-controls-toggle-closed-captions-button, video::-webkit-media-controls-toggle-closed-captions-button):
14
        New style for new button.
15
16
        * html/HTMLMediaElement.cpp:
17
        (WebCore::HTMLMediaElement::HTMLMediaElement):
18
        Initialize new variable for keeping track of whether default tracks should be ignored.
19
20
        (WebCore::HTMLMediaElement::prepareForLoad):
21
        Do not set closedCaptionsVisible to false, we should instead honor the
22
        checks for default out-of-band tracks.
23
24
        (WebCore::HTMLMediaElement::userIsInterestedInThisTrackKind):
25
        Add checks for when user has requested visible captions and when default tracks
26
        should be ignored.
27
28
        (WebCore::HTMLMediaElement::hasClosedCaptions):
29
        Return true if we have any text tracks.
30
31
        (WebCore::HTMLMediaElement::setClosedCaptionsVisible):
32
        Update the text track display and the closed captions button when the
33
        closed captions button is toggled.
34
35
        (WebCore::HTMLMediaElement::updateClosedCaptionsControls):
36
        New function that updates both the text track display and the closed
37
        captions button.
38
39
        (WebCore::HTMLMediaElement::configureTextTrackDisplay):
40
        If the visibility of any text tracks has changed, update the display and
41
        the controls.
42
43
        * html/HTMLMediaElement.h:
44
        (HTMLMediaElement):
45
        New function updateClosedCaptionsControls()
46
47
        Adding the button:
48
        * html/shadow/MediaControlElements.cpp:
49
        (WebCore::MediaControlTextTrackContainerElement::updateDisplay):
50
        * html/shadow/MediaControlRootElementChromium.cpp:
51
        (WebCore::MediaControlRootElementChromium::MediaControlRootElementChromium):
52
        (WebCore::MediaControlRootElementChromium::initializeControls):
53
        (WebCore::MediaControlRootElementChromium::setMediaController):
54
        (WebCore::MediaControlRootElementChromium::reset):
55
        (WebCore::MediaControlRootElementChromium::reportedError):
56
        (WebCore::MediaControlRootElementChromium::changedClosedCaptionsVisibility):
57
        (WebCore::MediaControlRootElementChromium::createTextTrackDisplay):
58
        * html/shadow/MediaControlRootElementChromium.h:
59
        (WebCore):
60
        (MediaControlRootElementChromium):
61
1
2012-08-23  Andreas Kling  <kling@webkit.org>
62
2012-08-23  Andreas Kling  <kling@webkit.org>
2
63
3
        Use immutable StylePropertySets for element inline style declarations.
64
        Use immutable StylePropertySets for element inline style declarations.
- a/Source/WebCore/css/mediaControlsChromium.css +13 lines
Lines 178-183 input[type="range"]::-webkit-media-slider-thumb { a/Source/WebCore/css/mediaControlsChromium.css_sec1
178
    margin-right: -7px;
178
    margin-right: -7px;
179
}
179
}
180
180
181
audio::-webkit-media-controls-toggle-closed-captions-button, video::-webkit-media-controls-toggle-closed-captions-button {
182
    -webkit-appearance: media-toggle-closed-captions-button;
183
    display: -webkit-box;
184
    border: none;
185
    box-sizing: border-box;
186
    width: 25px;
187
    height: 25px;
188
    line-height: 25px;
189
    margin-left: -5px;
190
    margin-right: 9px;
191
    padding: 0;
192
}
193
181
audio::-webkit-media-controls-fullscreen-button, video::-webkit-media-controls-fullscreen-button {
194
audio::-webkit-media-controls-fullscreen-button, video::-webkit-media-controls-fullscreen-button {
182
    -webkit-appearance: media-enter-fullscreen-button;
195
    -webkit-appearance: media-enter-fullscreen-button;
183
    display: -webkit-box;
196
    display: -webkit-box;
- a/Source/WebCore/html/HTMLMediaElement.cpp -4 / +49 lines
Lines 259-264 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum a/Source/WebCore/html/HTMLMediaElement.cpp_sec1
259
    , m_lastTextTrackUpdateTime(-1)
259
    , m_lastTextTrackUpdateTime(-1)
260
    , m_textTracks(0)
260
    , m_textTracks(0)
261
    , m_ignoreTrackDisplayUpdate(0)
261
    , m_ignoreTrackDisplayUpdate(0)
262
    , m_ignoreDefaultTracks(false)
262
#endif
263
#endif
263
#if ENABLE(WEB_AUDIO)
264
#if ENABLE(WEB_AUDIO)
264
    , m_audioSourceNode(0)
265
    , m_audioSourceNode(0)
Lines 736-742 void HTMLMediaElement::prepareForLoad() a/Source/WebCore/html/HTMLMediaElement.cpp_sec2
736
737
737
    m_playedTimeRanges = TimeRanges::create();
738
    m_playedTimeRanges = TimeRanges::create();
738
    m_lastSeekTime = 0;
739
    m_lastSeekTime = 0;
739
    m_closedCaptionsVisible = false;
740
740
741
    // The spec doesn't say to block the load event until we actually run the asynchronous section
741
    // The spec doesn't say to block the load event until we actually run the asynchronous section
742
    // algorithm, but do it now because we won't start that until after the timer fires and the 
742
    // algorithm, but do it now because we won't start that until after the timer fires and the 
Lines 2789-2794 bool HTMLMediaElement::userIsInterestedInThisTrackKind(String kind) const a/Source/WebCore/html/HTMLMediaElement.cpp_sec3
2789
    if (!settings)
2789
    if (!settings)
2790
        return false;
2790
        return false;
2791
2791
2792
    if (m_ignoreDefaultTracks)
2793
        return false;
2794
2795
    if (m_closedCaptionsVisible)
2796
        return true;
2797
2792
    if (kind == TextTrack::subtitlesKeyword())
2798
    if (kind == TextTrack::subtitlesKeyword())
2793
        return settings->shouldDisplaySubtitles();
2799
        return settings->shouldDisplaySubtitles();
2794
    if (kind == TextTrack::captionsKeyword())
2800
    if (kind == TextTrack::captionsKeyword())
Lines 3920-3926 PlatformLayer* HTMLMediaElement::platformLayer() const a/Source/WebCore/html/HTMLMediaElement.cpp_sec4
3920
3926
3921
bool HTMLMediaElement::hasClosedCaptions() const
3927
bool HTMLMediaElement::hasClosedCaptions() const
3922
{
3928
{
3923
    return m_player && m_player->hasClosedCaptions();
3929
    if (m_player && m_player->hasClosedCaptions())
3930
        return true;
3931
3932
#if ENABLE(VIDEO_TRACK)
3933
    if (RuntimeEnabledFeatures::webkitVideoTrackEnabled() && m_textTracks)
3934
    for (unsigned i = 0; i < m_textTracks->length(); ++i) {
3935
        if (m_textTracks->item(i)->kind() == TextTrack::captionsKeyword()
3936
            || m_textTracks->item(i)->kind() == TextTrack::subtitlesKeyword())
3937
            return true;
3938
    }
3939
#endif
3940
    return false;
3924
}
3941
}
3925
3942
3926
bool HTMLMediaElement::closedCaptionsVisible() const
3943
bool HTMLMediaElement::closedCaptionsVisible() const
Lines 3932-3944 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible) a/Source/WebCore/html/HTMLMediaElement.cpp_sec5
3932
{
3949
{
3933
    LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%s)", boolString(closedCaptionVisible));
3950
    LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%s)", boolString(closedCaptionVisible));
3934
3951
3935
    if (!m_player ||!hasClosedCaptions())
3952
    if (!m_player || !hasClosedCaptions())
3936
        return;
3953
        return;
3937
3954
3938
    m_closedCaptionsVisible = closedCaptionVisible;
3955
    m_closedCaptionsVisible = closedCaptionVisible;
3956
    m_ignoreDefaultTracks = !m_closedCaptionsVisible;
3939
    m_player->setClosedCaptionsVisible(closedCaptionVisible);
3957
    m_player->setClosedCaptionsVisible(closedCaptionVisible);
3958
3959
#if ENABLE(VIDEO_TRACK)    
3960
    if (RuntimeEnabledFeatures::webkitVideoTrackEnabled()) {
3961
        // Check whether existing caption/subtitle tracks should change visibility.
3962
        for (Node* node = firstChild(); node; node = node->nextSibling()) {
3963
            if (!node->hasTagName(trackTag))
3964
                continue;
3965
            HTMLTrackElement* trackElement = static_cast<HTMLTrackElement*>(node);
3966
            trackElement->setHasBeenConfigured(false);
3967
        }
3968
3969
        configureNewTextTracks();
3970
    }
3971
#else
3940
    if (hasMediaControls())
3972
    if (hasMediaControls())
3941
        mediaControls()->changedClosedCaptionsVisibility();
3973
        mediaControls()->changedClosedCaptionsVisibility();
3974
#endif
3942
}
3975
}
3943
3976
3944
void HTMLMediaElement::setWebkitClosedCaptionsVisible(bool visible)
3977
void HTMLMediaElement::setWebkitClosedCaptionsVisible(bool visible)
Lines 4102-4113 void HTMLMediaElement::configureTextTrackDisplay() a/Source/WebCore/html/HTMLMediaElement.cpp_sec6
4102
    if (m_haveVisibleTextTrack == haveVisibleTextTrack)
4135
    if (m_haveVisibleTextTrack == haveVisibleTextTrack)
4103
        return;
4136
        return;
4104
    m_haveVisibleTextTrack = haveVisibleTextTrack;
4137
    m_haveVisibleTextTrack = haveVisibleTextTrack;
4138
    m_closedCaptionsVisible = m_haveVisibleTextTrack;
4105
4139
4106
    if (!m_haveVisibleTextTrack && !hasMediaControls())
4140
    if (!m_haveVisibleTextTrack && !hasMediaControls())
4107
        return;
4141
        return;
4108
    if (!hasMediaControls() && !createMediaControls())
4142
    if (!hasMediaControls() && !createMediaControls())
4109
        return;
4143
        return;
4110
    mediaControls()->updateTextTrackDisplay();
4144
4145
    updateClosedCaptionsControls();
4146
}
4147
4148
void HTMLMediaElement::updateClosedCaptionsControls()
4149
{
4150
    if (hasMediaControls()) {
4151
        mediaControls()->changedClosedCaptionsVisibility();
4152
4153
        if (RuntimeEnabledFeatures::webkitVideoTrackEnabled())
4154
            mediaControls()->updateTextTrackDisplay();
4155
    }
4111
}
4156
}
4112
#endif
4157
#endif
4113
4158
- a/Source/WebCore/html/HTMLMediaElement.h +2 lines
Lines 242-247 public: a/Source/WebCore/html/HTMLMediaElement.h_sec1
242
    bool userIsInterestedInThisTrackKind(String) const;
242
    bool userIsInterestedInThisTrackKind(String) const;
243
    bool textTracksAreReady() const;
243
    bool textTracksAreReady() const;
244
    void configureTextTrackDisplay();
244
    void configureTextTrackDisplay();
245
    void updateClosedCaptionsControls();
245
246
246
    // TextTrackClient
247
    // TextTrackClient
247
    virtual void textTrackReadyStateChanged(TextTrack*);
248
    virtual void textTrackReadyStateChanged(TextTrack*);
Lines 653-658 private: a/Source/WebCore/html/HTMLMediaElement.h_sec2
653
654
654
    CueList m_currentlyActiveCues;
655
    CueList m_currentlyActiveCues;
655
    int m_ignoreTrackDisplayUpdate;
656
    int m_ignoreTrackDisplayUpdate;
657
    bool m_ignoreDefaultTracks;
656
#endif
658
#endif
657
659
658
#if ENABLE(WEB_AUDIO)
660
#if ENABLE(WEB_AUDIO)
- a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp +25 lines
Lines 84-89 MediaControlRootElementChromium::MediaControlRootElementChromium(Document* docum a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp_sec1
84
    , m_timeline(0)
84
    , m_timeline(0)
85
    , m_panelMuteButton(0)
85
    , m_panelMuteButton(0)
86
    , m_volumeSlider(0)
86
    , m_volumeSlider(0)
87
    , m_toggleClosedCaptionsButton(0)
87
    , m_fullscreenButton(0)
88
    , m_fullscreenButton(0)
88
    , m_panel(0)
89
    , m_panel(0)
89
    , m_enclosure(0)
90
    , m_enclosure(0)
Lines 164-169 bool MediaControlRootElementChromium::initializeControls(Document* document) a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp_sec2
164
    if (ec)
165
    if (ec)
165
        return false;
166
        return false;
166
167
168
    if (document->page()->theme()->supportsClosedCaptioning()) {
169
        RefPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(document);
170
        m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get();
171
        panel->appendChild(toggleClosedCaptionsButton.release(), ec, true);
172
        if (ec)
173
            return false;
174
    }
175
167
    RefPtr<MediaControlFullscreenButtonElement> fullscreenButton = MediaControlFullscreenButtonElement::create(document, this);
176
    RefPtr<MediaControlFullscreenButtonElement> fullscreenButton = MediaControlFullscreenButtonElement::create(document, this);
168
    m_fullscreenButton = fullscreenButton.get();
177
    m_fullscreenButton = fullscreenButton.get();
169
    panel->appendChild(fullscreenButton.release(), ec, true);
178
    panel->appendChild(fullscreenButton.release(), ec, true);
Lines 201-206 void MediaControlRootElementChromium::setMediaController(MediaControllerInterfac a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp_sec3
201
        m_panelMuteButton->setMediaController(controller);
210
        m_panelMuteButton->setMediaController(controller);
202
    if (m_volumeSlider)
211
    if (m_volumeSlider)
203
        m_volumeSlider->setMediaController(controller);
212
        m_volumeSlider->setMediaController(controller);
213
    if (m_toggleClosedCaptionsButton)
214
        m_toggleClosedCaptionsButton->setMediaController(controller);
204
    if (m_fullscreenButton)
215
    if (m_fullscreenButton)
205
        m_fullscreenButton->setMediaController(controller);
216
        m_fullscreenButton->setMediaController(controller);
206
    if (m_panel)
217
    if (m_panel)
Lines 265-270 void MediaControlRootElementChromium::reset() a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp_sec4
265
        }
276
        }
266
    }
277
    }
267
278
279
    if (m_toggleClosedCaptionsButton) {
280
        if (m_mediaController->hasClosedCaptions())
281
            m_toggleClosedCaptionsButton->show();
282
        else
283
            m_toggleClosedCaptionsButton->hide();
284
    }
285
268
    if (m_mediaController->supportsFullscreen() && m_mediaController->hasVideo())
286
    if (m_mediaController->supportsFullscreen() && m_mediaController->hasVideo())
269
        m_fullscreenButton->show();
287
        m_fullscreenButton->show();
270
    else
288
    else
Lines 332-337 void MediaControlRootElementChromium::reportedError() a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp_sec5
332
350
333
    m_panelMuteButton->hide();
351
    m_panelMuteButton->hide();
334
    m_volumeSlider->hide();
352
    m_volumeSlider->hide();
353
    if (m_toggleClosedCaptionsButton)
354
        m_toggleClosedCaptionsButton->hide();
335
    m_fullscreenButton->hide();
355
    m_fullscreenButton->hide();
336
}
356
}
337
357
Lines 417-422 void MediaControlRootElementChromium::stopHideFullscreenControlsTimer() a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp_sec6
417
437
418
void MediaControlRootElementChromium::changedClosedCaptionsVisibility()
438
void MediaControlRootElementChromium::changedClosedCaptionsVisibility()
419
{
439
{
440
    if (m_toggleClosedCaptionsButton)
441
        m_toggleClosedCaptionsButton->updateDisplayType();
420
}
442
}
421
443
422
void MediaControlRootElementChromium::changedMute()
444
void MediaControlRootElementChromium::changedMute()
Lines 465-470 void MediaControlRootElementChromium::createTextTrackDisplay() a/Source/WebCore/html/shadow/MediaControlRootElementChromium.cpp_sec7
465
    RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaControlTextTrackContainerElement::create(document());
487
    RefPtr<MediaControlTextTrackContainerElement> textDisplayContainer = MediaControlTextTrackContainerElement::create(document());
466
    m_textDisplayContainer = textDisplayContainer.get();
488
    m_textDisplayContainer = textDisplayContainer.get();
467
489
490
    if (m_mediaController)
491
        m_textDisplayContainer->setMediaController(m_mediaController);
492
468
    // Insert it before the first controller element so it always displays behind the controls.
493
    // Insert it before the first controller element so it always displays behind the controls.
469
    insertBefore(textDisplayContainer.release(), m_enclosure, ASSERT_NO_EXCEPTION, true);
494
    insertBefore(textDisplayContainer.release(), m_enclosure, ASSERT_NO_EXCEPTION, true);
470
}
495
}
- a/Source/WebCore/html/shadow/MediaControlRootElementChromium.h +2 lines
Lines 44-49 class MediaControlCurrentTimeDisplayElement; a/Source/WebCore/html/shadow/MediaControlRootElementChromium.h_sec1
44
class MediaControlTimeRemainingDisplayElement;
44
class MediaControlTimeRemainingDisplayElement;
45
class MediaControlTimelineElement;
45
class MediaControlTimelineElement;
46
class MediaControlVolumeSliderElement;
46
class MediaControlVolumeSliderElement;
47
class MediaControlToggleClosedCaptionsButtonElement;
47
class MediaControlFullscreenButtonElement;
48
class MediaControlFullscreenButtonElement;
48
class MediaControlTimeDisplayElement;
49
class MediaControlTimeDisplayElement;
49
class MediaControlTimelineContainerElement;
50
class MediaControlTimelineContainerElement;
Lines 146-151 private: a/Source/WebCore/html/shadow/MediaControlRootElementChromium.h_sec2
146
    MediaControlTimelineElement* m_timeline;
147
    MediaControlTimelineElement* m_timeline;
147
    MediaControlPanelMuteButtonElement* m_panelMuteButton;
148
    MediaControlPanelMuteButtonElement* m_panelMuteButton;
148
    MediaControlVolumeSliderElement* m_volumeSlider;
149
    MediaControlVolumeSliderElement* m_volumeSlider;
150
    MediaControlToggleClosedCaptionsButtonElement* m_toggleClosedCaptionsButton;
149
    MediaControlFullscreenButtonElement* m_fullscreenButton;
151
    MediaControlFullscreenButtonElement* m_fullscreenButton;
150
    MediaControlPanelElement* m_panel;
152
    MediaControlPanelElement* m_panel;
151
    MediaControlPanelEnclosureElement* m_enclosure;
153
    MediaControlPanelEnclosureElement* m_enclosure;
- a/LayoutTests/ChangeLog +12 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2012-08-23  Anna Cavender  <annacc@chromium.org>
2
3
        Create a toggle button for closed captions.
4
        https://bugs.webkit.org/show_bug.cgi?id=94395
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        This patch will create a button that toggles any captions or subtitles on or off.
9
10
        * media/video-controls-captions-expected.txt: Added.
11
        * media/video-controls-captions.html: Added.
12
1
2012-08-23  Shinya Kawanaka  <shinyak@chromium.org>
13
2012-08-23  Shinya Kawanaka  <shinyak@chromium.org>
2
14
3
        Needs update tests of Shadow DOM for keygen
15
        Needs update tests of Shadow DOM for keygen
- a/LayoutTests/media/video-controls-captions-expected.txt +12 lines
Line 0 a/LayoutTests/media/video-controls-captions-expected.txt_sec1
1
Tests that the closed captions button, when toggled, updates the text track display area. 
2
3
** Captions should be initially visible **
4
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'display').parentNode).display == 'block') OK
5
6
** Captions should not be visible after button is clicked **
7
No text track cue with display id '-webkit-media-text-track-display' is currently visible
8
9
** Captions should be visible again after button is clicked again **
10
EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'display').parentNode).display == 'block') OK
11
END OF TEST
12
- a/LayoutTests/media/video-controls-captions.html +73 lines
Line 0 a/LayoutTests/media/video-controls-captions.html_sec1
1
<html>
2
<head>
3
    <title>Test closed caption button toggling.</title>
4
    <script src=media-file.js></script>
5
    <script src=media-controls.js></script>
6
    <script src=video-test.js></script>
7
    <script>
8
        var captionsButtonCoordinates;
9
10
        function startTest()
11
        {
12
            consoleWrite("");
13
            consoleWrite("** Captions should be initially visible **");
14
            checkCaptionsDisplay();
15
16
            if (window.eventSender) {
17
                try {
18
                    captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggle-closed-captions-button");
19
                } catch (exception) {
20
                    testRunner.notifyDone();
21
                    return;
22
                }
23
24
                consoleWrite("");       
25
                consoleWrite("** Captions should not be visible after button is clicked **");
26
                clickCCButton();
27
                checkCaptionsDisplay();
28
29
                consoleWrite("");
30
                consoleWrite("** Captions should be visible again after button is clicked again **");
31
                clickCCButton();
32
                checkCaptionsDisplay();
33
34
                endTest();
35
36
            } else {
37
                failTest();
38
            }
39
        }
40
41
        function clickCCButton()
42
        {
43
            eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
44
            eventSender.mouseDown();
45
            eventSender.mouseUp();
46
        }
47
48
        function checkCaptionsDisplay()
49
        {
50
            // The display type is "block" when visible, otherwise there is no cue to display.
51
            testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').parentNode).display", "block");
52
        }
53
54
        function loaded()
55
        {
56
            findMediaElement();
57
            var testTrack = document.querySelector('track');
58
59
            waitForEventsAndCall([[video, 'canplaythrough'], [testTrack, 'load']], startTest);
60
61
            video.src = findMediaFile('video', 'content/counting');
62
        }
63
64
    </script>
65
</head>
66
<body onload="loaded()">
67
    Tests that the closed captions button, when toggled, updates the text track display area. <br>
68
    <video controls >
69
        <track src="track/captions-webvtt/captions-fast.vtt" kind="captions" default >
70
    </video>
71
72
</body>
73
</html>

Return to Bug 94395