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

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

Issue 1240433007: Separate VTTCue from VTTCueBox and LayoutVTTCue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: empty constructor, explicit keyword Created 5 years, 5 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/layout/LayoutVTTCue.h ('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
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/shadow/MediaControls.h"
30 #include "core/html/track/vtt/VTTCue.h"
31 #include "core/layout/LayoutInline.h" 30 #include "core/layout/LayoutInline.h"
32 #include "core/layout/LayoutState.h" 31 #include "core/layout/LayoutState.h"
33 32
34 namespace blink { 33 namespace blink {
35 34
36 LayoutVTTCue::LayoutVTTCue(VTTCueBox* element) 35 LayoutVTTCue::LayoutVTTCue(ContainerNode* node, float snapToLinesPosition)
37 : LayoutBlockFlow(element) 36 : LayoutBlockFlow(node)
38 , m_cue(element->getCue()) 37 , m_snapToLinesPosition(snapToLinesPosition)
39 { 38 {
40 } 39 }
41 40
42 class SnapToLinesLayouter { 41 class SnapToLinesLayouter {
43 STACK_ALLOCATED(); 42 STACK_ALLOCATED();
44 public: 43 public:
45 SnapToLinesLayouter(LayoutVTTCue& cueBox, const IntRect& controlsRect, float linePosition) 44 SnapToLinesLayouter(LayoutVTTCue& cueBox, const IntRect& controlsRect)
46 : m_cueBox(cueBox) 45 : m_cueBox(cueBox)
47 , m_controlsRect(controlsRect) 46 , m_controlsRect(controlsRect)
48 , m_linePosition(linePosition)
49 { 47 {
50 } 48 }
51 49
52 void layout(); 50 void layout();
53 51
54 private: 52 private:
55 bool isOutside() const; 53 bool isOutside() const;
56 bool isOverlapping() const; 54 bool isOverlapping() const;
57 LayoutUnit computeInitialPositionAdjustment(LayoutUnit&) const; 55 LayoutUnit computeInitialPositionAdjustment(LayoutUnit&) const;
58 bool shouldSwitchDirection(InlineFlowBox*, LayoutUnit) const; 56 bool shouldSwitchDirection(InlineFlowBox*, LayoutUnit) const;
59 57
60 void moveBoxesBy(LayoutUnit distance) 58 void moveBoxesBy(LayoutUnit distance)
61 { 59 {
62 m_cueBox.setLogicalTop(m_cueBox.logicalTop() + distance); 60 m_cueBox.setLogicalTop(m_cueBox.logicalTop() + distance);
63 } 61 }
64 62
65 InlineFlowBox* findFirstLineBox() const; 63 InlineFlowBox* findFirstLineBox() const;
66 64
67 LayoutPoint m_specifiedPosition; 65 LayoutPoint m_specifiedPosition;
68 LayoutVTTCue& m_cueBox; 66 LayoutVTTCue& m_cueBox;
69 IntRect m_controlsRect; 67 IntRect m_controlsRect;
70 float m_linePosition;
71 }; 68 };
72 69
73 InlineFlowBox* SnapToLinesLayouter::findFirstLineBox() const 70 InlineFlowBox* SnapToLinesLayouter::findFirstLineBox() const
74 { 71 {
75 if (!m_cueBox.firstChild()->isLayoutInline()) 72 if (!m_cueBox.firstChild()->isLayoutInline())
76 return nullptr; 73 return nullptr;
77 return toLayoutInline(m_cueBox.firstChild())->firstLineBox(); 74 return toLayoutInline(m_cueBox.firstChild())->firstLineBox();
78 } 75 }
79 76
80 LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste p) const 77 LayoutUnit SnapToLinesLayouter::computeInitialPositionAdjustment(LayoutUnit& ste p) const
81 { 78 {
79 ASSERT(std::isfinite(m_cueBox.snapToLinesPosition()));
80
82 // 6. Let line position be the text track cue computed line position. 81 // 6. Let line position be the text track cue computed line position.
83 // 7. Round line position to an integer by adding 0.5 and then flooring it. 82 // 7. Round line position to an integer by adding 0.5 and then flooring it.
84 LayoutUnit linePosition = floorf(m_linePosition + 0.5f); 83 LayoutUnit linePosition = floorf(m_cueBox.snapToLinesPosition() + 0.5f);
85 84
86 WritingMode writingMode = m_cueBox.style()->writingMode(); 85 WritingMode writingMode = m_cueBox.style()->writingMode();
87 // 8. Vertical Growing Left: Add one to line position then negate it. 86 // 8. Vertical Growing Left: Add one to line position then negate it.
88 if (writingMode == RightToLeftWritingMode) 87 if (writingMode == RightToLeftWritingMode)
89 linePosition = -(linePosition + 1); 88 linePosition = -(linePosition + 1);
90 89
91 // 9. Let position be the result of multiplying step and line position. 90 // 9. Let position be the result of multiplying step and line position.
92 LayoutUnit position = step * linePosition; 91 LayoutUnit position = step * linePosition;
93 92
94 // 10. Vertical Growing Left: Decrease position by the width of the 93 // 10. Vertical Growing Left: Decrease position by the width of the
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if (!adjustment) 305 if (!adjustment)
307 return; 306 return;
308 307
309 setY(location().y() + adjustment); 308 setY(location().y() + adjustment);
310 } 309 }
311 310
312 void LayoutVTTCue::layout() 311 void LayoutVTTCue::layout()
313 { 312 {
314 LayoutBlockFlow::layout(); 313 LayoutBlockFlow::layout();
315 314
316 // If WebVTT Regions are used, the regular WebVTT layout algorithm is no
317 // longer necessary, since cues having the region parameter set do not have
318 // any positioning parameters. Also, in this case, the regions themselves
319 // have positioning information.
320 if (!m_cue->regionId().isEmpty())
321 return;
322
323 ASSERT(firstChild()); 315 ASSERT(firstChild());
324 316
325 LayoutState state(*this, locationOffset()); 317 LayoutState state(*this, locationOffset());
326 318
327 // Determine the area covered by the media controls, if any. If the controls 319 // 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 320 // 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 321 // 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.) 322 // before text tracks, so that the layout is up-to-date here.)
331 ASSERT(parent()->node()->isTextTrackContainer()); 323 ASSERT(parent()->node()->isTextTrackContainer());
332 IntRect controlsRect; 324 IntRect controlsRect;
333 if (LayoutObject* parentSibling = parent()->nextSibling()) { 325 if (LayoutObject* parentSibling = parent()->nextSibling()) {
334 // Only a part of the media controls is used for overlap avoidance. 326 // Only a part of the media controls is used for overlap avoidance.
335 MediaControls* controls = toMediaControls(parentSibling->node()); 327 MediaControls* controls = toMediaControls(parentSibling->node());
336 if (LayoutObject* controlsLayout = controls->layoutObjectForTextTrackLay out()) 328 if (LayoutObject* controlsLayout = controls->layoutObjectForTextTrackLay out())
337 controlsRect = controlsLayout->absoluteBoundingBoxRect(); 329 controlsRect = controlsLayout->absoluteBoundingBoxRect();
338 } 330 }
339 331
340 // 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.
341 if (m_cue->snapToLines()) { 333 if (!std::isnan(m_snapToLinesPosition)) {
342 SnapToLinesLayouter(*this, controlsRect, m_cue->calculateComputedLinePos ition()).layout(); 334 SnapToLinesLayouter(*this, controlsRect).layout();
343 335
344 adjustForTopAndBottomMarginBorderAndPadding(); 336 adjustForTopAndBottomMarginBorderAndPadding();
345 } else { 337 } else {
346 repositionCueSnapToLinesNotSet(); 338 repositionCueSnapToLinesNotSet();
347 } 339 }
348 } 340 }
349 341
350 } // namespace blink 342 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutVTTCue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698