Bug 882718 - Implement GetCueListByTimeInterval() at TextTrackCueList object. r=rillian
MozReview-Commit-ID: 1T3EEfG83ec
--- 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;