Title: [114640] trunk
Revision
114640
Author
commit-qu...@webkit.org
Date
2012-04-19 09:27:25 -0700 (Thu, 19 Apr 2012)

Log Message

Display a TextTrackCue when snap-to-lines flag is not set
https://bugs.webkit.org/show_bug.cgi?id=79750

Patch by Victor Carbune <vcarb...@adobe.com> on 2012-04-19
Reviewed by Eric Carlson.

Source/WebCore:

Support for positioning of a cue on top of the video element when snap-to-lines is not set.

Test: media/track/track-cue-rendering-snap-to-lines-not-set.html

* css/mediaControls.css:
(video::-webkit-media-text-track-container): Marked the container as
flexible box in order to use all the available space on top of the controls.
(video::-webkit-media-text-track-background): Added background default settings.
(video::-webkit-media-text-track-display): Added default position.
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlTextTrackContainerElement::updateDisplay): Updated comments.
* html/track/TextTrackCue.cpp:
(WebCore):
(WebCore::TextTrackCue::TextTrackCue): Updated constructor to calculate
the computed line position.
(WebCore::TextTrackCue::setLine): Updated call to calculate the computed line
position.
(WebCore::TextTrackCue::setPosition):
(WebCore::TextTrackCue::calculateComputedLinePosition): Partial calculation of the
computated line position.
(WebCore::TextTrackCue::calculateDisplayParameters): Updated display parameter computations
required by the spec.
(WebCore::TextTrackCue::getDisplayTree): Updated positioning attributes when snap-to-lines
is not set. Added extra anonymous box for background, because setting position:absolute
on the display tree determines the background to cover the whole block, not just inline.
(WebCore::TextTrackCue::getPositionCoordinates): Determine coordinates as required by the spec.
* html/track/TextTrackCue.h:
(TextTrackCue):

LayoutTests:

Added tests to support positioning of cues when snap-to-lines set.

* media/media-controls.js:
(textTrackDisplayElement): Added an extra parameter, to return the display
box of the N-th active cue.
* media/track/captions-webvtt/captions-snap-to-lines-not-set.vtt: Added.
* media/track/track-cue-rendering-expected.txt: Updated background color check.
* media/track/track-cue-rendering-snap-to-lines-not-set-expected.txt: Added.
* media/track/track-cue-rendering-snap-to-lines-not-set.html: Added.
* media/track/track-cue-rendering.html: Updated background color check.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (114639 => 114640)


--- trunk/LayoutTests/ChangeLog	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/LayoutTests/ChangeLog	2012-04-19 16:27:25 UTC (rev 114640)
@@ -1,3 +1,21 @@
+2012-04-19  Victor Carbune  <vcarb...@adobe.com>
+
+        Display a TextTrackCue when snap-to-lines flag is not set
+        https://bugs.webkit.org/show_bug.cgi?id=79750
+
+        Reviewed by Eric Carlson.
+
+        Added tests to support positioning of cues when snap-to-lines set.
+
+        * media/media-controls.js:
+        (textTrackDisplayElement): Added an extra parameter, to return the display
+        box of the N-th active cue.
+        * media/track/captions-webvtt/captions-snap-to-lines-not-set.vtt: Added.
+        * media/track/track-cue-rendering-expected.txt: Updated background color check.
+        * media/track/track-cue-rendering-snap-to-lines-not-set-expected.txt: Added.
+        * media/track/track-cue-rendering-snap-to-lines-not-set.html: Added.
+        * media/track/track-cue-rendering.html: Updated background color check.
+
 2012-04-19  Filip Pizlo  <fpi...@apple.com>
 
         JSC testing should have complete coverage over typed array types

Modified: trunk/LayoutTests/media/media-controls.js (114639 => 114640)


--- trunk/LayoutTests/media/media-controls.js	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/LayoutTests/media/media-controls.js	2012-04-19 16:27:25 UTC (rev 114640)
@@ -32,7 +32,7 @@
     return new Array(x, y);
 }
 
-function textTrackDisplayElement(parentElement, id)
+function textTrackDisplayElement(parentElement, id, cueNumber)
 {
     var textTrackContainerID = "-webkit-media-text-track-container";
     var containerElement = mediaControlsElement(internals.shadowRoot(parentElement).firstChild, "-webkit-media-text-track-container");
@@ -49,5 +49,13 @@
     if (!displayElement)
         throw "No text track cue with display id '" + controlID + "' is currently visible";
 
+    if (cueNumber) {
+        for (i = 0; i < cueNumber; i++)
+            displayElement = displayElement.nextSibling;
+
+        if (!displayElement)
+            throw "There are not " + cueNumber + " text track cues visible";
+    }
+
     return displayElement;
 }

