| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/track/AutomaticTrackSelection.h" | 5 #include "core/html/track/AutomaticTrackSelection.h" |
| 6 | 6 |
| 7 #include "core/html/track/TextTrack.h" | 7 #include "core/html/track/TextTrack.h" |
| 8 #include "core/html/track/TextTrackList.h" | 8 #include "core/html/track/TextTrackList.h" |
| 9 #include "platform/Language.h" | 9 #include "platform/Language.h" |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 DCHECK(group.tracks.size()); | 68 DCHECK(group.tracks.size()); |
| 69 | 69 |
| 70 // First, find the track in the group that should be enabled (if any). | 70 // First, find the track in the group that should be enabled (if any). |
| 71 HeapVector<Member<TextTrack>> currentlyEnabledTracks; | 71 HeapVector<Member<TextTrack>> currentlyEnabledTracks; |
| 72 TextTrack* trackToEnable = nullptr; | 72 TextTrack* trackToEnable = nullptr; |
| 73 TextTrack* defaultTrack = nullptr; | 73 TextTrack* defaultTrack = nullptr; |
| 74 TextTrack* preferredTrack = nullptr; | 74 TextTrack* preferredTrack = nullptr; |
| 75 TextTrack* fallbackTrack = nullptr; | 75 TextTrack* fallbackTrack = nullptr; |
| 76 int highestTrackScore = 0; | 76 int highestTrackScore = 0; |
| 77 | 77 |
| 78 for (size_t i = 0; i < group.tracks.size(); ++i) { | 78 for (const auto& textTrack : group.tracks) { |
| 79 TextTrack* textTrack = group.tracks[i]; | |
| 80 | |
| 81 if (m_configuration.disableCurrentlyEnabledTracks && | 79 if (m_configuration.disableCurrentlyEnabledTracks && |
| 82 textTrack->mode() == TextTrack::showingKeyword()) | 80 textTrack->mode() == TextTrack::showingKeyword()) |
| 83 currentlyEnabledTracks.append(textTrack); | 81 currentlyEnabledTracks.append(textTrack); |
| 84 | 82 |
| 85 int trackScore = textTrackSelectionScore(*textTrack); | 83 int trackScore = textTrackSelectionScore(*textTrack); |
| 86 | 84 |
| 87 if (textTrack->kind() == preferredTrackKind()) | 85 if (textTrack->kind() == preferredTrackKind()) |
| 88 trackScore += 1; | 86 trackScore += 1; |
| 89 if (trackScore) { | 87 if (trackScore) { |
| 90 // * If the text track kind is subtitles or captions and the user has | 88 // * If the text track kind is subtitles or captions and the user has |
| (...skipping 29 matching lines...) Expand all Loading... |
| 120 | 118 |
| 121 if (!trackToEnable && m_configuration.forceEnableSubtitleOrCaptionTrack && | 119 if (!trackToEnable && m_configuration.forceEnableSubtitleOrCaptionTrack && |
| 122 group.kind == TrackGroup::CaptionsAndSubtitles) { | 120 group.kind == TrackGroup::CaptionsAndSubtitles) { |
| 123 if (fallbackTrack) | 121 if (fallbackTrack) |
| 124 trackToEnable = fallbackTrack; | 122 trackToEnable = fallbackTrack; |
| 125 else | 123 else |
| 126 trackToEnable = group.tracks[0]; | 124 trackToEnable = group.tracks[0]; |
| 127 } | 125 } |
| 128 | 126 |
| 129 if (currentlyEnabledTracks.size()) { | 127 if (currentlyEnabledTracks.size()) { |
| 130 for (size_t i = 0; i < currentlyEnabledTracks.size(); ++i) { | 128 for (const auto& textTrack : currentlyEnabledTracks) { |
| 131 TextTrack* textTrack = currentlyEnabledTracks[i]; | |
| 132 if (textTrack != trackToEnable) | 129 if (textTrack != trackToEnable) |
| 133 textTrack->setMode(TextTrack::disabledKeyword()); | 130 textTrack->setMode(TextTrack::disabledKeyword()); |
| 134 } | 131 } |
| 135 } | 132 } |
| 136 | 133 |
| 137 if (trackToEnable) | 134 if (trackToEnable) |
| 138 trackToEnable->setMode(TextTrack::showingKeyword()); | 135 trackToEnable->setMode(TextTrack::showingKeyword()); |
| 139 } | 136 } |
| 140 | 137 |
| 141 void AutomaticTrackSelection::enableDefaultMetadataTextTracks( | 138 void AutomaticTrackSelection::enableDefaultMetadataTextTracks( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 performAutomaticTextTrackSelection(captionAndSubtitleTracks); | 204 performAutomaticTextTrackSelection(captionAndSubtitleTracks); |
| 208 if (descriptionTracks.tracks.size()) | 205 if (descriptionTracks.tracks.size()) |
| 209 performAutomaticTextTrackSelection(descriptionTracks); | 206 performAutomaticTextTrackSelection(descriptionTracks); |
| 210 if (chapterTracks.tracks.size()) | 207 if (chapterTracks.tracks.size()) |
| 211 performAutomaticTextTrackSelection(chapterTracks); | 208 performAutomaticTextTrackSelection(chapterTracks); |
| 212 if (metadataTracks.tracks.size()) | 209 if (metadataTracks.tracks.size()) |
| 213 enableDefaultMetadataTextTracks(metadataTracks); | 210 enableDefaultMetadataTextTracks(metadataTracks); |
| 214 } | 211 } |
| 215 | 212 |
| 216 } // namespace blink | 213 } // namespace blink |
| OLD | NEW |