Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
6 #include "mozilla/dom/TextTrackCueList.h"
7 #include "mozilla/dom/TextTrackCueListBinding.h"
8 #include "mozilla/dom/TextTrackCue.h"
10 namespace mozilla {
11 namespace dom {
13 class CompareCuesByTime
14 {
15 public:
16 bool Equals(TextTrackCue* aOne, TextTrackCue* aTwo) const {
17 return aOne->StartTime() == aTwo->StartTime() &&
18 aOne->EndTime() == aTwo->EndTime();
19 }
20 bool LessThan(TextTrackCue* aOne, TextTrackCue* aTwo) const {
21 return aOne->StartTime() < aTwo->StartTime() ||
22 (aOne->StartTime() == aTwo->StartTime() &&
23 aOne->EndTime() < aTwo->EndTime());
24 }
25 };
27 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(TextTrackCueList, mParent, mList)
29 NS_IMPL_CYCLE_COLLECTING_ADDREF(TextTrackCueList)
30 NS_IMPL_CYCLE_COLLECTING_RELEASE(TextTrackCueList)
31 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrackCueList)
32 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
33 NS_INTERFACE_MAP_ENTRY(nsISupports)
34 NS_INTERFACE_MAP_END
36 TextTrackCueList::TextTrackCueList(nsISupports* aParent) : mParent(aParent)
37 {
38 SetIsDOMBinding();
39 }
41 JSObject*
42 TextTrackCueList::WrapObject(JSContext* aCx)
43 {
44 return TextTrackCueListBinding::Wrap(aCx, this);
45 }
47 TextTrackCue*
48 TextTrackCueList::IndexedGetter(uint32_t aIndex, bool& aFound)
49 {
50 aFound = aIndex < mList.Length();
51 return aFound ? mList[aIndex] : nullptr;
52 }
54 TextTrackCue*
55 TextTrackCueList::operator[](uint32_t aIndex)
56 {
57 return mList.SafeElementAt(aIndex, nullptr);
58 }
60 TextTrackCue*
61 TextTrackCueList::GetCueById(const nsAString& aId)
62 {
63 if (aId.IsEmpty()) {
64 return nullptr;
65 }
67 for (uint32_t i = 0; i < mList.Length(); i++) {
68 if (aId.Equals(mList[i]->Id())) {
69 return mList[i];
70 }
71 }
72 return nullptr;
73 }
75 void
76 TextTrackCueList::AddCue(TextTrackCue& aCue)
77 {
78 if (mList.Contains(&aCue)) {
79 return;
80 }
81 mList.InsertElementSorted(&aCue, CompareCuesByTime());
82 }
84 void
85 TextTrackCueList::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
86 {
87 if (!mList.Contains(&aCue)) {
88 aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
89 return;
90 }
91 mList.RemoveElement(&aCue);
92 }
94 void
95 TextTrackCueList::RemoveCueAt(uint32_t aIndex)
96 {
97 if (aIndex < mList.Length()) {
98 mList.RemoveElementAt(aIndex);
99 }
100 }
102 void
103 TextTrackCueList::RemoveAll()
104 {
105 mList.Clear();
106 }
108 void
109 TextTrackCueList::GetArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
110 {
111 aCues = nsTArray<nsRefPtr<TextTrackCue> >(mList);
112 }
115 } // namespace dom
116 } // namespace mozilla