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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2539023002: Media Controls: Use events to update controls for closed captions. (Closed)
Patch Set: zqzhang review comments Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track) { 1234 void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track) {
1235 if (webMediaPlayer() && 1235 if (webMediaPlayer() &&
1236 m_textTracksWhenResourceSelectionBegan.contains(track)) { 1236 m_textTracksWhenResourceSelectionBegan.contains(track)) {
1237 if (track->getReadinessState() != TextTrack::Loading) 1237 if (track->getReadinessState() != TextTrack::Loading)
1238 setReadyState(static_cast<ReadyState>(webMediaPlayer()->getReadyState())); 1238 setReadyState(static_cast<ReadyState>(webMediaPlayer()->getReadyState()));
1239 } else { 1239 } else {
1240 // The track readiness state might have changed as a result of the user 1240 // The track readiness state might have changed as a result of the user
1241 // clicking the captions button. In this case, a check whether all the 1241 // clicking the captions button. In this case, a check whether all the
1242 // resources have failed loading should be done in order to hide the CC 1242 // resources have failed loading should be done in order to hide the CC
1243 // button. 1243 // button.
1244 // TODO(mlamouri): when an HTMLTrackElement fails to load, it is not
1245 // propagated to the TextTrack object in a web exposed fashion. We have to
1246 // keep relying on a custom glue to the controls while this is taken care
1247 // of on the web side. See https://crbug.com/669977
1244 if (mediaControls() && 1248 if (mediaControls() &&
1245 track->getReadinessState() == TextTrack::FailedToLoad) 1249 track->getReadinessState() == TextTrack::FailedToLoad) {
1246 mediaControls()->refreshClosedCaptionsButtonVisibility(); 1250 mediaControls()->onTrackElementFailedToLoad();
1251 }
1247 } 1252 }
1248 } 1253 }
1249 1254
1250 void HTMLMediaElement::textTrackModeChanged(TextTrack* track) { 1255 void HTMLMediaElement::textTrackModeChanged(TextTrack* track) {
1251 // Mark this track as "configured" so configureTextTracks won't change the 1256 // Mark this track as "configured" so configureTextTracks won't change the
1252 // mode again. 1257 // mode again.
1253 if (track->trackType() == TextTrack::TrackElement) 1258 if (track->trackType() == TextTrack::TrackElement)
1254 track->setHasBeenConfigured(true); 1259 track->setHasBeenConfigured(true);
1255 1260
1256 configureTextTrackDisplay(); 1261 configureTextTrackDisplay();
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 m_autoplaying = false; 1690 m_autoplaying = false;
1686 } 1691 }
1687 } 1692 }
1688 } 1693 }
1689 1694
1690 scheduleEvent(EventTypeNames::canplaythrough); 1695 scheduleEvent(EventTypeNames::canplaythrough);
1691 1696
1692 shouldUpdateDisplayState = true; 1697 shouldUpdateDisplayState = true;
1693 } 1698 }
1694 1699
1695 if (shouldUpdateDisplayState) { 1700 if (shouldUpdateDisplayState)
1696 updateDisplayState(); 1701 updateDisplayState();
1697 if (mediaControls())
1698 mediaControls()->refreshClosedCaptionsButtonVisibility();
1699 }
1700 1702
1701 updatePlayState(); 1703 updatePlayState();
1702 cueTimeline().updateActiveCues(currentTime()); 1704 cueTimeline().updateActiveCues(currentTime());
1703 } 1705 }
1704 1706
1705 void HTMLMediaElement::progressEventTimerFired(TimerBase*) { 1707 void HTMLMediaElement::progressEventTimerFired(TimerBase*) {
1706 if (m_networkState != kNetworkLoading) 1708 if (m_networkState != kNetworkLoading)
1707 return; 1709 return;
1708 1710
1709 double time = WTF::currentTime(); 1711 double time = WTF::currentTime();
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 // preferences and the requirements of the relevant specification for the 2592 // preferences and the requirements of the relevant specification for the
2591 // data. 2593 // data.
2592 // - This will happen in honorUserPreferencesForAutomaticTextTrackSelection() 2594 // - This will happen in honorUserPreferencesForAutomaticTextTrackSelection()
2593 scheduleTextTrackResourceLoad(); 2595 scheduleTextTrackResourceLoad();
2594 2596
2595 // 8. Add the new text track to the media element's list of text tracks. 2597 // 8. Add the new text track to the media element's list of text tracks.
2596 // 9. Fire an event with the name addtrack, that does not bubble and is not 2598 // 9. Fire an event with the name addtrack, that does not bubble and is not
2597 // cancelable, and that uses the TrackEvent interface, with the track 2599 // cancelable, and that uses the TrackEvent interface, with the track
2598 // attribute initialized to the text track's TextTrack object, at the media 2600 // attribute initialized to the text track's TextTrack object, at the media
2599 // element's textTracks attribute's TextTrackList object. 2601 // element's textTracks attribute's TextTrackList object.
2600 addTextTrack(textTrack); 2602 textTracks()->append(textTrack);
2601 } 2603 }
2602 2604
2603 void HTMLMediaElement::removeTextTrack(WebInbandTextTrack* webTrack) { 2605 void HTMLMediaElement::removeTextTrack(WebInbandTextTrack* webTrack) {
2604 if (!m_textTracks) 2606 if (!m_textTracks)
2605 return; 2607 return;
2606 2608
2607 // This cast is safe because we created the InbandTextTrack with the 2609 // This cast is safe because we created the InbandTextTrack with the
2608 // WebInbandTextTrack passed to mediaPlayerDidAddTextTrack. 2610 // WebInbandTextTrack passed to mediaPlayerDidAddTextTrack.
2609 InbandTextTrack* textTrack = 2611 InbandTextTrack* textTrack =
2610 static_cast<InbandTextTrack*>(webTrack->client()); 2612 static_cast<InbandTextTrack*>(webTrack->client());
2611 if (!textTrack) 2613 if (!textTrack)
2612 return; 2614 return;
2613 2615
2614 removeTextTrack(textTrack); 2616 m_textTracks->remove(textTrack);
2615 }
2616
2617 void HTMLMediaElement::textTracksChanged() {
2618 if (mediaControls())
2619 mediaControls()->refreshClosedCaptionsButtonVisibility();
2620 }
2621
2622 void HTMLMediaElement::addTextTrack(TextTrack* track) {
2623 textTracks()->append(track);
2624
2625 textTracksChanged();
2626 }
2627
2628 void HTMLMediaElement::removeTextTrack(TextTrack* track) {
2629 m_textTracks->remove(track);
2630
2631 textTracksChanged();
2632 } 2617 }
2633 2618
2634 void HTMLMediaElement::forgetResourceSpecificTracks() { 2619 void HTMLMediaElement::forgetResourceSpecificTracks() {
2635 // Implements the "forget the media element's media-resource-specific tracks" 2620 // Implements the "forget the media element's media-resource-specific tracks"
2636 // algorithm. The order is explicitly specified as text, then audio, and 2621 // algorithm. The order is explicitly specified as text, then audio, and
2637 // finally video. Also 'removetrack' events should not be fired. 2622 // finally video. Also 'removetrack' events should not be fired.
2638 if (m_textTracks) { 2623 if (m_textTracks) {
2639 TrackDisplayUpdateScope scope(this->cueTimeline()); 2624 TrackDisplayUpdateScope scope(this->cueTimeline());
2640 m_textTracks->removeAllInbandTracks(); 2625 m_textTracks->removeAllInbandTracks();
2641 textTracksChanged();
2642 } 2626 }
2643 2627
2644 m_audioTracks->removeAll(); 2628 m_audioTracks->removeAll();
2645 m_videoTracks->removeAll(); 2629 m_videoTracks->removeAll();
2646 2630
2647 m_audioTracksTimer.stop(); 2631 m_audioTracksTimer.stop();
2648 } 2632 }
2649 2633
2650 TextTrack* HTMLMediaElement::addTextTrack(const AtomicString& kind, 2634 TextTrack* HTMLMediaElement::addTextTrack(const AtomicString& kind,
2651 const AtomicString& label, 2635 const AtomicString& label,
(...skipping 12 matching lines...) Expand all
2664 TextTrack* textTrack = TextTrack::create(kind, label, language); 2648 TextTrack* textTrack = TextTrack::create(kind, label, language);
2665 // ..., its text track readiness state to the text track loaded state, ... 2649 // ..., its text track readiness state to the text track loaded state, ...
2666 textTrack->setReadinessState(TextTrack::Loaded); 2650 textTrack->setReadinessState(TextTrack::Loaded);
2667 2651
2668 // 3. Add the new text track to the media element's list of text tracks. 2652 // 3. Add the new text track to the media element's list of text tracks.
2669 // 4. Queue a task to fire a trusted event with the name addtrack, that 2653 // 4. Queue a task to fire a trusted event with the name addtrack, that
2670 // does not bubble and is not cancelable, and that uses the TrackEvent 2654 // does not bubble and is not cancelable, and that uses the TrackEvent
2671 // interface, with the track attribute initialised to the new text 2655 // interface, with the track attribute initialised to the new text
2672 // track's TextTrack object, at the media element's textTracks 2656 // track's TextTrack object, at the media element's textTracks
2673 // attribute's TextTrackList object. 2657 // attribute's TextTrackList object.
2674 addTextTrack(textTrack); 2658 textTracks()->append(textTrack);
2675 2659
2676 // Note: Due to side effects when changing track parameters, we have to 2660 // Note: Due to side effects when changing track parameters, we have to
2677 // first append the track to the text track list. 2661 // first append the track to the text track list.
2678 // FIXME: Since setMode() will cause a 'change' event to be queued on the 2662 // FIXME: Since setMode() will cause a 'change' event to be queued on the
2679 // same task source as the 'addtrack' event (see above), the order is 2663 // same task source as the 'addtrack' event (see above), the order is
2680 // wrong. (The 'change' event shouldn't be fired at all in this case...) 2664 // wrong. (The 'change' event shouldn't be fired at all in this case...)
2681 2665
2682 // ..., its text track mode to the text track hidden mode, ... 2666 // ..., its text track mode to the text track hidden mode, ...
2683 textTrack->setMode(TextTrack::hiddenKeyword()); 2667 textTrack->setMode(TextTrack::hiddenKeyword());
2684 2668
(...skipping 11 matching lines...) Expand all
2696 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement) { 2680 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement) {
2697 // 4.8.10.12.3 Sourcing out-of-band text tracks 2681 // 4.8.10.12.3 Sourcing out-of-band text tracks
2698 // When a track element's parent element changes and the new parent is a media 2682 // When a track element's parent element changes and the new parent is a media
2699 // element, then the user agent must add the track element's corresponding 2683 // element, then the user agent must add the track element's corresponding
2700 // text track to the media element's list of text tracks ... [continues in 2684 // text track to the media element's list of text tracks ... [continues in
2701 // TextTrackList::append] 2685 // TextTrackList::append]
2702 TextTrack* textTrack = trackElement->track(); 2686 TextTrack* textTrack = trackElement->track();
2703 if (!textTrack) 2687 if (!textTrack)
2704 return; 2688 return;
2705 2689
2706 addTextTrack(textTrack); 2690 textTracks()->append(textTrack);
2707 2691
2708 // Do not schedule the track loading until parsing finishes so we don't start 2692 // Do not schedule the track loading until parsing finishes so we don't start
2709 // before all tracks in the markup have been added. 2693 // before all tracks in the markup have been added.
2710 if (isFinishedParsingChildren()) 2694 if (isFinishedParsingChildren())
2711 scheduleTextTrackResourceLoad(); 2695 scheduleTextTrackResourceLoad();
2712 } 2696 }
2713 2697
2714 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement) { 2698 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement) {
2715 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr); 2699 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr);
2716 BLINK_MEDIA_LOG << "didRemoveTrackElement(" << (void*)this << ") - 'src' is " 2700 BLINK_MEDIA_LOG << "didRemoveTrackElement(" << (void*)this << ") - 'src' is "
2717 << urlForLoggingMedia(url); 2701 << urlForLoggingMedia(url);
2718 2702
2719 TextTrack* textTrack = trackElement->track(); 2703 TextTrack* textTrack = trackElement->track();
2720 if (!textTrack) 2704 if (!textTrack)
2721 return; 2705 return;
2722 2706
2723 textTrack->setHasBeenConfigured(false); 2707 textTrack->setHasBeenConfigured(false);
2724 2708
2725 if (!m_textTracks) 2709 if (!m_textTracks)
2726 return; 2710 return;
2727 2711
2728 // 4.8.10.12.3 Sourcing out-of-band text tracks 2712 // 4.8.10.12.3 Sourcing out-of-band text tracks
2729 // When a track element's parent element changes and the old parent was a 2713 // When a track element's parent element changes and the old parent was a
2730 // media element, then the user agent must remove the track element's 2714 // media element, then the user agent must remove the track element's
2731 // corresponding text track from the media element's list of text tracks. 2715 // corresponding text track from the media element's list of text tracks.
2732 removeTextTrack(textTrack); 2716 m_textTracks->remove(textTrack);
2733 2717
2734 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack); 2718 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack);
2735 if (index != kNotFound) 2719 if (index != kNotFound)
2736 m_textTracksWhenResourceSelectionBegan.remove(index); 2720 m_textTracksWhenResourceSelectionBegan.remove(index);
2737 } 2721 }
2738 2722
2739 void HTMLMediaElement::honorUserPreferencesForAutomaticTextTrackSelection() { 2723 void HTMLMediaElement::honorUserPreferencesForAutomaticTextTrackSelection() {
2740 if (!m_textTracks || !m_textTracks->length()) 2724 if (!m_textTracks || !m_textTracks->length())
2741 return; 2725 return;
2742 2726
2743 if (!m_shouldPerformAutomaticTrackSelection) 2727 if (!m_shouldPerformAutomaticTrackSelection)
2744 return; 2728 return;
2745 2729
2746 AutomaticTrackSelection::Configuration configuration; 2730 AutomaticTrackSelection::Configuration configuration;
2747 if (m_processingPreferenceChange) 2731 if (m_processingPreferenceChange)
2748 configuration.disableCurrentlyEnabledTracks = true; 2732 configuration.disableCurrentlyEnabledTracks = true;
2749 if (m_textTracksVisible) 2733 if (m_textTracksVisible)
2750 configuration.forceEnableSubtitleOrCaptionTrack = true; 2734 configuration.forceEnableSubtitleOrCaptionTrack = true;
2751 2735
2752 Settings* settings = document().settings(); 2736 Settings* settings = document().settings();
2753 if (settings) 2737 if (settings)
2754 configuration.textTrackKindUserPreference = 2738 configuration.textTrackKindUserPreference =
2755 settings->textTrackKindUserPreference(); 2739 settings->textTrackKindUserPreference();
2756 2740
2757 AutomaticTrackSelection trackSelection(configuration); 2741 AutomaticTrackSelection trackSelection(configuration);
2758 trackSelection.perform(*m_textTracks); 2742 trackSelection.perform(*m_textTracks);
2759
2760 textTracksChanged();
2761 } 2743 }
2762 2744
2763 bool HTMLMediaElement::havePotentialSourceChild() { 2745 bool HTMLMediaElement::havePotentialSourceChild() {
2764 // Stash the current <source> node and next nodes so we can restore them after 2746 // Stash the current <source> node and next nodes so we can restore them after
2765 // checking to see there is another potential. 2747 // checking to see there is another potential.
2766 HTMLSourceElement* currentSourceNode = m_currentSourceNode; 2748 HTMLSourceElement* currentSourceNode = m_currentSourceNode;
2767 Node* nextNode = m_nextChildNodeToConsider; 2749 Node* nextNode = m_nextChildNodeToConsider;
2768 2750
2769 KURL nextURL = selectNextSourceChild(0, DoNothing); 2751 KURL nextURL = selectNextSourceChild(0, DoNothing);
2770 2752
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
3413 document().layoutViewItem().compositor()->setNeedsCompositingUpdate( 3395 document().layoutViewItem().compositor()->setNeedsCompositingUpdate(
3414 CompositingUpdateRebuildTree); 3396 CompositingUpdateRebuildTree);
3415 m_inOverlayFullscreenVideo = false; 3397 m_inOverlayFullscreenVideo = false;
3416 } 3398 }
3417 3399
3418 WebLayer* HTMLMediaElement::platformLayer() const { 3400 WebLayer* HTMLMediaElement::platformLayer() const {
3419 return m_webLayer; 3401 return m_webLayer;
3420 } 3402 }
3421 3403
3422 bool HTMLMediaElement::hasClosedCaptions() const { 3404 bool HTMLMediaElement::hasClosedCaptions() const {
3423 if (m_textTracks) { 3405 if (!m_textTracks)
3424 for (unsigned i = 0; i < m_textTracks->length(); ++i) { 3406 return false;
3425 if (m_textTracks->anonymousIndexedGetter(i)->canBeRendered()) 3407
3426 return true; 3408 for (unsigned i = 0; i < m_textTracks->length(); ++i) {
3427 } 3409 if (m_textTracks->anonymousIndexedGetter(i)->canBeRendered())
3410 return true;
3428 } 3411 }
3412
3429 return false; 3413 return false;
3430 } 3414 }
3431 3415
3432 bool HTMLMediaElement::textTracksVisible() const { 3416 bool HTMLMediaElement::textTracksVisible() const {
3433 return m_textTracksVisible; 3417 return m_textTracksVisible;
3434 } 3418 }
3435 3419
3436 static void assertShadowRootChildren(ShadowRoot& shadowRoot) { 3420 static void assertShadowRootChildren(ShadowRoot& shadowRoot) {
3437 #if DCHECK_IS_ON() 3421 #if DCHECK_IS_ON()
3438 // There can be up to two children, either or both of the text 3422 // There can be up to two children, either or both of the text
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3625 3609
3626 if (m_processingPreferenceChange) 3610 if (m_processingPreferenceChange)
3627 return; 3611 return;
3628 3612
3629 bool haveVisibleTextTrack = m_textTracks->hasShowingTracks(); 3613 bool haveVisibleTextTrack = m_textTracks->hasShowingTracks();
3630 m_textTracksVisible = haveVisibleTextTrack; 3614 m_textTracksVisible = haveVisibleTextTrack;
3631 3615
3632 if (!haveVisibleTextTrack && !mediaControls()) 3616 if (!haveVisibleTextTrack && !mediaControls())
3633 return; 3617 return;
3634 3618
3635 if (mediaControls())
3636 mediaControls()->changedClosedCaptionsVisibility();
3637
3638 cueTimeline().updateActiveCues(currentTime()); 3619 cueTimeline().updateActiveCues(currentTime());
3639 3620
3640 // Note: The "time marches on" algorithm (updateActiveCues) runs the "rules 3621 // Note: The "time marches on" algorithm (updateActiveCues) runs the "rules
3641 // for updating the text track rendering" (updateTextTrackDisplay) only for 3622 // for updating the text track rendering" (updateTextTrackDisplay) only for
3642 // "affected tracks", i.e. tracks where the the active cues have changed. 3623 // "affected tracks", i.e. tracks where the the active cues have changed.
3643 // This misses cues in tracks that changed mode between hidden and showing. 3624 // This misses cues in tracks that changed mode between hidden and showing.
3644 // This appears to be a spec bug, which we work around here: 3625 // This appears to be a spec bug, which we work around here:
3645 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28236 3626 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28236
3646 updateTextTrackDisplay(); 3627 updateTextTrackDisplay();
3647 } 3628 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
4027 4008
4028 DEFINE_TRACE(HTMLMediaElement::AudioClientImpl) { 4009 DEFINE_TRACE(HTMLMediaElement::AudioClientImpl) {
4029 visitor->trace(m_client); 4010 visitor->trace(m_client);
4030 } 4011 }
4031 4012
4032 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) { 4013 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) {
4033 visitor->trace(m_client); 4014 visitor->trace(m_client);
4034 } 4015 }
4035 4016
4036 } // namespace blink 4017 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698