Changeset 135934 in webkit


Ignore:
Timestamp:
Nov 27, 2012 3:45:13 PM (11 years ago)
Author:
dino@apple.com
Message:

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:
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r135928 r135934  
     12012-11-27  Dean Jackson  <dino@apple.com>
     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
    1252012-11-27  Tony Chang  <tony@chromium.org>
    226
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r135928 r135934  
    37083708webkit.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.
     3711webkit.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
  • trunk/LayoutTests/platform/efl/TestExpectations

    r135919 r135934  
    17051705webkit.org/b/102493 fast/events/mouse-cursor.html [ Failure ]
    17061706
     1707# EFL still has the CC toggle button, not the menu of tracks.
     1708webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
     1709
    17071710# Fails until we enable the Resource Timing API.
    17081711webkit.org/b/61138 http/tests/w3c/webperf/submission/resource-timing [ Skip ]
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r135926 r135934  
    14001400webkit.org/b/102993 media/video-zoom-controls.html [ Failure ]
    14011401
     1402# GTK still has the CC toggle button, not the menu of tracks.
     1403webkit.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
    14031406webkit.org/b/102776 webkit.org/b/102993 media/media-document-audio-repaint.html [ Failure ]
  • trunk/LayoutTests/platform/mac/TestExpectations

    r135919 r135934  
    12151215webkit.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.
     1218webkit.org/b/101670 media/video-controls-captions.html [ Skip ]
     1219
    12171220# Overflowing LayoutUnits cause RenderGeometryMap assertions
    12181221webkit.org/b/67434 [ Debug ] fast/overflow/overflow-height-float-not-removed-crash.html [ Skip ]
  • trunk/LayoutTests/platform/qt/TestExpectations

    r135917 r135934  
    23832383webkit.org/b/102993 fast/repaint/slider-thumb-float.html [ Failure ]
    23842384
     2385# QT still has the CC toggle button, not the menu of tracks.
     2386webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
     2387
    23852388# New, but failing test
    23862389webkit.org/b/101035 fast/images/exif-orientation-image-document.html
  • trunk/LayoutTests/platform/win/TestExpectations

    r135913 r135934  
    23502350webkit.org/b/98666 webkit.org/b/102993 fast/repaint/slider-thumb-float.html [ Failure ]
    23512351
     2352# Win doesn't support track menu
     2353webkit.org/b/101670 media/video-controls-captions-trackmenu.html [ Skip ]
     2354
    23522355#https://bugs.webkit.org/show_bug.cgi?id=98079
    23532356http/tests/security/cross-origin-local-storage-wk1.html
  • trunk/Source/WebCore/ChangeLog

    r135927 r135934  
     12012-11-27  Dean Jackson  <dino@apple.com>
     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
    1392012-11-27  Joshua Bell  <jsbell@chromium.org>
    240
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r135906 r135934  
    29992999}
    30003000
     3001void 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
    30013017void HTMLMediaElement::configureTextTracks()
    30023018{
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r135886 r135934  
    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;
  • trunk/Source/WebCore/html/shadow/MediaControlElements.cpp

    r134507 r135934  
    3737#include "DOMTokenList.h"
    3838#include "EventNames.h"
     39#include "EventTarget.h"
    3940#include "FloatConversion.h"
    4041#include "FloatPoint.h"
     
    6465#include "Text.h"
    6566#if ENABLE(VIDEO_TRACK)
     67#include "TextTrack.h"
    6668#include "TextTrackList.h"
    6769#endif
     
    7779static const float cScanRepeatDelay = 1.5f;
    7880static const float cScanMaximumRate = 8;
     81
     82#if ENABLE(VIDEO_TRACK)
     83static const char* textTracksOffAttrValue = "-1"; // This must match HTMLMediaElement::textTracksOffIndex()
     84static const int textTracksIndexNotFound = -2;
     85#endif
    7986
    8087HTMLMediaElement* toParentMediaElement(Node* node)
     
    99106    return static_cast<MediaControlElement*>(element)->displayType();
    100107}
     108
     109#if ENABLE(VIDEO_TRACK)
     110static const AtomicString& trackIndexAttributeName()
     111{
     112    DEFINE_STATIC_LOCAL(AtomicString, name, ("x-webkit-track-index", AtomicString::ConstructFromLiteral));
     113    return name;
     114}
     115
     116static int trackListIndexForElement(Element* element)
     117{
     118    const AtomicString trackIndexAttributeValue = element->getAttribute(trackIndexAttributeName());
     119    if (trackIndexAttributeValue.isNull() || trackIndexAttributeValue.isEmpty())
     120        return textTracksIndexNotFound;
     121    bool ok;
     122    int trackIndex = trackIndexAttributeValue.toInt(&ok);
     123    if (!ok)
     124        return textTracksIndexNotFound;
     125    return trackIndex;
     126}
     127#endif
    101128
    102129// ----------------------------
     
    902929void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType()
    903930{
    904     setDisplayType(mediaController()->closedCaptionsVisible() ? MediaHideClosedCaptionsButton : MediaShowClosedCaptionsButton);
     931    bool captionsVisible = mediaController()->closedCaptionsVisible();
     932    setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowClosedCaptionsButton);
     933    setChecked(captionsVisible);
    905934}
    906935
     
    908937{
    909938    if (event->type() == eventNames().clickEvent) {
    910         // FIXME: This is now incorrectly doing two things at once: showing the list of captions and toggling display.
    911         // https://bugs.webkit.org/show_bug.cgi?id=101670
     939        // FIXME: It's not great that the shared code is dictating behavior of platform-specific
     940        // UI. Not all ports may want the closed captions button to toggle a list of tracks, so
     941        // we have to use #if.
     942        // https://bugs.webkit.org/show_bug.cgi?id=101877
     943#if !PLATFORM(MAC)
    912944        mediaController()->setClosedCaptionsVisible(!mediaController()->closedCaptionsVisible());
    913945        setChecked(mediaController()->closedCaptionsVisible());
     946        updateDisplayType();
     947#else
    914948        m_controls->toggleClosedCaptionTrackList();
    915         updateDisplayType();
     949#endif
    916950        event->setDefaultHandled();
    917951    }
     
    928962// ----------------------------
    929963
    930 inline MediaControlClosedCaptionsTrackListElement::MediaControlClosedCaptionsTrackListElement(Document* document)
     964inline MediaControlClosedCaptionsTrackListElement::MediaControlClosedCaptionsTrackListElement(Document* document, MediaControls* controls)
    931965    : MediaControlElement(document)
    932 {
    933 }
    934 
    935 PassRefPtr<MediaControlClosedCaptionsTrackListElement> MediaControlClosedCaptionsTrackListElement::create(Document* document)
    936 {
    937     RefPtr<MediaControlClosedCaptionsTrackListElement> element = adoptRef(new MediaControlClosedCaptionsTrackListElement(document));
     966    , m_controls(controls)
     967{
     968}
     969
     970PassRefPtr<MediaControlClosedCaptionsTrackListElement> MediaControlClosedCaptionsTrackListElement::create(Document* document, MediaControls* controls)
     971{
     972    ASSERT(controls);
     973    RefPtr<MediaControlClosedCaptionsTrackListElement> element = adoptRef(new MediaControlClosedCaptionsTrackListElement(document, controls));
    938974    return element.release();
    939975}
     
    941977void MediaControlClosedCaptionsTrackListElement::defaultEventHandler(Event* event)
    942978{
    943     // FIXME: Hook this up to actual text tracks.
    944     // https://bugs.webkit.org/show_bug.cgi?id=101670
    945     UNUSED_PARAM(event);
     979#if ENABLE(VIDEO_TRACK)
     980    if (event->type() == eventNames().clickEvent) {
     981        // FIXME: Add modifier key for exclusivity override.
     982        // http://webkit.org/b/103361
     983
     984        Node* target = event->target()->toNode();
     985        if (!target || !target->isElementNode())
     986            return;
     987
     988        // When we created the elements in the track list, we gave them a custom
     989        // attribute representing the index in the HTMLMediaElement's list of tracks.
     990        // Check if the event target has such a custom element and, if so,
     991        // tell the HTMLMediaElement to enable that track.
     992
     993        int trackIndex = trackListIndexForElement(toElement(target));
     994        if (trackIndex == textTracksIndexNotFound)
     995            return;
     996       
     997        HTMLMediaElement* mediaElement = toParentMediaElement(this);
     998        if (!mediaElement)
     999            return;
     1000
     1001        mediaElement->toggleTrackAtIndex(trackIndex);
     1002
     1003        // We've selected a track to display, so we can now close the menu.
     1004        m_controls->toggleClosedCaptionTrackList();
     1005        updateDisplay();
     1006    }
     1007
     1008    MediaControlElement::defaultEventHandler(event);
     1009#endif
    9461010}
    9471011
     
    9531017
    9541018void MediaControlClosedCaptionsTrackListElement::updateDisplay()
     1019{
     1020#if ENABLE(VIDEO_TRACK)
     1021    DEFINE_STATIC_LOCAL(AtomicString, selectedClassValue, ("selected", AtomicString::ConstructFromLiteral));
     1022
     1023    if (!mediaController()->hasClosedCaptions())
     1024        return;
     1025
     1026    HTMLMediaElement* mediaElement = toParentMediaElement(this);
     1027    if (!mediaElement)
     1028        return;
     1029
     1030    TextTrackList* trackList = mediaElement->textTracks();
     1031
     1032    if (!trackList || !trackList->length())
     1033        return;
     1034
     1035    bool captionsVisible = mediaElement->closedCaptionsVisible();
     1036    for (unsigned i = 0, length = menuItems.size(); i < length; ++i) {
     1037        RefPtr<Element> trackItem = menuItems[i];
     1038        int trackIndex = trackListIndexForElement(trackItem.get());
     1039        if (trackIndex != textTracksIndexNotFound) {
     1040            if (trackIndex == HTMLMediaElement::textTracksOffIndex()) {
     1041                if (captionsVisible)
     1042                    trackItem->classList()->remove(selectedClassValue, ASSERT_NO_EXCEPTION);
     1043                else
     1044                    trackItem->classList()->add(selectedClassValue, ASSERT_NO_EXCEPTION);
     1045            } else {
     1046                TextTrack* track = trackList->item(trackIndex);
     1047                if (!track)
     1048                    continue;
     1049                if (track->mode() == TextTrack::showingKeyword())
     1050                    trackItem->classList()->add(selectedClassValue, ASSERT_NO_EXCEPTION);
     1051                else
     1052                    trackItem->classList()->remove(selectedClassValue, ASSERT_NO_EXCEPTION);
     1053            }
     1054        }
     1055    }
     1056#endif
     1057}
     1058
     1059void MediaControlClosedCaptionsTrackListElement::resetTrackListMenu()
    9551060{
    9561061#if ENABLE(VIDEO_TRACK)
    9571062    // Remove any existing content.
    9581063    removeChildren();
     1064    menuItems.clear();
    9591065
    9601066    if (!mediaController()->hasClosedCaptions())
     
    9881094    trackItem = doc->createElement(liTag, ASSERT_NO_EXCEPTION);
    9891095    trackItem->appendChild(doc->createTextNode("Off"));
    990     // FIXME: These lists are not yet live. Mark the Off entry as the selected one for now.
    991     trackItem->setAttribute(classAttr, "selected");
     1096    trackItem->setAttribute(trackIndexAttributeName(), textTracksOffAttrValue, ASSERT_NO_EXCEPTION);
    9921097    captionsList->appendChild(trackItem);
     1098    menuItems.append(trackItem);
    9931099
    9941100    trackItem = doc->createElement(liTag, ASSERT_NO_EXCEPTION);
    9951101    trackItem->appendChild(doc->createTextNode("Off"));
    996     // FIXME: These lists are not yet live. Mark the Off entry as the selected one for now.
    997     trackItem->setAttribute(classAttr, "selected");
     1102    trackItem->setAttribute(trackIndexAttributeName(), textTracksOffAttrValue, ASSERT_NO_EXCEPTION);
    9981103    subtitlesList->appendChild(trackItem);
     1104    menuItems.append(trackItem);
    9991105
    10001106    bool hasCaptions = false;
     
    10041110        TextTrack* track = trackList->item(i);
    10051111        trackItem = doc->createElement(liTag, ASSERT_NO_EXCEPTION);
     1112
     1113        // Add a custom attribute to the <li> element which will allow
     1114        // us to easily associate the user tapping here with the
     1115        // track. Since this list is rebuilt if the tracks change, we
     1116        // should always be in sync.
     1117        trackItem->setAttribute(trackIndexAttributeName(), String::number(i), ASSERT_NO_EXCEPTION);
     1118
    10061119        AtomicString labelText = track->label();
    10071120        if (labelText.isNull() || labelText.isEmpty())
     
    10191132        }
    10201133        trackItem->appendChild(doc->createTextNode(labelText));
     1134        menuItems.append(trackItem);
    10211135    }
    10221136
     
    10281142    if (hasSubtitles)
    10291143        appendChild(subtitlesSection);
     1144
     1145    updateDisplay();
    10301146#endif
    10311147}
  • trunk/Source/WebCore/html/shadow/MediaControlElements.h

    r134507 r135934  
    416416class MediaControlClosedCaptionsTrackListElement : public MediaControlElement {
    417417public:
    418     static PassRefPtr<MediaControlClosedCaptionsTrackListElement> create(Document*);
     418    static PassRefPtr<MediaControlClosedCaptionsTrackListElement> create(Document*, MediaControls*);
    419419
    420420    virtual void defaultEventHandler(Event*);
     
    422422
    423423    void updateDisplay();
    424 
    425 private:
    426     MediaControlClosedCaptionsTrackListElement(Document*);
     424    void resetTrackListMenu();
     425
     426private:
     427    MediaControlClosedCaptionsTrackListElement(Document*, MediaControls*);
    427428
    428429    virtual MediaControlElementType displayType() const { return MediaClosedCaptionsTrackList; }
    429430    virtual const AtomicString& shadowPseudoId() const;
     431
     432    typedef Vector<RefPtr<Element> > TrackMenuItems;
     433    TrackMenuItems menuItems;
     434    MediaControls* m_controls;
    430435};
    431436
  • trunk/Source/WebCore/html/shadow/MediaControlsApple.cpp

    r134507 r135934  
    150150        RefPtr<MediaControlClosedCaptionsContainerElement> closedCaptionsContainer = MediaControlClosedCaptionsContainerElement::create(document);
    151151
    152         RefPtr<MediaControlClosedCaptionsTrackListElement> closedCaptionsTrackList = MediaControlClosedCaptionsTrackListElement::create(document);
     152        RefPtr<MediaControlClosedCaptionsTrackListElement> closedCaptionsTrackList = MediaControlClosedCaptionsTrackListElement::create(document, controls.get());
    153153        controls->m_closedCaptionsTrackList = closedCaptionsTrackList.get();
    154154        closedCaptionsContainer->appendChild(closedCaptionsTrackList.release(), ec, true);
     
    290290}
    291291
     292void MediaControlsApple::changedClosedCaptionsVisibility()
     293{
     294    MediaControls::changedClosedCaptionsVisibility();
     295    if (m_closedCaptionsTrackList)
     296        m_closedCaptionsTrackList->updateDisplay();
     297}
     298
    292299void MediaControlsApple::reset()
    293300{
     
    324331            m_toggleClosedCaptionsButton->show();
    325332            if (m_closedCaptionsTrackList)
    326                 m_closedCaptionsTrackList->updateDisplay();
     333                m_closedCaptionsTrackList->resetTrackListMenu();
    327334        } else
    328335            m_toggleClosedCaptionsButton->hide();
  • trunk/Source/WebCore/html/shadow/MediaControlsApple.h

    r134507 r135934  
    5959    virtual void updateStatusDisplay() OVERRIDE;
    6060
     61    virtual void changedClosedCaptionsVisibility() OVERRIDE;
    6162    void toggleClosedCaptionTrackList();
    6263
Note: See TracChangeset for help on using the changeset viewer.