From 4a945299ed679a1b7e5e67360d613734d646458f Mon Sep 17 00:00:00 2001 From: "bechen@mozilla.com" Date: Fri, 10 Nov 2017 11:40:57 +0800 Subject: [PATCH] Bug 1338030 - region : integrate the RegionNodeBox and RegionCueStyleBox. r=rillian MozReview-Commit-ID: 8M9x31q2dSK --HG-- extra : rebase_source : 93d49147d626cf2b5add5d81b5476b5efb696262 --- dom/media/webvtt/vtt.jsm | 61 ++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/dom/media/webvtt/vtt.jsm b/dom/media/webvtt/vtt.jsm index 3a57830bd2c0..3ce5bfa45fe3 100644 --- a/dom/media/webvtt/vtt.jsm +++ b/dom/media/webvtt/vtt.jsm @@ -1049,29 +1049,66 @@ const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); }; (function() { - var styleBox, cue; + var styleBox, cue, controlBarBox; if (controlBarShown) { + controlBarBox = BoxPosition.getSimpleBoxPosition(controlBar); // Add an empty output box that cover the same region as video control bar. - boxPositions.push(BoxPosition.getSimpleBoxPosition(controlBar)); + boxPositions.push(controlBarBox); } + // https://w3c.github.io/webvtt/#processing-model 6.1.12.1 + // Create regionNode + var regionNodeBoxes = {}; + var regionNodeBox; + for (var i = 0; i < cues.length; i++) { cue = cues[i]; + if (cue.region != null) { + // 6.1.14.1 + styleBox = new RegionCueStyleBox(window, cue); - // Compute the intial position and styles of the cue div. - styleBox = new CueStyleBox(window, cue, styleOptions); - styleBox.cueDiv.style.setProperty("--cue-font-size", fontSize + "px"); - rootOfCues.appendChild(styleBox.div); + if (!regionNodeBoxes[cue.region.id]) { + // create regionNode + // Adjust the container hieght to exclude the controlBar + var adjustContainerBox = BoxPosition.getSimpleBoxPosition(rootOfCues); + if (controlBarShown) { + adjustContainerBox.height -= controlBarBox.height; + adjustContainerBox.bottom += controlBarBox.height; + } + regionNodeBox = new RegionNodeBox(window, cue.region, adjustContainerBox); + regionNodeBoxes[cue.region.id] = regionNodeBox; + } + // 6.1.14.3 + var currentRegionBox = regionNodeBoxes[cue.region.id]; + var currentRegionNodeDiv = currentRegionBox.div; + // 6.1.14.3.2 + // TODO: fix me, it looks like the we need to set/change "top" attribute at the styleBox.div + // to do the "scroll up", however, we do not implement it yet? + if (cue.region.scroll == "up" && currentRegionNodeDiv.childElementCount > 0) { + styleBox.div.style.transitionProperty = "top"; + styleBox.div.style.transitionDuration = "0.433s"; + } - // Move the cue div to it's correct line position. - moveBoxToLinePosition(window, styleBox, containerBox, boxPositions); + currentRegionNodeDiv.appendChild(styleBox.div); + rootOfCues.appendChild(currentRegionNodeDiv); + cue.displayState = styleBox.div; + boxPositions.push(BoxPosition.getSimpleBoxPosition(currentRegionBox)); + } else { + // Compute the intial position and styles of the cue div. + styleBox = new CueStyleBox(window, cue, styleOptions); + styleBox.cueDiv.style.setProperty("--cue-font-size", fontSize + "px"); + rootOfCues.appendChild(styleBox.div); - // Remember the computed div so that we don't have to recompute it later - // if we don't have too. - cue.displayState = styleBox.div; + // Move the cue div to it's correct line position. + moveBoxToLinePosition(window, styleBox, containerBox, boxPositions); - boxPositions.push(BoxPosition.getSimpleBoxPosition(styleBox)); + // Remember the computed div so that we don't have to recompute it later + // if we don't have too. + cue.displayState = styleBox.div; + + boxPositions.push(BoxPosition.getSimpleBoxPosition(styleBox)); + } } })(); };