|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 et tw=78: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_dom_TextTrackCueList_h |
|
8 #define mozilla_dom_TextTrackCueList_h |
|
9 |
|
10 #include "nsTArray.h" |
|
11 #include "nsCOMPtr.h" |
|
12 #include "nsCycleCollectionParticipant.h" |
|
13 #include "nsWrapperCache.h" |
|
14 #include "mozilla/ErrorResult.h" |
|
15 |
|
16 namespace mozilla { |
|
17 namespace dom { |
|
18 |
|
19 class TextTrackCue; |
|
20 |
|
21 class TextTrackCueList MOZ_FINAL : public nsISupports |
|
22 , public nsWrapperCache |
|
23 { |
|
24 public: |
|
25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
26 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextTrackCueList) |
|
27 |
|
28 // TextTrackCueList WebIDL |
|
29 TextTrackCueList(nsISupports* aParent); |
|
30 |
|
31 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
32 |
|
33 nsISupports* GetParentObject() const |
|
34 { |
|
35 return mParent; |
|
36 } |
|
37 |
|
38 uint32_t Length() const |
|
39 { |
|
40 return mList.Length(); |
|
41 } |
|
42 |
|
43 TextTrackCue* IndexedGetter(uint32_t aIndex, bool& aFound); |
|
44 TextTrackCue* operator[](uint32_t aIndex); |
|
45 TextTrackCue* GetCueById(const nsAString& aId); |
|
46 |
|
47 // Adds a cue to mList by performing an insertion sort on mList. |
|
48 // We expect most files to already be sorted, so an insertion sort starting |
|
49 // from the end of the current array should be more efficient than a general |
|
50 // sort step after all cues are loaded. |
|
51 void AddCue(TextTrackCue& aCue); |
|
52 void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv); |
|
53 void RemoveCueAt(uint32_t aIndex); |
|
54 void RemoveAll(); |
|
55 void GetArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues); |
|
56 |
|
57 private: |
|
58 nsCOMPtr<nsISupports> mParent; |
|
59 |
|
60 // A sorted list of TextTrackCues sorted by earliest start time. If the start |
|
61 // times are equal then it will be sorted by end time, earliest first. |
|
62 nsTArray< nsRefPtr<TextTrackCue> > mList; |
|
63 }; |
|
64 |
|
65 } // namespace dom |
|
66 } // namespace mozilla |
|
67 |
|
68 #endif // mozilla_dom_TextTrackCueList_h |