| 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 11 matching lines...) Expand all Loading... |
| 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/track/vtt/VTTCue.h" | 29 #include "core/html/track/vtt/VTTCue.h" |
| 30 #include "core/layout/LayoutInline.h" | 30 #include "core/layout/LayoutInline.h" |
| 31 #include "core/layout/LayoutState.h" | 31 #include "core/layout/LayoutState.h" |
| 32 #include "core/layout/LayoutTextTrackContainer.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, IntRect& controlsRect, float lineP
osition) |
| 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 ASSERT(!m_cueBox.nextSibling()); |
| 131 |
| 132 if (cueBoxRect.intersects(m_controlsRect)) |
| 133 return true; |
| 134 |
| 126 return false; | 135 return false; |
| 127 } | 136 } |
| 128 | 137 |
| 129 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay
outUnit step) const | 138 bool SnapToLinesLayouter::shouldSwitchDirection(InlineFlowBox* firstLineBox, Lay
outUnit step) const |
| 130 { | 139 { |
| 131 // 21. Horizontal: If step is negative and the top of the first line box in | 140 // 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 | 141 // 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 | 142 // 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. | 143 // title area, jump to the step labeled switch direction. |
| 135 // Vertical: If step is negative and the left edge of the first line | 144 // 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 | 319 // longer necessary, since cues having the region parameter set do not have |
| 311 // any positioning parameters. Also, in this case, the regions themselves | 320 // any positioning parameters. Also, in this case, the regions themselves |
| 312 // have positioning information. | 321 // have positioning information. |
| 313 if (!m_cue->regionId().isEmpty()) | 322 if (!m_cue->regionId().isEmpty()) |
| 314 return; | 323 return; |
| 315 | 324 |
| 316 ASSERT(firstChild()); | 325 ASSERT(firstChild()); |
| 317 | 326 |
| 318 LayoutState state(*this, locationOffset()); | 327 LayoutState state(*this, locationOffset()); |
| 319 | 328 |
| 329 ASSERT(parent()->node()->isTextTrackContainer()); |
| 330 IntRect controlsRect = static_cast<LayoutTextTrackContainer*>(parent())->con
trolsRect(); |
| 331 |
| 320 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings - step 13. | 332 // http://dev.w3.org/html5/webvtt/#dfn-apply-webvtt-cue-settings - step 13. |
| 321 if (m_cue->snapToLines()) { | 333 if (m_cue->snapToLines()) { |
| 322 SnapToLinesLayouter(*this, m_cue->calculateComputedLinePosition()).layou
t(); | 334 SnapToLinesLayouter(*this, controlsRect, m_cue->calculateComputedLinePos
ition()).layout(); |
| 323 | 335 |
| 324 adjustForTopAndBottomMarginBorderAndPadding(); | 336 adjustForTopAndBottomMarginBorderAndPadding(); |
| 325 } else { | 337 } else { |
| 326 repositionCueSnapToLinesNotSet(); | 338 repositionCueSnapToLinesNotSet(); |
| 327 } | 339 } |
| 328 } | 340 } |
| 329 | 341 |
| 330 } // namespace blink | 342 } // namespace blink |
| 331 | 343 |
| OLD | NEW |