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

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: ready for review 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 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track) { 1306 void HTMLMediaElement::textTrackReadyStateChanged(TextTrack* track) {
1307 if (webMediaPlayer() && 1307 if (webMediaPlayer() &&
1308 m_textTracksWhenResourceSelectionBegan.contains(track)) { 1308 m_textTracksWhenResourceSelectionBegan.contains(track)) {
1309 if (track->getReadinessState() != TextTrack::Loading) 1309 if (track->getReadinessState() != TextTrack::Loading)
1310 setReadyState(static_cast<ReadyState>(webMediaPlayer()->getReadyState())); 1310 setReadyState(static_cast<ReadyState>(webMediaPlayer()->getReadyState()));
1311 } else { 1311 } else {
1312 // The track readiness state might have changed as a result of the user 1312 // The track readiness state might have changed as a result of the user
1313 // clicking the captions button. In this case, a check whether all the 1313 // clicking the captions button. In this case, a check whether all the
1314 // resources have failed loading should be done in order to hide the CC 1314 // resources have failed loading should be done in order to hide the CC
1315 // button. 1315 // button.
1316 // TODO(mlamouri): when an HTMLTrackElement fails to load, it is not
1317 // propagated to the TextTrack object in a web exposed fashion. We have to
1318 // keep relying on a custom glue to the controls while this is taken care
1319 // of on the web side. See https://crbug.com/669977
1316 if (mediaControls() && 1320 if (mediaControls() &&
1317 track->getReadinessState() == TextTrack::FailedToLoad) 1321 track->getReadinessState() == TextTrack::FailedToLoad) {
1318 mediaControls()->refreshClosedCaptionsButtonVisibility(); 1322 mediaControls()->onTrackElementFailedToLoad();
1323 }
1319 } 1324 }
1320 } 1325 }
1321 1326
1322 void HTMLMediaElement::textTrackModeChanged(TextTrack* track) { 1327 void HTMLMediaElement::textTrackModeChanged(TextTrack* track) {
1323 // Mark this track as "configured" so configureTextTracks won't change the 1328 // Mark this track as "configured" so configureTextTracks won't change the
1324 // mode again. 1329 // mode again.
1325 if (track->trackType() == TextTrack::TrackElement) 1330 if (track->trackType() == TextTrack::TrackElement)
1326 track->setHasBeenConfigured(true); 1331 track->setHasBeenConfigured(true);
1327 1332
1328 configureTextTrackDisplay(); 1333 configureTextTrackDisplay();
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 m_autoplaying = false; 1766 m_autoplaying = false;
1762 } 1767 }
1763 } 1768 }
1764 } 1769 }
1765 1770
1766 scheduleEvent(EventTypeNames::canplaythrough); 1771 scheduleEvent(EventTypeNames::canplaythrough);
1767 1772
1768 shouldUpdateDisplayState = true; 1773 shouldUpdateDisplayState = true;
1769 } 1774 }
1770 1775
1771 if (shouldUpdateDisplayState) { 1776 if (shouldUpdateDisplayState)
1772 updateDisplayState(); 1777 updateDisplayState();
1773 if (mediaControls())
1774 mediaControls()->refreshClosedCaptionsButtonVisibility();
1775 }
1776 1778
1777 updatePlayState(); 1779 updatePlayState();
1778 cueTimeline().updateActiveCues(currentTime()); 1780 cueTimeline().updateActiveCues(currentTime());
1779 } 1781 }
1780 1782
1781 void HTMLMediaElement::progressEventTimerFired(TimerBase*) { 1783 void HTMLMediaElement::progressEventTimerFired(TimerBase*) {
1782 if (m_networkState != kNetworkLoading) 1784 if (m_networkState != kNetworkLoading)
1783 return; 1785 return;
1784 1786
1785 double time = WTF::currentTime(); 1787 double time = WTF::currentTime();
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 // preferences and the requirements of the relevant specification for the 2690 // preferences and the requirements of the relevant specification for the
2689 // data. 2691 // data.
2690 // - This will happen in honorUserPreferencesForAutomaticTextTrackSelection() 2692 // - This will happen in honorUserPreferencesForAutomaticTextTrackSelection()
2691 scheduleTextTrackResourceLoad(); 2693 scheduleTextTrackResourceLoad();
2692 2694
2693 // 8. Add the new text track to the media element's list of text tracks. 2695 // 8. Add the new text track to the media element's list of text tracks.
2694 // 9. Fire an event with the name addtrack, that does not bubble and is not 2696 // 9. Fire an event with the name addtrack, that does not bubble and is not
2695 // cancelable, and that uses the TrackEvent interface, with the track 2697 // cancelable, and that uses the TrackEvent interface, with the track
2696 // attribute initialized to the text track's TextTrack object, at the media 2698 // attribute initialized to the text track's TextTrack object, at the media
2697 // element's textTracks attribute's TextTrackList object. 2699 // element's textTracks attribute's TextTrackList object.
2698 addTextTrack(textTrack); 2700 textTracks()->append(textTrack);
2699 } 2701 }
2700 2702
2701 void HTMLMediaElement::removeTextTrack(WebInbandTextTrack* webTrack) { 2703 void HTMLMediaElement::removeTextTrack(WebInbandTextTrack* webTrack) {
2702 if (!m_textTracks) 2704 if (!m_textTracks)
2703 return; 2705 return;
2704 2706
2705 // This cast is safe because we created the InbandTextTrack with the 2707 // This cast is safe because we created the InbandTextTrack with the
2706 // WebInbandTextTrack passed to mediaPlayerDidAddTextTrack. 2708 // WebInbandTextTrack passed to mediaPlayerDidAddTextTrack.
2707 InbandTextTrack* textTrack = 2709 InbandTextTrack* textTrack =
2708 static_cast<InbandTextTrack*>(webTrack->client()); 2710 static_cast<InbandTextTrack*>(webTrack->client());
2709 if (!textTrack) 2711 if (!textTrack)
2710 return; 2712 return;
2711 2713
2712 removeTextTrack(textTrack); 2714 m_textTracks->remove(textTrack);
2713 }
2714
2715 void HTMLMediaElement::textTracksChanged() {
2716 if (mediaControls())
2717 mediaControls()->refreshClosedCaptionsButtonVisibility();
2718 }
2719
2720 void HTMLMediaElement::addTextTrack(TextTrack* track) {
2721 textTracks()->append(track);
2722
2723 textTracksChanged();
2724 }
2725
2726 void HTMLMediaElement::removeTextTrack(TextTrack* track) {
2727 m_textTracks->remove(track);
2728
2729 textTracksChanged();
2730 } 2715 }
2731 2716
2732 void HTMLMediaElement::forgetResourceSpecificTracks() { 2717 void HTMLMediaElement::forgetResourceSpecificTracks() {
2733 // Implements the "forget the media element's media-resource-specific tracks" 2718 // Implements the "forget the media element's media-resource-specific tracks"
2734 // algorithm. The order is explicitly specified as text, then audio, and 2719 // algorithm. The order is explicitly specified as text, then audio, and
2735 // finally video. Also 'removetrack' events should not be fired. 2720 // finally video. Also 'removetrack' events should not be fired.
2736 if (m_textTracks) { 2721 if (m_textTracks) {
2737 TrackDisplayUpdateScope scope(this->cueTimeline()); 2722 TrackDisplayUpdateScope scope(this->cueTimeline());
2738 m_textTracks->removeAllInbandTracks(); 2723 m_textTracks->removeAllInbandTracks();
2739 textTracksChanged();
2740 } 2724 }
2741 2725
2742 m_audioTracks->removeAll(); 2726 m_audioTracks->removeAll();
2743 m_videoTracks->removeAll(); 2727 m_videoTracks->removeAll();
2744 2728
2745 m_audioTracksTimer.stop(); 2729 m_audioTracksTimer.stop();
2746 } 2730 }
2747 2731
2748 TextTrack* HTMLMediaElement::addTextTrack(const AtomicString& kind, 2732 TextTrack* HTMLMediaElement::addTextTrack(const AtomicString& kind,
2749 const AtomicString& label, 2733 const AtomicString& label,
(...skipping 12 matching lines...) Expand all
2762 TextTrack* textTrack = TextTrack::create(kind, label, language); 2746 TextTrack* textTrack = TextTrack::create(kind, label, language);
2763 // ..., its text track readiness state to the text track loaded state, ... 2747 // ..., its text track readiness state to the text track loaded state, ...
2764 textTrack->setReadinessState(TextTrack::Loaded); 2748 textTrack->setReadinessState(TextTrack::Loaded);
2765 2749
2766 // 3. Add the new text track to the media element's list of text tracks. 2750 // 3. Add the new text track to the media element's list of text tracks.
2767 // 4. Queue a task to fire a trusted event with the name addtrack, that 2751 // 4. Queue a task to fire a trusted event with the name addtrack, that
2768 // does not bubble and is not cancelable, and that uses the TrackEvent 2752 // does not bubble and is not cancelable, and that uses the TrackEvent
2769 // interface, with the track attribute initialised to the new text 2753 // interface, with the track attribute initialised to the new text
2770 // track's TextTrack object, at the media element's textTracks 2754 // track's TextTrack object, at the media element's textTracks
2771 // attribute's TextTrackList object. 2755 // attribute's TextTrackList object.
2772 addTextTrack(textTrack); 2756 textTracks()->append(textTrack);
2773 2757
2774 // Note: Due to side effects when changing track parameters, we have to 2758 // Note: Due to side effects when changing track parameters, we have to
2775 // first append the track to the text track list. 2759 // first append the track to the text track list.
2776 // FIXME: Since setMode() will cause a 'change' event to be queued on the 2760 // FIXME: Since setMode() will cause a 'change' event to be queued on the
2777 // same task source as the 'addtrack' event (see above), the order is 2761 // same task source as the 'addtrack' event (see above), the order is
2778 // wrong. (The 'change' event shouldn't be fired at all in this case...) 2762 // wrong. (The 'change' event shouldn't be fired at all in this case...)
2779 2763
2780 // ..., its text track mode to the text track hidden mode, ... 2764 // ..., its text track mode to the text track hidden mode, ...
2781 textTrack->setMode(TextTrack::hiddenKeyword()); 2765 textTrack->setMode(TextTrack::hiddenKeyword());
2782 2766
(...skipping 11 matching lines...) Expand all
2794 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement) { 2778 void HTMLMediaElement::didAddTrackElement(HTMLTrackElement* trackElement) {
2795 // 4.8.10.12.3 Sourcing out-of-band text tracks 2779 // 4.8.10.12.3 Sourcing out-of-band text tracks
2796 // When a track element's parent element changes and the new parent is a media 2780 // When a track element's parent element changes and the new parent is a media
2797 // element, then the user agent must add the track element's corresponding 2781 // element, then the user agent must add the track element's corresponding
2798 // text track to the media element's list of text tracks ... [continues in 2782 // text track to the media element's list of text tracks ... [continues in
2799 // TextTrackList::append] 2783 // TextTrackList::append]
2800 TextTrack* textTrack = trackElement->track(); 2784 TextTrack* textTrack = trackElement->track();
2801 if (!textTrack) 2785 if (!textTrack)
2802 return; 2786 return;
2803 2787
2804 addTextTrack(textTrack); 2788 textTracks()->append(textTrack);
2805 2789
2806 // Do not schedule the track loading until parsing finishes so we don't start 2790 // Do not schedule the track loading until parsing finishes so we don't start
2807 // before all tracks in the markup have been added. 2791 // before all tracks in the markup have been added.
2808 if (isFinishedParsingChildren()) 2792 if (isFinishedParsingChildren())
2809 scheduleTextTrackResourceLoad(); 2793 scheduleTextTrackResourceLoad();
2810 } 2794 }
2811 2795
2812 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement) { 2796 void HTMLMediaElement::didRemoveTrackElement(HTMLTrackElement* trackElement) {
2813 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr); 2797 KURL url = trackElement->getNonEmptyURLAttribute(srcAttr);
2814 BLINK_MEDIA_LOG << "didRemoveTrackElement(" << (void*)this << ") - 'src' is " 2798 BLINK_MEDIA_LOG << "didRemoveTrackElement(" << (void*)this << ") - 'src' is "
2815 << urlForLoggingMedia(url); 2799 << urlForLoggingMedia(url);
2816 2800
2817 TextTrack* textTrack = trackElement->track(); 2801 TextTrack* textTrack = trackElement->track();
2818 if (!textTrack) 2802 if (!textTrack)
2819 return; 2803 return;
2820 2804
2821 textTrack->setHasBeenConfigured(false); 2805 textTrack->setHasBeenConfigured(false);
2822 2806
2823 if (!m_textTracks) 2807 if (!m_textTracks)
2824 return; 2808 return;
2825 2809
2826 // 4.8.10.12.3 Sourcing out-of-band text tracks 2810 // 4.8.10.12.3 Sourcing out-of-band text tracks
2827 // When a track element's parent element changes and the old parent was a 2811 // When a track element's parent element changes and the old parent was a
2828 // media element, then the user agent must remove the track element's 2812 // media element, then the user agent must remove the track element's
2829 // corresponding text track from the media element's list of text tracks. 2813 // corresponding text track from the media element's list of text tracks.
2830 removeTextTrack(textTrack); 2814 m_textTracks->remove(textTrack);
2831 2815
2832 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack); 2816 size_t index = m_textTracksWhenResourceSelectionBegan.find(textTrack);
2833 if (index != kNotFound) 2817 if (index != kNotFound)
2834 m_textTracksWhenResourceSelectionBegan.remove(index); 2818 m_textTracksWhenResourceSelectionBegan.remove(index);
2835 } 2819 }
2836 2820
2837 void HTMLMediaElement::honorUserPreferencesForAutomaticTextTrackSelection() { 2821 void HTMLMediaElement::honorUserPreferencesForAutomaticTextTrackSelection() {
2838 if (!m_textTracks || !m_textTracks->length()) 2822 if (!m_textTracks || !m_textTracks->length())
2839 return; 2823 return;
2840 2824
2841 if (!m_shouldPerformAutomaticTrackSelection) 2825 if (!m_shouldPerformAutomaticTrackSelection)
2842 return; 2826 return;
2843 2827
2844 AutomaticTrackSelection::Configuration configuration; 2828 AutomaticTrackSelection::Configuration configuration;
2845 if (m_processingPreferenceChange) 2829 if (m_processingPreferenceChange)
2846 configuration.disableCurrentlyEnabledTracks = true; 2830 configuration.disableCurrentlyEnabledTracks = true;
2847 if (m_textTracksVisible) 2831 if (m_textTracksVisible)
2848 configuration.forceEnableSubtitleOrCaptionTrack = true; 2832 configuration.forceEnableSubtitleOrCaptionTrack = true;
2849 2833
2850 Settings* settings = document().settings(); 2834 Settings* settings = document().settings();
2851 if (settings) 2835 if (settings)
2852 configuration.textTrackKindUserPreference = 2836 configuration.textTrackKindUserPreference =
2853 settings->textTrackKindUserPreference(); 2837 settings->textTrackKindUserPreference();
2854 2838
2855 AutomaticTrackSelection trackSelection(configuration); 2839 AutomaticTrackSelection trackSelection(configuration);
2856 trackSelection.perform(*m_textTracks); 2840 trackSelection.perform(*m_textTracks);
2857
2858 textTracksChanged();
2859 } 2841 }
2860 2842
2861 bool HTMLMediaElement::havePotentialSourceChild() { 2843 bool HTMLMediaElement::havePotentialSourceChild() {
2862 // Stash the current <source> node and next nodes so we can restore them after 2844 // Stash the current <source> node and next nodes so we can restore them after
2863 // checking to see there is another potential. 2845 // checking to see there is another potential.
2864 HTMLSourceElement* currentSourceNode = m_currentSourceNode; 2846 HTMLSourceElement* currentSourceNode = m_currentSourceNode;
2865 Node* nextNode = m_nextChildNodeToConsider; 2847 Node* nextNode = m_nextChildNodeToConsider;
2866 2848
2867 KURL nextURL = selectNextSourceChild(0, DoNothing); 2849 KURL nextURL = selectNextSourceChild(0, DoNothing);
2868 2850
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
3513 document().layoutViewItem().compositor()->setNeedsCompositingUpdate( 3495 document().layoutViewItem().compositor()->setNeedsCompositingUpdate(
3514 CompositingUpdateRebuildTree); 3496 CompositingUpdateRebuildTree);
3515 m_inOverlayFullscreenVideo = false; 3497 m_inOverlayFullscreenVideo = false;
3516 } 3498 }
3517 3499
3518 WebLayer* HTMLMediaElement::platformLayer() const { 3500 WebLayer* HTMLMediaElement::platformLayer() const {
3519 return m_webLayer; 3501 return m_webLayer;
3520 } 3502 }
3521 3503
3522 bool HTMLMediaElement::hasClosedCaptions() const { 3504 bool HTMLMediaElement::hasClosedCaptions() const {
3523 if (m_textTracks) { 3505 if (!m_textTracks)
3524 for (unsigned i = 0; i < m_textTracks->length(); ++i) { 3506 return false;
3525 if (m_textTracks->anonymousIndexedGetter(i)->canBeRendered()) 3507
3526 return true; 3508 for (unsigned i = 0; i < m_textTracks->length(); ++i) {
3527 } 3509 if (m_textTracks->anonymousIndexedGetter(i)->canBeRendered())
3510 return true;
3528 } 3511 }
3512
3529 return false; 3513 return false;
3530 } 3514 }
3531 3515
3532 bool HTMLMediaElement::textTracksVisible() const { 3516 bool HTMLMediaElement::textTracksVisible() const {
3533 return m_textTracksVisible; 3517 return m_textTracksVisible;
3534 } 3518 }
3535 3519
3536 static void assertShadowRootChildren(ShadowRoot& shadowRoot) { 3520 static void assertShadowRootChildren(ShadowRoot& shadowRoot) {
3537 #if DCHECK_IS_ON() 3521 #if DCHECK_IS_ON()
3538 // There can be up to two children, either or both of the text 3522 // 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
3725 3709
3726 if (m_processingPreferenceChange) 3710 if (m_processingPreferenceChange)
3727 return; 3711 return;
3728 3712
3729 bool haveVisibleTextTrack = m_textTracks->hasShowingTracks(); 3713 bool haveVisibleTextTrack = m_textTracks->hasShowingTracks();
3730 m_textTracksVisible = haveVisibleTextTrack; 3714 m_textTracksVisible = haveVisibleTextTrack;
3731 3715
3732 if (!haveVisibleTextTrack && !mediaControls()) 3716 if (!haveVisibleTextTrack && !mediaControls())
3733 return; 3717 return;
3734 3718
3735 if (mediaControls())
3736 mediaControls()->changedClosedCaptionsVisibility();
3737
3738 cueTimeline().updateActiveCues(currentTime()); 3719 cueTimeline().updateActiveCues(currentTime());
3739 3720
3740 // Note: The "time marches on" algorithm (updateActiveCues) runs the "rules 3721 // Note: The "time marches on" algorithm (updateActiveCues) runs the "rules
3741 // for updating the text track rendering" (updateTextTrackDisplay) only for 3722 // for updating the text track rendering" (updateTextTrackDisplay) only for
3742 // "affected tracks", i.e. tracks where the the active cues have changed. 3723 // "affected tracks", i.e. tracks where the the active cues have changed.
3743 // This misses cues in tracks that changed mode between hidden and showing. 3724 // This misses cues in tracks that changed mode between hidden and showing.
3744 // This appears to be a spec bug, which we work around here: 3725 // This appears to be a spec bug, which we work around here:
3745 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28236 3726 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28236
3746 updateTextTrackDisplay(); 3727 updateTextTrackDisplay();
3747 } 3728 }
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
4193 4174
4194 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4175 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4195 const { 4176 const {
4196 IntRect result; 4177 IntRect result;
4197 if (LayoutObject* object = m_element->layoutObject()) 4178 if (LayoutObject* object = m_element->layoutObject())
4198 result = object->absoluteBoundingBoxRect(); 4179 result = object->absoluteBoundingBoxRect();
4199 return result; 4180 return result;
4200 } 4181 }
4201 4182
4202 } // namespace blink 4183 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698