Bug 1409983 - Reorder the shouldCompute() funciton and "remove all child nodes of MediaElement" in vtt.jsm. r=alwu
We should call shouldCompute() function first, then remove all children of MediaElement.
MozReview-Commit-ID: 6623Xn6T4mx
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -907,38 +907,24 @@ const { XPCOMUtils } = require("resource
// and regions will be placed into.
// @param controls A Control bar element. Cues' position will be
// affected and repositioned according to it.
WebVTT.processCues = function(window, cues, overlay, controls) {
if (!window || !cues || !overlay) {
return null;
}
- // Remove all previous children.
- while (overlay.firstChild) {
- overlay.firstChild.remove();
- }
-
var controlBar;
var controlBarShown;
-
if (controls) {
controlBar = controls.ownerDocument.getAnonymousElementByAttribute(
controls, "anonid", "controlBar");
controlBarShown = controlBar ? !!controlBar.clientHeight : false;
}
- var rootOfCues = window.document.createElement("div");
- rootOfCues.style.position = "absolute";
- rootOfCues.style.left = "0";
- rootOfCues.style.right = "0";
- rootOfCues.style.top = "0";
- rootOfCues.style.bottom = "0";
- overlay.appendChild(rootOfCues);
-
// Determine if we need to compute the display states of the cues. This could
// be the case if a cue's state has been changed since the last computation or
// if it has not been computed yet.
function shouldCompute(cues) {
if (overlay.lastControlBarShownStatus != controlBarShown) {
return true;
}
@@ -947,24 +933,32 @@ const { XPCOMUtils } = require("resource
return true;
}
}
return false;
}
// We don't need to recompute the cues' display states. Just reuse them.
if (!shouldCompute(cues)) {
- for (var i = 0; i < cues.length; i++) {
- rootOfCues.appendChild(cues[i].displayState);
- }
- overlay.lastControlBarShownStatus = controlBarShown;
return;
}
overlay.lastControlBarShownStatus = controlBarShown;
+ // Remove all previous children.
+ while (overlay.firstChild) {
+ overlay.firstChild.remove();
+ }
+ var rootOfCues = window.document.createElement("div");
+ rootOfCues.style.position = "absolute";
+ rootOfCues.style.left = "0";
+ rootOfCues.style.right = "0";
+ rootOfCues.style.top = "0";
+ rootOfCues.style.bottom = "0";
+ overlay.appendChild(rootOfCues);
+
var boxPositions = [],
containerBox = BoxPosition.getSimpleBoxPosition(rootOfCues),
fontSize = Math.round(containerBox.height * FONT_SIZE_PERCENT * 100) / 100;
var styleOptions = {
font: fontSize + "px " + FONT_STYLE
};
(function() {