tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TextTrackCueList.h (2444B)


      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 "nsCOMPtr.h"
     11 #include "nsCycleCollectionParticipant.h"
     12 #include "nsTArray.h"
     13 #include "nsTHashSet.h"
     14 #include "nsWrapperCache.h"
     15 
     16 namespace mozilla {
     17 class ErrorResult;
     18 
     19 namespace dom {
     20 
     21 class TextTrackCue;
     22 
     23 class TextTrackCueList final : public nsISupports, public nsWrapperCache {
     24 public:
     25  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     26  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TextTrackCueList)
     27 
     28  // TextTrackCueList WebIDL
     29  explicit TextTrackCueList(nsISupports* aParent);
     30 
     31  JSObject* WrapObject(JSContext* aCx,
     32                       JS::Handle<JSObject*> aGivenProto) override;
     33 
     34  nsISupports* GetParentObject() const { return mParent; }
     35 
     36  uint32_t Length() const { return mList.Length(); }
     37 
     38  bool IsEmpty() const { return mList.Length() == 0; }
     39 
     40  TextTrackCue* IndexedGetter(uint32_t aIndex, bool& aFound);
     41  TextTrackCue* operator[](uint32_t aIndex);
     42  TextTrackCue* GetCueById(const nsAString& aId);
     43  TextTrackCueList& operator=(const TextTrackCueList& aOther);
     44 
     45  // Adds a cue to mList by performing an insertion sort on mList.
     46  // We expect most files to already be sorted, so an insertion sort starting
     47  // from the end of the current array should be more efficient than a general
     48  // sort step after all cues are loaded.
     49  void AddCue(TextTrackCue& aCue);
     50  void RemoveCue(TextTrackCue& aCue);
     51  void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
     52  void GetArray(nsTArray<RefPtr<TextTrackCue>>& aCues);
     53 
     54  void SetCuesInactive();
     55 
     56  void NotifyCueUpdated(TextTrackCue* aCue);
     57  bool IsCueExist(TextTrackCue* aCue) const;
     58  nsTArray<RefPtr<TextTrackCue>>& GetCuesArray();
     59 
     60 private:
     61  ~TextTrackCueList();
     62 
     63  nsCOMPtr<nsISupports> mParent;
     64 
     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;
     68 
     69  // Utilized for rapid cue existence verification.
     70  nsTHashSet<TextTrackCue*> mCueSet;
     71 };
     72 
     73 }  // namespace dom
     74 }  // namespace mozilla
     75 
     76 #endif  // mozilla_dom_TextTrackCueList_h