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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 if (m_configuration.disableCurrentlyEnabledTracks && | 81 if (m_configuration.disableCurrentlyEnabledTracks && |
82 textTrack->mode() == TextTrack::showingKeyword()) | 82 textTrack->mode() == TextTrack::showingKeyword()) |
83 currentlyEnabledTracks.append(textTrack); | 83 currentlyEnabledTracks.append(textTrack); |
84 | 84 |
85 int trackScore = textTrackSelectionScore(*textTrack); | 85 int trackScore = textTrackSelectionScore(*textTrack); |
86 | 86 |
87 if (textTrack->kind() == preferredTrackKind()) | 87 if (textTrack->kind() == preferredTrackKind()) |
88 trackScore += 1; | 88 trackScore += 1; |
89 if (trackScore) { | 89 if (trackScore) { |
90 // * If the text track kind is subtitles or captions and the user has indi
cated an interest in having a | 90 // * If the text track kind is subtitles or captions and the user has |
91 // track with this text track kind, text track language, and text track la
bel enabled, and there is no | 91 // indicated an interest in having a track with this text track kind, text |
92 // other text track in the media element's list of text tracks with a text
track kind of either subtitles | 92 // track language, and text track label enabled, and there is no other |
93 // or captions whose text track mode is showing | 93 // text track in the media element's list of text tracks with a text track |
| 94 // kind of either subtitles or captions whose text track mode is showing |
94 // Let the text track mode be showing. | 95 // Let the text track mode be showing. |
95 if (trackScore > highestTrackScore) { | 96 if (trackScore > highestTrackScore) { |
96 preferredTrack = textTrack; | 97 preferredTrack = textTrack; |
97 highestTrackScore = trackScore; | 98 highestTrackScore = trackScore; |
98 } | 99 } |
99 if (!defaultTrack && textTrack->isDefault()) | 100 if (!defaultTrack && textTrack->isDefault()) |
100 defaultTrack = textTrack; | 101 defaultTrack = textTrack; |
101 | 102 |
102 if (!fallbackTrack) | 103 if (!fallbackTrack) |
103 fallbackTrack = textTrack; | 104 fallbackTrack = textTrack; |
104 } else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault()) { | 105 } else if (!group.visibleTrack && !defaultTrack && textTrack->isDefault()) { |
105 // * If the track element has a default attribute specified, and there is
no other text track in the media | 106 // * If the track element has a default attribute specified, and there is |
106 // element's list of text tracks whose text track mode is showing or showi
ng by default | 107 // no other text track in the media element's list of text tracks whose |
| 108 // text track mode is showing or showing by default |
107 // Let the text track mode be showing by default. | 109 // Let the text track mode be showing by default. |
108 defaultTrack = textTrack; | 110 defaultTrack = textTrack; |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 if (m_configuration.textTrackKindUserPreference != | 114 if (m_configuration.textTrackKindUserPreference != |
113 TextTrackKindUserPreference::Default) | 115 TextTrackKindUserPreference::Default) |
114 trackToEnable = preferredTrack; | 116 trackToEnable = preferredTrack; |
115 | 117 |
116 if (!trackToEnable && defaultTrack) | 118 if (!trackToEnable && defaultTrack) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 DCHECK_EQ(kind, TextTrack::metadataKeyword()); | 181 DCHECK_EQ(kind, TextTrack::metadataKeyword()); |
180 currentGroup = &metadataTracks; | 182 currentGroup = &metadataTracks; |
181 } | 183 } |
182 | 184 |
183 if (!currentGroup->visibleTrack && | 185 if (!currentGroup->visibleTrack && |
184 textTrack->mode() == TextTrack::showingKeyword()) | 186 textTrack->mode() == TextTrack::showingKeyword()) |
185 currentGroup->visibleTrack = textTrack; | 187 currentGroup->visibleTrack = textTrack; |
186 if (!currentGroup->defaultTrack && textTrack->isDefault()) | 188 if (!currentGroup->defaultTrack && textTrack->isDefault()) |
187 currentGroup->defaultTrack = textTrack; | 189 currentGroup->defaultTrack = textTrack; |
188 | 190 |
189 // Do not add this track to the group if it has already been automatically c
onfigured | 191 // Do not add this track to the group if it has already been automatically |
190 // as we only want to perform selection once per track so that adding anothe
r track | 192 // configured as we only want to perform selection once per track so that |
191 // after the initial configuration doesn't reconfigure every track - only th
ose that | 193 // adding another track after the initial configuration doesn't reconfigure |
192 // should be changed by the new addition. For example all metadata tracks ar
e | 194 // every track - only those that should be changed by the new addition. For |
193 // disabled by default, and we don't want a track that has been enabled by s
cript | 195 // example all metadata tracks are disabled by default, and we don't want a |
194 // to be disabled automatically when a new metadata track is added later. | 196 // track that has been enabled by script to be disabled automatically when a |
| 197 // new metadata track is added later. |
195 if (textTrack->hasBeenConfigured()) | 198 if (textTrack->hasBeenConfigured()) |
196 continue; | 199 continue; |
197 | 200 |
198 if (textTrack->language().length()) | 201 if (textTrack->language().length()) |
199 currentGroup->hasSrcLang = true; | 202 currentGroup->hasSrcLang = true; |
200 currentGroup->tracks.append(textTrack); | 203 currentGroup->tracks.append(textTrack); |
201 } | 204 } |
202 | 205 |
203 if (captionAndSubtitleTracks.tracks.size()) | 206 if (captionAndSubtitleTracks.tracks.size()) |
204 performAutomaticTextTrackSelection(captionAndSubtitleTracks); | 207 performAutomaticTextTrackSelection(captionAndSubtitleTracks); |
205 if (descriptionTracks.tracks.size()) | 208 if (descriptionTracks.tracks.size()) |
206 performAutomaticTextTrackSelection(descriptionTracks); | 209 performAutomaticTextTrackSelection(descriptionTracks); |
207 if (chapterTracks.tracks.size()) | 210 if (chapterTracks.tracks.size()) |
208 performAutomaticTextTrackSelection(chapterTracks); | 211 performAutomaticTextTrackSelection(chapterTracks); |
209 if (metadataTracks.tracks.size()) | 212 if (metadataTracks.tracks.size()) |
210 enableDefaultMetadataTextTracks(metadataTracks); | 213 enableDefaultMetadataTextTracks(metadataTracks); |
211 } | 214 } |
212 | 215 |
213 } // namespace blink | 216 } // namespace blink |
OLD | NEW |