Index: Source/core/html/track/AutomaticTrackSelection.cpp |
diff --git a/Source/core/html/track/AutomaticTrackSelection.cpp b/Source/core/html/track/AutomaticTrackSelection.cpp |
index 925a3bea2e6ab542bdcb36d668a97a59d13ab080..1fcc703008a60097116ae9b9cce877c7ccb95f09 100644 |
--- a/Source/core/html/track/AutomaticTrackSelection.cpp |
+++ b/Source/core/html/track/AutomaticTrackSelection.cpp |
@@ -62,6 +62,15 @@ AutomaticTrackSelection::AutomaticTrackSelection(const Configuration& configurat |
{ |
} |
+const AtomicString& AutomaticTrackSelection::preferredTrackKind() |
+{ |
+ if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreference::Subtitles) |
+ return TextTrack::subtitlesKeyword(); |
+ if (m_configuration.textTrackKindUserPreference == TextTrackKindUserPreference::Captions) |
+ return TextTrack::captionsKeyword(); |
+ return nullAtom; |
+} |
+ |
void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGroup& group) |
{ |
ASSERT(group.tracks.size()); |
@@ -70,8 +79,11 @@ void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou |
WillBeHeapVector<RefPtrWillBeMember<TextTrack>> currentlyEnabledTracks; |
RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; |
RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; |
+ RefPtrWillBeRawPtr<TextTrack> preferredTrack = nullptr; |
RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; |
+ |
int highestTrackScore = 0; |
+ |
for (size_t i = 0; i < group.tracks.size(); ++i) { |
RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i]; |
@@ -79,24 +91,23 @@ void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou |
currentlyEnabledTracks.append(textTrack); |
int trackScore = textTrackSelectionScore(*textTrack); |
+ |
+ if (textTrack->kind() == preferredTrackKind()) |
+ trackScore += 1; |
if (trackScore) { |
- // * If the text track kind is { [subtitles or captions] [descriptions] } and the user has indicated an interest in having a |
+ // * If the text track kind is subtitles or captions and the user has indicated an interest in having a |
// track with this text track kind, text track language, and text track label enabled, and there is no |
// other text track in the media element's list of text tracks with a text track kind of either subtitles |
// or captions whose text track mode is showing |
- // ... |
- // * If the text track kind is chapters and the text track language is one that the user agent has reason |
- // to believe is appropriate for the user, and there is no other text track in the media element's list of |
- // text tracks with a text track kind of chapters whose text track mode is showing |
// Let the text track mode be showing. |
if (trackScore > highestTrackScore) { |
+ preferredTrack = textTrack; |
highestTrackScore = trackScore; |
- trackToEnable = textTrack; |
} |
- |
if (!defaultTrack && textTrack->isDefault()) |
defaultTrack = textTrack; |
- if (!defaultTrack && !fallbackTrack) |
+ |
+ if (!fallbackTrack) |
fallbackTrack = textTrack; |
} else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault()) { |
// * If the track element has a default attribute specified, and there is no other text track in the media |
@@ -106,22 +117,19 @@ void AutomaticTrackSelection::performAutomaticTextTrackSelection(const TrackGrou |
} |
} |
+ if (m_configuration.textTrackKindUserPreference != TextTrackKindUserPreference::Default) |
+ trackToEnable = preferredTrack; |
+ |
if (!trackToEnable && defaultTrack) |
trackToEnable = defaultTrack; |
- // If no track matches the user's preferred language and non was marked 'default', enable the first track |
- // because the user has explicitly stated a preference for this kind of track. |
- if (!fallbackTrack && m_configuration.forceEnableSubtitleOrCaptionTrack && group.kind == TrackGroup::CaptionsAndSubtitles) |
- fallbackTrack = group.tracks[0]; |
- |
- if (!trackToEnable && fallbackTrack) |
- trackToEnable = fallbackTrack; |
+ if (!trackToEnable && m_configuration.forceEnableSubtitleOrCaptionTrack && group.kind == TrackGroup::CaptionsAndSubtitles) |
+ trackToEnable = fallbackTrack ? fallbackTrack : group.tracks[0]; |
if (currentlyEnabledTracks.size()) { |
for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { |
RefPtrWillBeRawPtr<TextTrack> textTrack = currentlyEnabledTracks[i]; |
- if (textTrack != trackToEnable) |
fs
2015/07/07 08:22:05
Nit: Restore this test.
srivats
2015/07/07 18:44:49
Done.
|
- textTrack->setMode(TextTrack::disabledKeyword()); |
+ textTrack->setMode(TextTrack::disabledKeyword()); |
} |
} |
@@ -162,7 +170,7 @@ void AutomaticTrackSelection::perform(TextTrackList& textTracks) |
String kind = textTrack->kind(); |
TrackGroup* currentGroup; |
- if (kind == TextTrack::subtitlesKeyword() || kind == TextTrack::captionsKeyword()) { |
+ if (kind == TextTrack::captionsKeyword() || kind == TextTrack::subtitlesKeyword()) { |
fs
2015/07/07 08:22:05
Nit: Restore this.
srivats
2015/07/07 18:44:49
Done.
|
currentGroup = &captionAndSubtitleTracks; |
} else if (kind == TextTrack::descriptionsKeyword()) { |
currentGroup = &descriptionTracks; |