зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1551385 - part1 : let 'processCue()' handle cleaning cues div. r=heycam
We can actually let `processCue()` to handle rendering cues or cleaning displayed cues, no need to use another way to clear the cue. The advantages is to make the code cleaner and easier to read, now we just need to know JS side would handle all rendering stuffs for us. We don't need to have different behavior when there is no showing cue. The way we clear displayed cues are intuitive, we would remove all child nodes under the overlay, which are used to display cues. Differential Revision: https://phabricator.services.mozilla.com/D31171 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
59b691b66e
Коммит
102628f8e2
|
@ -240,40 +240,39 @@ void TextTrackManager::UpdateCueDisplay() {
|
|||
mUpdateCueDisplayDispatched = false;
|
||||
|
||||
if (!mMediaElement || !mTextTracks || IsShutdown()) {
|
||||
WEBVTT_LOG("Abort UpdateCueDisplay.");
|
||||
return;
|
||||
}
|
||||
|
||||
nsIFrame* frame = mMediaElement->GetPrimaryFrame();
|
||||
nsVideoFrame* videoFrame = do_QueryFrame(frame);
|
||||
if (!videoFrame) {
|
||||
WEBVTT_LOG("Abort UpdateCueDisplay, because of no video frame.");
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> overlay = videoFrame->GetCaptionOverlay();
|
||||
nsCOMPtr<nsIContent> controls = videoFrame->GetVideoControls();
|
||||
if (!overlay) {
|
||||
WEBVTT_LOG("Abort UpdateCueDisplay, because of no overlay.");
|
||||
return;
|
||||
}
|
||||
|
||||
nsPIDOMWindowInner* window = mMediaElement->OwnerDoc()->GetInnerWindow();
|
||||
if (!window) {
|
||||
WEBVTT_LOG("Abort UpdateCueDisplay, because of no window.");
|
||||
}
|
||||
|
||||
nsTArray<RefPtr<TextTrackCue>> showingCues;
|
||||
mTextTracks->GetShowingCues(showingCues);
|
||||
|
||||
if (showingCues.Length() > 0) {
|
||||
WEBVTT_LOG("UpdateCueDisplay, processCues, showingCuesNum=%zu",
|
||||
showingCues.Length());
|
||||
RefPtr<nsVariantCC> jsCues = new nsVariantCC();
|
||||
|
||||
jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE, &NS_GET_IID(EventTarget),
|
||||
showingCues.Length(),
|
||||
static_cast<void*>(showingCues.Elements()));
|
||||
nsPIDOMWindowInner* window = mMediaElement->OwnerDoc()->GetInnerWindow();
|
||||
if (window) {
|
||||
sParserWrapper->ProcessCues(window, jsCues, overlay, controls);
|
||||
}
|
||||
} else if (overlay->Length() > 0) {
|
||||
WEBVTT_LOG("UpdateCueDisplay EmptyString");
|
||||
nsContentUtils::SetNodeTextContent(overlay, EmptyString(), true);
|
||||
}
|
||||
WEBVTT_LOG("UpdateCueDisplay, processCues, showingCuesNum=%zu",
|
||||
showingCues.Length());
|
||||
RefPtr<nsVariantCC> jsCues = new nsVariantCC();
|
||||
jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE, &NS_GET_IID(EventTarget),
|
||||
showingCues.Length(),
|
||||
static_cast<void*>(showingCues.Elements()));
|
||||
nsCOMPtr<nsIContent> controls = videoFrame->GetVideoControls();
|
||||
sParserWrapper->ProcessCues(window, jsCues, overlay, controls);
|
||||
}
|
||||
|
||||
void TextTrackManager::NotifyCueAdded(TextTrackCue& aCue) {
|
||||
|
|
|
@ -1084,14 +1084,25 @@ XPCOMUtils.defineLazyPreferenceGetter(this, "supportPseudo",
|
|||
return parseContent(window, cuetext, PARSE_CONTENT_MODE.DOCUMENT_FRAGMENT);
|
||||
};
|
||||
|
||||
function clearAllCuesDiv(overlay) {
|
||||
while (overlay.firstChild) {
|
||||
overlay.firstChild.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Runs the processing model over the cues and regions passed to it.
|
||||
// @param overlay A block level element (usually a div) that the computed cues
|
||||
// Spec https://www.w3.org/TR/webvtt1/#processing-model
|
||||
// @parem window : JS window
|
||||
// @param cues : the VTT cues are going to be displayed.
|
||||
// @param overlay : A block level element (usually a div) that the computed cues
|
||||
// and regions will be placed into.
|
||||
// @param controls A Control bar element. Cues' position will be
|
||||
// @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;
|
||||
if (!cues) {
|
||||
LOG(`Abort processing because no cue.`);
|
||||
clearAllCuesDiv(overlay);
|
||||
return;
|
||||
}
|
||||
|
||||
let controlBar, controlBarShown;
|
||||
|
@ -1123,14 +1134,12 @@ XPCOMUtils.defineLazyPreferenceGetter(this, "supportPseudo",
|
|||
|
||||
// We don't need to recompute the cues' display states. Just reuse them.
|
||||
if (!shouldCompute(cues)) {
|
||||
LOG(`Abort processing because no need to compute cues' display state.`);
|
||||
return;
|
||||
}
|
||||
overlay.lastControlBarShownStatus = controlBarShown;
|
||||
|
||||
// Remove all previous children.
|
||||
while (overlay.firstChild) {
|
||||
overlay.firstChild.remove();
|
||||
}
|
||||
clearAllCuesDiv(overlay);
|
||||
let rootOfCues = window.document.createElement("div");
|
||||
rootOfCues.style.position = "absolute";
|
||||
rootOfCues.style.left = "0";
|
||||
|
|
Загрузка…
Ссылка в новой задаче