Added: trunk/LayoutTests/media/track/captions-webvtt/captions-snap-to-lines-not-set.vtt (0 => 114640)


--- trunk/LayoutTests/media/track/captions-webvtt/captions-snap-to-lines-not-set.vtt	                        (rev 0)
+++ trunk/LayoutTests/media/track/captions-webvtt/captions-snap-to-lines-not-set.vtt	2012-04-19 16:27:25 UTC (rev 114640)
@@ -0,0 +1,61 @@
+WEBVTT FILE
+
+1
+00:00:00.000 --> 00:00:00.500
+This is a demo track to illustrate positioning features of cues.
+
+2
+00:00:00.500 --> 00:00:01.000 line:50% position:50%
+Using HTML5 captions, you can position the cues anywhere.
+
+3
+00:00:01.000 --> 00:00:01.500 line:0% position:0%
+For example, here is a cue on the top left-corner.
+
+4
+00:00:01.500 --> 00:00:02.000 line:0% position:100%
+Or on the top-right corner.
+
+5
+00:00:02.000 --> 00:00:02.500 line:100% position:100%
+Bottom-right corner.
+
+6
+00:00:02.500 --> 00:00:03.000 line:100% position:0%
+And, as you might expect, the bottom-left one.
+
+7
+00:00:03.000 --> 00:00:03.500 line:50% position:50%
+Cues are implicitly displayed within the viewport area.
+
+8
+00:00:03.500 --> 00:00:04.000 line:100% position:50%
+And always on top of the controls, if these are visible.
+
+9
+00:00:04.000 --> 00:00:05.000 line:50% position:50%
+You may even have multiple cues in the same time.
+
+10
+00:00:04.000 --> 00:00:05.000 line:0% position:0%
+Top-left cue.
+
+11
+00:00:04.000 --> 00:00:05.000 line:0% position:100%
+Top-right cue.
+
+12
+00:00:04.000 --> 00:00:05.000 line:100% position:50%
+Bottom cue.
+
+13
+00:00:04.000 --> 00:00:05.000 line:25% position:100%
+Random cue 1.
+
+14
+00:00:04.000 --> 00:00:05.000 line:33% position:44%
+Random cue 2.
+
+15
+00:00:04.000 --> 00:00:05.000 line:55% position:23%
+Random cue 3.

Modified: trunk/LayoutTests/media/track/track-cue-rendering-expected.txt (114639 => 114640)


--- trunk/LayoutTests/media/track/track-cue-rendering-expected.txt	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/LayoutTests/media/track/track-cue-rendering-expected.txt	2012-04-19 16:27:25 UTC (rev 114640)
@@ -46,6 +46,6 @@
 
 EXPECTED (getComputedStyle(textTrackDisplayElement(video)).fontFamily == 'sans-serif') OK
 EXPECTED (getComputedStyle(textTrackDisplayElement(video)).color == 'rgba(255, 255, 255, 0)') OK
-EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'display')).backgroundColor == 'rgba(0, 0, 0, 0.796875)') OK
+EXPECTED (getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor == 'rgba(0, 0, 0, 0.796875)') OK
 END OF TEST
 

Added: trunk/LayoutTests/media/track/track-cue-rendering-snap-to-lines-not-set-expected.txt (0 => 114640)


