Skip to content

Commit 7af44ef

Browse files
author
Álvaro Velad Galván
authored
fix(UI): Fix writing-mode support in old versions of Tizen and WebOS (shaka-project#3330)
1 parent df5340f commit 7af44ef

File tree

2 files changed

+46
-29
lines changed

2 files changed

+46
-29
lines changed

lib/text/ui_text_displayer.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,14 @@ shaka.text.UITextDisplayer = class {
408408

409409
style.textAlign = cue.textAlign;
410410
style.textDecoration = cue.textDecoration.join(' ');
411-
style.writingMode = cue.writingMode;
411+
412+
// Prefixed version required for old versions of Chromium, eg: Tizen, WebOS
413+
// https://caniuse.com/css-writing-mode
414+
if ('writingMode' in document.documentElement.style) {
415+
style.writingMode = cue.writingMode;
416+
} else if ('webkitWritingMode' in document.documentElement.style) {
417+
style.webkitWritingMode = cue.writingMode;
418+
}
412419

413420
// The size is a number giving the size of the text container, to be
414421
// interpreted as a percentage of the video, as defined by the writing

test/text/ui_text_displayer_unit.js

+38-28
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,26 @@ describe('UITextDisplayer', () => {
9090
videoContainer.querySelector('.shaka-text-container');
9191
const captions = textContainer.querySelector('span');
9292
const cssObj = parseCssText(captions.style.cssText);
93-
expect(cssObj).toEqual(
94-
jasmine.objectContaining({
95-
'color': 'green',
96-
'background-color': 'black',
97-
'direction': 'ltr',
98-
'font-size': '10px',
99-
'font-style': 'normal',
100-
'font-weight': 400,
101-
'line-height': 2,
102-
'text-align': 'center',
103-
// TODO: Old versions of Tizen and WebOS only supports the webkit
104-
// prefixed version. Until we support the prefixed version, this
105-
// has to be maintained. https://caniuse.com/css-writing-mode
106-
// 'writing-mode': 'horizontal-tb',
107-
}));
93+
94+
const expectCssObj = {
95+
'color': 'green',
96+
'background-color': 'black',
97+
'direction': 'ltr',
98+
'font-size': '10px',
99+
'font-style': 'normal',
100+
'font-weight': 400,
101+
'line-height': 2,
102+
'text-align': 'center',
103+
};
104+
// Old versions of Tizen and WebOS only supports the webkit prefixed
105+
// version. https://caniuse.com/css-writing-mode
106+
if ('writingMode' in document.documentElement.style) {
107+
expectCssObj['writing-mode'] = 'horizontal-tb';
108+
} else if ('webkitWritingMode' in document.documentElement.style) {
109+
expectCssObj['-webkit-writing-mode'] = 'horizontal-tb';
110+
}
111+
112+
expect(cssObj).toEqual(jasmine.objectContaining(expectCssObj));
108113
});
109114

110115
it('correctly displays styles for nested cues', async () => {
@@ -132,19 +137,24 @@ describe('UITextDisplayer', () => {
132137
videoContainer.querySelector('.shaka-text-container');
133138
const captions = textContainer.querySelector('span');
134139
const cssObj = parseCssText(captions.style.cssText);
135-
expect(cssObj).toEqual(
136-
jasmine.objectContaining({
137-
'color': 'green',
138-
'background-color': 'black',
139-
'font-size': '10px',
140-
'font-style': 'normal',
141-
'font-weight': 400,
142-
'text-align': 'center',
143-
// TODO: Old versions of Tizen and WebOS only supports the webkit
144-
// prefixed version. Until we support the prefixed version, this
145-
// has to be maintained. https://caniuse.com/css-writing-mode
146-
// 'writing-mode': 'horizontal-tb',
147-
}));
140+
141+
const expectCssObj = {
142+
'color': 'green',
143+
'background-color': 'black',
144+
'font-size': '10px',
145+
'font-style': 'normal',
146+
'font-weight': 400,
147+
'text-align': 'center',
148+
};
149+
// Old versions of Tizen and WebOS only supports the webkit prefixed
150+
// version. https://caniuse.com/css-writing-mode
151+
if ('writingMode' in document.documentElement.style) {
152+
expectCssObj['writing-mode'] = 'horizontal-tb';
153+
} else if ('webkitWritingMode' in document.documentElement.style) {
154+
expectCssObj['-webkit-writing-mode'] = 'horizontal-tb';
155+
}
156+
157+
expect(cssObj).toEqual(jasmine.objectContaining(expectCssObj));
148158
});
149159

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

0 commit comments

Comments
 (0)