Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1120)

Side by Side Diff: Source/core/layout/LayoutVTTCue.cpp

Issue 1306833003: Sync snap-to-lines VTT cue layout steps with spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Typo Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/track/vtt/VTTCue.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 { 71 {
72 if (!m_cueBox.firstChild()->isLayoutInline()) 72 if (!m_cueBox.firstChild()->isLayoutInline())
73 return nullptr; 73 return nullptr;
74 return toLayoutInline(m_cueBox.firstChild())->firstLineBox(); 74 return toLayoutInline(m_cueBox.firstChild())->firstLineBox();
75 } 75 }
76 76
77 LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste p) const 77 LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste p) const
78 { 78 {
79 ASSERT(std::isfinite(m_cueBox.snapToLinesPosition())); 79 ASSERT(std::isfinite(m_cueBox.snapToLinesPosition()));
80 80
81 // 6. Let line position be the text track cue computed line position. 81 // 6. Let line be cue's computed line.
82 // 7. Round line position to an integer by adding 0.5 and then flooring it. 82 // 7. Round line to an integer by adding 0.5 and then flooring it.
83 LayoutUnit linePosition = floorf(m_cueBox.snapToLinesPosition() + 0.5f); 83 LayoutUnit linePosition = floorf(m_cueBox.snapToLinesPosition() + 0.5f);
84 84
85 WritingMode writingMode = m_cueBox.style()->writingMode(); 85 WritingMode writingMode = m_cueBox.style()->writingMode();
86 // 8. Vertical Growing Left: Add one to line position then negate it. 86 // 8. Vertical Growing Left: Add one to line then negate it.
87 if (writingMode == RightToLeftWritingMode) 87 if (writingMode == RightToLeftWritingMode)
88 linePosition = -(linePosition + 1); 88 linePosition = -(linePosition + 1);
89 89
90 // 9. Let position be the result of multiplying step and line position. 90 // 9. Let position be the result of multiplying step and line offset.
91 LayoutUnit position = step * linePosition; 91 LayoutUnit position = step * linePosition;
92 92
93 // 10. Vertical Growing Left: Decrease position by the width of the 93 // 10. Vertical Growing Left: Decrease position by the width of the
94 // bounding box of the boxes in boxes, then increase position by step. 94 // bounding box of the boxes in boxes, then increase position by step.
95 if (writingMode == RightToLeftWritingMode) { 95 if (writingMode == RightToLeftWritingMode) {
96 position -= m_cueBox.size().width(); 96 position -= m_cueBox.size().width();
97 position += step; 97 position += step;
98 } 98 }
99 99
100 // 11. If line position is less than zero... 100 // 11. If line is less than zero...
101 if (linePosition < 0) { 101 if (linePosition < 0) {
102 LayoutBlock* parentBlock = m_cueBox.containingBlock(); 102 LayoutBlock* parentBlock = m_cueBox.containingBlock();
103 103
104 // Horizontal / Vertical: ... then increase position by the 104 // ... then increase position by max dimension ...
105 // height / width of the video's rendering area ...
106 position += blink::isHorizontalWritingMode(writingMode) ? parentBlock->s ize().height() : parentBlock->size().width(); 105 position += blink::isHorizontalWritingMode(writingMode) ? parentBlock->s ize().height() : parentBlock->size().width();
107 106
108 // ... and negate step. 107 // ... and negate step.
109 step = -step; 108 step = -step;
110 } 109 }
111 return position; 110 return position;
112 } 111 }
113 112
114 bool SnapToLinesLayouter::isOutside() const 113 bool SnapToLinesLayouter::isOutside() const
115 { 114 {
(...skipping 11 matching lines...) Expand all
127 } 126 }
128 127
129 if (cueBoxRect.intersects(m_controlsRect)) 128 if (cueBoxRect.intersects(m_controlsRect))
130 return true; 129 return true;
131 130
132 return false; 131 return false;
133 } 132 }
134 133
135 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay outUnit step) const 134 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay outUnit step) const
136 { 135 {
137 // 21. Horizontal: If step is negative and the top of the first line box in 136 // 17. Horizontal: If step is negative and the top of the first line box in
138 // boxes is now above the top of the title area, or if step is positive and 137 // boxes is now above the top of the title area, or if step is positive and
139 // the bottom of the first line box in boxes is now below the bottom of the 138 // the bottom of the first line box in boxes is now below the bottom of the
140 // title area, jump to the step labeled switch direction. 139 // title area, jump to the step labeled switch direction.
141 // Vertical: If step is negative and the left edge of the first line 140 // Vertical: If step is negative and the left edge of the first line
142 // box in boxes is now to the left of the left edge of the title area, or 141 // box in boxes is now to the left of the left edge of the title area, or
143 // if step is positive and the right edge of the first line box in boxes is 142 // if step is positive and the right edge of the first line box in boxes is
144 // now to the right of the right edge of the title area, jump to the step 143 // now to the right of the right edge of the title area, jump to the step
145 // labeled switch direction. 144 // labeled switch direction.
146 LayoutUnit logicalTop = m_cueBox.logicalTop(); 145 LayoutUnit logicalTop = m_cueBox.logicalTop();
147 if (step < 0 && logicalTop < 0) 146 if (step < 0 && logicalTop < 0)
(...skipping 26 matching lines...) Expand all
174 173
175 // 12. Move all boxes in boxes ... 174 // 12. Move all boxes in boxes ...
176 // Horizontal: ... down by the distance given by position 175 // Horizontal: ... down by the distance given by position
177 // Vertical: ... right by the distance given by position 176 // Vertical: ... right by the distance given by position
178 moveBoxesBy(positionAdjustment); 177 moveBoxesBy(positionAdjustment);
179 178
180 // 13. Remember the position of all the boxes in boxes as their specified 179 // 13. Remember the position of all the boxes in boxes as their specified
181 // position. 180 // position.
182 m_specifiedPosition = m_cueBox.location(); 181 m_specifiedPosition = m_cueBox.location();
183 182
184 // 14. Let best position be null. It will hold a position for boxes, much 183 // XX. Let switched be false.
185 // like specified position in the previous step.
186 // 15. Let best position score be null.
187
188 // 16. Let switched be false.
189 bool switched = false; 184 bool switched = false;
190 185
191 // Step 17 skipped. (margin == 0; title area == video area) 186 // Step 14 skipped. (margin == 0; title area == video area)
192 187
193 // 18. Step loop: If none of the boxes in boxes would overlap any of the 188 // 15. Step loop: If none of the boxes in boxes would overlap any of the
194 // boxes in output, and all of the boxes in output are entirely within the 189 // boxes in output, and all of the boxes in output are entirely within the
195 // title area box, then jump to the step labeled done positioning below. 190 // title area box, then jump to the step labeled done positioning below.
196 while (isOutside() || isOverlapping()) { 191 while (isOutside() || isOverlapping()) {
197 // 19. Let current position score be the percentage of the area of the 192 // 16. Let current position score be the percentage of the area of the
198 // bounding box of the boxes in boxes that is outside the title area 193 // bounding box of the boxes in boxes that is outside the title area
199 // box. 194 // box.
200 // 20. If best position is null (i.e. this is the first run through
201 // this loop, switched is still false, the boxes in boxes are at their
202 // specified position, and best position score is still null), or if
203 // current position score is a lower percentage than that in best
204 // position score, then remember the position of all the boxes in boxes
205 // as their best position, and set best position score to current
206 // position score.
207 if (!shouldSwitchDirection(firstLineBox, step)) { 195 if (!shouldSwitchDirection(firstLineBox, step)) {
208 // 22. Horizontal: Move all the boxes in boxes down by the distance 196 // 18. Horizontal: Move all the boxes in boxes down by the distance
209 // given by step. (If step is negative, then this will actually 197 // given by step. (If step is negative, then this will actually
210 // result in an upwards movement of the boxes in absolute terms.) 198 // result in an upwards movement of the boxes in absolute terms.)
211 // Vertical: Move all the boxes in boxes right by the distance 199 // Vertical: Move all the boxes in boxes right by the distance
212 // given by step. (If step is negative, then this will actually 200 // given by step. (If step is negative, then this will actually
213 // result in a leftwards movement of the boxes in absolute terms.) 201 // result in a leftwards movement of the boxes in absolute terms.)
214 moveBoxesBy(step); 202 moveBoxesBy(step);
215 203
216 // 23. Jump back to the step labeled step loop. 204 // 19. Jump back to the step labeled step loop.
217 continue; 205 continue;
218 } 206 }
219 207
220 // 24. Switch direction: If switched is true, then move all the boxes in 208 // 20. Switch direction: If switched is true, then remove all the boxes
221 // boxes back to their best position, and jump to the step labeled done 209 // in boxes, and jump to the step labeled done positioning below.
222 // positioning below. 210 if (switched) {
211 // This does not "remove" the boxes, but rather just pushes them
212 // out of the viewport. Otherwise we'd need to mutate the layout
213 // tree during layout.
214 m_cueBox.setLogicalTop(m_cueBox.containingBlock()->logicalHeight() + 1);
215 break;
216 }
223 217
224 // 25. Otherwise, move all the boxes in boxes back to their specified 218 // 21. Otherwise, move all the boxes in boxes back to their specified
225 // position as determined in the earlier step. 219 // position as determined in the earlier step.
226 m_cueBox.setLocation(m_specifiedPosition); 220 m_cueBox.setLocation(m_specifiedPosition);
227 221
228 // XX. If switched is true, jump to the step labeled done 222 // 22. Negate step.
229 // positioning below.
230 if (switched)
231 break;
232
233 // 26. Negate step.
234 step = -step; 223 step = -step;
235 224
236 // 27. Set switched to true. 225 // 23. Set switched to true.
237 switched = true; 226 switched = true;
238 227
239 // 28. Jump back to the step labeled step loop. 228 // 24. Jump back to the step labeled step loop.
240 } 229 }
241 } 230 }
242 231
243 void LayoutVTTCue::repositionCueSnapToLinesNotSet() 232 void LayoutVTTCue::repositionCueSnapToLinesNotSet()
244 { 233 {
245 // FIXME: Implement overlapping detection when snap-to-lines is not set. htt p://wkb.ug/84296 234 // FIXME: Implement overlapping detection when snap-to-lines is not set. htt p://wkb.ug/84296
246 235
247 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings 236 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings
248 // Step 13, "If cue's text track cue snap-to-lines flag is not set". 237 // Step 13, "If cue's text track cue snap-to-lines flag is not set".
249 238
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (!std::isnan(m_snapToLinesPosition)) { 322 if (!std::isnan(m_snapToLinesPosition)) {
334 SnapToLinesLayouter(*this, controlsRect).layout(); 323 SnapToLinesLayouter(*this, controlsRect).layout();
335 324
336 adjustForTopAndBottomMarginBorderAndPadding(); 325 adjustForTopAndBottomMarginBorderAndPadding();
337 } else { 326 } else {
338 repositionCueSnapToLinesNotSet(); 327 repositionCueSnapToLinesNotSet();
339 } 328 }
340 } 329 }
341 330
342 } // namespace blink 331 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/track/vtt/VTTCue.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698