OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
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 * | 7 * |
8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
10 * disclaimer. | 10 * disclaimer. |
(...skipping 16 matching lines...) Expand all Loading... |
27 * OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #include "core/layout/line/LineWidth.h" | 30 #include "core/layout/line/LineWidth.h" |
31 | 31 |
32 #include "core/layout/api/LineLayoutRubyRun.h" | 32 #include "core/layout/api/LineLayoutRubyRun.h" |
33 #include "core/layout/shapes/ShapeOutsideInfo.h" | 33 #include "core/layout/shapes/ShapeOutsideInfo.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 LineWidth::LineWidth(LineLayoutBlockFlow block, bool isFirstLine, IndentTextOrNo
t shouldIndentText) | 37 LineWidth::LineWidth(LineLayoutBlockFlow block, bool isFirstLine, IndentTextOrNo
t indentText) |
38 : m_block(block) | 38 : m_block(block) |
39 , m_uncommittedWidth(0) | 39 , m_uncommittedWidth(0) |
40 , m_committedWidth(0) | 40 , m_committedWidth(0) |
41 , m_overhangWidth(0) | 41 , m_overhangWidth(0) |
42 , m_trailingWhitespaceWidth(0) | 42 , m_trailingWhitespaceWidth(0) |
43 , m_left(0) | 43 , m_left(0) |
44 , m_right(0) | 44 , m_right(0) |
45 , m_availableWidth(0) | 45 , m_availableWidth(0) |
46 , m_isFirstLine(isFirstLine) | 46 , m_isFirstLine(isFirstLine) |
47 , m_shouldIndentText(shouldIndentText) | 47 , m_indentText(indentText) |
48 { | 48 { |
49 updateAvailableWidth(); | 49 updateAvailableWidth(); |
50 } | 50 } |
51 | 51 |
52 void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight) | 52 void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight) |
53 { | 53 { |
54 LayoutUnit height = m_block.logicalHeight(); | 54 LayoutUnit height = m_block.logicalHeight(); |
55 LayoutUnit logicalHeight = m_block.minLineHeightForReplacedObject(m_isFirstL
ine, replacedHeight); | 55 LayoutUnit logicalHeight = m_block.minLineHeightForReplacedObject(m_isFirstL
ine, replacedHeight); |
56 m_left = m_block.logicalLeftOffsetForLine(height, shouldIndentText(), logica
lHeight).toFloat(); | 56 m_left = m_block.logicalLeftOffsetForLine(height, indentText(), logicalHeigh
t).toFloat(); |
57 m_right = m_block.logicalRightOffsetForLine(height, shouldIndentText(), logi
calHeight).toFloat(); | 57 m_right = m_block.logicalRightOffsetForLine(height, indentText(), logicalHei
ght).toFloat(); |
58 | 58 |
59 computeAvailableWidthFromLeftAndRight(); | 59 computeAvailableWidthFromLeftAndRight(); |
60 } | 60 } |
61 | 61 |
62 void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(const FloatingObject& ne
wFloat) | 62 void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(const FloatingObject& ne
wFloat) |
63 { | 63 { |
64 LayoutUnit height = m_block.logicalHeight(); | 64 LayoutUnit height = m_block.logicalHeight(); |
65 if (height < m_block.logicalTopForFloat(newFloat) || height >= m_block.logic
alBottomForFloat(newFloat)) | 65 if (height < m_block.logicalTopForFloat(newFloat) || height >= m_block.logic
alBottomForFloat(newFloat)) |
66 return; | 66 return; |
67 | 67 |
68 ShapeOutsideDeltas shapeDeltas; | 68 ShapeOutsideDeltas shapeDeltas; |
69 if (ShapeOutsideInfo* shapeOutsideInfo = newFloat.layoutObject()->shapeOutsi
deInfo()) { | 69 if (ShapeOutsideInfo* shapeOutsideInfo = newFloat.layoutObject()->shapeOutsi
deInfo()) { |
70 LayoutUnit lineHeight = m_block.lineHeight(m_isFirstLine, m_block.isHori
zontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes
); | 70 LayoutUnit lineHeight = m_block.lineHeight(m_isFirstLine, m_block.isHori
zontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes
); |
71 shapeDeltas = shapeOutsideInfo->computeDeltasForContainingBlockLine(m_bl
ock, newFloat, m_block.logicalHeight(), lineHeight); | 71 shapeDeltas = shapeOutsideInfo->computeDeltasForContainingBlockLine(m_bl
ock, newFloat, m_block.logicalHeight(), lineHeight); |
72 } | 72 } |
73 | 73 |
74 if (newFloat.type() == FloatingObject::FloatLeft) { | 74 if (newFloat.type() == FloatingObject::FloatLeft) { |
75 float newLeft = m_block.logicalRightForFloat(newFloat).toFloat(); | 75 float newLeft = m_block.logicalRightForFloat(newFloat).toFloat(); |
76 if (shapeDeltas.isValid()) { | 76 if (shapeDeltas.isValid()) { |
77 if (shapeDeltas.lineOverlapsShape()) | 77 if (shapeDeltas.lineOverlapsShape()) |
78 newLeft += shapeDeltas.rightMarginBoxDelta(); | 78 newLeft += shapeDeltas.rightMarginBoxDelta(); |
79 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. | 79 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. |
80 newLeft = m_left; | 80 newLeft = m_left; |
81 } | 81 } |
82 if (shouldIndentText() && m_block.style()->isLeftToRightDirection()) | 82 if (indentText() == IndentText && m_block.style()->isLeftToRightDirectio
n()) |
83 newLeft += floorToInt(m_block.textIndentOffset()); | 83 newLeft += floorToInt(m_block.textIndentOffset()); |
84 m_left = std::max<float>(m_left, newLeft); | 84 m_left = std::max<float>(m_left, newLeft); |
85 } else { | 85 } else { |
86 float newRight = m_block.logicalLeftForFloat(newFloat).toFloat(); | 86 float newRight = m_block.logicalLeftForFloat(newFloat).toFloat(); |
87 if (shapeDeltas.isValid()) { | 87 if (shapeDeltas.isValid()) { |
88 if (shapeDeltas.lineOverlapsShape()) | 88 if (shapeDeltas.lineOverlapsShape()) |
89 newRight += shapeDeltas.leftMarginBoxDelta(); | 89 newRight += shapeDeltas.leftMarginBoxDelta(); |
90 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. | 90 else // Per the CSS Shapes spec, If the line doesn't overlap the sha
pe, then ignore this shape for this line. |
91 newRight = m_right; | 91 newRight = m_right; |
92 } | 92 } |
93 if (shouldIndentText() && !m_block.style()->isLeftToRightDirection()) | 93 if (indentText() == IndentText && !m_block.style()->isLeftToRightDirecti
on()) |
94 newRight -= floorToInt(m_block.textIndentOffset()); | 94 newRight -= floorToInt(m_block.textIndentOffset()); |
95 m_right = std::min<float>(m_right, newRight); | 95 m_right = std::min<float>(m_right, newRight); |
96 } | 96 } |
97 | 97 |
98 computeAvailableWidthFromLeftAndRight(); | 98 computeAvailableWidthFromLeftAndRight(); |
99 } | 99 } |
100 | 100 |
101 void LineWidth::commit() | 101 void LineWidth::commit() |
102 { | 102 { |
103 m_committedWidth += m_uncommittedWidth; | 103 m_committedWidth += m_uncommittedWidth; |
104 m_uncommittedWidth = 0; | 104 m_uncommittedWidth = 0; |
105 } | 105 } |
106 | 106 |
107 void LineWidth::applyOverhang(LineLayoutRubyRun rubyRun, LineLayoutItem startLay
outItem, LineLayoutItem endLayoutItem) | 107 void LineWidth::applyOverhang(LineLayoutRubyRun rubyRun, LineLayoutItem startLay
outItem, LineLayoutItem endLayoutItem) |
108 { | 108 { |
109 int startOverhang; | 109 int startOverhang; |
110 int endOverhang; | 110 int endOverhang; |
111 rubyRun.getOverhang(m_isFirstLine, startLayoutItem, endLayoutItem, startOver
hang, endOverhang); | 111 rubyRun.getOverhang(m_isFirstLine, startLayoutItem, endLayoutItem, startOver
hang, endOverhang); |
112 | 112 |
113 startOverhang = std::min<int>(startOverhang, m_committedWidth); | 113 startOverhang = std::min<int>(startOverhang, m_committedWidth); |
114 m_availableWidth += startOverhang; | 114 m_availableWidth += startOverhang; |
115 | 115 |
116 endOverhang = std::max(std::min<int>(endOverhang, m_availableWidth - current
Width()), 0); | 116 endOverhang = std::max(std::min<int>(endOverhang, m_availableWidth - current
Width()), 0); |
117 m_availableWidth += endOverhang; | 117 m_availableWidth += endOverhang; |
118 m_overhangWidth += startOverhang + endOverhang; | 118 m_overhangWidth += startOverhang + endOverhang; |
119 } | 119 } |
120 | 120 |
121 inline static float availableWidthAtOffset(LineLayoutBlockFlow block, const Layo
utUnit& offset, bool shouldIndentText, float& newLineLeft, | 121 inline static float availableWidthAtOffset(LineLayoutBlockFlow block, const Layo
utUnit& offset, IndentTextOrNot indentText, float& newLineLeft, |
122 float& newLineRight, const LayoutUnit& lineHeight = 0) | 122 float& newLineRight, const LayoutUnit& lineHeight = 0) |
123 { | 123 { |
124 newLineLeft = block.logicalLeftOffsetForLine(offset, shouldIndentText, lineH
eight).toFloat(); | 124 newLineLeft = block.logicalLeftOffsetForLine(offset, indentText, lineHeight)
.toFloat(); |
125 newLineRight = block.logicalRightOffsetForLine(offset, shouldIndentText, lin
eHeight).toFloat(); | 125 newLineRight = block.logicalRightOffsetForLine(offset, indentText, lineHeigh
t).toFloat(); |
126 return std::max(0.0f, newLineRight - newLineLeft); | 126 return std::max(0.0f, newLineRight - newLineLeft); |
127 } | 127 } |
128 | 128 |
129 void LineWidth::updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWid
th, const float& newLineLeft, const float& newLineRight) | 129 void LineWidth::updateLineDimension(LayoutUnit newLineTop, LayoutUnit newLineWid
th, const float& newLineLeft, const float& newLineRight) |
130 { | 130 { |
131 if (newLineWidth <= m_availableWidth) | 131 if (newLineWidth <= m_availableWidth) |
132 return; | 132 return; |
133 | 133 |
134 m_block.setLogicalHeight(newLineTop); | 134 m_block.setLogicalHeight(newLineTop); |
135 m_availableWidth = newLineWidth + m_overhangWidth; | 135 m_availableWidth = newLineWidth + m_overhangWidth; |
136 m_left = newLineLeft; | 136 m_left = newLineLeft; |
137 m_right = newLineRight; | 137 m_right = newLineRight; |
138 } | 138 } |
139 | 139 |
140 void LineWidth::wrapNextToShapeOutside(bool isFirstLine) | 140 void LineWidth::wrapNextToShapeOutside(bool isFirstLine) |
141 { | 141 { |
142 LayoutUnit lineHeight = m_block.lineHeight(isFirstLine, m_block.isHorizontal
WritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); | 142 LayoutUnit lineHeight = m_block.lineHeight(isFirstLine, m_block.isHorizontal
WritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes); |
143 LayoutUnit lineLogicalTop = m_block.logicalHeight(); | 143 LayoutUnit lineLogicalTop = m_block.logicalHeight(); |
144 LayoutUnit newLineTop = lineLogicalTop; | 144 LayoutUnit newLineTop = lineLogicalTop; |
145 LayoutUnit floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lineLogi
calTop); | 145 LayoutUnit floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lineLogi
calTop); |
146 | 146 |
147 float newLineWidth; | 147 float newLineWidth; |
148 float newLineLeft = m_left; | 148 float newLineLeft = m_left; |
149 float newLineRight = m_right; | 149 float newLineRight = m_right; |
150 while (true) { | 150 while (true) { |
151 newLineWidth = availableWidthAtOffset(m_block, newLineTop, shouldIndentT
ext(), newLineLeft, newLineRight, lineHeight); | 151 newLineWidth = availableWidthAtOffset(m_block, newLineTop, indentText(),
newLineLeft, newLineRight, lineHeight); |
152 if (newLineWidth >= m_uncommittedWidth) | 152 if (newLineWidth >= m_uncommittedWidth) |
153 break; | 153 break; |
154 | 154 |
155 if (newLineTop >= floatLogicalBottom) | 155 if (newLineTop >= floatLogicalBottom) |
156 break; | 156 break; |
157 | 157 |
158 newLineTop++; | 158 newLineTop++; |
159 } | 159 } |
160 updateLineDimension(newLineTop, newLineWidth, newLineLeft, newLineRight); | 160 updateLineDimension(newLineTop, newLineWidth, newLineLeft, newLineRight); |
161 } | 161 } |
(...skipping 12 matching lines...) Expand all Loading... |
174 | 174 |
175 FloatingObject* lastFloatFromPreviousLine = m_block.lastFloatFromPreviousLin
e(); | 175 FloatingObject* lastFloatFromPreviousLine = m_block.lastFloatFromPreviousLin
e(); |
176 if (lastFloatFromPreviousLine && lastFloatFromPreviousLine->layoutObject
()->shapeOutsideInfo()) | 176 if (lastFloatFromPreviousLine && lastFloatFromPreviousLine->layoutObject
()->shapeOutsideInfo()) |
177 return wrapNextToShapeOutside(isFirstLine); | 177 return wrapNextToShapeOutside(isFirstLine); |
178 | 178 |
179 while (true) { | 179 while (true) { |
180 floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lastFloatLogica
lBottom, ShapeOutsideFloatShapeOffset); | 180 floatLogicalBottom = m_block.nextFloatLogicalBottomBelow(lastFloatLogica
lBottom, ShapeOutsideFloatShapeOffset); |
181 if (floatLogicalBottom <= lastFloatLogicalBottom) | 181 if (floatLogicalBottom <= lastFloatLogicalBottom) |
182 break; | 182 break; |
183 | 183 |
184 newLineWidth = availableWidthAtOffset(m_block, floatLogicalBottom, shoul
dIndentText(), newLineLeft, newLineRight); | 184 newLineWidth = availableWidthAtOffset(m_block, floatLogicalBottom, inden
tText(), newLineLeft, newLineRight); |
185 lastFloatLogicalBottom = floatLogicalBottom; | 185 lastFloatLogicalBottom = floatLogicalBottom; |
186 | 186 |
187 if (newLineWidth >= m_uncommittedWidth) | 187 if (newLineWidth >= m_uncommittedWidth) |
188 break; | 188 break; |
189 } | 189 } |
190 updateLineDimension(lastFloatLogicalBottom, newLineWidth, newLineLeft, newLi
neRight); | 190 updateLineDimension(lastFloatLogicalBottom, newLineWidth, newLineLeft, newLi
neRight); |
191 } | 191 } |
192 | 192 |
193 void LineWidth::computeAvailableWidthFromLeftAndRight() | 193 void LineWidth::computeAvailableWidthFromLeftAndRight() |
194 { | 194 { |
195 m_availableWidth = max(0.0f, m_right - m_left) + m_overhangWidth; | 195 m_availableWidth = max(0.0f, m_right - m_left) + m_overhangWidth; |
196 } | 196 } |
197 | 197 |
198 } | 198 } |
OLD | NEW |