1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef mozilla_dom_TextTrackManager_h
9 #define mozilla_dom_TextTrackManager_h
11 #include "mozilla/dom/TextTrack.h"
12 #include "mozilla/dom/TextTrackList.h"
13 #include "mozilla/dom/TextTrackCueList.h"
14 #include "mozilla/StaticPtr.h"
16 class nsIWebVTTParserWrapper
;
21 class HTMLMediaElement
;
23 class CompareTextTracks
{
25 HTMLMediaElement
* mMediaElement
;
27 explicit CompareTextTracks(HTMLMediaElement
* aMediaElement
);
28 int32_t TrackChildPosition(TextTrack
* aTrack
) const;
29 bool Equals(TextTrack
* aOne
, TextTrack
* aTwo
) const;
30 bool LessThan(TextTrack
* aOne
, TextTrack
* aTwo
) const;
36 class TextTrackManager MOZ_FINAL
: public nsIDOMEventListener
41 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
42 NS_DECL_CYCLE_COLLECTION_CLASS(TextTrackManager
)
44 NS_DECL_NSIDOMEVENTLISTENER
46 explicit TextTrackManager(HTMLMediaElement
* aMediaElement
);
48 TextTrackList
* GetTextTracks() const;
49 already_AddRefed
<TextTrack
> AddTextTrack(TextTrackKind aKind
,
50 const nsAString
& aLabel
,
51 const nsAString
& aLanguage
,
53 TextTrackReadyState aReadyState
,
54 TextTrackSource aTextTrackSource
);
55 void AddTextTrack(TextTrack
* aTextTrack
);
56 void RemoveTextTrack(TextTrack
* aTextTrack
, bool aPendingListOnly
);
59 void AddCue(TextTrackCue
& aCue
);
60 void AddCues(TextTrack
* aTextTrack
);
63 * Overview of WebVTT cuetext and anonymous content setup.
65 * WebVTT nodes are the parsed version of WebVTT cuetext. WebVTT cuetext is
66 * the portion of a WebVTT cue that specifies what the caption will actually
67 * show up as on screen.
69 * WebVTT cuetext can contain markup that loosely relates to HTML markup. It
70 * can contain tags like <b>, <u>, <i>, <c>, <v>, <ruby>, <rt>, <lang>,
71 * including timestamp tags.
73 * When the caption is ready to be displayed the WebVTT nodes are converted
74 * over to anonymous DOM content. <i>, <u>, <b>, <ruby>, and <rt> all become
75 * HTMLElements of their corresponding HTML markup tags. <c> and <v> are
76 * converted to <span> tags. Timestamp tags are converted to XML processing
77 * instructions. Additionally, all cuetext tags support specifying of classes.
78 * This takes the form of <foo.class.subclass>. These classes are then parsed
79 * and set as the anonymous content's class attribute.
81 * Rules on constructing DOM objects from WebVTT nodes can be found here
82 * http://dev.w3.org/html5/webvtt/#webvtt-cue-text-dom-construction-rules.
83 * Current rules are taken from revision on April 15, 2013.
87 * Converts the TextTrackCue's cuetext into a tree of DOM objects and attaches
88 * it to a div on it's owning TrackElement's MediaElement's caption overlay.
90 void UpdateCueDisplay();
92 void PopulatePendingList();
96 // The HTMLMediaElement that this TextTrackManager manages the TextTracks of.
97 nsRefPtr
<HTMLMediaElement
> mMediaElement
;
99 // List of the TextTrackManager's owning HTMLMediaElement's TextTracks.
100 nsRefPtr
<TextTrackList
> mTextTracks
;
101 // List of text track objects awaiting loading.
102 nsRefPtr
<TextTrackList
> mPendingTextTracks
;
103 // List of newly introduced Text Track cues.
104 nsRefPtr
<TextTrackCueList
> mNewCues
;
106 static StaticRefPtr
<nsIWebVTTParserWrapper
> sParserWrapper
;
108 bool performedTrackSelection
;
110 // Runs the algorithm for performing automatic track selection.
111 void HonorUserPreferencesForTrackSelection();
112 // Performs track selection for a single TextTrackKind.
113 void PerformTrackSelection(TextTrackKind aTextTrackKind
);
114 //Performs track selection for a set of TextTrackKinds, for example,
115 // 'subtitles' and 'captions' should be selected together.
116 void PerformTrackSelection(TextTrackKind aTextTrackKinds
[], uint32_t size
);
117 void GetTextTracksOfKinds(TextTrackKind aTextTrackKinds
[], uint32_t size
,
118 nsTArray
<TextTrack
*>& aTextTracks
);
119 void GetTextTracksOfKind(TextTrackKind aTextTrackKind
,
120 nsTArray
<TextTrack
*>& aTextTracks
);
121 bool TrackIsDefault(TextTrack
* aTextTrack
);
125 } // namespace mozilla
127 #endif // mozilla_dom_TextTrackManager_h