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 "TimeUnits.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/DefineEnum.h"
13 #include "mozilla/dom/TextTrackBinding.h"
15 #include "nsCycleCollectionParticipant.h"
18 namespace mozilla::dom
{
22 class TextTrackCueList
;
23 class HTMLTrackElement
;
24 class HTMLMediaElement
;
26 enum class TextTrackSource
: uint8_t {
29 MediaResourceSpecific
,
32 // Constants for numeric readyState property values.
33 MOZ_DEFINE_ENUM_CLASS_WITH_BASE_AND_TOSTRING(TextTrackReadyState
, uint8_t,
34 (NotLoaded
, Loading
, Loaded
,
37 class TextTrack final
: public DOMEventTargetHelper
{
39 NS_DECL_ISUPPORTS_INHERITED
40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextTrack
, DOMEventTargetHelper
)
42 TextTrack(nsPIDOMWindowInner
* aOwnerWindow
, TextTrackKind aKind
,
43 const nsAString
& aLabel
, const nsAString
& aLanguage
,
44 TextTrackMode aMode
, TextTrackReadyState aReadyState
,
45 TextTrackSource aTextTrackSource
);
46 TextTrack(nsPIDOMWindowInner
* aOwnerWindow
, TextTrackList
* aTextTrackList
,
47 TextTrackKind aKind
, const nsAString
& aLabel
,
48 const nsAString
& aLanguage
, TextTrackMode aMode
,
49 TextTrackReadyState aReadyState
, TextTrackSource aTextTrackSource
);
51 void SetDefaultSettings();
53 JSObject
* WrapObject(JSContext
* aCx
,
54 JS::Handle
<JSObject
*> aGivenProto
) override
;
56 TextTrackKind
Kind() const { return mKind
; }
57 void GetLabel(nsAString
& aLabel
) const;
58 void GetLanguage(nsAString
& aLanguage
) const;
59 void GetInBandMetadataTrackDispatchType(nsAString
& aType
) const {
62 void GetId(nsAString
& aId
) const;
64 TextTrackMode
Mode() const { return mMode
; }
65 void SetMode(TextTrackMode aValue
);
67 TextTrackCueList
* GetCues() const {
68 if (mMode
== TextTrackMode::Disabled
) {
74 TextTrackCueList
* GetActiveCues();
75 void GetActiveCueArray(nsTArray
<RefPtr
<TextTrackCue
> >& aCues
);
77 TextTrackReadyState
ReadyState() const;
78 void SetReadyState(TextTrackReadyState aState
);
80 void AddCue(TextTrackCue
& aCue
);
81 void RemoveCue(TextTrackCue
& aCue
, ErrorResult
& aRv
);
82 void SetDirty() { mDirty
= true; }
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
);
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;
122 HTMLMediaElement
* GetMediaElement() const;
124 RefPtr
<TextTrackList
> mTextTrackList
;
132 RefPtr
<TextTrackCueList
> mCueList
;
133 RefPtr
<TextTrackCueList
> mActiveCueList
;
134 RefPtr
<HTMLTrackElement
> mTrackElement
;
137 TextTrackReadyState mReadyState
;
140 // An enum that represents where the track was sourced from.
141 TextTrackSource mTextTrackSource
;
144 } // namespace mozilla::dom
146 #endif // mozilla_dom_TextTrack_h