Bug 1281888 - The closed caption button should appear if there are 'captions' tracks. r?ralin
MozReview-Commit-ID: 2cHgR9lyxAK
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1217,34 +1217,37 @@
default:
return;
}
} catch(e) { /* ignore any exception from setting .currentTime */ }
event.preventDefault(); // Prevent page scrolling
},
- get videoSubtitles() {
- return Array.prototype.filter.call(this.video.textTracks, function (tt) {
- return tt.kind === "subtitles";
- });
+ isSupportedTextTrack : function(textTrack) {
+ return textTrack.kind == "subtitles" ||
+ textTrack.kind == "captions";
+ },
+
+ get overlayableTextTracks() {
+ return Array.prototype.filter.call(this.video.textTracks, this.isSupportedTextTrack);
},
isClosedCaptionOn : function () {
- for (let tt of this.videoSubtitles) {
+ for (let tt of this.overlayableTextTracks) {
if (tt.mode === "showing") {
return true;
}
}
return false;
},
setClosedCaptionButtonState : function () {
- if (!this.videoSubtitles.length || this.videocontrols.isTouchControl) {
+ if (!this.overlayableTextTracks.length || this.videocontrols.isTouchControl) {
this.closedCaptionButton.setAttribute("hidden", "true");
return;
}
this.closedCaptionButton.removeAttribute("hidden");
if (this.isClosedCaptionOn()) {
this.closedCaptionButton.setAttribute("enabled", "true");
@@ -1261,17 +1264,17 @@
tti.setAttribute("on", "true");
} else {
tti.removeAttribute("on");
}
}
},
addNewTextTrack : function (tt) {
- if (tt.kind !== "subtitles") {
+ if (!this.isSupportedTextTrack(tt)) {
return;
}
if (tt.index && tt.index < this.textTracksCount) {
return;
}
tt.index = this.textTracksCount++;
@@ -1294,17 +1297,17 @@
this.textTrackList.appendChild(ttBtn);
if (tt.mode === "showing" && tt.index) {
this.changeTextTrack(tt.index);
}
},
changeTextTrack : function (index) {
- for (let tt of this.videoSubtitles) {
+ for (let tt of this.overlayableTextTracks) {
if (tt.index === index) {
tt.mode = "showing";
this.currentTextTrackIndex = tt.index;
} else {
tt.mode = "disabled";
}
}
@@ -1318,18 +1321,18 @@
this.setClosedCaptionButtonState();
},
onControlBarTransitioned : function () {
this.textTrackList.setAttribute("hidden", "true");
},
toggleClosedCaption : function () {
- if (this.videoSubtitles.length === 1) {
- const lastTTIdx = this.videoSubtitles[0].index;
+ if (this.overlayableTextTracks.length === 1) {
+ const lastTTIdx = this.overlayableTextTracks[0].index;
return this.changeTextTrack(this.isClosedCaptionOn() ? 0 : lastTTIdx);
}
if (this.textTrackList.hasAttribute("hidden")) {
this.textTrackList.removeAttribute("hidden");
} else {
this.textTrackList.setAttribute("hidden", "true");
@@ -1386,17 +1389,17 @@
initTextTracks : function () {
const offLabel = this.textTrackList.getAttribute("offlabel");
this.addNewTextTrack({
label: offLabel,
kind: "subtitles"
});
- for (let tt of this.videoSubtitles) {
+ for (let tt of this.overlayableTextTracks) {
this.addNewTextTrack(tt);
}
this.setClosedCaptionButtonState();
},
isEventWithin : function (event, parent1, parent2) {
function isDescendant (node) {