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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/layout/LayoutVTTCue.h" | 27 #include "core/layout/LayoutVTTCue.h" |
28 | 28 |
| 29 #include "core/html/shadow/MediaControls.h" |
29 #include "core/html/track/vtt/VTTCue.h" | 30 #include "core/html/track/vtt/VTTCue.h" |
30 #include "core/layout/LayoutInline.h" | 31 #include "core/layout/LayoutInline.h" |
31 #include "core/layout/LayoutState.h" | 32 #include "core/layout/LayoutState.h" |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
34 | 35 |
35 LayoutVTTCue::LayoutVTTCue(VTTCueBox* element) | 36 LayoutVTTCue::LayoutVTTCue(VTTCueBox* element) |
36 : LayoutBlockFlow(element) | 37 : LayoutBlockFlow(element) |
37 , m_cue(element->getCue()) | 38 , m_cue(element->getCue()) |
38 { | 39 { |
39 } | 40 } |
40 | 41 |
41 class SnapToLinesLayouter { | 42 class SnapToLinesLayouter { |
42 STACK_ALLOCATED(); | 43 STACK_ALLOCATED(); |
43 public: | 44 public: |
44 SnapToLinesLayouter(LayoutVTTCue& cueBox, float linePosition) | 45 SnapToLinesLayouter(LayoutVTTCue& cueBox, const IntRect& controlsRect, float
linePosition) |
45 : m_cueBox(cueBox) | 46 : m_cueBox(cueBox) |
| 47 , m_controlsRect(controlsRect) |
46 , m_linePosition(linePosition) | 48 , m_linePosition(linePosition) |
47 { | 49 { |
48 } | 50 } |
49 | 51 |
50 void layout(); | 52 void layout(); |
51 | 53 |
52 private: | 54 private: |
53 bool isOutside() const; | 55 bool isOutside() const; |
54 bool isOverlapping() const; | 56 bool isOverlapping() const; |
55 LayoutUnit computeInitialPositionAdjustment(LayoutUnit&) const; | 57 LayoutUnit computeInitialPositionAdjustment(LayoutUnit&) const; |
56 bool shouldSwitchDirection(InlineFlowBox*, LayoutUnit) const; | 58 bool shouldSwitchDirection(InlineFlowBox*, LayoutUnit) const; |
57 | 59 |
58 void moveBoxesBy(LayoutUnit distance) | 60 void moveBoxesBy(LayoutUnit distance) |
59 { | 61 { |
60 m_cueBox.setLogicalTop(m_cueBox.logicalTop() + distance); | 62 m_cueBox.setLogicalTop(m_cueBox.logicalTop() + distance); |
61 } | 63 } |
62 | 64 |
63 InlineFlowBox* findFirstLineBox() const; | 65 InlineFlowBox* findFirstLineBox() const; |
64 | 66 |
65 LayoutPoint m_specifiedPosition; | 67 LayoutPoint m_specifiedPosition; |
66 LayoutVTTCue& m_cueBox; | 68 LayoutVTTCue& m_cueBox; |
| 69 IntRect m_controlsRect; |
67 float m_linePosition; | 70 float m_linePosition; |
68 }; | 71 }; |
69 | 72 |
70 InlineFlowBox* SnapToLinesLayouter::findFirstLineBox() const | 73 InlineFlowBox* SnapToLinesLayouter::findFirstLineBox() const |
71 { | 74 { |
72 if (!m_cueBox.firstChild()->isLayoutInline()) | 75 if (!m_cueBox.firstChild()->isLayoutInline()) |
73 return nullptr; | 76 return nullptr; |
74 return toLayoutInline(m_cueBox.firstChild())->firstLineBox(); | 77 return toLayoutInline(m_cueBox.firstChild())->firstLineBox(); |
75 } | 78 } |
76 | 79 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return position; | 112 return position; |
110 } | 113 } |
111 | 114 |
112 bool SnapToLinesLayouter::isOutside() const | 115 bool SnapToLinesLayouter::isOutside() const |
113 { | 116 { |
114 return !m_cueBox.containingBlock()->absoluteBoundingBoxRect().contains(m_cue
Box.absoluteContentBox()); | 117 return !m_cueBox.containingBlock()->absoluteBoundingBoxRect().contains(m_cue
Box.absoluteContentBox()); |
115 } | 118 } |
116 | 119 |
117 bool SnapToLinesLayouter::isOverlapping() const | 120 bool SnapToLinesLayouter::isOverlapping() const |
118 { | 121 { |
| 122 IntRect cueBoxRect = m_cueBox.absoluteBoundingBoxRect(); |
119 for (LayoutObject* box = m_cueBox.previousSibling(); box; box = box->previou
sSibling()) { | 123 for (LayoutObject* box = m_cueBox.previousSibling(); box; box = box->previou
sSibling()) { |
120 IntRect boxRect = box->absoluteBoundingBoxRect(); | 124 IntRect boxRect = box->absoluteBoundingBoxRect(); |
121 | 125 |
122 if (m_cueBox.absoluteBoundingBoxRect().intersects(boxRect)) | 126 if (cueBoxRect.intersects(boxRect)) |
123 return true; | 127 return true; |
124 } | 128 } |
125 | 129 |
| 130 if (cueBoxRect.intersects(m_controlsRect)) |
| 131 return true; |
| 132 |
126 return false; | 133 return false; |
127 } | 134 } |
128 | 135 |
129 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay
outUnit step) const | 136 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay
outUnit step) const |
130 { | 137 { |
131 // 21. Horizontal: If step is negative and the top of the first line box in | 138 // 21. Horizontal: If step is negative and the top of the first line box in |
132 // boxes is now above the top of the title area, or if step is positive and | 139 // boxes is now above the top of the title area, or if step is positive and |
133 // the bottom of the first line box in boxes is now below the bottom of the | 140 // the bottom of the first line box in boxes is now below the bottom of the |
134 // title area, jump to the step labeled switch direction. | 141 // title area, jump to the step labeled switch direction. |
135 // Vertical: If step is negative and the left edge of the first line | 142 // Vertical: If step is negative and the left edge of the first line |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // longer necessary, since cues having the region parameter set do not have | 317 // longer necessary, since cues having the region parameter set do not have |
311 // any positioning parameters. Also, in this case, the regions themselves | 318 // any positioning parameters. Also, in this case, the regions themselves |
312 // have positioning information. | 319 // have positioning information. |
313 if (!m_cue->regionId().isEmpty()) | 320 if (!m_cue->regionId().isEmpty()) |
314 return; | 321 return; |
315 | 322 |
316 ASSERT(firstChild()); | 323 ASSERT(firstChild()); |
317 | 324 |
318 LayoutState state(*this, locationOffset()); | 325 LayoutState state(*this, locationOffset()); |
319 | 326 |
| 327 // Determine the area covered by the media controls, if any. If the controls |
| 328 // are present, they are the next sibling of the text track container, which |
| 329 // is our parent. (LayoutMedia ensures that the media controls are laid out |
| 330 // before text tracks, so that the layout is up-to-date here.) |
| 331 ASSERT(parent()->node()->isTextTrackContainer()); |
| 332 IntRect controlsRect; |
| 333 if (LayoutObject* parentSibling = parent()->nextSibling()) { |
| 334 // Only a part of the media controls is used for overlap avoidance. |
| 335 MediaControls* controls = toMediaControls(parentSibling->node()); |
| 336 if (LayoutObject* controlsLayout = controls->layoutObjectForTextTrackLay
out()) |
| 337 controlsRect = controlsLayout->absoluteBoundingBoxRect(); |
| 338 } |
| 339 |
320 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings - step 13. | 340 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings - step 13. |
321 if (m_cue->snapToLines()) { | 341 if (m_cue->snapToLines()) { |
322 SnapToLinesLayouter(*this, m_cue->calculateComputedLinePosition()).layou
t(); | 342 SnapToLinesLayouter(*this, controlsRect, m_cue->calculateComputedLinePos
ition()).layout(); |
323 | 343 |
324 adjustForTopAndBottomMarginBorderAndPadding(); | 344 adjustForTopAndBottomMarginBorderAndPadding(); |
325 } else { | 345 } else { |
326 repositionCueSnapToLinesNotSet(); | 346 repositionCueSnapToLinesNotSet(); |
327 } | 347 } |
328 } | 348 } |
329 | 349 |
330 } // namespace blink | 350 } // namespace blink |
331 | |
OLD | NEW |