Backed out changeset f594e6f00208 (bug 1940883) for causing crashes in bug 1941164.
[gecko.git] / dom / media / webvtt / TextTrackCueList.h
blobf590f94d8cca0712a11d5cf0c13ddc9c8ae1e7ff
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/. */
7 #ifndef mozilla_dom_TextTrackCueList_h
8 #define mozilla_dom_TextTrackCueList_h
10 #include "nsTArray.h"
11 #include "nsCOMPtr.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsWrapperCache.h"
15 namespace mozilla {
16 class ErrorResult;
18 namespace dom {
20 class TextTrackCue;
22 class TextTrackCueList final : public nsISupports, public nsWrapperCache {
23 public:
24 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TextTrackCueList)
27 // TextTrackCueList WebIDL
28 explicit TextTrackCueList(nsISupports* aParent);
30 JSObject* WrapObject(JSContext* aCx,
31 JS::Handle<JSObject*> aGivenProto) override;
33 nsISupports* GetParentObject() const { return mParent; }
35 uint32_t Length() const { return mList.Length(); }
37 bool IsEmpty() const { return mList.Length() == 0; }
39 TextTrackCue* IndexedGetter(uint32_t aIndex, bool& aFound);
40 TextTrackCue* operator[](uint32_t aIndex);
41 TextTrackCue* GetCueById(const nsAString& aId);
42 TextTrackCueList& operator=(const TextTrackCueList& aOther);
43 // Adds a cue to mList by performing an insertion sort on mList.
44 // We expect most files to already be sorted, so an insertion sort starting
45 // from the end of the current array should be more efficient than a general
46 // sort step after all cues are loaded.
47 void AddCue(TextTrackCue& aCue);
48 void RemoveCue(TextTrackCue& aCue);
49 void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
50 void RemoveCueAt(uint32_t aIndex);
51 void RemoveAll();
52 void GetArray(nsTArray<RefPtr<TextTrackCue>>& aCues);
54 void SetCuesInactive();
56 void NotifyCueUpdated(TextTrackCue* aCue);
57 bool IsCueExist(TextTrackCue* aCue);
58 nsTArray<RefPtr<TextTrackCue>>& GetCuesArray();
60 private:
61 ~TextTrackCueList();
63 nsCOMPtr<nsISupports> mParent;
65 // A sorted list of TextTrackCues sorted by earliest start time. If the start
66 // times are equal then it will be sorted by end time, earliest first.
67 nsTArray<RefPtr<TextTrackCue>> mList;
70 } // namespace dom
71 } // namespace mozilla
73 #endif // mozilla_dom_TextTrackCueList_h