Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/TextTrackCueList.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include "mozilla/dom/TextTrackCueList.h"
7
#include "mozilla/dom/TextTrackCueListBinding.h"
8
#include "mozilla/dom/TextTrackCue.h"
9
10
namespace mozilla {
11
namespace dom {
12
13
class CompareCuesByTime
14
{
15
public:
16
0
  bool Equals(TextTrackCue* aOne, TextTrackCue* aTwo) const {
17
0
    return false;
18
0
  }
19
0
  bool LessThan(TextTrackCue* aOne, TextTrackCue* aTwo) const {
20
0
    return aOne->StartTime() < aTwo->StartTime() ||
21
0
           (aOne->StartTime() == aTwo->StartTime() &&
22
0
            aOne->EndTime() >= aTwo->EndTime());
23
0
  }
24
};
25
26
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TextTrackCueList, mParent, mList)
27
28
NS_IMPL_CYCLE_COLLECTING_ADDREF(TextTrackCueList)
29
NS_IMPL_CYCLE_COLLECTING_RELEASE(TextTrackCueList)
30
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrackCueList)
31
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
32
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
33
0
NS_INTERFACE_MAP_END
34
35
TextTrackCueList::TextTrackCueList(nsISupports* aParent) : mParent(aParent)
36
0
{
37
0
}
38
39
TextTrackCueList::~TextTrackCueList()
40
0
{}
41
42
JSObject*
43
TextTrackCueList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
44
0
{
45
0
  return TextTrackCueList_Binding::Wrap(aCx, this, aGivenProto);
46
0
}
47
48
TextTrackCue*
49
TextTrackCueList::IndexedGetter(uint32_t aIndex, bool& aFound)
50
0
{
51
0
  aFound = aIndex < mList.Length();
52
0
  if (!aFound) {
53
0
    return nullptr;
54
0
  }
55
0
  return mList[aIndex];
56
0
}
57
58
TextTrackCue*
59
TextTrackCueList::operator[](uint32_t aIndex)
60
0
{
61
0
  return mList.SafeElementAt(aIndex, nullptr);
62
0
}
63
64
TextTrackCueList&
65
TextTrackCueList::operator=(const TextTrackCueList& aOther)
66
0
{
67
0
  mList = aOther.mList;
68
0
  return *this;
69
0
}
70
71
TextTrackCue*
72
TextTrackCueList::GetCueById(const nsAString& aId)
73
0
{
74
0
  if (aId.IsEmpty()) {
75
0
    return nullptr;
76
0
  }
77
0
78
0
  for (uint32_t i = 0; i < mList.Length(); i++) {
79
0
    if (aId.Equals(mList[i]->Id())) {
80
0
      return mList[i];
81
0
    }
82
0
  }
83
0
  return nullptr;
84
0
}
85
86
void
87
TextTrackCueList::AddCue(TextTrackCue& aCue)
88
0
{
89
0
  if (mList.Contains(&aCue)) {
90
0
    return;
91
0
  }
92
0
  mList.InsertElementSorted(&aCue, CompareCuesByTime());
93
0
}
94
95
void
96
TextTrackCueList::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
97
0
{
98
0
  if (!mList.Contains(&aCue)) {
99
0
    aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
100
0
    return;
101
0
  }
102
0
  mList.RemoveElement(&aCue);
103
0
}
104
105
void
106
TextTrackCueList::RemoveCue(TextTrackCue& aCue)
107
0
{
108
0
  mList.RemoveElement(&aCue);
109
0
}
110
111
void
112
TextTrackCueList::RemoveCueAt(uint32_t aIndex)
113
0
{
114
0
  if (aIndex < mList.Length()) {
115
0
    mList.RemoveElementAt(aIndex);
116
0
  }
117
0
}
118
119
void
120
TextTrackCueList::RemoveAll()
121
0
{
122
0
  mList.Clear();
123
0
}
124
125
void
126
TextTrackCueList::GetArray(nsTArray<RefPtr<TextTrackCue> >& aCues)
127
0
{
128
0
  aCues = nsTArray<RefPtr<TextTrackCue> >(mList);
129
0
}
130
131
132
void
133
TextTrackCueList::SetCuesInactive()
134
0
{
135
0
  for(uint32_t i = 0; i < mList.Length(); ++i) {
136
0
    mList[i]->SetActive(false);
137
0
  }
138
0
}
139
140
already_AddRefed<TextTrackCueList>
141
TextTrackCueList::GetCueListByTimeInterval(media::Interval<double>& aInterval)
142
0
{
143
0
  RefPtr<TextTrackCueList> output = new TextTrackCueList(mParent);
144
0
  for (uint32_t i = 0; i < mList.Length(); ++i) {
145
0
    TextTrackCue* cue = mList[i];
146
0
    if (cue->StartTime() <= aInterval.mEnd &&
147
0
        aInterval.mStart <= cue->EndTime()) {
148
0
      output->AddCue(*cue);
149
0
    }
150
0
  }
151
0
  return output.forget();
152
0
}
153
154
void
155
TextTrackCueList::NotifyCueUpdated(TextTrackCue *aCue)
156
0
{
157
0
  if (aCue) {
158
0
    mList.RemoveElement(aCue);
159
0
    mList.InsertElementSorted(aCue, CompareCuesByTime());
160
0
  }
161
0
}
162
163
bool
164
TextTrackCueList::IsCueExist(TextTrackCue *aCue)
165
0
{
166
0
  if (aCue && mList.Contains(aCue)) {
167
0
    return true;
168
0
  }
169
0
  return false;
170
0
}
171
172
nsTArray<RefPtr<TextTrackCue>>&
173
TextTrackCueList::GetCuesArray()
174
0
{
175
0
  return mList;
176
0
}
177
178
} // namespace dom
179
} // namespace mozilla