--- trunk/LayoutTests/media/track/track-cue-rendering-snap-to-lines-not-set-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-cue-rendering-snap-to-lines-not-set-expected.txt	2012-04-19 16:27:25 UTC (rev 114640)
@@ -0,0 +1,110 @@
+Test that TextTrack's cues are rendered correctly when the snap to lines flag is not set.
+EVENT(canplaythrough)
+
+The track container and the media controls should completely cover the video element
+EXPECTED (cueDisplayContainer.offsetHeight + controlsPanelElement.offsetHeight == video.videoHeight == 'true') OK
+EXPECTED (cueDisplayContainer.offsetWidth == video.videoWidth == 'true') OK
+
+** Default **
+EVENT(seeked)
+Active cues: 1
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'This is a demo track to illustrate positioning features of cues.') OK
+Cue left position (percentage): 0
+Cue top position (percentage): 100
+
+** Center **
+EVENT(seeked)
+Active cues: 1
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'Using HTML5 captions, you can position the cues anywhere.') OK
+Cue left position (percentage): 50
+Cue top position (percentage): 50
+
+** Top left **
+EVENT(seeked)
+Active cues: 1
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'For example, here is a cue on the top left-corner.') OK
+Cue left position (percentage): 0
+Cue top position (percentage): 0
+
+** Top right **
+EVENT(seeked)
+Active cues: 1
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'Or on the top-right corner.') OK
+Cue left position (percentage): 100
+Cue top position (percentage): 0
+
+** Bottom right **
+EVENT(seeked)
+Active cues: 1
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'Bottom-right corner.') OK
+Cue left position (percentage): 100
+Cue top position (percentage): 100
+
+** Bottom left **
+EVENT(seeked)
+Active cues: 1
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'And, as you might expect, the bottom-left one.') OK
+Cue left position (percentage): 0
+Cue top position (percentage): 100
+
+** Bottom center **
+EVENT(seeked)
+Active cues: 1
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'Cues are implicitly displayed within the viewport area.') OK
+Cue left position (percentage): 50
+Cue top position (percentage): 50
+
+** Multiple cues **
+EVENT(seeked)
+Active cues: 7
+
+* Cue 0 *
+EXPECTED (cueDisplayElement.innerText == 'You may even have multiple cues in the same time.') OK
+Cue left position (percentage): 50
+Cue top position (percentage): 50
+
+* Cue 1 *
+EXPECTED (cueDisplayElement.innerText == 'Top-left cue.') OK
+Cue left position (percentage): 0
+Cue top position (percentage): 0
+
+* Cue 2 *
+EXPECTED (cueDisplayElement.innerText == 'Top-right cue.') OK
+Cue left position (percentage): 100
+Cue top position (percentage): 0
+
+* Cue 3 *
+EXPECTED (cueDisplayElement.innerText == 'Bottom cue.') OK
+Cue left position (percentage): 50
+Cue top position (percentage): 100
+
+* Cue 4 *
+EXPECTED (cueDisplayElement.innerText == 'Random cue 1.') OK
+Cue left position (percentage): 100
+Cue top position (percentage): 25
+
+* Cue 5 *
+EXPECTED (cueDisplayElement.innerText == 'Random cue 2.') OK
+Cue left position (percentage): 44
+Cue top position (percentage): 33
+
+* Cue 6 *
+EXPECTED (cueDisplayElement.innerText == 'Random cue 3.') OK
+Cue left position (percentage): 23
+Cue top position (percentage): 55
+END OF TEST
+

Added: trunk/LayoutTests/media/track/track-cue-rendering-snap-to-lines-not-set.html (0 => 114640)


