Skip to content

Commit

Permalink
fix(UI): Fix writing-mode support in old versions of Tizen and WebOS (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván authored Apr 19, 2021
1 parent df5340f commit 7af44ef
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 29 deletions.
9 changes: 8 additions & 1 deletion lib/text/ui_text_displayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,14 @@ shaka.text.UITextDisplayer = class {

style.textAlign = cue.textAlign;
style.textDecoration = cue.textDecoration.join(' ');
style.writingMode = cue.writingMode;

// Prefixed version required for old versions of Chromium, eg: Tizen, WebOS
// https://caniuse.com/css-writing-mode
if ('writingMode' in document.documentElement.style) {
style.writingMode = cue.writingMode;
} else if ('webkitWritingMode' in document.documentElement.style) {
style.webkitWritingMode = cue.writingMode;
}

// The size is a number giving the size of the text container, to be
// interpreted as a percentage of the video, as defined by the writing
Expand Down
66 changes: 38 additions & 28 deletions test/text/ui_text_displayer_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,26 @@ describe('UITextDisplayer', () => {
videoContainer.querySelector('.shaka-text-container');
const captions = textContainer.querySelector('span');
const cssObj = parseCssText(captions.style.cssText);
expect(cssObj).toEqual(
jasmine.objectContaining({
'color': 'green',
'background-color': 'black',
'direction': 'ltr',
'font-size': '10px',
'font-style': 'normal',
'font-weight': 400,
'line-height': 2,
'text-align': 'center',
// TODO: Old versions of Tizen and WebOS only supports the webkit
// prefixed version. Until we support the prefixed version, this
// has to be maintained. https://caniuse.com/css-writing-mode
// 'writing-mode': 'horizontal-tb',
}));

const expectCssObj = {
'color': 'green',
'background-color': 'black',
'direction': 'ltr',
'font-size': '10px',
'font-style': 'normal',
'font-weight': 400,
'line-height': 2,
'text-align': 'center',
};
// Old versions of Tizen and WebOS only supports the webkit prefixed
// version. https://caniuse.com/css-writing-mode
if ('writingMode' in document.documentElement.style) {
expectCssObj['writing-mode'] = 'horizontal-tb';
} else if ('webkitWritingMode' in document.documentElement.style) {
expectCssObj['-webkit-writing-mode'] = 'horizontal-tb';
}

expect(cssObj).toEqual(jasmine.objectContaining(expectCssObj));
});

it('correctly displays styles for nested cues', async () => {
Expand Down Expand Up @@ -132,19 +137,24 @@ describe('UITextDisplayer', () => {
videoContainer.querySelector('.shaka-text-container');
const captions = textContainer.querySelector('span');
const cssObj = parseCssText(captions.style.cssText);
expect(cssObj).toEqual(
jasmine.objectContaining({
'color': 'green',
'background-color': 'black',
'font-size': '10px',
'font-style': 'normal',
'font-weight': 400,
'text-align': 'center',
// TODO: Old versions of Tizen and WebOS only supports the webkit
// prefixed version. Until we support the prefixed version, this
// has to be maintained. https://caniuse.com/css-writing-mode
// 'writing-mode': 'horizontal-tb',
}));

const expectCssObj = {
'color': 'green',
'background-color': 'black',
'font-size': '10px',
'font-style': 'normal',
'font-weight': 400,
'text-align': 'center',
};
// Old versions of Tizen and WebOS only supports the webkit prefixed
// version. https://caniuse.com/css-writing-mode
if ('writingMode' in document.documentElement.style) {
expectCssObj['writing-mode'] = 'horizontal-tb';
} else if ('webkitWritingMode' in document.documentElement.style) {
expectCssObj['-webkit-writing-mode'] = 'horizontal-tb';
}

expect(cssObj).toEqual(jasmine.objectContaining(expectCssObj));
});

it('correctly displays styles for cellResolution units', async () => {
Expand Down

0 comments on commit 7af44ef

Please sign in to comment.