void RenderTextTrackCue::repositionCueSnapToLinesSet() { InlineFlowBox* firstLineBox; LayoutUnit step; LayoutUnit position; if (!initializeLayoutParameters(firstLineBox, step, position)) return; bool switched; placeBoxInDefaultPosition(position, switched); // 11. Step loop: If none of the boxes in boxes would overlap any of the boxes // in output and all the boxes in output are within the video's rendering area // then jump to the step labeled done positioning. while (isOutside() || isOverlapping()) { if (!shouldSwitchDirection(firstLineBox, step)) // 13. Move all the boxes in boxes ... // 14. Jump back to the step labeled step loop. moveBoxesByStep(step); else if (!switchDirection(switched, step)) break; // 19. Jump back to the step labeled step loop. } // Acommodate extra top and bottom padding, border or margin. // Note: this is supported only for internal UA styling, not through the cue selector. if (hasInlineDirectionBordersPaddingOrMargin()) moveIfNecessaryToKeepWithinContainer(); }
void RenderVTTCue::repositionCueSnapToLinesSet() { InlineFlowBox* firstLineBox; LayoutUnit step; LayoutUnit position; if (!findFirstLineBox(firstLineBox)) return; if (!initializeLayoutParameters(firstLineBox, step, position)) return; bool switched; placeBoxInDefaultPosition(position, switched); // 11. Step loop: If none of the boxes in boxes would overlap any of the boxes // in output and all the boxes in output are within the video's rendering area // then jump to the step labeled done positioning. while (isOutside() || isOverlapping()) { if (!shouldSwitchDirection(firstLineBox, step)) { // 13. Move all the boxes in boxes ... // 14. Jump back to the step labeled step loop. moveBoxesByStep(step); } else if (!switchDirection(switched, step)) { break; } // 19. Jump back to the step labeled step loop. } // Acommodate extra top and bottom padding, border or margin. // Note: this is supported only for internal UA styling, not through the cue selector. if (hasInlineDirectionBordersPaddingOrMargin()) { IntRect containerRect = containingBlock()->absoluteBoundingBoxRect(); IntRect cueRect = absoluteBoundingBoxRect(); int topOverflow = cueRect.y() - containerRect.y(); int bottomOverflow = containerRect.y() + containerRect.height() - cueRect.y() - cueRect.height(); int adjustment = 0; if (topOverflow < 0) adjustment = -topOverflow; else if (bottomOverflow < 0) adjustment = bottomOverflow; if (adjustment) setY(y() + adjustment); } }
void SnapToLinesLayouter::layout() { // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings // Step 13, "If cue's text track cue snap-to-lines flag is set". InlineFlowBox* firstLineBox = findFirstLineBox(); if (!firstLineBox) return; // Steps 1-3 skipped. // 4. Horizontal: Let step be the height of the first line box in boxes. // Vertical: Let step be the width of the first line box in boxes. LayoutUnit step = firstLineBox->logicalHeight(); // 5. If step is zero, then jump to the step labeled done positioning below. if (!step) return; // Steps 6-11. LayoutUnit positionAdjustment = computeInitialPositionAdjustment(step); // 12. Move all boxes in boxes ... // Horizontal: ... down by the distance given by position // Vertical: ... right by the distance given by position moveBoxesBy(positionAdjustment); // 13. Remember the position of all the boxes in boxes as their specified // position. m_specifiedPosition = m_cueBox.location(); // 14. Let best position be null. It will hold a position for boxes, much // like specified position in the previous step. // 15. Let best position score be null. // 16. Let switched be false. bool switched = false; // Step 17 skipped. (margin == 0; title area == video area) // 18. 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 // title area box, then jump to the step labeled done positioning below. while (isOutside() || isOverlapping()) { // 19. 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 // 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)) { // 22. Horizontal: Move all the boxes in boxes down by the distance // given by step. (If step is negative, then this will actually // result in an upwards movement of the boxes in absolute terms.) // Vertical: Move all the boxes in boxes right by the distance // given by step. (If step is negative, then this will actually // result in a leftwards movement of the boxes in absolute terms.) moveBoxesBy(step); // 23. Jump back to the step labeled step loop. continue; } // 24. Switch direction: If switched is true, then move all the boxes in // boxes back to their best position, and jump to the step labeled done // positioning below. // 25. Otherwise, move all the boxes in boxes back to their specified // position as determined in the earlier step. m_cueBox.setLocation(m_specifiedPosition); // XX. If switched is true, jump to the step labeled done // positioning below. if (switched) break; // 26. Negate step. step = -step; // 27. Set switched to true. switched = true; // 28. Jump back to the step labeled step loop. } }