Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / dom / media / TextTrack.h
blob8207b08bc41883da580147c5d4b04d799bf82990
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_TextTrack_h
8 #define mozilla_dom_TextTrack_h
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/TextTrackBinding.h"
12 #include "nsCOMPtr.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsString.h"
15 #include "TimeUnits.h"
17 namespace mozilla {
18 namespace dom {
20 class TextTrackList;
21 class TextTrackCue;
22 class TextTrackCueList;
23 class HTMLTrackElement;
24 class HTMLMediaElement;
26 enum TextTrackSource { Track, AddTextTrack, MediaResourceSpecific };
28 // Constants for numeric readyState property values.
29 enum TextTrackReadyState {
30 NotLoaded = 0U,
31 Loading = 1U,
32 Loaded = 2U,
33 FailedToLoad = 3U
36 class TextTrack final : public DOMEventTargetHelper {
37 public:
38 NS_DECL_ISUPPORTS_INHERITED
39 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextTrack, DOMEventTargetHelper)
41 TextTrack(nsPIDOMWindowInner* aOwnerWindow, TextTrackKind aKind,
42 const nsAString& aLabel, const nsAString& aLanguage,
43 TextTrackMode aMode, TextTrackReadyState aReadyState,
44 TextTrackSource aTextTrackSource);
45 TextTrack(nsPIDOMWindowInner* aOwnerWindow, TextTrackList* aTextTrackList,
46 TextTrackKind aKind, const nsAString& aLabel,
47 const nsAString& aLanguage, TextTrackMode aMode,
48 TextTrackReadyState aReadyState, TextTrackSource aTextTrackSource);
50 void SetDefaultSettings();
52 JSObject* WrapObject(JSContext* aCx,
53 JS::Handle<JSObject*> aGivenProto) override;
55 TextTrackKind Kind() const { return mKind; }
56 void GetLabel(nsAString& aLabel) const;
57 void GetLanguage(nsAString& aLanguage) const;
58 void GetInBandMetadataTrackDispatchType(nsAString& aType) const {
59 aType = mType;
61 void GetId(nsAString& aId) const;
63 TextTrackMode Mode() const { return mMode; }
64 void SetMode(TextTrackMode aValue);
66 TextTrackCueList* GetCues() const {
67 if (mMode == TextTrackMode::Disabled) {
68 return nullptr;
70 return mCueList;
73 TextTrackCueList* GetActiveCues();
74 void GetActiveCueArray(nsTArray<RefPtr<TextTrackCue> >& aCues);
76 TextTrackReadyState ReadyState() const;
77 void SetReadyState(TextTrackReadyState aState);
78 void SetReadyState(uint32_t aReadyState);
80 void AddCue(TextTrackCue& aCue);
81 void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
82 void SetDirty() { mDirty = true; }
83 void SetCuesDirty();
85 TextTrackList* GetTextTrackList();
86 void SetTextTrackList(TextTrackList* aTextTrackList);
88 IMPL_EVENT_HANDLER(cuechange)
90 HTMLTrackElement* GetTrackElement();
91 void SetTrackElement(HTMLTrackElement* aTrackElement);
93 TextTrackSource GetTextTrackSource() { return mTextTrackSource; }
95 void SetCuesInactive();
97 void NotifyCueUpdated(TextTrackCue* aCue);
99 void DispatchAsyncTrustedEvent(const nsString& aEventName);
101 bool IsLoaded();
103 // Called when associated cue's active flag has been changed, and then we
104 // would add or remove the cue to the active cue list.
105 void NotifyCueActiveStateChanged(TextTrackCue* aCue);
107 // Use this function to request current cues, which start time are less than
108 // or equal to the current playback position and whose end times are greater
109 // than the current playback position, and other cues, which are not in the
110 // current cues. Because there would be LOTS of cues in the other cues, and we
111 // don't actually need all of them. Therefore, we use a time interval to get
112 // the cues which are overlapping within the time interval.
113 void GetCurrentCuesAndOtherCues(RefPtr<TextTrackCueList>& aCurrentCues,
114 RefPtr<TextTrackCueList>& aOtherCues,
115 const media::TimeInterval& aInterval) const;
117 void ClearAllCues();
119 private:
120 ~TextTrack();
122 HTMLMediaElement* GetMediaElement() const;
124 RefPtr<TextTrackList> mTextTrackList;
126 TextTrackKind mKind;
127 nsString mLabel;
128 nsString mLanguage;
129 nsString mType;
130 TextTrackMode mMode;
132 RefPtr<TextTrackCueList> mCueList;
133 RefPtr<TextTrackCueList> mActiveCueList;
134 RefPtr<HTMLTrackElement> mTrackElement;
136 uint32_t mCuePos;
137 TextTrackReadyState mReadyState;
138 bool mDirty;
140 // An enum that represents where the track was sourced from.
141 TextTrackSource mTextTrackSource;
144 } // namespace dom
145 } // namespace mozilla
147 #endif // mozilla_dom_TextTrack_h