--- trunk/LayoutTests/media/track/track-cue-rendering-snap-to-lines-not-set.html	                        (rev 0)
+++ trunk/LayoutTests/media/track/track-cue-rendering-snap-to-lines-not-set.html	2012-04-19 16:27:25 UTC (rev 114640)
@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=""
+        <script src=""
+        <script src=""
+
+        <script>
+
+        var testTrack;
+        var cueDisplayElement;
+        var cueDisplayContainer;
+        var controlsPanelElement;
+        var seekedCount = 0;
+
+        var testCaseDescription = [
+                "Default",
+                "Center",
+                "Top left",
+                "Top right",
+                "Bottom right",
+                "Bottom left",
+                "Bottom center",
+                "Multiple cues"
+        ];
+
+        var testCaseSeekTime = [
+                0.10,
+                0.60,
+                1.10,
+                1.60,
+                2.10,
+                2.60,
+                3.10,
+                4.10
+        ];
+
+        var currentTestCase = 0;
+
+        function seeked()
+        {
+            consoleWrite("Active cues: " + testTrack.track.activeCues.length);
+
+            for (var i = 0; i < testTrack.track.activeCues.length; ++i) {
+                
+                cueDisplayElement = textTrackDisplayElement(video, 'display', i);
+
+                consoleWrite("");
+                consoleWrite("* Cue " + i + " *");
+                testExpected("cueDisplayElement.innerText", testTrack.track.activeCues[i].text);
+
+                consoleWrite("Cue left position (percentage): " + Math.round(cueDisplayElement.offsetLeft / cueDisplayContainer.offsetWidth * 100));
+                consoleWrite("Cue top position (percentage): " + Math.round(cueDisplayElement.offsetTop / cueDisplayContainer.offsetHeight * 100));
+            }
+
+            runNextTestCase();
+        };
+
+        function runNextTestCase()
+        {
+            if (currentTestCase == testCaseDescription.length) {
+                endTest();
+                return;
+            }
+
+            consoleWrite("");
+            consoleWrite("** " +  testCaseDescription[currentTestCase] + " **");
+
+            video.currentTime = testCaseSeekTime[currentTestCase];
+            waitForEvent('seeked', seeked, false, true);
+
+            currentTestCase++;
+        }
+
+        function testInitialContainer()
+        {
+            consoleWrite("");
+            consoleWrite("The track container and the media controls should completely cover the video element");
+            testExpected("cueDisplayContainer.offsetHeight + controlsPanelElement.offsetHeight == video.videoHeight", true);
+            testExpected("cueDisplayContainer.offsetWidth == video.videoWidth", true);
+        }
+
+        function loaded()
+        {
+            consoleWrite("Test that TextTrack's cues are rendered correctly when the snap to lines flag is not set.");
+
+            findMediaElement();
+            testTrack = document.querySelector('track');
+            video.src = "" '../content/test');
+            controlsPanelElement = mediaControlsElement(internals.shadowRoot(video).firstChild, '-webkit-media-controls-panel');
+
+            waitForEvent('canplaythrough', function() {
+                cueDisplayContainer = textTrackDisplayElement(video);
+                testInitialContainer();
+                runNextTestCase();
+            });
+        }
+
+        </script>
+    </head>
+    <body _onload_="loaded()">
+        <video controls>
+            <track src="" kind="captions" default>
+        </video>
+    </body>
+</html>

Modified: trunk/LayoutTests/media/track/track-cue-rendering.html (114639 => 114640)


--- trunk/LayoutTests/media/track/track-cue-rendering.html	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/LayoutTests/media/track/track-cue-rendering.html	2012-04-19 16:27:25 UTC (rev 114640)
@@ -32,7 +32,7 @@
 
             testExpected("getComputedStyle(textTrackDisplayElement(video)).fontFamily", "sans-serif");
             testExpected("getComputedStyle(textTrackDisplayElement(video)).color", "rgba(255, 255, 255, 0)");
-            testExpected("getComputedStyle(textTrackDisplayElement(video, 'display')).backgroundColor", "rgba(0, 0, 0, 0.796875)");
+            testExpected("getComputedStyle(textTrackDisplayElement(video, 'display').firstChild).backgroundColor", "rgba(0, 0, 0, 0.796875)");
 
             endTest();
 

Modified: trunk/Source/WebCore/ChangeLog (114639 => 114640)


--- trunk/Source/WebCore/ChangeLog	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/Source/WebCore/ChangeLog	2012-04-19 16:27:25 UTC (rev 114640)
@@ -1,3 +1,39 @@
+2012-04-19  Victor Carbune  <vcarb...@adobe.com>
+
+        Display a TextTrackCue when snap-to-lines flag is not set
+        https://bugs.webkit.org/show_bug.cgi?id=79750
+
+        Reviewed by Eric Carlson.
+
+        Support for positioning of a cue on top of the video element when snap-to-lines is not set.
+
+        Test: media/track/track-cue-rendering-snap-to-lines-not-set.html
+
+        * css/mediaControls.css:
+        (video::-webkit-media-text-track-container): Marked the container as
+        flexible box in order to use all the available space on top of the controls.
+        (video::-webkit-media-text-track-background): Added background default settings.
+        (video::-webkit-media-text-track-display): Added default position.
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlTextTrackContainerElement::updateDisplay): Updated comments.
+        * html/track/TextTrackCue.cpp:
+        (WebCore):
+        (WebCore::TextTrackCue::TextTrackCue): Updated constructor to calculate
+        the computed line position.
+        (WebCore::TextTrackCue::setLine): Updated call to calculate the computed line
+        position.
+        (WebCore::TextTrackCue::setPosition):
+        (WebCore::TextTrackCue::calculateComputedLinePosition): Partial calculation of the
+        computated line position.
+        (WebCore::TextTrackCue::calculateDisplayParameters): Updated display parameter computations
+        required by the spec.
+        (WebCore::TextTrackCue::getDisplayTree): Updated positioning attributes when snap-to-lines
+        is not set. Added extra anonymous box for background, because setting position:absolute
+        on the display tree determines the background to cover the whole block, not just inline.
+        (WebCore::TextTrackCue::getPositionCoordinates): Determine coordinates as required by the spec.
+        * html/track/TextTrackCue.h:
+        (TextTrackCue):
+
 2012-04-19  Pavel Feldman  <pfeld...@chromium.org>
 
         Web Inspector: introduce styles panel as an experiment

