Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: Source/core/html/track/AutomaticTrackSelection.cpp

Issue 1118613002: Hook up Android closed captions 'enabled' setting to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed lgtm comment and rebased Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1a9dd43693ca1b66d1df0d085438896f3aaf24e2 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() const
+{
+ 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,16 +117,14 @@ 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) {
« no previous file with comments | « Source/core/html/track/AutomaticTrackSelection.h ('k') | Source/core/html/track/TextTrackKindUserPreference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698