Bug 1274884 - Add/Remove cue into MediaElement when TextTrack::mMode changed. r=rillian
authorbechen <bechen@mozilla.com>
Thu, 02 Jun 2016 16:08:32 +0800
changeset 301067 2cbc8d093dfaa7a72b48127a584c7ccdcdd315e5
parent 301066 3a5b19ff2f4105f3a1fa610a4480711ca4609718
child 301068 ff0dfc12d86e25c3a16e40dcd16af8b1b8f6ba3d
push id30325
push userkwierso@gmail.com
push dateWed, 08 Jun 2016 23:17:01 +0000
treeherdermozilla-central@051765f8237d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1274884
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1274884 - Add/Remove cue into MediaElement when TextTrack::mMode changed. r=rillian MozReview-Commit-ID: 9PGEV5g8iv3
dom/html/HTMLMediaElement.h
dom/html/TextTrackManager.cpp
dom/html/TextTrackManager.h
dom/media/TextTrack.cpp
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -690,19 +690,19 @@ public:
   }
 
   void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly = false) {
     if (mTextTrackManager) {
       mTextTrackManager->RemoveTextTrack(aTextTrack, aPendingListOnly);
     }
   }
 
-  void AddCue(TextTrackCue& aCue) {
+  void NotifyCueAdded(TextTrackCue& aCue) {
     if (mTextTrackManager) {
-      mTextTrackManager->AddCue(aCue);
+      mTextTrackManager->NotifyCueAdded(aCue);
     }
   }
   void NotifyCueRemoved(TextTrackCue& aCue) {
     if (mTextTrackManager) {
       mTextTrackManager->NotifyCueRemoved(aCue);
     }
   }
 
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -250,17 +250,17 @@ TextTrackManager::UpdateCueDisplay()
       sParserWrapper->ProcessCues(window, jsCues, overlay);
     }
   } else if (overlay->Length() > 0) {
     nsContentUtils::SetNodeTextContent(overlay, EmptyString(), true);
   }
 }
 
 void
-TextTrackManager::AddCue(TextTrackCue& aCue)
+TextTrackManager::NotifyCueAdded(TextTrackCue& aCue)
 {
   if (mNewCues) {
     mNewCues->AddCue(aCue);
   }
   DispatchTimeMarchesOn();
 }
 
 void
--- a/dom/html/TextTrackManager.h
+++ b/dom/html/TextTrackManager.h
@@ -51,17 +51,17 @@ public:
                                            const nsAString& aLanguage,
                                            TextTrackMode aMode,
                                            TextTrackReadyState aReadyState,
                                            TextTrackSource aTextTrackSource);
   void AddTextTrack(TextTrack* aTextTrack);
   void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly);
   void DidSeek();
 
-  void AddCue(TextTrackCue& aCue);
+  void NotifyCueAdded(TextTrackCue& aCue);
   void AddCues(TextTrack* aTextTrack);
   void NotifyCueRemoved(TextTrackCue& aCue);
   /**
    * Overview of WebVTT cuetext and anonymous content setup.
    *
    * WebVTT nodes are the parsed version of WebVTT cuetext. WebVTT cuetext is
    * the portion of a WebVTT cue that specifies what the caption will actually
    * show up as on screen.
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -89,17 +89,35 @@ TextTrack::WrapObject(JSContext* aCx, JS
 
 void
 TextTrack::SetMode(TextTrackMode aValue)
 {
   if (mMode != aValue) {
     mMode = aValue;
     if (aValue == TextTrackMode::Disabled) {
       SetCuesInactive();
-      //TODO: Apply the rules for text track cue rendering Bug 865407
+      // Remove all the cues in MediaElement.
+      if (mTextTrackList) {
+        HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
+        if (mediaElement) {
+          for (size_t i = 0; i < mCueList->Length(); ++i) {
+            mediaElement->NotifyCueRemoved(*(*mCueList)[i]);
+          }
+        }
+      }
+    } else {
+      // Add all the cues into MediaElement.
+      if (mTextTrackList) {
+        HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
+        if (mediaElement) {
+          for (size_t i = 0; i < mCueList->Length(); ++i) {
+            mediaElement->NotifyCueAdded(*(*mCueList)[i]);
+          }
+        }
+      }
     }
     if (mTextTrackList) {
       mTextTrackList->CreateAndDispatchChangeEvent();
     }
   }
 }
 
 void
@@ -114,18 +132,18 @@ TextTrack::GetId(nsAString& aId) const
 
 void
 TextTrack::AddCue(TextTrackCue& aCue)
 {
   mCueList->AddCue(aCue);
   aCue.SetTrack(this);
   if (mTextTrackList) {
     HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
-    if (mediaElement) {
-      mediaElement->AddCue(aCue);
+    if (mediaElement && (mMode != TextTrackMode::Disabled)) {
+      mediaElement->NotifyCueAdded(aCue);
     }
   }
   SetDirty();
 }
 
 void
 TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
 {