OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Victor Carbune (victor@rosedu.org) | 2 * Copyright (C) 2012 Victor Carbune (victor@rosedu.org) |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 void RenderVTTCue::trace(Visitor* visitor) | 41 void RenderVTTCue::trace(Visitor* visitor) |
42 { | 42 { |
43 visitor->trace(m_cue); | 43 visitor->trace(m_cue); |
44 RenderBlockFlow::trace(visitor); | 44 RenderBlockFlow::trace(visitor); |
45 } | 45 } |
46 | 46 |
47 class SnapToLinesLayouter { | 47 class SnapToLinesLayouter { |
48 STACK_ALLOCATED(); | 48 STACK_ALLOCATED(); |
49 public: | 49 public: |
50 SnapToLinesLayouter(RenderVTTCue& cueBox, VTTCue::WritingDirection writingDi
rection, float linePosition) | 50 SnapToLinesLayouter(RenderVTTCue& cueBox, float linePosition) |
51 : m_cueBox(cueBox) | 51 : m_cueBox(cueBox) |
52 , m_cueWritingDirection(writingDirection) | |
53 , m_linePosition(linePosition) | 52 , m_linePosition(linePosition) |
54 { | 53 { |
55 } | 54 } |
56 | 55 |
57 void layout(); | 56 void layout(); |
58 | 57 |
59 private: | 58 private: |
60 bool isOutside() const; | 59 bool isOutside() const; |
61 bool isOverlapping() const; | 60 bool isOverlapping() const; |
62 LayoutUnit computeInitialPositionAdjustment(LayoutUnit&) const; | 61 LayoutUnit computeInitialPositionAdjustment(LayoutUnit&) const; |
63 bool shouldSwitchDirection(InlineFlowBox*, LayoutUnit) const; | 62 bool shouldSwitchDirection(InlineFlowBox*, LayoutUnit) const; |
64 | 63 |
65 void moveBoxesBy(LayoutUnit distance) | 64 void moveBoxesBy(LayoutUnit distance) |
66 { | 65 { |
67 if (m_cueWritingDirection == VTTCue::Horizontal) | 66 m_cueBox.setLogicalTop(m_cueBox.logicalTop() + distance); |
68 m_cueBox.setY(m_cueBox.location().y() + distance); | |
69 else | |
70 m_cueBox.setX(m_cueBox.location().x() + distance); | |
71 } | 67 } |
72 | 68 |
73 InlineFlowBox* findFirstLineBox() const; | 69 InlineFlowBox* findFirstLineBox() const; |
74 | 70 |
75 LayoutPoint m_specifiedPosition; | 71 LayoutPoint m_specifiedPosition; |
76 RenderVTTCue& m_cueBox; | 72 RenderVTTCue& m_cueBox; |
77 VTTCue::WritingDirection m_cueWritingDirection; | |
78 float m_linePosition; | 73 float m_linePosition; |
79 }; | 74 }; |
80 | 75 |
81 InlineFlowBox* SnapToLinesLayouter::findFirstLineBox() const | 76 InlineFlowBox* SnapToLinesLayouter::findFirstLineBox() const |
82 { | 77 { |
83 if (!m_cueBox.firstChild()->isRenderInline()) | 78 if (!m_cueBox.firstChild()->isRenderInline()) |
84 return nullptr; | 79 return nullptr; |
85 return toRenderInline(m_cueBox.firstChild())->firstLineBox(); | 80 return toRenderInline(m_cueBox.firstChild())->firstLineBox(); |
86 } | 81 } |
87 | 82 |
88 LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste
p) const | 83 LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste
p) const |
89 { | 84 { |
90 // 6. Let line position be the text track cue computed line position. | 85 // 6. Let line position be the text track cue computed line position. |
91 // 7. Round line position to an integer by adding 0.5 and then flooring it. | 86 // 7. Round line position to an integer by adding 0.5 and then flooring it. |
92 LayoutUnit linePosition = floorf(m_linePosition + 0.5f); | 87 LayoutUnit linePosition = floorf(m_linePosition + 0.5f); |
93 | 88 |
| 89 WritingMode writingMode = m_cueBox.style()->writingMode(); |
94 // 8. Vertical Growing Left: Add one to line position then negate it. | 90 // 8. Vertical Growing Left: Add one to line position then negate it. |
95 if (m_cueWritingDirection == VTTCue::VerticalGrowingLeft) | 91 if (writingMode == RightToLeftWritingMode) |
96 linePosition = -(linePosition + 1); | 92 linePosition = -(linePosition + 1); |
97 | 93 |
98 // 9. Let position be the result of multiplying step and line position. | 94 // 9. Let position be the result of multiplying step and line position. |
99 LayoutUnit position = step * linePosition; | 95 LayoutUnit position = step * linePosition; |
100 | 96 |
101 // 10. Vertical Growing Left: Decrease position by the width of the | 97 // 10. Vertical Growing Left: Decrease position by the width of the |
102 // bounding box of the boxes in boxes, then increase position by step. | 98 // bounding box of the boxes in boxes, then increase position by step. |
103 if (m_cueWritingDirection == VTTCue::VerticalGrowingLeft) { | 99 if (writingMode == RightToLeftWritingMode) { |
104 position -= m_cueBox.size().width(); | 100 position -= m_cueBox.size().width(); |
105 position += step; | 101 position += step; |
106 } | 102 } |
107 | 103 |
108 // 11. If line position is less than zero... | 104 // 11. If line position is less than zero... |
109 if (linePosition < 0) { | 105 if (linePosition < 0) { |
110 RenderBlock* parentBlock = m_cueBox.containingBlock(); | 106 RenderBlock* parentBlock = m_cueBox.containingBlock(); |
111 | 107 |
112 // Horizontal / Vertical: ... then increase position by the | 108 // Horizontal / Vertical: ... then increase position by the |
113 // height / width of the video's rendering area ... | 109 // height / width of the video's rendering area ... |
114 position += m_cueWritingDirection == VTTCue::Horizontal ? parentBlock->s
ize().height() : parentBlock->size().width(); | 110 position += blink::isHorizontalWritingMode(writingMode) ? parentBlock->s
ize().height() : parentBlock->size().width(); |
115 | 111 |
116 // ... and negate step. | 112 // ... and negate step. |
117 step = -step; | 113 step = -step; |
118 } | 114 } |
119 return position; | 115 return position; |
120 } | 116 } |
121 | 117 |
122 bool SnapToLinesLayouter::isOutside() const | 118 bool SnapToLinesLayouter::isOutside() const |
123 { | 119 { |
124 return !m_cueBox.containingBlock()->absoluteBoundingBoxRect().contains(m_cue
Box.absoluteContentBox()); | 120 return !m_cueBox.containingBlock()->absoluteBoundingBoxRect().contains(m_cue
Box.absoluteContentBox()); |
125 } | 121 } |
126 | 122 |
127 bool SnapToLinesLayouter::isOverlapping() const | 123 bool SnapToLinesLayouter::isOverlapping() const |
128 { | 124 { |
129 for (RenderObject* box = m_cueBox.previousSibling(); box; box = box->previou
sSibling()) { | 125 for (RenderObject* box = m_cueBox.previousSibling(); box; box = box->previou
sSibling()) { |
130 IntRect boxRect = box->absoluteBoundingBoxRect(); | 126 IntRect boxRect = box->absoluteBoundingBoxRect(); |
131 | 127 |
132 if (m_cueBox.absoluteBoundingBoxRect().intersects(boxRect)) | 128 if (m_cueBox.absoluteBoundingBoxRect().intersects(boxRect)) |
133 return true; | 129 return true; |
134 } | 130 } |
135 | 131 |
136 return false; | 132 return false; |
137 } | 133 } |
138 | 134 |
139 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay
outUnit step) const | 135 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay
outUnit step) const |
140 { | 136 { |
141 LayoutUnit top = m_cueBox.location().y(); | |
142 LayoutUnit left = m_cueBox.location().x(); | |
143 LayoutUnit bottom = top + firstLineBox->size().height(); | |
144 LayoutUnit right = left + firstLineBox->size().width(); | |
145 | |
146 // 21. Horizontal: If step is negative and the top of the first line box in | 137 // 21. Horizontal: If step is negative and the top of the first line box in |
147 // boxes is now above the top of the title area, or if step is positive and | 138 // boxes is now above the top of the title area, or if step is positive and |
148 // the bottom of the first line box in boxes is now below the bottom of the | 139 // the bottom of the first line box in boxes is now below the bottom of the |
149 // title area, jump to the step labeled switch direction. | 140 // title area, jump to the step labeled switch direction. |
150 LayoutUnit parentHeight = m_cueBox.containingBlock()->size().height(); | 141 // Vertical: If step is negative and the left edge of the first line |
151 if (m_cueWritingDirection == VTTCue::Horizontal && ((step < 0 && top < 0) ||
(step > 0 && bottom > parentHeight))) | |
152 return true; | |
153 | |
154 // 21. Vertical: If step is negative and the left edge of the first line | |
155 // box in boxes is now to the left of the left edge of the title area, or | 142 // box in boxes is now to the left of the left edge of the title area, or |
156 // if step is positive and the right edge of the first line box in boxes is | 143 // if step is positive and the right edge of the first line box in boxes is |
157 // now to the right of the right edge of the title area, jump to the step | 144 // now to the right of the right edge of the title area, jump to the step |
158 // labeled switch direction. | 145 // labeled switch direction. |
159 LayoutUnit parentWidth = m_cueBox.containingBlock()->size().width(); | 146 LayoutUnit logicalTop = m_cueBox.logicalTop(); |
160 if (m_cueWritingDirection != VTTCue::Horizontal && ((step < 0 && left < 0) |
| (step > 0 && right > parentWidth))) | 147 if (step < 0 && logicalTop < 0) |
161 return true; | 148 return true; |
162 | 149 if (step > 0 && logicalTop + firstLineBox->logicalHeight() > m_cueBox.contai
ningBlock()->logicalHeight()) |
| 150 return true; |
163 return false; | 151 return false; |
164 } | 152 } |
165 | 153 |
166 void SnapToLinesLayouter::layout() | 154 void SnapToLinesLayouter::layout() |
167 { | 155 { |
168 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings | 156 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings |
169 // Step 13, "If cue's text track cue snap-to-lines flag is set". | 157 // Step 13, "If cue's text track cue snap-to-lines flag is set". |
170 | 158 |
171 InlineFlowBox* firstLineBox = findFirstLineBox(); | 159 InlineFlowBox* firstLineBox = findFirstLineBox(); |
172 if (!firstLineBox) | 160 if (!firstLineBox) |
173 return; | 161 return; |
174 | 162 |
175 // Steps 1-3 skipped. | 163 // Steps 1-3 skipped. |
176 // 4. Horizontal: Let step be the height of the first line box in boxes. | 164 // 4. Horizontal: Let step be the height of the first line box in boxes. |
177 // Vertical: Let step be the width of the first line box in boxes. | 165 // Vertical: Let step be the width of the first line box in boxes. |
178 LayoutUnit step = m_cueWritingDirection == VTTCue::Horizontal ? firstLineBox
->size().height() : firstLineBox->size().width(); | 166 LayoutUnit step = firstLineBox->logicalHeight(); |
179 | 167 |
180 // 5. If step is zero, then jump to the step labeled done positioning below. | 168 // 5. If step is zero, then jump to the step labeled done positioning below. |
181 if (!step) | 169 if (!step) |
182 return; | 170 return; |
183 | 171 |
184 // Steps 6-11. | 172 // Steps 6-11. |
185 LayoutUnit positionAdjustment = computeInitialPositionAdjustment(step); | 173 LayoutUnit positionAdjustment = computeInitialPositionAdjustment(step); |
186 | 174 |
187 // 12. Move all boxes in boxes ... | 175 // 12. Move all boxes in boxes ... |
188 // Horizontal: ... down by the distance given by position | 176 // Horizontal: ... down by the distance given by position |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // have positioning information. | 318 // have positioning information. |
331 if (!m_cue->regionId().isEmpty()) | 319 if (!m_cue->regionId().isEmpty()) |
332 return; | 320 return; |
333 | 321 |
334 ASSERT(firstChild()); | 322 ASSERT(firstChild()); |
335 | 323 |
336 LayoutState state(*this, locationOffset()); | 324 LayoutState state(*this, locationOffset()); |
337 | 325 |
338 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings - step 13. | 326 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings - step 13. |
339 if (m_cue->snapToLines()) { | 327 if (m_cue->snapToLines()) { |
340 SnapToLinesLayouter(*this, m_cue->getWritingDirection(), m_cue->calculat
eComputedLinePosition()).layout(); | 328 SnapToLinesLayouter(*this, m_cue->calculateComputedLinePosition()).layou
t(); |
341 | 329 |
342 adjustForTopAndBottomMarginBorderAndPadding(); | 330 adjustForTopAndBottomMarginBorderAndPadding(); |
343 } else { | 331 } else { |
344 repositionCueSnapToLinesNotSet(); | 332 repositionCueSnapToLinesNotSet(); |
345 } | 333 } |
346 } | 334 } |
347 | 335 |
348 } // namespace blink | 336 } // namespace blink |
349 | 337 |
OLD | NEW |