Modified: trunk/Source/WebCore/css/mediaControls.css (114639 => 114640)


--- trunk/Source/WebCore/css/mediaControls.css	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/Source/WebCore/css/mediaControls.css	2012-04-19 16:27:25 UTC (rev 114640)
@@ -221,11 +221,21 @@
     text-decoration: none;
     pointer-events: none;
     -webkit-user-select: none;
+
+    -webkit-box-flex: 1;
 }
 
-video::-webkit-media-text-track-display {
+video::-webkit-media-text-track-background {
     display: inline;
     background-color: rgba(0, 0, 0, 0.8);
+    padding: 2px 2px;
+    white-space: pre-wrap;
+}
+
+video::-webkit-media-text-track-display {
+    position: absolute;
     color: rgba(255, 255, 255, 1);
-    padding: 0px 2px;
+
+    top: 100%;
+    -webkit-transform: translate(0%, -100%);
 }

Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.cpp (114639 => 114640)


--- trunk/Source/WebCore/html/shadow/MediaControlElements.cpp	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.cpp	2012-04-19 16:27:25 UTC (rev 114640)
@@ -1290,10 +1290,11 @@
         if (displayTree->hasChildNodes() && !contains(displayTree.get()))
             appendChild(displayTree, ASSERT_NO_EXCEPTION, true);
 
-        // The display tree of a cue is removed when the active flag of the cue is unset.
+        // Note: the display tree of a cue is removed when the active flag of the cue is unset.
 
-        // FIXME(BUG 79750): Render the TextTrackCue when snap-to-lines is set.
-        // FIXME(BUG 79751): Render the TextTrackCue when snap-to-lines is not set.
+        // FIXME(BUG 79751): Render the TextTrackCue when snap-to-lines is set.
+
+        // FIXME(BUG 84296): Implement overlapping detection for cue boxes when snap-to-lines is not set.
     }
 
     // 11. Return output.

Modified: trunk/Source/WebCore/html/track/TextTrackCue.cpp (114639 => 114640)


--- trunk/Source/WebCore/html/track/TextTrackCue.cpp	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/Source/WebCore/html/track/TextTrackCue.cpp	2012-04-19 16:27:25 UTC (rev 114640)
@@ -49,6 +49,8 @@
 namespace WebCore {
 
 static const int invalidCueIndex = -1;
+static const int undefinedPosition = -1;
+static const int autoSize = 0;
 
 static const String& startKeyword()
 {
@@ -90,7 +92,8 @@
     , m_startTime(start)
     , m_endTime(end)
     , m_content(content)
-    , m_linePosition(-1)
+    , m_linePosition(undefinedPosition)
+    , m_computedLinePosition(undefinedPosition)
     , m_textPosition(50)
     , m_cueSize(100)
     , m_cueIndex(invalidCueIndex)
@@ -102,9 +105,22 @@
     , m_snapToLines(true)
     , m_displayTreeShouldChange(true)
     , m_displayTree(HTMLDivElement::create(static_cast<Document*>(context)))
+    , m_displayXPosition(undefinedPosition)
+    , m_displayYPosition(undefinedPosition)
 {
     ASSERT(m_scriptExecutionContext->isDocument());
+
+    // The text track cue writing directions are directly relatd to the
+    // block-flow element, which can be set through the CSS writing modes.
+    m_displayWritingModeMap[Horizontal] = CSSValueHorizontalTb;
+    m_displayWritingModeMap[VerticalGrowingLeft] = CSSValueVerticalLr;
+    m_displayWritingModeMap[VerticalGrowingRight] = CSSValueVerticalRl;
+
     parseSettings(settings);
+
+    // A text track cue has a text track cue computed line position whose value
+    // is defined in terms of the other aspects of the cue.
+    m_computedLinePosition = calculateComputedLinePosition();
 }
 
 TextTrackCue::~TextTrackCue()
@@ -235,13 +251,14 @@
         ec = INDEX_SIZE_ERR;
         return;
     }
-    
+
     // Otherwise, set the text track cue line position to the new value.
     if (m_linePosition == position)
         return;
-    
+
     cueWillChange();
-    m_linePosition = position; 
+    m_linePosition = position;
+    m_computedLinePosition = calculateComputedLinePosition();
     cueDidChange();
 }
 
