Bug 1325001 - TextTrackList::GetShowingCues should return cues whose kind is Subtitles or Captions. r=rillian draft
authorbechen <bechen@mozilla.com>
Mon, 22 May 2017 11:30:22 +0800
changeset 582217 2c4d6b0b052758f1bb01a7794365bf75b556304c
parent 582183 74566d5345f4cab06c5683d4b620124104801e65
child 629701 e6aff42eabe06aa5e6e27c9510ccf1226a9e5d20
push id60008
push userbechen@mozilla.com
push dateMon, 22 May 2017 03:31:10 +0000
reviewersrillian
bugs1325001
milestone55.0a1
Bug 1325001 - TextTrackList::GetShowingCues should return cues whose kind is Subtitles or Captions. r=rillian We should only render the Subtitles/Captions cue on the screen. In addition, rename the activeCues to showingCues. Because the meaning of "active" and "showing" are different. Showing means we can see the cue on the screen, active means the current playback time touches the cue. MozReview-Commit-ID: 1BfHhxFXBDP
dom/html/TextTrackManager.cpp
dom/media/TextTrackList.cpp
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -271,28 +271,28 @@ TextTrackManager::UpdateCueDisplay()
   }
 
   nsCOMPtr<nsIContent> overlay = videoFrame->GetCaptionOverlay();
   nsCOMPtr<nsIContent> controls = videoFrame->GetVideoControls();
   if (!overlay) {
     return;
   }
 
-  nsTArray<RefPtr<TextTrackCue> > activeCues;
-  mTextTracks->GetShowingCues(activeCues);
+  nsTArray<RefPtr<TextTrackCue> > showingCues;
+  mTextTracks->GetShowingCues(showingCues);
 
-  if (activeCues.Length() > 0) {
+  if (showingCues.Length() > 0) {
     WEBVTT_LOG("UpdateCueDisplay ProcessCues");
-    WEBVTT_LOGV("UpdateCueDisplay activeCues.Length() %" PRIuSIZE, activeCues.Length());
+    WEBVTT_LOGV("UpdateCueDisplay showingCues.Length() %" PRIuSIZE, showingCues.Length());
     RefPtr<nsVariantCC> jsCues = new nsVariantCC();
 
     jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE,
                        &NS_GET_IID(nsIDOMEventTarget),
-                       activeCues.Length(),
-                       static_cast<void*>(activeCues.Elements()));
+                       showingCues.Length(),
+                       static_cast<void*>(showingCues.Elements()));
     nsPIDOMWindowInner* window = mMediaElement->OwnerDoc()->GetInnerWindow();
     if (window) {
       sParserWrapper->ProcessCues(window, jsCues, overlay, controls);
     }
   } else if (overlay->Length() > 0) {
     WEBVTT_LOG("UpdateCueDisplay EmptyString");
     nsContentUtils::SetNodeTextContent(overlay, EmptyString(), true);
   }
--- a/dom/media/TextTrackList.cpp
+++ b/dom/media/TextTrackList.cpp
@@ -38,19 +38,22 @@ TextTrackList::TextTrackList(nsPIDOMWind
 
 TextTrackList::~TextTrackList()
 {
 }
 
 void
 TextTrackList::GetShowingCues(nsTArray<RefPtr<TextTrackCue> >& aCues)
 {
+  // Only Subtitles and Captions can show on the screen.
   nsTArray< RefPtr<TextTrackCue> > cues;
   for (uint32_t i = 0; i < Length(); i++) {
-    if (mTextTracks[i]->Mode() == TextTrackMode::Showing) {
+    if (mTextTracks[i]->Mode() == TextTrackMode::Showing &&
+        (mTextTracks[i]->Kind() == TextTrackKind::Subtitles ||
+         mTextTracks[i]->Kind() == TextTrackKind::Captions)) {
       mTextTracks[i]->GetActiveCueArray(cues);
       aCues.AppendElements(cues);
     }
   }
 }
 
 JSObject*
 TextTrackList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)