From 985efe81dfe73756199d3f807ad3ad9a76c2a177 Mon Sep 17 00:00:00 2001 From: Andrew Quartey Date: Mon, 6 Jan 2014 13:03:50 -0500 Subject: [PATCH] Bug 882718 - Part a: Add list of newly introduced cues to TextTrackManager. r=rillian --- .../html/content/public/HTMLMediaElement.h | 6 +++++ content/html/content/src/TextTrackManager.cpp | 24 ++++++++++++++++++- content/html/content/src/TextTrackManager.h | 6 +++++ content/media/TextTrack.cpp | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/content/html/content/public/HTMLMediaElement.h b/content/html/content/public/HTMLMediaElement.h index abe169843e8..7bcb547493f 100644 --- a/content/html/content/public/HTMLMediaElement.h +++ b/content/html/content/public/HTMLMediaElement.h @@ -535,6 +535,12 @@ public: } } + void AddCue(TextTrackCue& aCue) { + if (mTextTrackManager) { + mTextTrackManager->AddCue(aCue); + } + } + /** * A public wrapper for FinishDecoderSetup() */ diff --git a/content/html/content/src/TextTrackManager.cpp b/content/html/content/src/TextTrackManager.cpp index 4a6e33e0fd9..fd9ab144eec 100644 --- a/content/html/content/src/TextTrackManager.cpp +++ b/content/html/content/src/TextTrackManager.cpp @@ -12,7 +12,8 @@ namespace mozilla { namespace dom { -NS_IMPL_CYCLE_COLLECTION_2(TextTrackManager, mTextTracks, mPendingTextTracks) +NS_IMPL_CYCLE_COLLECTION_3(TextTrackManager, mTextTracks, + mPendingTextTracks, mNewCues) NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(TextTrackManager, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(TextTrackManager, Release) @@ -20,6 +21,7 @@ TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement) : mMediaElement(aMediaElement) { MOZ_COUNT_CTOR(TextTrackManager); + mNewCues = new TextTrackCueList(mMediaElement->OwnerDoc()->GetParentObject()); mTextTracks = new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject()); mPendingTextTracks = new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject()); @@ -43,6 +45,7 @@ TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel, nsRefPtr ttrack = mTextTracks->AddTextTrack(mMediaElement, aKind, aLabel, aLanguage); ttrack->SetReadyState(HTMLTrackElement::LOADED); + AddCues(ttrack); return ttrack.forget(); } @@ -50,6 +53,19 @@ void TextTrackManager::AddTextTrack(TextTrack* aTextTrack) { mTextTracks->AddTextTrack(aTextTrack); + AddCues(aTextTrack); +} + +void +TextTrackManager::AddCues(TextTrack* aTextTrack) +{ + TextTrackCueList* cueList = aTextTrack->GetCues(); + if (cueList) { + bool dummy; + for (uint32_t i = 0; i < cueList->Length(); ++i) { + mNewCues->AddCue(*cueList->IndexedGetter(i, dummy)); + } + } } void @@ -75,6 +91,12 @@ TextTrackManager::Update(double aTime) mTextTracks->Update(aTime); } +void +TextTrackManager::AddCue(TextTrackCue& aCue) +{ + mNewCues->AddCue(aCue); +} + void TextTrackManager::PopulatePendingList() { diff --git a/content/html/content/src/TextTrackManager.h b/content/html/content/src/TextTrackManager.h index 36b9c55eefb..90cef65227a 100644 --- a/content/html/content/src/TextTrackManager.h +++ b/content/html/content/src/TextTrackManager.h @@ -10,6 +10,7 @@ #include "mozilla/dom/TextTrack.h" #include "mozilla/dom/TextTrackList.h" +#include "mozilla/dom/TextTrackCueList.h" namespace mozilla { namespace dom { @@ -33,6 +34,9 @@ public: void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly); void DidSeek(); + void AddCue(TextTrackCue& aCue); + void AddCues(TextTrack* aTextTrack); + // Update the display of cues on the video as per the current play back time // of aTime. void Update(double aTime); @@ -49,6 +53,8 @@ private: nsRefPtr mTextTracks; // List of text track objects awaiting loading. nsRefPtr mPendingTextTracks; + // List of newly introduced Text Track cues. + nsRefPtr mNewCues; }; } // namespace dom diff --git a/content/media/TextTrack.cpp b/content/media/TextTrack.cpp index f5516e6932d..3724d235d1b 100644 --- a/content/media/TextTrack.cpp +++ b/content/media/TextTrack.cpp @@ -101,6 +101,7 @@ void TextTrack::AddCue(TextTrackCue& aCue) { mCueList->AddCue(aCue); + mMediaElement->AddCue(aCue); SetDirty(); }