Skip to content

Commit 94f4512

Browse files
author
Vincent Valot
committed
add basic support of ttml span in p
1 parent 592b7e5 commit 94f4512

File tree

6 files changed

+48
-14
lines changed

6 files changed

+48
-14
lines changed

demo/demo.less

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,18 @@ footer .mdl-mega-footer__link-list {
384384
width: 100%;
385385
height: 100%;
386386
margin: auto;
387+
388+
@cueColors: cyan, red, yellow, blue;
389+
390+
each(@cueColors, {
391+
::cue(.@{key}) {
392+
color: @value;
393+
}
394+
395+
::cue(.background-@{key}) {
396+
background-color: @value;
397+
}
398+
});
387399
}
388400

389401
/* Style the intermediate tooltip attach points, required for tooltips to be

demo/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ class ShakaDemoMain {
893893
if (this.nativeControlsEnabled_) {
894894
this.controls_.setEnabledShakaControls(false);
895895
this.controls_.setEnabledNativeControls(true);
896+
897+
await this.player_.setTextTrackVisibility(true);
896898
} else {
897899
this.controls_.setEnabledShakaControls(true);
898900
this.controls_.setEnabledNativeControls(false);

lib/text/simple_text_displayer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ shaka.text.SimpleTextDisplayer.convertToTextTrackCue_ = function(shakaCue) {
221221
vttCue.position = shakaCue.position;
222222
}
223223

224+
if (shakaCue.color !== null) {
225+
vttCue.text = `<c.${shakaCue.color}>${shakaCue.payload}</c>`
226+
}
227+
224228
return vttCue;
225229
};
226230

lib/text/ttml_text_parser.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,27 +266,42 @@ shaka.text.TtmlTextParser.getLeafNodes_ = function(element) {
266266

267267
let childNodes = element.childNodes;
268268
for (let i = 0; i < childNodes.length; i++) {
269-
// Currently we don't support styles applicable to span
270-
// elements, so they are ignored.
271-
let isSpanChildOfP = childNodes[i].nodeName == 'span' &&
272-
element.nodeName == 'p';
273-
if (childNodes[i].nodeType == Node.ELEMENT_NODE &&
274-
childNodes[i].nodeName != 'br' && !isSpanChildOfP) {
269+
const childNodeItem = childNodes[i];
270+
271+
if (childNodeItem.nodeType == Node.ELEMENT_NODE && childNodeItem.nodeName !== 'br') {
275272
// Get the leaves the child might contain.
276-
goog.asserts.assert(childNodes[i] instanceof Element,
273+
goog.asserts.assert(childNodeItem instanceof Element,
277274
'Node should be Element!');
278275
let leafChildren = shaka.text.TtmlTextParser.getLeafNodes_(
279-
/** @type {Element} */(childNodes[i]));
276+
/** @type {Element} */(childNodeItem));
280277
goog.asserts.assert(leafChildren.length > 0,
281278
'Only a null Element should return no leaves!');
282-
result = result.concat(leafChildren);
279+
280+
const nearestAncestor = element.hasAttribute('begin') ? element : element.closest('[begin]');
281+
282+
if (nearestAncestor) {
283+
const begin = nearestAncestor.getAttribute('begin');
284+
const end = nearestAncestor.getAttribute('end');
285+
const region = nearestAncestor.getAttribute('region');
286+
287+
result = result.concat(leafChildren.map(leafChild => {
288+
leafChild.setAttribute('begin', begin);
289+
leafChild.setAttribute('end', end);
290+
leafChild.setAttribute('region', leafChild.getAttribute('region') || region);
291+
292+
return leafChild;
293+
}));
294+
} else {
295+
result = result.concat(leafChildren);
296+
}
283297
}
284298
}
285299

286300
// if no result at this point, the element itself must be a leaf.
287301
if (!result.length) {
288302
result.push(element);
289303
}
304+
290305
return result;
291306
};
292307

ui/less/containers.less

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,11 @@
196196

197197
/* Set the captions in the middle horizontally by default. */
198198
display: flex;
199-
justify-content: center;
199+
flex-direction: column;
200+
justify-content: flex-end;
200201

201202
/* Set the captions at the bottom by default. */
202-
align-items: flex-end;
203+
align-items: center;
203204

204205
/* If the captions are too long to fit in the video container, hide the
205206
* overflow content. */

ui/text_displayer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ shaka.ui.TextDisplayer = class {
223223
// captions inside the text container. Before means at the top of the
224224
// text container, and after means at the bottom.
225225
if (cue.displayAlign == Cue.displayAlign.BEFORE) {
226-
panelStyle.alignItems = 'flex-start';
226+
panelStyle.justifyContent = 'flex-start';
227227
} else if (cue.displayAlign == Cue.displayAlign.CENTER) {
228-
panelStyle.alignItems = 'flex-top';
228+
panelStyle.justifyContent = 'center';
229229
} else {
230-
panelStyle.alignItems = 'flex-end';
230+
panelStyle.justifyContent = 'flex-end';
231231
}
232232

233233
captionsStyle.fontFamily = cue.fontFamily;

0 commit comments

Comments
 (0)