Line data Source code
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 : #include "Intervals.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : class TextTrackCue;
21 :
22 : class TextTrackCueList final : public nsISupports
23 : , public nsWrapperCache
24 : {
25 : public:
26 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextTrackCueList)
28 :
29 : // TextTrackCueList WebIDL
30 : explicit TextTrackCueList(nsISupports* aParent);
31 :
32 : JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
33 :
34 0 : nsISupports* GetParentObject() const
35 : {
36 0 : return mParent;
37 : }
38 :
39 0 : uint32_t Length() const
40 : {
41 0 : return mList.Length();
42 : }
43 :
44 0 : bool IsEmpty() const
45 : {
46 0 : return mList.Length() == 0;
47 : }
48 :
49 : TextTrackCue* IndexedGetter(uint32_t aIndex, bool& aFound);
50 : TextTrackCue* operator[](uint32_t aIndex);
51 : TextTrackCue* GetCueById(const nsAString& aId);
52 : TextTrackCueList& operator=(const TextTrackCueList& aOther);
53 : // Adds a cue to mList by performing an insertion sort on mList.
54 : // We expect most files to already be sorted, so an insertion sort starting
55 : // from the end of the current array should be more efficient than a general
56 : // sort step after all cues are loaded.
57 : void AddCue(TextTrackCue& aCue);
58 : void RemoveCue(TextTrackCue& aCue);
59 : void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
60 : void RemoveCueAt(uint32_t aIndex);
61 : void RemoveAll();
62 : void GetArray(nsTArray<RefPtr<TextTrackCue> >& aCues);
63 :
64 : void SetCuesInactive();
65 :
66 : already_AddRefed<TextTrackCueList>
67 : GetCueListByTimeInterval(media::Interval<double>& aInterval);
68 : void NotifyCueUpdated(TextTrackCue *aCue);
69 : bool IsCueExist(TextTrackCue *aCue);
70 : nsTArray<RefPtr<TextTrackCue>>& GetCuesArray();
71 :
72 : private:
73 : ~TextTrackCueList();
74 :
75 : nsCOMPtr<nsISupports> mParent;
76 :
77 : // A sorted list of TextTrackCues sorted by earliest start time. If the start
78 : // times are equal then it will be sorted by end time, earliest first.
79 : nsTArray< RefPtr<TextTrackCue> > mList;
80 : };
81 :
82 : } // namespace dom
83 : } // namespace mozilla
84 :
85 : #endif // mozilla_dom_TextTrackCueList_h
|