Commit 6fb78300 authored by fs@opera.com's avatar fs@opera.com

Sync snap-to-lines VTT cue layout steps with spec

 * Sync step documentation ('line position' -> 'line' and similar.)
 * Remove remnants of 'best position' and re-number steps.
 * Implement new cue dodging logic.

BUG=301580

Review URL: https://codereview.chromium.org/1306833003

git-svn-id: svn://svn.chromium.org/blink/trunk@200987 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 78efd70d
<!DOCTYPE html>
<script src="../media-file.js"></script>
<script>
var mediaFile = findMediaFile('video', '../content/test');
</script>
<style>
.container {
position: relative;
display: inline-block;
width: 320px;
height: 240px;
}
.cue {
position: absolute;
top: 0;
left: 0;
right: 0;
overflow: hidden;
}
.cue.start {
text-align: start;
}
.cue > span {
font-family: sans-serif;
background: green;
color: green;
font-size: 120px;
padding: 2px;
}
</style>
<div class="container">
<video><script>document.currentScript.parentNode.src = mediaFile;</script></video>
<div class=video>
<div class="cue start"><span>PAS</span></div>
</div>
</div>
<!DOCTYPE html>
<script src="../media-file.js"></script>
<script>
var mediaFile = findMediaFile('video', '../content/test');
function addCue(track, cueData) {
var cue = new VTTCue(0, 10, 'XXX');
for (var prop in cueData)
cue[prop] = cueData[prop];
track.addCue(cue);
}
</script>
<style>
video::cue {
font-size: 120px;
color: green;
background-color: green;
}
</style>
<video>
<script>
var video = document.currentScript.parentNode;
var track = video.addTextTrack('subtitles');
addCue(track, { line: 0, align: 'start', text: 'PAS' });
// This cue will not fit, and will not be displayed.
addCue(track, { line: 1, align: 'start', text: 'FAI' });
track.mode = 'showing';
video.src = mediaFile;
</script>
</video>
...@@ -78,16 +78,16 @@ LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste ...@@ -78,16 +78,16 @@ LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste
{ {
ASSERT(std::isfinite(m_cueBox.snapToLinesPosition())); ASSERT(std::isfinite(m_cueBox.snapToLinesPosition()));
// 6. Let line position be the text track cue computed line position. // 6. Let line be cue's computed line.
// 7. Round line position to an integer by adding 0.5 and then flooring it. // 7. Round line to an integer by adding 0.5 and then flooring it.
LayoutUnit linePosition = floorf(m_cueBox.snapToLinesPosition() + 0.5f); LayoutUnit linePosition = floorf(m_cueBox.snapToLinesPosition() + 0.5f);
WritingMode writingMode = m_cueBox.style()->writingMode(); WritingMode writingMode = m_cueBox.style()->writingMode();
// 8. Vertical Growing Left: Add one to line position then negate it. // 8. Vertical Growing Left: Add one to line then negate it.
if (writingMode == RightToLeftWritingMode) if (writingMode == RightToLeftWritingMode)
linePosition = -(linePosition + 1); linePosition = -(linePosition + 1);
// 9. Let position be the result of multiplying step and line position. // 9. Let position be the result of multiplying step and line offset.
LayoutUnit position = step * linePosition; LayoutUnit position = step * linePosition;
// 10. Vertical Growing Left: Decrease position by the width of the // 10. Vertical Growing Left: Decrease position by the width of the
...@@ -97,12 +97,11 @@ LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste ...@@ -97,12 +97,11 @@ LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste
position += step; position += step;
} }
// 11. If line position is less than zero... // 11. If line is less than zero...
if (linePosition < 0) { if (linePosition < 0) {
LayoutBlock* parentBlock = m_cueBox.containingBlock(); LayoutBlock* parentBlock = m_cueBox.containingBlock();
// Horizontal / Vertical: ... then increase position by the // ... then increase position by max dimension ...
// height / width of the video's rendering area ...
position += blink::isHorizontalWritingMode(writingMode) ? parentBlock->size().height() : parentBlock->size().width(); position += blink::isHorizontalWritingMode(writingMode) ? parentBlock->size().height() : parentBlock->size().width();
// ... and negate step. // ... and negate step.
...@@ -134,7 +133,7 @@ bool SnapToLinesLayouter::isOverlapping() const ...@@ -134,7 +133,7 @@ bool SnapToLinesLayouter::isOverlapping() const
bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, LayoutUnit step) const bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, LayoutUnit step) const
{ {
// 21. Horizontal: If step is negative and the top of the first line box in // 17. Horizontal: If step is negative and the top of the first line box in
// boxes is now above the top of the title area, or if step is positive and // boxes is now above the top of the title area, or if step is positive and
// the bottom of the first line box in boxes is now below the bottom of the // the bottom of the first line box in boxes is now below the bottom of the
// title area, jump to the step labeled switch direction. // title area, jump to the step labeled switch direction.
...@@ -181,31 +180,20 @@ void SnapToLinesLayouter::layout() ...@@ -181,31 +180,20 @@ void SnapToLinesLayouter::layout()
// position. // position.
m_specifiedPosition = m_cueBox.location(); m_specifiedPosition = m_cueBox.location();
// 14. Let best position be null. It will hold a position for boxes, much // XX. Let switched be false.
// like specified position in the previous step.
// 15. Let best position score be null.
// 16. Let switched be false.
bool switched = false; bool switched = false;
// Step 17 skipped. (margin == 0; title area == video area) // Step 14 skipped. (margin == 0; title area == video area)
// 18. Step loop: If none of the boxes in boxes would overlap any of the // 15. Step loop: If none of the boxes in boxes would overlap any of the
// boxes in output, and all of the boxes in output are entirely within the // boxes in output, and all of the boxes in output are entirely within the
// title area box, then jump to the step labeled done positioning below. // title area box, then jump to the step labeled done positioning below.
while (isOutside() || isOverlapping()) { while (isOutside() || isOverlapping()) {
// 19. Let current position score be the percentage of the area of the // 16. Let current position score be the percentage of the area of the
// bounding box of the boxes in boxes that is outside the title area // bounding box of the boxes in boxes that is outside the title area
// box. // box.
// 20. If best position is null (i.e. this is the first run through
// this loop, switched is still false, the boxes in boxes are at their
// specified position, and best position score is still null), or if
// current position score is a lower percentage than that in best
// position score, then remember the position of all the boxes in boxes
// as their best position, and set best position score to current
// position score.
if (!shouldSwitchDirection(firstLineBox, step)) { if (!shouldSwitchDirection(firstLineBox, step)) {
// 22. Horizontal: Move all the boxes in boxes down by the distance // 18. Horizontal: Move all the boxes in boxes down by the distance
// given by step. (If step is negative, then this will actually // given by step. (If step is negative, then this will actually
// result in an upwards movement of the boxes in absolute terms.) // result in an upwards movement of the boxes in absolute terms.)
// Vertical: Move all the boxes in boxes right by the distance // Vertical: Move all the boxes in boxes right by the distance
...@@ -213,30 +201,31 @@ void SnapToLinesLayouter::layout() ...@@ -213,30 +201,31 @@ void SnapToLinesLayouter::layout()
// result in a leftwards movement of the boxes in absolute terms.) // result in a leftwards movement of the boxes in absolute terms.)
moveBoxesBy(step); moveBoxesBy(step);
// 23. Jump back to the step labeled step loop. // 19. Jump back to the step labeled step loop.
continue; continue;
} }
// 24. Switch direction: If switched is true, then move all the boxes in // 20. Switch direction: If switched is true, then remove all the boxes
// boxes back to their best position, and jump to the step labeled done // in boxes, and jump to the step labeled done positioning below.
// positioning below. if (switched) {
// This does not "remove" the boxes, but rather just pushes them
// out of the viewport. Otherwise we'd need to mutate the layout
// tree during layout.
m_cueBox.setLogicalTop(m_cueBox.containingBlock()->logicalHeight() + 1);
break;
}
// 25. Otherwise, move all the boxes in boxes back to their specified // 21. Otherwise, move all the boxes in boxes back to their specified
// position as determined in the earlier step. // position as determined in the earlier step.
m_cueBox.setLocation(m_specifiedPosition); m_cueBox.setLocation(m_specifiedPosition);
// XX. If switched is true, jump to the step labeled done // 22. Negate step.
// positioning below.
if (switched)
break;
// 26. Negate step.
step = -step; step = -step;
// 27. Set switched to true. // 23. Set switched to true.
switched = true; switched = true;
// 28. Jump back to the step labeled step loop. // 24. Jump back to the step labeled step loop.
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment