Bug 882718 - Implement GetCueListByTimeInterval() at TextTrackCueList object. r=rillian draft
authorbechen <bechen@mozilla.com>
Wed, 01 Jun 2016 13:35:54 +0800
changeset 373766 ae68a45a10921bcb1556dc9d0ddbba8cda4ae361
parent 373765 5bcdef7b8ca08ce9938f1ce2bf24d752dcecd16b
child 373767 de92f37386b5adddc995f529e9a5db58379354a1
push id19838
push userbechen@mozilla.com
push dateWed, 01 Jun 2016 07:10:27 +0000
reviewersrillian
bugs882718
milestone49.0a1
Bug 882718 - Implement GetCueListByTimeInterval() at TextTrackCueList object. r=rillian MozReview-Commit-ID: 1T3EEfG83ec
dom/media/TextTrackCueList.cpp
dom/media/TextTrackCueList.h
--- a/dom/media/TextTrackCueList.cpp
+++ b/dom/media/TextTrackCueList.cpp
@@ -120,10 +120,24 @@ TextTrackCueList::GetArray(nsTArray<RefP
 void
 TextTrackCueList::SetCuesInactive()
 {
   for(uint32_t i = 0; i < mList.Length(); ++i) {
     mList[i]->SetActive(false);
   }
 }
 
+already_AddRefed<TextTrackCueList>
+TextTrackCueList::GetCueListByTimeInterval(media::Interval<double>& aInterval)
+{
+  RefPtr<TextTrackCueList> output = new TextTrackCueList(mParent);
+  for (uint32_t i = 0; i < mList.Length(); ++i) {
+    TextTrackCue* cue = mList[i];
+    if (cue->StartTime() <= aInterval.mEnd &&
+        aInterval.mStart <= cue->EndTime()) {
+      output->AddCue(*cue);
+    }
+  }
+  return output.forget();
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/TextTrackCueList.h
+++ b/dom/media/TextTrackCueList.h
@@ -7,16 +7,17 @@
 #ifndef mozilla_dom_TextTrackCueList_h
 #define mozilla_dom_TextTrackCueList_h
 
 #include "nsTArray.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsWrapperCache.h"
 #include "mozilla/ErrorResult.h"
+#include "Intervals.h"
 
 namespace mozilla {
 namespace dom {
 
 class TextTrackCue;
 
 class TextTrackCueList final : public nsISupports
                              , public nsWrapperCache
@@ -51,16 +52,19 @@ public:
   void AddCue(TextTrackCue& aCue);
   void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
   void RemoveCueAt(uint32_t aIndex);
   void RemoveAll();
   void GetArray(nsTArray<RefPtr<TextTrackCue> >& aCues);
 
   void SetCuesInactive();
 
+  already_AddRefed<TextTrackCueList>
+  GetCueListByTimeInterval(media::Interval<double>& aInterval);
+
 private:
   ~TextTrackCueList();
 
   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< RefPtr<TextTrackCue> > mList;