@@ -260,7 +277,7 @@
         return;
     
     cueWillChange();
-    m_textPosition = position; 
+    m_textPosition = position;
     cueDidChange();
 }
 
@@ -396,22 +413,131 @@
     }
 }
 
-void TextTrackCue::determineDisplayParameters()
+int TextTrackCue::calculateComputedLinePosition()
 {
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#text-track-cue-computed-line-position
+
+    // If the text track cue line position is numeric, then that is the text
+    // track cue computed line position.
+    if (m_linePosition != undefinedPosition)
+        return m_linePosition;
+
+    // If the text track cue snap-to-lines flag of the text track cue is not
+    // set, the text track cue computed line position is the value 100;
+    if (!m_snapToLines)
+        return 100;
+
+    // Otherwise, it is the value returned by the following algorithm:
+
+    // FIXME(BUG 79751): Complete determination algorithm when it is actually
+    // used - when displaying a TextTrackCue having snap-to-lines flag set.
+
+    return 100;
+}
+
+void TextTrackCue::calculateDisplayParameters()
+{
     // FIXME(BUG 79749): Determine the text direction using the BIDI algorithm.
     // Steps 10.2, 10.3
+    m_displayDirection = CSSValueLtr;
 
-    // FIXME(BUG 79747): Determine the display parameters from the rules.
-    // Steps 10.1, 10.4 - 10.10
+    // 10.4 If the text track cue writing direction is horizontal, then let
+    // block-flow be 'tb'. Otherwise, if the text track cue writing direction is
+    // vertical growing left, then let block-flow be 'lr'. Otherwise, the text
+    // track cue writing direction is vertical growing right; let block-flow be
+    // 'rl'.
+
+    m_displayWritingMode = m_displayWritingModeMap[m_writingDirection];
+
+    // 10.5 Determine the value of maximum size for cue as per the appropriate
+    // rules from the following list:
+    int maximumSize = m_textPosition;
+    if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displayDirection == CSSValueLtr)
+            || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displayDirection == CSSValueRtl)
+            || (m_writingDirection == VerticalGrowingLeft && m_cueAlignment == Start)
+            || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == End)) {
+        maximumSize = 100 - m_textPosition;
+    } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_displayDirection == CSSValueLtr)
+            || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_displayDirection == CSSValueRtl)
+            || (m_writingDirection == VerticalGrowingLeft && m_cueAlignment == End)
+            || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == End)) {
+        maximumSize = m_textPosition;
+    } else if (m_cueAlignment == Middle) {
+        maximumSize = m_textPosition <= 50 ? m_textPosition : (100 - m_textPosition);
+        maximumSize = maximumSize * 2;
+    }
+
+    // 10.6 If the text track cue size is less than maximum size, then let size
+    // be text track cue size. Otherwise, let size be maximum size.
+    m_displaySize = std::min(m_cueSize, maximumSize);
+
+    // 10.7 If the text track cue writing direction is horizontal, then let
+    // width be 'size vw' and height be 'auto'. Otherwise, let width be 'auto'
+    // and height be 'size vh'. (These are CSS values used by the next section
+    // to set CSS properties for the rendering; 'vw' and 'vh' are CSS units.)
+    m_displayWidth = m_writingDirection == Horizontal ? m_displaySize : autoSize;
+    m_displayHeight = m_writingDirection == Horizontal ? autoSize : m_displaySize;
+
+    // 10.8 Determine the value of x-position or y-position for cue as per the
+    // appropriate rules from the following list:
+    if ((m_writingDirection == Horizontal && m_cueAlignment == Start && m_displayDirection == CSSValueLtr)
+            || (m_writingDirection == Horizontal && m_cueAlignment == End && m_displayDirection == CSSValueRtl)) {
+        m_displayXPosition = m_textPosition;
+    } else if ((m_writingDirection == Horizontal && m_cueAlignment == End && m_displayDirection == CSSValueLtr)
+            || (m_writingDirection == Horizontal && m_cueAlignment == Start && m_displayDirection == CSSValueRtl)) {
+        m_displayXPosition = 100 - m_textPosition;
+    }
+
+    if ((m_writingDirection == VerticalGrowingLeft && m_cueAlignment == Start)
+            || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == Start)) {
+        m_displayYPosition = m_textPosition;
+    } else if ((m_writingDirection == VerticalGrowingLeft && m_cueAlignment == End)
+            || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == End)) {
+        m_displayYPosition = 100 - m_textPosition;
+    }
+
+    if (m_writingDirection == Horizontal && m_cueAlignment == Middle) {
+        m_displayXPosition = m_textPosition - m_displaySize / 2;
+
+        if (m_displayDirection == CSSValueRtl)
+           m_displayXPosition = 100 - m_displayXPosition;
+    }
+
+    if ((m_writingDirection == VerticalGrowingLeft && m_cueAlignment == Middle)
+        || (m_writingDirection == VerticalGrowingRight && m_cueAlignment == Middle))
+        m_displayYPosition = m_textPosition - m_displaySize / 2;
+
+    // 10.9 Determine the value of whichever of x-position or y-position is not
+    // yet calculated for cue as per the appropriate rules from the following
+    // list:
+    if (m_snapToLines && m_displayYPosition == undefinedPosition && m_writingDirection == Horizontal)
+        m_displayYPosition = 0;
+
+    if (!m_snapToLines && m_writingDirection == Horizontal)
+        m_displayYPosition = m_computedLinePosition;
+
+    if (m_snapToLines && m_displayXPosition == undefinedPosition
+            && (m_writingDirection == VerticalGrowingLeft || m_writingDirection == VerticalGrowingRight))
+        m_displayXPosition = 0;
+
+    if (!m_snapToLines && (m_writingDirection == VerticalGrowingLeft || m_writingDirection == VerticalGrowingRight))
+        m_displayXPosition = m_computedLinePosition;
+
+    // 10.10 Let left be 'x-position vw' and top be 'y-position vh'.
+
+    // FIXME(Bug 79916): CSS top and left properties need to be applied.
 }
 
 PassRefPtr<HTMLDivElement> TextTrackCue::getDisplayTree()
 {
+    DEFINE_STATIC_LOCAL(const AtomicString, trackBackgroundShadowPseudoId, ("-webkit-media-text-track-background"));
+    DEFINE_STATIC_LOCAL(const AtomicString, trackDisplayBoxShadowPseudoId, ("-webkit-media-text-track-display"));
+
     if (!m_displayTreeShouldChange)
         return m_displayTree;
 
     // 10.1 - 10.10
-    determineDisplayParameters();
+    calculateDisplayParameters();
 
     // 10.11. Apply the terms of the CSS specifications to nodes within the
     // following constraints, thus obtaining a set of CSS boxes positioned
@@ -423,9 +549,14 @@
     // The children of the nodes must be wrapped in an anonymous box whose
     // 'display' property has the value 'inline'. This is the WebVTT cue
     // background box.
-    m_displayTree->setShadowPseudoId(AtomicString("-webkit-media-text-track-display"), ASSERT_NO_EXCEPTION);
-    m_displayTree->appendChild(getCueAsHTML(), ASSERT_NO_EXCEPTION, true);
+    RefPtr<HTMLDivElement> cueBackgroundBox = HTMLDivElement::create(static_cast<Document*>(m_scriptExecutionContext));
 
+    cueBackgroundBox->setShadowPseudoId(trackBackgroundShadowPseudoId);
+    cueBackgroundBox->appendChild(getCueAsHTML(), ASSERT_NO_EXCEPTION, true);
+
+    m_displayTree->setShadowPseudoId(trackDisplayBoxShadowPseudoId, ASSERT_NO_EXCEPTION);
+    m_displayTree->appendChild(cueBackgroundBox, ASSERT_NO_EXCEPTION, true);
+
     // FIXME(BUG 79916): Runs of children of WebVTT Ruby Objects that are not
     // WebVTT Ruby Text Objects must be wrapped in anonymous boxes whose
     // 'display' property has the value 'ruby-base'.
@@ -440,6 +571,31 @@
 
     // FIXME(BUG 79750, 79751): Steps 10.12 - 10.14
 
+    if (!m_snapToLines) {
+        std::pair<double, double> position = getPositionCoordinates();
+
+        // 10.13.1 Set up x and y:
+        m_displayTree->setInlineStyleProperty(CSSPropertyLeft, position.first, CSSPrimitiveValue::CSS_PERCENTAGE);
+        m_displayTree->setInlineStyleProperty(CSSPropertyTop, position.second, CSSPrimitiveValue::CSS_PERCENTAGE);
+
+        // 10.13.2 Position the boxes in boxes such that the point x% along the
+        // width of the bounding box of the boxes in boxes is x% of the way
+        // across the width of the video's rendering area, and the point y%
+        // along the height of the bounding box of the boxes in boxes is y%
+        // of the way across the height of the video's rendering area, while
+        // maintaining the relative positions of the boxes in boxes to each
+        // other.
+        String translateX = "-" + String::number(position.first) + "%";
+        String translateY = "-" + String::number(position.second) + "%";
+        String webkitTransformTranslateValue = "translate(" + translateX + "," + translateY + ")";
+
+        m_displayTree->setInlineStyleProperty(CSSPropertyWebkitTransform,
+                                              webkitTransformTranslateValue);
+
+        m_displayTree->setInlineStyleProperty(CSSPropertyWhiteSpace,
+                                              CSSValuePre);
+    }
+
     m_displayTreeShouldChange = false;
 
     // 10.15. Let cue's text track cue display state have the CSS boxes in
@@ -447,6 +603,43 @@
     return m_displayTree;
 }
 
