OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ight reserved. | 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ight reserved. |
4 * Copyright (C) 2010 Google Inc. All rights reserved. | 4 * Copyright (C) 2010 Google Inc. All rights reserved. |
5 * Copyright (C) 2013 Adobe Systems Incorporated. | 5 * Copyright (C) 2013 Adobe Systems Incorporated. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 #ifndef BreakingContextInlineHeaders_h | 24 #ifndef BreakingContextInlineHeaders_h |
25 #define BreakingContextInlineHeaders_h | 25 #define BreakingContextInlineHeaders_h |
26 | 26 |
27 #include "core/layout/LayoutInline.h" | 27 #include "core/layout/LayoutInline.h" |
28 #include "core/layout/LayoutListMarker.h" | 28 #include "core/layout/LayoutListMarker.h" |
29 #include "core/layout/LayoutObject.h" | 29 #include "core/layout/LayoutObject.h" |
30 #include "core/layout/LayoutRubyRun.h" | 30 #include "core/layout/LayoutRubyRun.h" |
31 #include "core/layout/LayoutTextCombine.h" | 31 #include "core/layout/LayoutTextCombine.h" |
32 #include "core/layout/TextRunConstructor.h" | 32 #include "core/layout/TextRunConstructor.h" |
| 33 #include "core/layout/api/LineLayoutBox.h" |
33 #include "core/layout/line/InlineIterator.h" | 34 #include "core/layout/line/InlineIterator.h" |
34 #include "core/layout/line/InlineTextBox.h" | 35 #include "core/layout/line/InlineTextBox.h" |
35 #include "core/layout/line/LayoutTextInfo.h" | 36 #include "core/layout/line/LayoutTextInfo.h" |
36 #include "core/layout/line/LineBreaker.h" | 37 #include "core/layout/line/LineBreaker.h" |
37 #include "core/layout/line/LineInfo.h" | 38 #include "core/layout/line/LineInfo.h" |
38 #include "core/layout/line/LineWidth.h" | 39 #include "core/layout/line/LineWidth.h" |
39 #include "core/layout/line/TrailingObjects.h" | 40 #include "core/layout/line/TrailingObjects.h" |
40 #include "core/layout/line/WordMeasurement.h" | 41 #include "core/layout/line/WordMeasurement.h" |
41 #include "core/layout/svg/LayoutSVGInlineText.h" | 42 #include "core/layout/svg/LayoutSVGInlineText.h" |
42 #include "core/paint/DeprecatedPaintLayer.h" | 43 #include "core/paint/DeprecatedPaintLayer.h" |
43 #include "platform/text/TextBreakIterator.h" | 44 #include "platform/text/TextBreakIterator.h" |
| 45 #include "wtf/Vector.h" |
44 | 46 |
45 namespace blink { | 47 namespace blink { |
46 | 48 |
47 // We don't let our line box tree for a single line get any deeper than this. | 49 // We don't let our line box tree for a single line get any deeper than this. |
48 const unsigned cMaxLineDepth = 200; | 50 const unsigned cMaxLineDepth = 200; |
49 | 51 |
50 class BreakingContext { | 52 class BreakingContext { |
51 public: | 53 public: |
52 BreakingContext(InlineBidiResolver& resolver, LineInfo& inLineInfo, LineWidt
h& lineWidth, LayoutTextInfo& inLayoutTextInfo, FloatingObject* inLastFloatFromP
reviousLine, bool appliedStartWidth, LayoutBlockFlow* block) | 54 BreakingContext(InlineBidiResolver& resolver, LineInfo& inLineInfo, LineWidt
h& lineWidth, LayoutTextInfo& inLayoutTextInfo, FloatingObject* inLastFloatFromP
reviousLine, bool appliedStartWidth, LineLayoutBlockFlow block) |
53 : m_resolver(resolver) | 55 : m_resolver(resolver) |
54 , m_current(resolver.position()) | 56 , m_current(resolver.position()) |
55 , m_lineBreak(resolver.position()) | 57 , m_lineBreak(resolver.position()) |
56 , m_block(block) | 58 , m_block(block) |
57 , m_lastObject(m_current.object()) | 59 , m_lastObject(m_current.object()) |
58 , m_nextObject(nullptr) | 60 , m_nextObject(nullptr) |
59 , m_currentStyle(nullptr) | 61 , m_currentStyle(nullptr) |
60 , m_blockStyle(block->style()) | 62 , m_blockStyle(block->style()) |
61 , m_lineInfo(inLineInfo) | 63 , m_lineInfo(inLineInfo) |
62 , m_layoutTextInfo(inLayoutTextInfo) | 64 , m_layoutTextInfo(inLayoutTextInfo) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 110 |
109 private: | 111 private: |
110 void skipTrailingWhitespace(InlineIterator&, const LineInfo&); | 112 void skipTrailingWhitespace(InlineIterator&, const LineInfo&); |
111 | 113 |
112 InlineBidiResolver& m_resolver; | 114 InlineBidiResolver& m_resolver; |
113 | 115 |
114 InlineIterator m_current; | 116 InlineIterator m_current; |
115 InlineIterator m_lineBreak; | 117 InlineIterator m_lineBreak; |
116 InlineIterator m_startOfIgnoredSpaces; | 118 InlineIterator m_startOfIgnoredSpaces; |
117 | 119 |
118 LayoutBlockFlow* m_block; | 120 LineLayoutBlockFlow m_block; |
119 LayoutObject* m_lastObject; | 121 LayoutObject* m_lastObject; |
120 LayoutObject* m_nextObject; | 122 LayoutObject* m_nextObject; |
121 | 123 |
122 const ComputedStyle* m_currentStyle; | 124 const ComputedStyle* m_currentStyle; |
123 const ComputedStyle* m_blockStyle; | 125 const ComputedStyle* m_blockStyle; |
124 | 126 |
125 LineInfo& m_lineInfo; | 127 LineInfo& m_lineInfo; |
126 | 128 |
127 LayoutTextInfo& m_layoutTextInfo; | 129 LayoutTextInfo& m_layoutTextInfo; |
128 | 130 |
(...skipping 17 matching lines...) Expand all Loading... |
146 bool m_collapseWhiteSpace; | 148 bool m_collapseWhiteSpace; |
147 bool m_startingNewParagraph; | 149 bool m_startingNewParagraph; |
148 bool m_allowImagesToBreak; | 150 bool m_allowImagesToBreak; |
149 bool m_atEnd; | 151 bool m_atEnd; |
150 | 152 |
151 LineMidpointState& m_lineMidpointState; | 153 LineMidpointState& m_lineMidpointState; |
152 | 154 |
153 TrailingObjects m_trailingObjects; | 155 TrailingObjects m_trailingObjects; |
154 }; | 156 }; |
155 | 157 |
| 158 // When ignoring spaces, this needs to be called for objects that need line boxe
s such as LayoutInlines or |
| 159 // hard line breaks to ensure that they're not ignored. |
| 160 inline void ensureLineBoxInsideIgnoredSpaces(LineMidpointState* midpointState, L
ayoutObject* renderer) |
| 161 { |
| 162 InlineIterator midpoint(0, LineLayoutItem(renderer), 0); |
| 163 midpointState->stopIgnoringSpaces(midpoint); |
| 164 midpointState->startIgnoringSpaces(midpoint); |
| 165 } |
| 166 |
156 inline bool shouldCollapseWhiteSpace(const ComputedStyle& style, const LineInfo&
lineInfo, WhitespacePosition whitespacePosition) | 167 inline bool shouldCollapseWhiteSpace(const ComputedStyle& style, const LineInfo&
lineInfo, WhitespacePosition whitespacePosition) |
157 { | 168 { |
158 // CSS2 16.6.1 | 169 // CSS2 16.6.1 |
159 // If a space (U+0020) at the beginning of a line has 'white-space' set to '
normal', 'nowrap', or 'pre-line', it is removed. | 170 // If a space (U+0020) at the beginning of a line has 'white-space' set to '
normal', 'nowrap', or 'pre-line', it is removed. |
160 // If a space (U+0020) at the end of a line has 'white-space' set to 'normal
', 'nowrap', or 'pre-line', it is also removed. | 171 // If a space (U+0020) at the end of a line has 'white-space' set to 'normal
', 'nowrap', or 'pre-line', it is also removed. |
161 // If spaces (U+0020) or tabs (U+0009) at the end of a line have 'white-spac
e' set to 'pre-wrap', UAs may visually collapse them. | 172 // If spaces (U+0020) or tabs (U+0009) at the end of a line have 'white-spac
e' set to 'pre-wrap', UAs may visually collapse them. |
162 return style.collapseWhiteSpace() | 173 return style.collapseWhiteSpace() |
163 || (whitespacePosition == TrailingWhitespace && style.whiteSpace() == PR
E_WRAP && (!lineInfo.isEmpty() || !lineInfo.previousLineBrokeCleanly())); | 174 || (whitespacePosition == TrailingWhitespace && style.whiteSpace() == PR
E_WRAP && (!lineInfo.isEmpty() || !lineInfo.previousLineBrokeCleanly())); |
164 } | 175 } |
165 | 176 |
166 inline bool requiresLineBoxForContent(LayoutInline* flow, const LineInfo& lineIn
fo) | 177 inline bool requiresLineBoxForContent(LayoutInline* flow, const LineInfo& lineIn
fo) |
167 { | 178 { |
168 LayoutObject* parent = flow->parent(); | 179 LayoutObject* parent = flow->parent(); |
169 if (flow->document().inNoQuirksMode() | 180 if (flow->document().inNoQuirksMode() |
170 && (flow->style(lineInfo.isFirstLine())->lineHeight() != parent->style(l
ineInfo.isFirstLine())->lineHeight() | 181 && (flow->style(lineInfo.isFirstLine())->lineHeight() != parent->style(l
ineInfo.isFirstLine())->lineHeight() |
171 || flow->style()->verticalAlign() != parent->style()->verticalAlign() | 182 || flow->style()->verticalAlign() != parent->style()->verticalAlign() |
172 || !parent->style()->font().fontMetrics().hasIdenticalAscentDescentAndLi
neGap(flow->style()->font().fontMetrics()))) | 183 || !parent->style()->font().fontMetrics().hasIdenticalAscentDescentAndLi
neGap(flow->style()->font().fontMetrics()))) |
173 return true; | 184 return true; |
174 return false; | 185 return false; |
175 } | 186 } |
176 | 187 |
177 inline bool alwaysRequiresLineBox(LayoutObject* flow) | 188 inline bool alwaysRequiresLineBox(LayoutObject* flow) |
178 { | 189 { |
179 // FIXME: Right now, we only allow line boxes for inlines that are truly emp
ty. | 190 // FIXME: Right now, we only allow line boxes for inlines that are truly emp
ty. |
180 // We need to fix this, though, because at the very least, inlines containin
g only | 191 // We need to fix this, though, because at the very least, inlines containin
g only |
181 // ignorable whitespace should should also have line boxes. | 192 // ignorable whitespace should should also have line boxes. |
182 return isEmptyInline(flow) && toLayoutInline(flow)->hasInlineDirectionBorder
sPaddingOrMargin(); | 193 return isEmptyInline(LineLayoutItem(flow)) && toLayoutInline(flow)->hasInlin
eDirectionBordersPaddingOrMargin(); |
183 } | 194 } |
184 | 195 |
185 inline bool requiresLineBox(const InlineIterator& it, const LineInfo& lineInfo =
LineInfo(), WhitespacePosition whitespacePosition = LeadingWhitespace) | 196 inline bool requiresLineBox(const InlineIterator& it, const LineInfo& lineInfo =
LineInfo(), WhitespacePosition whitespacePosition = LeadingWhitespace) |
186 { | 197 { |
187 if (it.object()->isFloatingOrOutOfFlowPositioned()) | 198 if (it.object()->isFloatingOrOutOfFlowPositioned()) |
188 return false; | 199 return false; |
189 | 200 |
190 if (it.object()->isLayoutInline() && !alwaysRequiresLineBox(it.object()) &&
!requiresLineBoxForContent(toLayoutInline(it.object()), lineInfo)) | 201 if (it.object()->isLayoutInline() && !alwaysRequiresLineBox(it.object()) &&
!requiresLineBoxForContent(toLayoutInline(it.object()), lineInfo)) |
191 return false; | 202 return false; |
192 | 203 |
193 if (!shouldCollapseWhiteSpace(it.object()->styleRef(), lineInfo, whitespaceP
osition) || it.object()->isBR()) | 204 if (!shouldCollapseWhiteSpace(it.object()->styleRef(), lineInfo, whitespaceP
osition) || it.object()->isBR()) |
194 return true; | 205 return true; |
195 | 206 |
196 UChar current = it.current(); | 207 UChar current = it.current(); |
197 bool notJustWhitespace = current != spaceCharacter && current != tabulationC
haracter && current != softHyphenCharacter && (current != newlineCharacter || it
.object()->preservesNewline()); | 208 bool notJustWhitespace = current != spaceCharacter && current != tabulationC
haracter && current != softHyphenCharacter && (current != newlineCharacter || it
.object()->preservesNewline()); |
198 return notJustWhitespace || isEmptyInline(it.object()); | 209 return notJustWhitespace || isEmptyInline(LineLayoutItem(it.object())); |
199 } | 210 } |
200 | 211 |
201 inline void setStaticPositions(LayoutBlockFlow* block, LayoutBox* child) | 212 inline void setStaticPositions(LineLayoutBlockFlow block, LayoutBox* child) |
202 { | 213 { |
203 ASSERT(child->isOutOfFlowPositioned()); | 214 ASSERT(child->isOutOfFlowPositioned()); |
204 // FIXME: The math here is actually not really right. It's a best-guess appr
oximation that | 215 // FIXME: The math here is actually not really right. It's a best-guess appr
oximation that |
205 // will work for the common cases | 216 // will work for the common cases |
206 LayoutObject* containerBlock = child->container(); | 217 LayoutObject* containerBlock = child->container(); |
207 LayoutUnit blockHeight = block->logicalHeight(); | 218 LayoutUnit blockHeight = block.logicalHeight(); |
208 if (containerBlock->isLayoutInline()) { | 219 if (containerBlock->isLayoutInline()) { |
209 // A relative positioned inline encloses us. In this case, we also have
to determine our | 220 // A relative positioned inline encloses us. In this case, we also have
to determine our |
210 // position as though we were an inline. Set |staticInlinePosition| and
|staticBlockPosition| on the relative positioned | 221 // position as though we were an inline. Set |staticInlinePosition| and
|staticBlockPosition| on the relative positioned |
211 // inline so that we can obtain the value later. | 222 // inline so that we can obtain the value later. |
212 toLayoutInline(containerBlock)->layer()->setStaticInlinePosition(block->
startAlignedOffsetForLine(blockHeight, false)); | 223 toLayoutInline(containerBlock)->layer()->setStaticInlinePosition(block.s
tartAlignedOffsetForLine(blockHeight, false)); |
213 toLayoutInline(containerBlock)->layer()->setStaticBlockPosition(blockHei
ght); | 224 toLayoutInline(containerBlock)->layer()->setStaticBlockPosition(blockHei
ght); |
214 | 225 |
215 // If |child| is a leading or trailing positioned object this is its onl
y opportunity to ensure it moves with an inline | 226 // If |child| is a leading or trailing positioned object this is its onl
y opportunity to ensure it moves with an inline |
216 // container changing width. | 227 // container changing width. |
217 child->moveWithEdgeOfInlineContainerIfNecessary(child->isHorizontalWriti
ngMode()); | 228 child->moveWithEdgeOfInlineContainerIfNecessary(child->isHorizontalWriti
ngMode()); |
218 } | 229 } |
219 block->updateStaticInlinePositionForChild(*child, blockHeight); | 230 block.updateStaticInlinePositionForChild(*child, blockHeight); |
220 child->layer()->setStaticBlockPosition(blockHeight); | 231 child->layer()->setStaticBlockPosition(blockHeight); |
221 } | 232 } |
222 | 233 |
223 // FIXME: The entire concept of the skipTrailingWhitespace function is flawed, s
ince we really need to be building | 234 // FIXME: The entire concept of the skipTrailingWhitespace function is flawed, s
ince we really need to be building |
224 // line boxes even for containers that may ultimately collapse away. Otherwise w
e'll never get positioned | 235 // line boxes even for containers that may ultimately collapse away. Otherwise w
e'll never get positioned |
225 // elements quite right. In other words, we need to build this function's work i
nto the normal line | 236 // elements quite right. In other words, we need to build this function's work i
nto the normal line |
226 // object iteration process. | 237 // object iteration process. |
227 // NB. this function will insert any floating elements that would otherwise | 238 // NB. this function will insert any floating elements that would otherwise |
228 // be skipped but it will not position them. | 239 // be skipped but it will not position them. |
229 inline void BreakingContext::skipTrailingWhitespace(InlineIterator& iterator, co
nst LineInfo& lineInfo) | 240 inline void BreakingContext::skipTrailingWhitespace(InlineIterator& iterator, co
nst LineInfo& lineInfo) |
230 { | 241 { |
231 while (!iterator.atEnd() && !requiresLineBox(iterator, lineInfo, TrailingWhi
tespace)) { | 242 while (!iterator.atEnd() && !requiresLineBox(iterator, lineInfo, TrailingWhi
tespace)) { |
232 LayoutObject* object = iterator.object(); | 243 LayoutObject* object = iterator.object(); |
233 if (object->isOutOfFlowPositioned()) | 244 if (object->isOutOfFlowPositioned()) |
234 setStaticPositions(m_block, toLayoutBox(object)); | 245 setStaticPositions(m_block, toLayoutBox(object)); |
235 else if (object->isFloating()) | 246 else if (object->isFloating()) |
236 m_block->insertFloatingObject(*toLayoutBox(object)); | 247 m_block.insertFloatingObject(*toLayoutBox(object)); |
237 iterator.increment(); | 248 iterator.increment(); |
238 } | 249 } |
239 } | 250 } |
240 | 251 |
241 inline void BreakingContext::initializeForCurrentObject() | 252 inline void BreakingContext::initializeForCurrentObject() |
242 { | 253 { |
243 m_currentStyle = m_current.object()->style(); | 254 m_currentStyle = m_current.object()->style(); |
244 m_nextObject = bidiNextSkippingEmptyInlines(m_block, m_current.object()); | 255 m_nextObject = bidiNextSkippingEmptyInlines(m_block, LineLayoutItem(m_curren
t.object())); |
245 if (m_nextObject && m_nextObject->parent() && !m_nextObject->parent()->isDes
cendantOf(m_current.object()->parent())) | 256 if (m_nextObject && m_nextObject->parent() && !m_nextObject->parent()->isDes
cendantOf(m_current.object()->parent())) |
246 m_includeEndWidth = true; | 257 m_includeEndWidth = true; |
247 | 258 |
248 m_currWS = m_current.object()->isReplaced() ? m_current.object()->parent()->
style()->whiteSpace() : m_currentStyle->whiteSpace(); | 259 m_currWS = m_current.object()->isReplaced() ? m_current.object()->parent()->
style()->whiteSpace() : m_currentStyle->whiteSpace(); |
249 m_lastWS = m_lastObject->isReplaced() ? m_lastObject->parent()->style()->whi
teSpace() : m_lastObject->style()->whiteSpace(); | 260 m_lastWS = m_lastObject->isReplaced() ? m_lastObject->parent()->style()->whi
teSpace() : m_lastObject->style()->whiteSpace(); |
250 | 261 |
251 bool isSVGText = m_current.object()->isSVGInlineText(); | 262 bool isSVGText = m_current.object()->isSVGInlineText(); |
252 m_autoWrap = !isSVGText && ComputedStyle::autoWrap(m_currWS); | 263 m_autoWrap = !isSVGText && ComputedStyle::autoWrap(m_currWS); |
253 m_autoWrapWasEverTrueOnLine = m_autoWrapWasEverTrueOnLine || m_autoWrap; | 264 m_autoWrapWasEverTrueOnLine = m_autoWrapWasEverTrueOnLine || m_autoWrap; |
254 | 265 |
255 m_preservesNewline = !isSVGText && ComputedStyle::preserveNewline(m_currWS); | 266 m_preservesNewline = !isSVGText && ComputedStyle::preserveNewline(m_currWS); |
256 | 267 |
257 m_collapseWhiteSpace = ComputedStyle::collapseWhiteSpace(m_currWS); | 268 m_collapseWhiteSpace = ComputedStyle::collapseWhiteSpace(m_currWS); |
258 } | 269 } |
259 | 270 |
260 inline void BreakingContext::increment() | 271 inline void BreakingContext::increment() |
261 { | 272 { |
262 // Clear out our character space bool, since inline <pre>s don't collapse wh
itespace | 273 // Clear out our character space bool, since inline <pre>s don't collapse wh
itespace |
263 // with adjacent inline normal/nowrap spans. | 274 // with adjacent inline normal/nowrap spans. |
264 if (!m_collapseWhiteSpace) | 275 if (!m_collapseWhiteSpace) |
265 m_currentCharacterIsSpace = false; | 276 m_currentCharacterIsSpace = false; |
266 | 277 |
267 m_current.moveToStartOf(m_nextObject); | 278 m_current.moveToStartOf(LineLayoutItem(m_nextObject)); |
268 m_atStart = false; | 279 m_atStart = false; |
269 } | 280 } |
270 | 281 |
271 inline void BreakingContext::handleBR(EClear& clear) | 282 inline void BreakingContext::handleBR(EClear& clear) |
272 { | 283 { |
273 if (m_width.fitsOnLine()) { | 284 if (m_width.fitsOnLine()) { |
274 LayoutObject* br = m_current.object(); | 285 LayoutObject* br = m_current.object(); |
275 m_lineBreak.moveToStartOf(br); | 286 m_lineBreak.moveToStartOf(LineLayoutItem(br)); |
276 m_lineBreak.increment(); | 287 m_lineBreak.increment(); |
277 | 288 |
278 // A <br> always breaks a line, so don't let the line be collapsed | 289 // A <br> always breaks a line, so don't let the line be collapsed |
279 // away. Also, the space at the end of a line with a <br> does not | 290 // away. Also, the space at the end of a line with a <br> does not |
280 // get collapsed away. It only does this if the previous line broke | 291 // get collapsed away. It only does this if the previous line broke |
281 // cleanly. Otherwise the <br> has no effect on whether the line is | 292 // cleanly. Otherwise the <br> has no effect on whether the line is |
282 // empty or not. | 293 // empty or not. |
283 if (m_startingNewParagraph) | 294 if (m_startingNewParagraph) |
284 m_lineInfo.setEmpty(false, m_block, &m_width); | 295 m_lineInfo.setEmpty(false, m_block, &m_width); |
285 m_trailingObjects.clear(); | 296 m_trailingObjects.clear(); |
286 m_lineInfo.setPreviousLineBrokeCleanly(true); | 297 m_lineInfo.setPreviousLineBrokeCleanly(true); |
287 | 298 |
288 // A <br> with clearance always needs a linebox in case the lines below
it get dirtied later and | 299 // A <br> with clearance always needs a linebox in case the lines below
it get dirtied later and |
289 // need to check for floats to clear - so if we're ignoring spaces, stop
ignoring them and add a | 300 // need to check for floats to clear - so if we're ignoring spaces, stop
ignoring them and add a |
290 // run for this object. | 301 // run for this object. |
291 if (m_ignoringSpaces && m_currentStyle->clear() != CNONE) | 302 if (m_ignoringSpaces && m_currentStyle->clear() != CNONE) |
292 m_lineMidpointState.ensureLineBoxInsideIgnoredSpaces(br); | 303 ensureLineBoxInsideIgnoredSpaces(&m_lineMidpointState, br); |
293 | 304 |
294 if (!m_lineInfo.isEmpty()) | 305 if (!m_lineInfo.isEmpty()) |
295 clear = m_currentStyle->clear(); | 306 clear = m_currentStyle->clear(); |
296 } | 307 } |
297 m_atEnd = true; | 308 m_atEnd = true; |
298 } | 309 } |
299 | 310 |
300 inline LayoutUnit borderPaddingMarginStart(LayoutInline* child) | 311 inline LayoutUnit borderPaddingMarginStart(LayoutInline* child) |
301 { | 312 { |
302 return child->marginStart() + child->paddingStart() + child->borderStart(); | 313 return child->marginStart() + child->paddingStart() + child->borderStart(); |
(...skipping 12 matching lines...) Expand all Loading... |
315 return checkSide; | 326 return checkSide; |
316 } | 327 } |
317 | 328 |
318 inline LayoutUnit inlineLogicalWidth(LayoutObject* child, bool start = true, boo
l end = true) | 329 inline LayoutUnit inlineLogicalWidth(LayoutObject* child, bool start = true, boo
l end = true) |
319 { | 330 { |
320 unsigned lineDepth = 1; | 331 unsigned lineDepth = 1; |
321 LayoutUnit extraWidth = 0; | 332 LayoutUnit extraWidth = 0; |
322 LayoutObject* parent = child->parent(); | 333 LayoutObject* parent = child->parent(); |
323 while (parent->isLayoutInline() && lineDepth++ < cMaxLineDepth) { | 334 while (parent->isLayoutInline() && lineDepth++ < cMaxLineDepth) { |
324 LayoutInline* parentAsLayoutInline = toLayoutInline(parent); | 335 LayoutInline* parentAsLayoutInline = toLayoutInline(parent); |
325 if (!isEmptyInline(parentAsLayoutInline)) { | 336 if (!isEmptyInline(LineLayoutItem(parentAsLayoutInline))) { |
326 if (start && shouldAddBorderPaddingMargin(child->previousSibling(),
start)) | 337 if (start && shouldAddBorderPaddingMargin(child->previousSibling(),
start)) |
327 extraWidth += borderPaddingMarginStart(parentAsLayoutInline); | 338 extraWidth += borderPaddingMarginStart(parentAsLayoutInline); |
328 if (end && shouldAddBorderPaddingMargin(child->nextSibling(), end)) | 339 if (end && shouldAddBorderPaddingMargin(child->nextSibling(), end)) |
329 extraWidth += borderPaddingMarginEnd(parentAsLayoutInline); | 340 extraWidth += borderPaddingMarginEnd(parentAsLayoutInline); |
330 if (!start && !end) | 341 if (!start && !end) |
331 return extraWidth; | 342 return extraWidth; |
332 } | 343 } |
333 child = parent; | 344 child = parent; |
334 parent = child->parent(); | 345 parent = child->parent(); |
335 } | 346 } |
336 return extraWidth; | 347 return extraWidth; |
337 } | 348 } |
338 | 349 |
339 inline void BreakingContext::handleOutOfFlowPositioned(Vector<LayoutBox*>& posit
ionedObjects) | 350 inline void BreakingContext::handleOutOfFlowPositioned(Vector<LayoutBox*>& posit
ionedObjects) |
340 { | 351 { |
341 // If our original display wasn't an inline type, then we can | 352 // If our original display wasn't an inline type, then we can |
342 // go ahead and determine our static inline position now. | 353 // go ahead and determine our static inline position now. |
343 LayoutBox* box = toLayoutBox(m_current.object()); | 354 LayoutBox* box = toLayoutBox(m_current.object()); |
344 bool isInlineType = box->style()->isOriginalDisplayInlineType(); | 355 bool isInlineType = box->style()->isOriginalDisplayInlineType(); |
345 if (!isInlineType) { | 356 if (!isInlineType) { |
346 m_block->setStaticInlinePositionForChild(*box, m_block->startOffsetForCo
ntent()); | 357 m_block.setStaticInlinePositionForChild(*box, m_block.startOffsetForCont
ent()); |
347 } else { | 358 } else { |
348 // If our original display was an INLINE type, then we can go ahead | 359 // If our original display was an INLINE type, then we can go ahead |
349 // and determine our static y position now. | 360 // and determine our static y position now. |
350 box->layer()->setStaticBlockPosition(m_block->logicalHeight()); | 361 box->layer()->setStaticBlockPosition(m_block.logicalHeight()); |
351 } | 362 } |
352 | 363 |
353 // If we're ignoring spaces, we have to stop and include this object and | 364 // If we're ignoring spaces, we have to stop and include this object and |
354 // then start ignoring spaces again. | 365 // then start ignoring spaces again. |
355 if (isInlineType || box->container()->isLayoutInline()) { | 366 if (isInlineType || box->container()->isLayoutInline()) { |
356 if (m_ignoringSpaces) | 367 if (m_ignoringSpaces) |
357 m_lineMidpointState.ensureLineBoxInsideIgnoredSpaces(box); | 368 ensureLineBoxInsideIgnoredSpaces(&m_lineMidpointState, box); |
358 m_trailingObjects.appendObjectIfNeeded(box); | 369 m_trailingObjects.appendObjectIfNeeded(box); |
359 } else { | 370 } else { |
360 positionedObjects.append(box); | 371 positionedObjects.append(box); |
361 } | 372 } |
362 m_width.addUncommittedWidth(inlineLogicalWidth(box).toFloat()); | 373 m_width.addUncommittedWidth(inlineLogicalWidth(box).toFloat()); |
363 // Reset prior line break context characters. | 374 // Reset prior line break context characters. |
364 m_layoutTextInfo.m_lineBreakIterator.resetPriorContext(); | 375 m_layoutTextInfo.m_lineBreakIterator.resetPriorContext(); |
365 } | 376 } |
366 | 377 |
367 inline void BreakingContext::handleFloat() | 378 inline void BreakingContext::handleFloat() |
368 { | 379 { |
369 LayoutBox* floatBox = toLayoutBox(m_current.object()); | 380 LayoutBox* floatBox = toLayoutBox(m_current.object()); |
370 FloatingObject* floatingObject = m_block->insertFloatingObject(*floatBox); | 381 FloatingObject* floatingObject = m_block.insertFloatingObject(*floatBox); |
371 // check if it fits in the current line. | 382 // check if it fits in the current line. |
372 // If it does, position it now, otherwise, position | 383 // If it does, position it now, otherwise, position |
373 // it after moving to next line (in newLine() func) | 384 // it after moving to next line (in newLine() func) |
374 // FIXME: Bug 110372: Properly position multiple stacked floats with non-rec
tangular shape outside. | 385 // FIXME: Bug 110372: Properly position multiple stacked floats with non-rec
tangular shape outside. |
375 if (m_floatsFitOnLine && m_width.fitsOnLine(m_block->logicalWidthForFloat(*f
loatingObject).toFloat(), ExcludeWhitespace)) { | 386 if (m_floatsFitOnLine && m_width.fitsOnLine(m_block.logicalWidthForFloat(*fl
oatingObject).toFloat(), ExcludeWhitespace)) { |
376 m_block->positionNewFloatOnLine(*floatingObject, m_lastFloatFromPrevious
Line, m_lineInfo, m_width); | 387 m_block.positionNewFloatOnLine(*floatingObject, m_lastFloatFromPreviousL
ine, m_lineInfo, m_width); |
377 if (m_lineBreak.object() == m_current.object()) { | 388 if (m_lineBreak.object() == m_current.object()) { |
378 ASSERT(!m_lineBreak.offset()); | 389 ASSERT(!m_lineBreak.offset()); |
379 m_lineBreak.increment(); | 390 m_lineBreak.increment(); |
380 } | 391 } |
381 } else { | 392 } else { |
382 m_floatsFitOnLine = false; | 393 m_floatsFitOnLine = false; |
383 } | 394 } |
384 // Update prior line break context characters, using U+FFFD (OBJECT REPLACEM
ENT CHARACTER) for floating element. | 395 // Update prior line break context characters, using U+FFFD (OBJECT REPLACEM
ENT CHARACTER) for floating element. |
385 m_layoutTextInfo.m_lineBreakIterator.updatePriorContext(replacementCharacter
); | 396 m_layoutTextInfo.m_lineBreakIterator.updatePriorContext(replacementCharacter
); |
386 } | 397 } |
387 | 398 |
388 // This is currently just used for list markers and inline flows that have line
boxes. Neither should | 399 // This is currently just used for list markers and inline flows that have line
boxes. Neither should |
389 // have an effect on whitespace at the start of the line. | 400 // have an effect on whitespace at the start of the line. |
390 inline bool shouldSkipWhitespaceAfterStartObject(LayoutBlockFlow* block, LayoutO
bject* o, LineMidpointState& lineMidpointState) | 401 inline bool shouldSkipWhitespaceAfterStartObject(LineLayoutBlockFlow block, Layo
utObject* o, LineMidpointState& lineMidpointState) |
391 { | 402 { |
392 LayoutObject* next = bidiNextSkippingEmptyInlines(block, o); | 403 LayoutObject* next = bidiNextSkippingEmptyInlines(block, LineLayoutItem(o)); |
393 while (next && next->isFloatingOrOutOfFlowPositioned()) | 404 while (next && next->isFloatingOrOutOfFlowPositioned()) |
394 next = bidiNextSkippingEmptyInlines(block, next); | 405 next = bidiNextSkippingEmptyInlines(block, LineLayoutItem(next)); |
395 | 406 |
396 if (next && !next->isBR() && next->isText() && toLayoutText(next)->textLengt
h() > 0) { | 407 if (next && !next->isBR() && next->isText() && toLayoutText(next)->textLengt
h() > 0) { |
397 LayoutText* nextText = toLayoutText(next); | 408 LayoutText* nextText = toLayoutText(next); |
398 UChar nextChar = nextText->characterAt(0); | 409 UChar nextChar = nextText->characterAt(0); |
399 if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) { | 410 if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) { |
400 lineMidpointState.startIgnoringSpaces(InlineIterator(0, o, 0)); | 411 lineMidpointState.startIgnoringSpaces(InlineIterator(0, LineLayoutIt
em(o), 0)); |
401 return true; | 412 return true; |
402 } | 413 } |
403 } | 414 } |
404 | 415 |
405 return false; | 416 return false; |
406 } | 417 } |
407 | 418 |
408 inline void BreakingContext::handleEmptyInline() | 419 inline void BreakingContext::handleEmptyInline() |
409 { | 420 { |
410 // This should only end up being called on empty inlines | 421 // This should only end up being called on empty inlines |
411 ASSERT(isEmptyInline(m_current.object())); | 422 ASSERT(isEmptyInline(LineLayoutItem(m_current.object()))); |
412 | 423 |
413 LayoutInline* flowBox = toLayoutInline(m_current.object()); | 424 LayoutInline* flowBox = toLayoutInline(m_current.object()); |
414 | 425 |
415 bool requiresLineBox = alwaysRequiresLineBox(m_current.object()); | 426 bool requiresLineBox = alwaysRequiresLineBox(m_current.object()); |
416 if (requiresLineBox || requiresLineBoxForContent(flowBox, m_lineInfo)) { | 427 if (requiresLineBox || requiresLineBoxForContent(flowBox, m_lineInfo)) { |
417 // An empty inline that only has line-height, vertical-align or font-met
rics will | 428 // An empty inline that only has line-height, vertical-align or font-met
rics will |
418 // not force linebox creation (and thus affect the height of the line) i
f the rest of the line is empty. | 429 // not force linebox creation (and thus affect the height of the line) i
f the rest of the line is empty. |
419 if (requiresLineBox) | 430 if (requiresLineBox) |
420 m_lineInfo.setEmpty(false, m_block, &m_width); | 431 m_lineInfo.setEmpty(false, m_block, &m_width); |
421 if (m_ignoringSpaces) { | 432 if (m_ignoringSpaces) { |
422 // If we are in a run of ignored spaces then ensure we get a linebox
if lineboxes are eventually | 433 // If we are in a run of ignored spaces then ensure we get a linebox
if lineboxes are eventually |
423 // created for the line... | 434 // created for the line... |
424 m_trailingObjects.clear(); | 435 m_trailingObjects.clear(); |
425 m_lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_current.objec
t()); | 436 ensureLineBoxInsideIgnoredSpaces(&m_lineMidpointState, m_current.obj
ect()); |
426 } else if (m_blockStyle->collapseWhiteSpace() && m_resolver.position().o
bject() == m_current.object() | 437 } else if (m_blockStyle->collapseWhiteSpace() && m_resolver.position().o
bject() == m_current.object() |
427 && shouldSkipWhitespaceAfterStartObject(m_block, m_current.object(),
m_lineMidpointState)) { | 438 && shouldSkipWhitespaceAfterStartObject(m_block, m_current.object(),
m_lineMidpointState)) { |
428 // If this object is at the start of the line, we need to behave lik
e list markers and | 439 // If this object is at the start of the line, we need to behave lik
e list markers and |
429 // start ignoring spaces. | 440 // start ignoring spaces. |
430 m_currentCharacterShouldCollapseIfPreWap = m_currentCharacterIsSpace
= true; | 441 m_currentCharacterShouldCollapseIfPreWap = m_currentCharacterIsSpace
= true; |
431 m_ignoringSpaces = true; | 442 m_ignoringSpaces = true; |
432 } else { | 443 } else { |
433 // If we are after a trailing space but aren't ignoring spaces yet t
hen ensure we get a linebox | 444 // If we are after a trailing space but aren't ignoring spaces yet t
hen ensure we get a linebox |
434 // if we encounter collapsible whitepace. | 445 // if we encounter collapsible whitepace. |
435 m_trailingObjects.appendObjectIfNeeded(m_current.object()); | 446 m_trailingObjects.appendObjectIfNeeded(m_current.object()); |
(...skipping 19 matching lines...) Expand all Loading... |
455 if (m_ignoringSpaces) | 466 if (m_ignoringSpaces) |
456 m_lineMidpointState.stopIgnoringSpaces(InlineIterator(0, m_current.objec
t(), 0)); | 467 m_lineMidpointState.stopIgnoringSpaces(InlineIterator(0, m_current.objec
t(), 0)); |
457 | 468 |
458 m_lineInfo.setEmpty(false, m_block, &m_width); | 469 m_lineInfo.setEmpty(false, m_block, &m_width); |
459 m_ignoringSpaces = false; | 470 m_ignoringSpaces = false; |
460 m_currentCharacterShouldCollapseIfPreWap = m_currentCharacterIsSpace = false
; | 471 m_currentCharacterShouldCollapseIfPreWap = m_currentCharacterIsSpace = false
; |
461 m_trailingObjects.clear(); | 472 m_trailingObjects.clear(); |
462 | 473 |
463 // Optimize for a common case. If we can't find whitespace after the list | 474 // Optimize for a common case. If we can't find whitespace after the list |
464 // item, then this is all moot. | 475 // item, then this is all moot. |
465 LayoutUnit replacedLogicalWidth = m_block->logicalWidthForChild(*replacedBox
) + m_block->marginStartForChild(*replacedBox) + m_block->marginEndForChild(*rep
lacedBox) + inlineLogicalWidth(m_current.object()); | 476 LayoutUnit replacedLogicalWidth = m_block.logicalWidthForChild(*replacedBox)
+ m_block.marginStartForChild(*replacedBox) + m_block.marginEndForChild(*replac
edBox) + inlineLogicalWidth(m_current.object()); |
466 if (m_current.object()->isListMarker()) { | 477 if (m_current.object()->isListMarker()) { |
467 if (m_blockStyle->collapseWhiteSpace() && shouldSkipWhitespaceAfterStart
Object(m_block, m_current.object(), m_lineMidpointState)) { | 478 if (m_blockStyle->collapseWhiteSpace() && shouldSkipWhitespaceAfterStart
Object(m_block, m_current.object(), m_lineMidpointState)) { |
468 // Like with inline flows, we start ignoring spaces to make sure tha
t any | 479 // Like with inline flows, we start ignoring spaces to make sure tha
t any |
469 // additional spaces we see will be discarded. | 480 // additional spaces we see will be discarded. |
470 m_currentCharacterShouldCollapseIfPreWap = m_currentCharacterIsSpace
= true; | 481 m_currentCharacterShouldCollapseIfPreWap = m_currentCharacterIsSpace
= true; |
471 m_ignoringSpaces = true; | 482 m_ignoringSpaces = true; |
472 } | 483 } |
473 if (toLayoutListMarker(m_current.object())->isInside()) | 484 if (toLayoutListMarker(m_current.object())->isInside()) |
474 m_width.addUncommittedWidth(replacedLogicalWidth.toFloat()); | 485 m_width.addUncommittedWidth(replacedLogicalWidth.toFloat()); |
475 } else { | 486 } else { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 } else if (nextText->isWordBreak()) { | 852 } else if (nextText->isWordBreak()) { |
842 checkForBreak = true; | 853 checkForBreak = true; |
843 } | 854 } |
844 | 855 |
845 if (!m_width.fitsOnLine() && !m_width.committedWidth()) | 856 if (!m_width.fitsOnLine() && !m_width.committedWidth()) |
846 m_width.fitBelowFloats(m_lineInfo.isFirstLine()); | 857 m_width.fitBelowFloats(m_lineInfo.isFirstLine()); |
847 | 858 |
848 bool canPlaceOnLine = m_width.fitsOnLine() || !m_autoWrapWasEverTrue
OnLine; | 859 bool canPlaceOnLine = m_width.fitsOnLine() || !m_autoWrapWasEverTrue
OnLine; |
849 if (canPlaceOnLine && checkForBreak) { | 860 if (canPlaceOnLine && checkForBreak) { |
850 m_width.commit(); | 861 m_width.commit(); |
851 m_lineBreak.moveToStartOf(m_nextObject); | 862 m_lineBreak.moveToStartOf(LineLayoutItem(m_nextObject)); |
852 } | 863 } |
853 } | 864 } |
854 } | 865 } |
855 | 866 |
856 ASSERT_WITH_SECURITY_IMPLICATION(m_currentStyle->refCount() > 0); | 867 ASSERT_WITH_SECURITY_IMPLICATION(m_currentStyle->refCount() > 0); |
857 if (checkForBreak && !m_width.fitsOnLine()) { | 868 if (checkForBreak && !m_width.fitsOnLine()) { |
858 // if we have floats, try to get below them. | 869 // if we have floats, try to get below them. |
859 if (m_currentCharacterIsSpace && !m_ignoringSpaces && m_currentStyle->co
llapseWhiteSpace()) | 870 if (m_currentCharacterIsSpace && !m_ignoringSpaces && m_currentStyle->co
llapseWhiteSpace()) |
860 m_trailingObjects.clear(); | 871 m_trailingObjects.clear(); |
861 | 872 |
(...skipping 14 matching lines...) Expand all Loading... |
876 } else if (m_blockStyle->autoWrap() && !m_width.fitsOnLine() && !m_width.com
mittedWidth()) { | 887 } else if (m_blockStyle->autoWrap() && !m_width.fitsOnLine() && !m_width.com
mittedWidth()) { |
877 // If the container autowraps but the current child does not then we sti
ll need to ensure that it | 888 // If the container autowraps but the current child does not then we sti
ll need to ensure that it |
878 // wraps and moves below any floats. | 889 // wraps and moves below any floats. |
879 m_width.fitBelowFloats(m_lineInfo.isFirstLine()); | 890 m_width.fitBelowFloats(m_lineInfo.isFirstLine()); |
880 } | 891 } |
881 | 892 |
882 if (!m_current.object()->isFloatingOrOutOfFlowPositioned()) { | 893 if (!m_current.object()->isFloatingOrOutOfFlowPositioned()) { |
883 m_lastObject = m_current.object(); | 894 m_lastObject = m_current.object(); |
884 if (m_lastObject->isReplaced() && m_autoWrap && (!m_lastObject->isImage(
) || m_allowImagesToBreak) && (!m_lastObject->isListMarker() || toLayoutListMark
er(m_lastObject)->isInside())) { | 895 if (m_lastObject->isReplaced() && m_autoWrap && (!m_lastObject->isImage(
) || m_allowImagesToBreak) && (!m_lastObject->isListMarker() || toLayoutListMark
er(m_lastObject)->isInside())) { |
885 m_width.commit(); | 896 m_width.commit(); |
886 m_lineBreak.moveToStartOf(m_nextObject); | 897 m_lineBreak.moveToStartOf(LineLayoutItem(m_nextObject)); |
887 } | 898 } |
888 } | 899 } |
889 } | 900 } |
890 | 901 |
891 inline IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBrea
k, const ComputedStyle& style) | 902 inline IndentTextOrNot requiresIndent(bool isFirstLine, bool isAfterHardLineBrea
k, const ComputedStyle& style) |
892 { | 903 { |
893 IndentTextOrNot shouldIndentText = DoNotIndentText; | 904 IndentTextOrNot shouldIndentText = DoNotIndentText; |
894 if (isFirstLine || (isAfterHardLineBreak && style.textIndentLine()) == TextI
ndentEachLine) | 905 if (isFirstLine || (isAfterHardLineBreak && style.textIndentLine()) == TextI
ndentEachLine) |
895 shouldIndentText = IndentText; | 906 shouldIndentText = IndentText; |
896 | 907 |
897 if (style.textIndentType() == TextIndentHanging) | 908 if (style.textIndentType() == TextIndentHanging) |
898 shouldIndentText = shouldIndentText == IndentText ? DoNotIndentText : In
dentText; | 909 shouldIndentText = shouldIndentText == IndentText ? DoNotIndentText : In
dentText; |
899 | 910 |
900 return shouldIndentText; | 911 return shouldIndentText; |
901 } | 912 } |
902 | 913 |
903 } | 914 } |
904 | 915 |
905 #endif // BreakingContextInlineHeaders_h | 916 #endif // BreakingContextInlineHeaders_h |
OLD | NEW |