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

--HG--
extra : rebase_source : 51c328d0b87b977aa2f2fefbc7ded150501985b2
This commit is contained in:
bechen@mozilla.com 2017-10-19 16:30:38 +08:00
parent c8c05d425a
commit de808e6708

View File

@ -912,28 +912,14 @@ const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
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.
@ -952,14 +938,22 @@ const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
// 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;