+std::pair<double, double> TextTrackCue::getPositionCoordinates()
+{
+    std::pair<double, double> coordinates;
+
+    if (m_writingDirection == Horizontal && m_displayDirection == CSSValueLtr) {
+        coordinates.first = m_textPosition;
+        coordinates.second = m_computedLinePosition;
+
+        return coordinates;
+    }
+
+    if (m_writingDirection == Horizontal && m_displayDirection == CSSValueRtl) {
+        coordinates.first = 100 - m_textPosition;
+        coordinates.second = m_computedLinePosition;
+
+        return coordinates;
+    }
+
+    if (m_writingDirection == VerticalGrowingLeft) {
+        coordinates.first = 100 - m_computedLinePosition;
+        coordinates.second = m_textPosition;
+
+        return coordinates;
+    }
+
+    if (m_writingDirection == VerticalGrowingRight) {
+        coordinates.first = m_computedLinePosition;
+        coordinates.second = m_textPosition;
+
+        return coordinates;
+    }
+
+    ASSERT_NOT_REACHED();
+
+    return coordinates;
+}
+
 TextTrackCue::CueSetting TextTrackCue::settingName(const String& name)
 {
     DEFINE_STATIC_LOCAL(const String, verticalKeyword, ("vertical"));

Modified: trunk/Source/WebCore/html/track/TextTrackCue.h (114639 => 114640)


--- trunk/Source/WebCore/html/track/TextTrackCue.h	2012-04-19 16:23:44 UTC (rev 114639)
+++ trunk/Source/WebCore/html/track/TextTrackCue.h	2012-04-19 16:27:25 UTC (rev 114640)
@@ -120,8 +120,12 @@
     TextTrackCue(ScriptExecutionContext*, const String& id, double start, double end, const String& content, const String& settings, bool pauseOnExit);
 
     void parseSettings(const String&);
-    void determineDisplayParameters();
 
+    int calculateComputedLinePosition();
+    void calculateDisplayParameters();
+
+    std::pair<double, double> getPositionCoordinates();
+
     void cueWillChange();
     void cueDidChange();
 
@@ -136,11 +140,17 @@
     double m_endTime;
     String m_content;
     int m_linePosition;
+    int m_computedLinePosition;
     int m_textPosition;
     int m_cueSize;
     int m_cueIndex;
 
-    enum WritingDirection { Horizontal, VerticalGrowingLeft, VerticalGrowingRight };
+    enum WritingDirection {
+        Horizontal,
+        VerticalGrowingLeft,
+        VerticalGrowingRight,
+        NumberOfWritingDirections
+    };
     WritingDirection m_writingDirection;
 
     enum Alignment { Start, Middle, End };
@@ -158,6 +168,18 @@
 
     bool m_displayTreeShouldChange;
     RefPtr<HTMLDivElement> m_displayTree;
+
+    int m_displayDirection;
+
+    int m_displayWritingModeMap[NumberOfWritingDirections];
+    int m_displayWritingMode;
+
+    int m_displaySize;
+    int m_displayHeight;
+    int m_displayWidth;
+
+    double m_displayXPosition;
+    double m_displayYPosition;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to