[Mac] add "automatic" text track menu item
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Apr 2013 22:23:47 +0000 (22:23 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Apr 2013 22:23:47 +0000 (22:23 +0000)
commitb0227f40a29769a3e312ce6b44dd55857a0a5cd9
treef4dedcbec1d9558c0c8dd2ec7f03789171172ee7
parente2ef42a0ea513c8c229ef781d7ef145664b28bc4
[Mac] add "automatic" text track menu item
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: https://svn.webkit.org/repository/webkit/trunk@147675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
35 files changed:
LayoutTests/ChangeLog
LayoutTests/media/media-captions.html
LayoutTests/media/track/track-cue-container-rendering-position.html
LayoutTests/media/track/track-cue-rendering-mode-changed.html
LayoutTests/media/track/track-in-band-expected.txt
LayoutTests/media/track/track-in-band.html
LayoutTests/media/track/track-user-preferences-expected.txt
LayoutTests/media/track/track-user-preferences.html
LayoutTests/media/trackmenu-test.js
LayoutTests/media/video-controls-captions-trackmenu-sorted.html
LayoutTests/media/video-controls-captions-trackmenu.html
LayoutTests/platform/mac/media/video-controls-captions-trackmenu-expected.txt
LayoutTests/platform/mac/media/video-controls-captions-trackmenu-sorted-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/English.lproj/Localizable.strings
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/shadow/MediaControlElementTypes.cpp
Source/WebCore/html/shadow/MediaControlElementTypes.h
Source/WebCore/html/shadow/MediaControlElements.cpp
Source/WebCore/html/shadow/MediaControlElements.h
Source/WebCore/html/shadow/MediaControlsApple.cpp
Source/WebCore/html/track/TextTrack.cpp
Source/WebCore/html/track/TextTrack.h
Source/WebCore/page/CaptionUserPreferences.cpp
Source/WebCore/page/CaptionUserPreferences.h
Source/WebCore/page/CaptionUserPreferencesMac.h
Source/WebCore/page/CaptionUserPreferencesMac.mm
Source/WebCore/platform/LocalizedStrings.cpp
Source/WebCore/platform/LocalizedStrings.h
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm