Bug 865407 - Part 3: Add TextTrackList::GetAllActiveCues(). r=rillian
authorRick Eyre <rick.eyre@hotmail.com>
Thu, 12 Dec 2013 10:57:21 -0500
changeset 163345 705f43739079c16edb44d0a91c9063b883d4c7c6
parent 163344 21977186a78eb577056d4c59eca8954e64950bdd
child 163346 401b8593a881f7c98d42129395b7f5abdc6343ba
push id25993
push userkwierso@gmail.com
push dateTue, 14 Jan 2014 23:24:56 +0000
treeherdermozilla-central@4e671e3183c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs865407
milestone29.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 865407 - Part 3: Add TextTrackList::GetAllActiveCues(). r=rillian
content/media/TextTrack.cpp
content/media/TextTrack.h
content/media/TextTrackCueList.cpp
content/media/TextTrackCueList.h
content/media/TextTrackList.cpp
content/media/TextTrackList.h
--- a/content/media/TextTrack.cpp
+++ b/content/media/TextTrack.cpp
@@ -137,21 +137,21 @@ TextTrack::RemoveRegion(const TextTrackR
   if (!mRegionList->GetRegionById(aRegion.Id())) {
     aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
     return;
   }
 
   mRegionList->RemoveTextTrackRegion(aRegion);
 }
 
-TextTrackCueList*
-TextTrack::GetActiveCues()
+void
+TextTrack::UpdateActiveCueList()
 {
   if (mMode == TextTrackMode::Disabled || !mMediaElement) {
-    return nullptr;
+    return;
   }
 
   // If we are dirty, i.e. an event happened that may cause the sorted mCueList
   // to have changed like a seek or an insert for a cue, than we need to rebuild
   // the active cue list from scratch.
   if (mDirty) {
     mCuePos = 0;
     mDirty = false;
@@ -171,19 +171,31 @@ TextTrack::GetActiveCues()
   // We can stop iterating safely once we encounter a cue that does not have
   // a valid start time as the cue list is sorted.
   for (; mCuePos < mCueList->Length() &&
          (*mCueList)[mCuePos]->StartTime() <= playbackTime; mCuePos++) {
     if ((*mCueList)[mCuePos]->EndTime() >= playbackTime) {
       mActiveCueList->AddCue(*(*mCueList)[mCuePos]);
     }
   }
+}
+
+TextTrackCueList*
+TextTrack::GetActiveCues() {
+  UpdateActiveCueList();
   return mActiveCueList;
 }
 
+void
+TextTrack::GetActiveCueArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
+{
+  UpdateActiveCueList();
+  mActiveCueList->GetArray(aCues);
+}
+
 uint16_t
 TextTrack::ReadyState() const
 {
   return mReadyState;
 }
 
 void
 TextTrack::SetReadyState(uint16_t aState)
--- a/content/media/TextTrack.h
+++ b/content/media/TextTrack.h
@@ -78,16 +78,17 @@ public:
   {
     if (mMode == TextTrackMode::Disabled) {
       return nullptr;
     }
     return mCueList;
   }
 
   TextTrackCueList* GetActiveCues();
+  void GetActiveCueArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues);
 
   TextTrackRegionList* GetRegions() const
   {
     if (mMode != TextTrackMode::Disabled) {
       return mRegionList;
     }
     return nullptr;
   }
@@ -104,16 +105,18 @@ public:
   void AddCue(TextTrackCue& aCue);
   void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
   void CueChanged(TextTrackCue& aCue);
   void SetDirty() { mDirty = true; }
 
   IMPL_EVENT_HANDLER(cuechange)
 
 private:
+  void UpdateActiveCueList();
+
   nsCOMPtr<nsISupports> mParent;
   nsRefPtr<HTMLMediaElement> mMediaElement;
 
   TextTrackKind mKind;
   nsString mLabel;
   nsString mLanguage;
   nsString mType;
   nsString mId;
--- a/content/media/TextTrackCueList.cpp
+++ b/content/media/TextTrackCueList.cpp
@@ -111,10 +111,17 @@ TextTrackCueList::RemoveCueAt(uint32_t a
 }
 
 void
 TextTrackCueList::RemoveAll()
 {
   mList.Clear();
 }
 
+void
+TextTrackCueList::GetArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
+{
+  aCues = nsTArray<nsRefPtr<TextTrackCue> >(mList);
+}
+
+
 } // namespace dom
 } // namespace mozilla
--- a/content/media/TextTrackCueList.h
+++ b/content/media/TextTrackCueList.h
@@ -51,16 +51,17 @@ public:
   // Adds a cue to mList by performing an insertion sort on mList.
   // We expect most files to already be sorted, so an insertion sort starting
   // from the end of the current array should be more efficient than a general
   // sort step after all cues are loaded.
   void AddCue(TextTrackCue& aCue);
   void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
   void RemoveCueAt(uint32_t aIndex);
   void RemoveAll();
+  void GetArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues);
 
 private:
   nsCOMPtr<nsISupports> mParent;
 
   // A sorted list of TextTrackCues sorted by earliest start time. If the start
   // times are equal then it will be sorted by end time, earliest first.
   nsTArray< nsRefPtr<TextTrackCue> > mList;
 };
--- a/content/media/TextTrackList.cpp
+++ b/content/media/TextTrackList.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/TextTrackList.h"
 #include "mozilla/dom/TextTrackListBinding.h"
 #include "mozilla/dom/TrackEvent.h"
 #include "nsThreadUtils.h"
+#include "mozilla/dom/TextTrackCue.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED_2(TextTrackList,
                                      nsDOMEventTargetHelper,
                                      mGlobal,
                                      mTextTracks)
@@ -30,16 +31,28 @@ void
 TextTrackList::Update(double aTime)
 {
   uint32_t length = Length(), i;
   for (i = 0; i < length; i++) {
     mTextTracks[i]->Update(aTime);
   }
 }
 
+void
+TextTrackList::GetAllActiveCues(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
+{
+  nsTArray< nsRefPtr<TextTrackCue> > cues;
+  for (uint32_t i = 0; i < Length(); i++) {
+    if (mTextTracks[i]->Mode() != TextTrackMode::Disabled) {
+      mTextTracks[i]->GetActiveCueArray(cues);
+      aCues.AppendElements(cues);
+    }
+  }
+}
+
 JSObject*
 TextTrackList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return TextTrackListBinding::Wrap(aCx, aScope, this);
 }
 
 TextTrack*
 TextTrackList::IndexedGetter(uint32_t aIndex, bool& aFound)
--- a/content/media/TextTrackList.h
+++ b/content/media/TextTrackList.h
@@ -36,16 +36,19 @@ public:
   uint32_t Length() const
   {
     return mTextTracks.Length();
   }
 
   // Time is in seconds.
   void Update(double aTime);
 
+  // Get all the current active cues.
+  void GetAllActiveCues(nsTArray<nsRefPtr<TextTrackCue> >& aCues);
+
   TextTrack* IndexedGetter(uint32_t aIndex, bool& aFound);
 
   already_AddRefed<TextTrack> AddTextTrack(HTMLMediaElement* aMediaElement,
                                            TextTrackKind aKind,
                                            const nsAString& aLabel,
                                            const nsAString& aLanguage);
   TextTrack* GetTrackById(const nsAString& aId);