Bug 1338030 - regionNodeBox : implementation RegionNodeBox which correspond to "WebVTT region object". r=rillian draft
authorbechen@mozilla.com <bechen@mozilla.com>
Fri, 10 Nov 2017 11:40:24 +0800
changeset 695985 7781f716438c6bf7e2b4550f0b77f245f674fd15
parent 695984 57706a7fbf36b2c65fa93362dbfbf9a30d2d7418
child 695986 5b63103e9786a94efcea0e0c7bb0988dfc0cf7a6
push id88606
push userbmo:bechen@mozilla.com
push dateFri, 10 Nov 2017 03:41:56 +0000
reviewersrillian
bugs1338030
milestone58.0a1
Bug 1338030 - regionNodeBox : implementation RegionNodeBox which correspond to "WebVTT region object". r=rillian MozReview-Commit-ID: FkrZD0iV1k9
dom/media/webvtt/vtt.jsm
--- a/dom/media/webvtt/vtt.jsm
+++ b/dom/media/webvtt/vtt.jsm
@@ -595,16 +595,51 @@ const { XPCOMUtils } = require("resource
         height: this.formatStyle(box.height, "px"),
         width: this.formatStyle(box.width, "px")
       });
     };
   }
   CueStyleBox.prototype = _objCreate(StyleBox.prototype);
   CueStyleBox.prototype.constructor = CueStyleBox;
 
+  function RegionNodeBox(window, region, container) {
+    StyleBox.call(this);
+
+    var boxLineHeight = container.height * 0.0533 // 0.0533vh ? 5.33vh
+    var boxHeight = boxLineHeight * region.lines;
+    var boxWidth = container.width * region.width / 100; // convert percentage to px
+
+    var regionNodeStyles = {
+      position: "absolute",
+      height: boxHeight + "px",
+      width: boxWidth + "px",
+      top: (region.viewportAnchorY * container.height / 100) - (region.regionAnchorY * boxHeight / 100) + "px",
+      left: (region.viewportAnchorX * container.width / 100) - (region.regionAnchorX * boxWidth / 100) + "px",
+      lineHeight: boxLineHeight + "px",
+      writingMode: "horizontal-tb",
+      backgroundColor: "rgba(0, 0, 0, 0.8)",
+      wordWrap: "break-word",
+      overflowWrap: "break-word",
+      font: (boxLineHeight/1.3) + "px sans-serif",
+      color: "rgba(255, 255, 255, 1)",
+      overflow: "hidden",
+      minHeight: "0px",
+      maxHeight: boxHeight + "px",
+      display: "inline-flex",
+      flexFlow: "column",
+      justifyContent: "flex-end",
+    };
+
+    this.div = window.document.createElement("div");
+    this.div.id = region.id; // useless?
+    this.applyStyles(regionNodeStyles);
+  }
+  RegionNodeBox.prototype = _objCreate(StyleBox.prototype);
+  RegionNodeBox.prototype.constructor = RegionNodeBox;
+
   // Represents the co-ordinates of an Element in a way that we can easily
   // compute things with such as if it overlaps or intersects with another Element.
   // Can initialize it with either a StyleBox or another BoxPosition.
   function BoxPosition(obj) {
     var isIE8 = (typeof navigator !== "undefined") &&
       (/MSIE\s8\.0/).test(navigator.userAgent);
 
     // Either a BoxPosition was passed in and we need to copy it, or a StyleBox