• eric.carlson@apple.com's avatar
    [Mac] add "automatic" text track menu item · 44f8c684
    eric.carlson@apple.com authored
    https://bugs.webkit.org/show_bug.cgi?id=113822
    
    Reviewed by Jer Noble.
    
    Source/WebCore: 
    
    No new tests, existing tests updated.
    
    * English.lproj/Localizable.strings: Add new track menu item.
    
    * html/HTMLMediaElement.cpp: 
    (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_captionDisplayMode.
    (WebCore::HTMLMediaElement::finishParsingChildren): LoadTextTrackResource -> ConfigureTextTracks.
    (WebCore::HTMLMediaElement::scheduleDelayedAction): Ditto.
    (WebCore::HTMLMediaElement::loadTimerFired): Ditto.
    (WebCore::HTMLMediaElement::loadInternal): Ditto. Flag the caption menu as invalid so it will
        be rebuilt again.
    (WebCore::HTMLMediaElement::mediaPlayerDidAddTrack): LoadTextTrackResource -> ConfigureTextTracks.
    (WebCore::HTMLMediaElement::didAddTrack): Ditto.
    (WebCore::HTMLMediaElement::configureTextTrackGroup): Deal with new track display modes.
    (WebCore::HTMLMediaElement::HTMLMediaElement::hasClosedCaptions): Minor cleanup.
    (WebCore::HTMLMediaElement::configureTextTrackGroup): Add some logging.
    (WebCore::HTMLMediaElement::configureTextTracks): Call updateActiveTextTrackCues so cue display
        is updated.
    (WebCore::HTMLMediaElement::captionPreferencesChanged): Deal with new track display modes.
    (WebCore::HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured): Add some logging.
    * html/HTMLMediaElement.h: Ditto.
    
    * html/shadow/MediaControlElementTypes.cpp: Remove trackIndexAttributeName and trackListIndexForElement.
    * html/shadow/MediaControlElementTypes.h: Ditto.
    
    * html/shadow/MediaControlElements.cpp:
    (WebCore::MediaControlClosedCaptionsTrackListElement::defaultEventHandler): Don't use track index,
        everything we need is in the track<->element map now.
    (WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): Ditto. Always rebuild the 
        track list because clear the map each time the menu goes away because it refs every track.
    (WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu): Don't set the track
        index attribute on the menu items, just use the map.
    * html/shadow/MediaControlElements.h:
    
    * html/shadow/MediaControlsApple.cpp:
    (WebCore::MediaControlsApple::changedClosedCaptionsVisibility): resetTrackListMenu is gone.
    (WebCore::MediaControlsApple::reset): Ditto.
    (WebCore::MediaControlsApple::closedCaptionTracksChanged): Ditto.
    
    * html/track/TextTrack.cpp:
    (WebCore::TextTrack::captionMenuOffItem): New, static TextTrack used for the menu "Off" item.
    (WebCore::TextTrack::captionMenuAutomaticItem): New, static TextTrack used for the menu "Automatic" item.
    * html/track/TextTrack.h:
    
    * page/CaptionUserPreferences.cpp:
    (WebCore::CaptionUserPreferences::shouldShowCaptions): Removed, we use captionDisplayMode instead.
    (WebCore::CaptionUserPreferences::captionDisplayMode): New.
    (WebCore::CaptionUserPreferences::setCaptionDisplayMode): New.
    (WebCore::CaptionUserPreferences::setPreferredLanguage): Make the parameter a const reference.
    (WebCore::CaptionUserPreferences::textTrackSelectionScore): Return 0 if the user doesn't want
        captions or subtitles.
    (WebCore::CaptionUserPreferences::textTrackLanguageSelectionScore): Take language as a parameter
        instead of assuming that it is always the entire language list.
    * page/CaptionUserPreferences.h:
    
    * page/CaptionUserPreferencesMac.h:
    * page/CaptionUserPreferencesMac.mm:
    (WebCore::CaptionUserPreferencesMac::shouldShowCaptions): Removed, we use captionDisplayMode instead.
    (WebCore::CaptionUserPreferencesMac::captionDisplayMode): New.
    (WebCore::CaptionUserPreferencesMac::setCaptionDisplayMode): New.
    (WebCore::CaptionUserPreferencesMac::setPreferredLanguage): Make the parameter a const reference.
    (WebCore::CaptionUserPreferencesMac::textTrackSelectionScore): Deal with "Automatic" mode.
        captions or subtitles.
    (WebCore::CaptionUserPreferences::textTrackLanguageSelectionScore): Take language as a parameter
        instead of assuming that it is always the entire language list.
    (WebCore::CaptionUserPreferencesMac::sortedTrackListForMenu): Insert "Off" and "Automatic" items.
    
    * platform/LocalizedStrings.cpp:
    (WebCore::textTrackAutomaticMenuItemText): New.
    * platform/LocalizedStrings.h:
    
    * platform/graphics/MediaPlayer.cpp:
    (WebCore::MediaPlayer::languageOfPrimaryAudioTrack): New.
    * platform/graphics/MediaPlayer.h:
    * platform/graphics/MediaPlayerPrivate.h:
    
    * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
    * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
    (WebCore::MediaPlayerPrivateAVFoundationObjC::languageOfPrimaryAudioTrack): Return the language
        of the main audio track.
    
    LayoutTests: 
    
    * media/media-captions.html: Opportunistic fix - don't look at state until we get the 'canplaythrough'
        event because the media engine state may not have been processed until that time.
    * media/track/track-cue-container-rendering-position.html: Don't assume that a cue has been 
        rendered immediately when the 'canplaythrough' event comes through.
    * media/track/track-cue-rendering-mode-changed.html: Ditto.
    * media/track/track-in-band-expected.txt: Don't check if cues have loaded, it doesn't matter
        for this test.
    * media/track/track-in-band.html: Ditto.
    * media/track/track-user-preferences-expected.txt: Changed name of utility function from 
        menuIndexForLanguage to indexOfMenuItemBeginningWith.
    * media/track/track-user-preferences.html: Move menuIndexForLanguage to trackmenu-test.js and
        change name to indexOfMenuItemBeginningWith. Clarify the message logged when a track loads
        but it should not.
    * media/trackmenu-test.js: Move some functions here from track-user-preferences.html
    (trackMenuList):
    (indexOfMenuItemBeginningWith):
    (selectCaptionMenuItem):
    * media/video-controls-captions-trackmenu-sorted.html: Update for new menu item.
    * media/video-controls-captions-trackmenu.html: Ditto.
    * platform/mac/media/video-controls-captions-trackmenu-expected.txt: Ditto.
    * platform/mac/media/video-controls-captions-trackmenu-sorted-expected.txt: Ditto.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    44f8c684
CaptionUserPreferences.h 3.6 KB