Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2393 static int textTrackLanguageSelectionScore(const TextTrack& track) | 2393 static int textTrackLanguageSelectionScore(const TextTrack& track) |
| 2394 { | 2394 { |
| 2395 if (track.language().isEmpty()) | 2395 if (track.language().isEmpty()) |
| 2396 return 0; | 2396 return 0; |
| 2397 | 2397 |
| 2398 Vector<AtomicString> languages = userPreferredLanguages(); | 2398 Vector<AtomicString> languages = userPreferredLanguages(); |
| 2399 size_t languageMatchIndex = indexOfBestMatchingLanguageInList(track.language (), languages); | 2399 size_t languageMatchIndex = indexOfBestMatchingLanguageInList(track.language (), languages); |
| 2400 if (languageMatchIndex >= languages.size()) | 2400 if (languageMatchIndex >= languages.size()) |
| 2401 return 0; | 2401 return 0; |
| 2402 | 2402 |
| 2403 // Matching a track language is more important than matching track type, so this multiplier must be | |
| 2404 // greater than the maximum value returned by textTrackSelectionScore. | |
| 2405 return (languages.size() - languageMatchIndex) * 10; | 2403 return (languages.size() - languageMatchIndex) * 10; |
|
acolwell GONE FROM CHROMIUM
2014/04/25 23:57:27
nit: Do we need the '* 10' here? If so, please add
philipj_slow
2014/04/26 00:02:07
Not any more, thanks!
| |
| 2406 } | 2404 } |
| 2407 | 2405 |
| 2408 static int textTrackSelectionScore(const TextTrack& track, Settings* settings) | 2406 static int textTrackSelectionScore(const TextTrack& track) |
| 2409 { | 2407 { |
| 2410 int trackScore = 0; | 2408 if (track.kind() != TextTrack::captionsKeyword() && track.kind() != TextTrac k::subtitlesKeyword()) |
| 2409 return 0; | |
| 2411 | 2410 |
| 2412 if (!settings) | 2411 return textTrackLanguageSelectionScore(track); |
| 2413 return trackScore; | |
| 2414 | |
| 2415 if (track.kind() != TextTrack::captionsKeyword() && track.kind() != TextTrac k::subtitlesKeyword()) | |
| 2416 return trackScore; | |
| 2417 | |
| 2418 if (track.kind() == TextTrack::subtitlesKeyword() && settings->shouldDisplay Subtitles()) | |
| 2419 trackScore = 1; | |
| 2420 else if (track.kind() == TextTrack::captionsKeyword() && settings->shouldDis playCaptions()) | |
| 2421 trackScore = 1; | |
| 2422 | |
| 2423 return trackScore + textTrackLanguageSelectionScore(track); | |
| 2424 } | 2412 } |
| 2425 | 2413 |
| 2426 void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) | 2414 void HTMLMediaElement::configureTextTrackGroup(const TrackGroup& group) |
| 2427 { | 2415 { |
| 2428 ASSERT(group.tracks.size()); | 2416 ASSERT(group.tracks.size()); |
| 2429 | 2417 |
| 2430 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%d)", group.kind); | 2418 WTF_LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%d)", group.kind); |
| 2431 | 2419 |
| 2432 Settings* settings = document().settings(); | |
| 2433 | |
| 2434 // First, find the track in the group that should be enabled (if any). | 2420 // First, find the track in the group that should be enabled (if any). |
| 2435 WillBeHeapVector<RefPtrWillBeMember<TextTrack> > currentlyEnabledTracks; | 2421 WillBeHeapVector<RefPtrWillBeMember<TextTrack> > currentlyEnabledTracks; |
| 2436 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; | 2422 RefPtrWillBeRawPtr<TextTrack> trackToEnable = nullptr; |
| 2437 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; | 2423 RefPtrWillBeRawPtr<TextTrack> defaultTrack = nullptr; |
| 2438 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; | 2424 RefPtrWillBeRawPtr<TextTrack> fallbackTrack = nullptr; |
| 2439 int highestTrackScore = 0; | 2425 int highestTrackScore = 0; |
| 2440 for (size_t i = 0; i < group.tracks.size(); ++i) { | 2426 for (size_t i = 0; i < group.tracks.size(); ++i) { |
| 2441 RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i]; | 2427 RefPtrWillBeRawPtr<TextTrack> textTrack = group.tracks[i]; |
| 2442 | 2428 |
| 2443 if (m_processingPreferenceChange && textTrack->mode() == TextTrack::show ingKeyword()) | 2429 if (m_processingPreferenceChange && textTrack->mode() == TextTrack::show ingKeyword()) |
| 2444 currentlyEnabledTracks.append(textTrack); | 2430 currentlyEnabledTracks.append(textTrack); |
| 2445 | 2431 |
| 2446 int trackScore = textTrackSelectionScore(*textTrack, settings); | 2432 int trackScore = textTrackSelectionScore(*textTrack); |
| 2447 if (trackScore) { | 2433 if (trackScore) { |
| 2448 // * If the text track kind is { [subtitles or captions] [descriptio ns] } and the user has indicated an interest in having a | 2434 // * If the text track kind is { [subtitles or captions] [descriptio ns] } and the user has indicated an interest in having a |
| 2449 // track with this text track kind, text track language, and text tr ack label enabled, and there is no | 2435 // track with this text track kind, text track language, and text tr ack label enabled, and there is no |
| 2450 // other text track in the media element's list of text tracks with a text track kind of either subtitles | 2436 // other text track in the media element's list of text tracks with a text track kind of either subtitles |
| 2451 // or captions whose text track mode is showing | 2437 // or captions whose text track mode is showing |
| 2452 // ... | 2438 // ... |
| 2453 // * If the text track kind is chapters and the text track language is one that the user agent has reason | 2439 // * If the text track kind is chapters and the text track language is one that the user agent has reason |
| 2454 // to believe is appropriate for the user, and there is no other tex t track in the media element's list of | 2440 // to believe is appropriate for the user, and there is no other tex t track in the media element's list of |
| 2455 // text tracks with a text track kind of chapters whose text track m ode is showing | 2441 // text tracks with a text track kind of chapters whose text track m ode is showing |
| 2456 // Let the text track mode be showing. | 2442 // Let the text track mode be showing. |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3633 | 3619 |
| 3634 void HTMLMediaElement::trace(Visitor* visitor) | 3620 void HTMLMediaElement::trace(Visitor* visitor) |
| 3635 { | 3621 { |
| 3636 visitor->trace(m_textTracks); | 3622 visitor->trace(m_textTracks); |
| 3637 visitor->trace(m_textTracksWhenResourceSelectionBegan); | 3623 visitor->trace(m_textTracksWhenResourceSelectionBegan); |
| 3638 Supplementable<HTMLMediaElement>::trace(visitor); | 3624 Supplementable<HTMLMediaElement>::trace(visitor); |
| 3639 HTMLElement::trace(visitor); | 3625 HTMLElement::trace(visitor); |
| 3640 } | 3626 } |
| 3641 | 3627 |
| 3642 } | 3628 } |
| OLD | NEW |