darin | 55ae73e | 2007-05-11 15:47:28 +0000 | [diff] [blame] | 1 | /* |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2 | * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved. |
eric@webkit.org | ddbec0aa | 2010-01-06 01:13:11 +0000 | [diff] [blame] | 4 | * Copyright (C) 2010 Google Inc. All rights reserved. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 20 | * |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 21 | */ |
darin | be4c67d | 2005-12-19 19:53:12 +0000 | [diff] [blame] | 22 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 23 | #include "config.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 24 | |
mitz@apple.com | 4c1ff32 | 2009-07-13 00:54:12 +0000 | [diff] [blame] | 25 | #include "BidiResolver.h" |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 26 | #include "Hyphenation.h" |
hyatt@apple.com | 71eeb44 | 2010-02-11 20:05:51 +0000 | [diff] [blame] | 27 | #include "InlineIterator.h" |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 28 | #include "InlineTextBox.h" |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 29 | #include "Logging.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 30 | #include "RenderArena.h" |
hyatt@apple.com | 4d046b7 | 2011-01-31 20:39:09 +0000 | [diff] [blame] | 31 | #include "RenderCombineText.h" |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 32 | #include "RenderFlowThread.h" |
hyatt@apple.com | c3c7e90 | 2009-01-28 21:48:33 +0000 | [diff] [blame] | 33 | #include "RenderInline.h" |
eric@webkit.org | b35848a | 2010-06-10 08:33:22 +0000 | [diff] [blame] | 34 | #include "RenderLayer.h" |
mjs | d26b297 | 2007-02-13 13:09:04 +0000 | [diff] [blame] | 35 | #include "RenderListMarker.h" |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 36 | #include "RenderRubyRun.h" |
hyatt | d804834 | 2006-05-31 01:48:18 +0000 | [diff] [blame] | 37 | #include "RenderView.h" |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 38 | #include "Settings.h" |
mitz@apple.com | 44fc513 | 2011-02-25 18:34:15 +0000 | [diff] [blame] | 39 | #include "TextBreakIterator.h" |
dbates@webkit.org | f6f05a9 | 2010-05-17 04:58:25 +0000 | [diff] [blame] | 40 | #include "TrailingFloatsRootInlineBox.h" |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 41 | #include "VerticalPositionCache.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 42 | #include "break_lines.h" |
mjs | bb86351 | 2006-05-09 09:27:55 +0000 | [diff] [blame] | 43 | #include <wtf/AlwaysInline.h> |
slewis@apple.com | a7615ca | 2008-07-12 05:51:33 +0000 | [diff] [blame] | 44 | #include <wtf/RefCountedLeakCounter.h> |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 45 | #include <wtf/StdLibExtras.h> |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 46 | #include <wtf/Vector.h> |
paroga@webkit.org | 10c9e1b | 2011-01-29 17:04:51 +0000 | [diff] [blame] | 47 | #include <wtf/unicode/CharacterNames.h> |
hyatt | 8c371e5 | 2004-06-16 01:19:26 +0000 | [diff] [blame] | 48 | |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 49 | #if ENABLE(SVG) |
zimmermann@webkit.org | 6e96afd | 2010-09-10 15:35:50 +0000 | [diff] [blame] | 50 | #include "RenderSVGInlineText.h" |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 51 | #include "SVGRootInlineBox.h" |
| 52 | #endif |
| 53 | |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 54 | using namespace std; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 55 | using namespace WTF; |
| 56 | using namespace Unicode; |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 57 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 58 | namespace WebCore { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 59 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 60 | // We don't let our line box tree for a single line get any deeper than this. |
| 61 | const unsigned cMaxLineDepth = 200; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 62 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 63 | class LineWidth { |
| 64 | public: |
| 65 | LineWidth(RenderBlock* block, bool isFirstLine) |
| 66 | : m_block(block) |
| 67 | , m_uncommittedWidth(0) |
| 68 | , m_committedWidth(0) |
| 69 | , m_overhangWidth(0) |
| 70 | , m_left(0) |
| 71 | , m_right(0) |
| 72 | , m_availableWidth(0) |
| 73 | , m_isFirstLine(isFirstLine) |
| 74 | { |
| 75 | ASSERT(block); |
| 76 | updateAvailableWidth(); |
| 77 | } |
| 78 | bool fitsOnLine() const { return currentWidth() <= m_availableWidth; } |
| 79 | bool fitsOnLine(float extra) const { return currentWidth() + extra <= m_availableWidth; } |
| 80 | float currentWidth() const { return m_committedWidth + m_uncommittedWidth; } |
| 81 | |
| 82 | // FIXME: We should eventually replace these three functions by ones that work on a higher abstraction. |
| 83 | float uncommittedWidth() const { return m_uncommittedWidth; } |
| 84 | float committedWidth() const { return m_committedWidth; } |
| 85 | float availableWidth() const { return m_availableWidth; } |
| 86 | |
| 87 | void updateAvailableWidth(); |
| 88 | void shrinkAvailableWidthForNewFloatIfNeeded(RenderBlock::FloatingObject*); |
| 89 | void addUncommittedWidth(float delta) { m_uncommittedWidth += delta; } |
| 90 | void commit() |
| 91 | { |
| 92 | m_committedWidth += m_uncommittedWidth; |
| 93 | m_uncommittedWidth = 0; |
| 94 | } |
| 95 | void applyOverhang(RenderRubyRun*, RenderObject* startRenderer, RenderObject* endRenderer); |
| 96 | void fitBelowFloats(); |
| 97 | |
| 98 | private: |
| 99 | void computeAvailableWidthFromLeftAndRight() |
| 100 | { |
| 101 | m_availableWidth = max(0, m_right - m_left) + m_overhangWidth; |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | RenderBlock* m_block; |
| 106 | float m_uncommittedWidth; |
| 107 | float m_committedWidth; |
| 108 | float m_overhangWidth; // The amount by which |m_availableWidth| has been inflated to account for possible contraction due to ruby overhang. |
| 109 | int m_left; |
| 110 | int m_right; |
| 111 | float m_availableWidth; |
| 112 | bool m_isFirstLine; |
| 113 | }; |
| 114 | |
| 115 | inline void LineWidth::updateAvailableWidth() |
| 116 | { |
| 117 | int height = m_block->logicalHeight(); |
| 118 | m_left = m_block->logicalLeftOffsetForLine(height, m_isFirstLine); |
| 119 | m_right = m_block->logicalRightOffsetForLine(height, m_isFirstLine); |
| 120 | |
| 121 | computeAvailableWidthFromLeftAndRight(); |
| 122 | } |
| 123 | |
| 124 | inline void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(RenderBlock::FloatingObject* newFloat) |
| 125 | { |
| 126 | int height = m_block->logicalHeight(); |
| 127 | if (height < m_block->logicalTopForFloat(newFloat) || height >= m_block->logicalBottomForFloat(newFloat)) |
| 128 | return; |
| 129 | |
| 130 | if (newFloat->type() == RenderBlock::FloatingObject::FloatLeft) { |
eae@chromium.org | d6dd62f | 2012-02-08 03:56:27 +0000 | [diff] [blame] | 131 | m_left = m_block->pixelSnappedLogicalRightForFloat(newFloat); |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 132 | if (m_isFirstLine && m_block->style()->isLeftToRightDirection()) |
| 133 | m_left += m_block->textIndentOffset(); |
| 134 | } else { |
eae@chromium.org | d6dd62f | 2012-02-08 03:56:27 +0000 | [diff] [blame] | 135 | m_right = m_block->pixelSnappedLogicalLeftForFloat(newFloat); |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 136 | if (m_isFirstLine && !m_block->style()->isLeftToRightDirection()) |
| 137 | m_right -= m_block->textIndentOffset(); |
| 138 | } |
| 139 | |
| 140 | computeAvailableWidthFromLeftAndRight(); |
| 141 | } |
| 142 | |
| 143 | void LineWidth::applyOverhang(RenderRubyRun* rubyRun, RenderObject* startRenderer, RenderObject* endRenderer) |
| 144 | { |
| 145 | int startOverhang; |
| 146 | int endOverhang; |
| 147 | rubyRun->getOverhang(m_isFirstLine, startRenderer, endRenderer, startOverhang, endOverhang); |
| 148 | |
| 149 | startOverhang = min<int>(startOverhang, m_committedWidth); |
| 150 | m_availableWidth += startOverhang; |
| 151 | |
| 152 | endOverhang = max(min<int>(endOverhang, m_availableWidth - currentWidth()), 0); |
| 153 | m_availableWidth += endOverhang; |
| 154 | m_overhangWidth += startOverhang + endOverhang; |
| 155 | } |
| 156 | |
| 157 | void LineWidth::fitBelowFloats() |
| 158 | { |
| 159 | ASSERT(!m_committedWidth); |
| 160 | ASSERT(!fitsOnLine()); |
| 161 | |
| 162 | int floatLogicalBottom; |
| 163 | int lastFloatLogicalBottom = m_block->logicalHeight(); |
| 164 | float newLineWidth = m_availableWidth; |
| 165 | float newLineLeft = m_left; |
| 166 | float newLineRight = m_right; |
| 167 | while (true) { |
| 168 | floatLogicalBottom = m_block->nextFloatLogicalBottomBelow(lastFloatLogicalBottom); |
hyatt@apple.com | d4d3bcf | 2011-10-04 18:17:04 +0000 | [diff] [blame] | 169 | if (floatLogicalBottom <= lastFloatLogicalBottom) |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 170 | break; |
| 171 | |
| 172 | newLineLeft = m_block->logicalLeftOffsetForLine(floatLogicalBottom, m_isFirstLine); |
| 173 | newLineRight = m_block->logicalRightOffsetForLine(floatLogicalBottom, m_isFirstLine); |
| 174 | newLineWidth = max(0.0f, newLineRight - newLineLeft); |
| 175 | lastFloatLogicalBottom = floatLogicalBottom; |
| 176 | if (newLineWidth >= m_uncommittedWidth) |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | if (newLineWidth > m_availableWidth) { |
| 181 | m_block->setLogicalHeight(lastFloatLogicalBottom); |
| 182 | m_availableWidth = newLineWidth + m_overhangWidth; |
| 183 | m_left = newLineLeft; |
| 184 | m_right = newLineRight; |
| 185 | } |
| 186 | } |
| 187 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 188 | class LineInfo { |
| 189 | public: |
| 190 | LineInfo() |
| 191 | : m_isFirstLine(true) |
| 192 | , m_isLastLine(false) |
| 193 | , m_isEmpty(true) |
| 194 | , m_previousLineBrokeCleanly(true) |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 195 | , m_floatPaginationStrut(0) |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 196 | , m_runsFromLeadingWhitespace(0) |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 197 | { } |
| 198 | |
| 199 | bool isFirstLine() const { return m_isFirstLine; } |
| 200 | bool isLastLine() const { return m_isLastLine; } |
| 201 | bool isEmpty() const { return m_isEmpty; } |
| 202 | bool previousLineBrokeCleanly() const { return m_previousLineBrokeCleanly; } |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 203 | LayoutUnit floatPaginationStrut() const { return m_floatPaginationStrut; } |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 204 | unsigned runsFromLeadingWhitespace() const { return m_runsFromLeadingWhitespace; } |
| 205 | void resetRunsFromLeadingWhitespace() { m_runsFromLeadingWhitespace = 0; } |
| 206 | void incrementRunsFromLeadingWhitespace() { m_runsFromLeadingWhitespace++; } |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 207 | |
| 208 | void setFirstLine(bool firstLine) { m_isFirstLine = firstLine; } |
| 209 | void setLastLine(bool lastLine) { m_isLastLine = lastLine; } |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 210 | void setEmpty(bool empty, RenderBlock* block = 0, LineWidth* lineWidth = 0) |
| 211 | { |
| 212 | if (m_isEmpty == empty) |
| 213 | return; |
| 214 | m_isEmpty = empty; |
| 215 | if (!empty && block && floatPaginationStrut()) { |
| 216 | block->setLogicalHeight(block->logicalHeight() + floatPaginationStrut()); |
| 217 | setFloatPaginationStrut(0); |
| 218 | lineWidth->updateAvailableWidth(); |
| 219 | } |
| 220 | } |
| 221 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 222 | void setPreviousLineBrokeCleanly(bool previousLineBrokeCleanly) { m_previousLineBrokeCleanly = previousLineBrokeCleanly; } |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 223 | void setFloatPaginationStrut(LayoutUnit strut) { m_floatPaginationStrut = strut; } |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 224 | |
| 225 | private: |
| 226 | bool m_isFirstLine; |
| 227 | bool m_isLastLine; |
| 228 | bool m_isEmpty; |
| 229 | bool m_previousLineBrokeCleanly; |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 230 | LayoutUnit m_floatPaginationStrut; |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 231 | unsigned m_runsFromLeadingWhitespace; |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 232 | }; |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 233 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 234 | static inline LayoutUnit borderPaddingMarginStart(RenderInline* child) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 235 | { |
hyatt@apple.com | 0415e5d | 2010-10-07 17:40:25 +0000 | [diff] [blame] | 236 | return child->marginStart() + child->paddingStart() + child->borderStart(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 237 | } |
| 238 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 239 | static inline LayoutUnit borderPaddingMarginEnd(RenderInline* child) |
rniwa@webkit.org | 33a346a | 2011-04-06 17:06:14 +0000 | [diff] [blame] | 240 | { |
| 241 | return child->marginEnd() + child->paddingEnd() + child->borderEnd(); |
| 242 | } |
| 243 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 244 | static LayoutUnit inlineLogicalWidth(RenderObject* child, bool start = true, bool end = true) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 245 | { |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 246 | unsigned lineDepth = 1; |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 247 | LayoutUnit extraWidth = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 248 | RenderObject* parent = child->parent(); |
rniwa@webkit.org | 63db8cb | 2011-04-06 21:08:20 +0000 | [diff] [blame] | 249 | while (parent->isRenderInline() && lineDepth++ < cMaxLineDepth) { |
| 250 | RenderInline* parentAsRenderInline = toRenderInline(parent); |
hyatt@apple.com | 40232f8 | 2009-02-04 04:26:08 +0000 | [diff] [blame] | 251 | if (start && !child->previousSibling()) |
rniwa@webkit.org | 63db8cb | 2011-04-06 21:08:20 +0000 | [diff] [blame] | 252 | extraWidth += borderPaddingMarginStart(parentAsRenderInline); |
hyatt@apple.com | 40232f8 | 2009-02-04 04:26:08 +0000 | [diff] [blame] | 253 | if (end && !child->nextSibling()) |
rniwa@webkit.org | 63db8cb | 2011-04-06 21:08:20 +0000 | [diff] [blame] | 254 | extraWidth += borderPaddingMarginEnd(parentAsRenderInline); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 255 | child = parent; |
| 256 | parent = child->parent(); |
| 257 | } |
| 258 | return extraWidth; |
| 259 | } |
| 260 | |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 261 | static void determineDirectionality(TextDirection& dir, InlineIterator iter) |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 262 | { |
| 263 | while (!iter.atEnd()) { |
| 264 | if (iter.atParagraphSeparator()) |
| 265 | return; |
| 266 | if (UChar current = iter.current()) { |
| 267 | Direction charDirection = direction(current); |
| 268 | if (charDirection == LeftToRight) { |
| 269 | dir = LTR; |
| 270 | return; |
| 271 | } |
| 272 | if (charDirection == RightToLeft || charDirection == RightToLeftArabic) { |
| 273 | dir = RTL; |
| 274 | return; |
| 275 | } |
| 276 | } |
| 277 | iter.increment(); |
| 278 | } |
| 279 | } |
| 280 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 281 | static void checkMidpoints(LineMidpointState& lineMidpointState, InlineIterator& lBreak) |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 282 | { |
| 283 | // Check to see if our last midpoint is a start point beyond the line break. If so, |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 284 | // shave it off the list, and shave off a trailing space if the previous end point doesn't |
| 285 | // preserve whitespace. |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 286 | if (lBreak.m_obj && lineMidpointState.numMidpoints && !(lineMidpointState.numMidpoints % 2)) { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 287 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 288 | InlineIterator& endpoint = midpoints[lineMidpointState.numMidpoints - 2]; |
| 289 | const InlineIterator& startpoint = midpoints[lineMidpointState.numMidpoints - 1]; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 290 | InlineIterator currpoint = endpoint; |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 291 | while (!currpoint.atEnd() && currpoint != startpoint && currpoint != lBreak) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 292 | currpoint.increment(); |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 293 | if (currpoint == lBreak) { |
| 294 | // We hit the line break before the start point. Shave off the start point. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 295 | lineMidpointState.numMidpoints--; |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 296 | if (endpoint.m_obj->style()->collapseWhiteSpace()) |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 297 | endpoint.m_pos--; |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 298 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 299 | } |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 300 | } |
| 301 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 302 | static void addMidpoint(LineMidpointState& lineMidpointState, const InlineIterator& midpoint) |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 303 | { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 304 | if (lineMidpointState.midpoints.size() <= lineMidpointState.numMidpoints) |
| 305 | lineMidpointState.midpoints.grow(lineMidpointState.numMidpoints + 10); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 306 | |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 307 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 308 | midpoints[lineMidpointState.numMidpoints++] = midpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 309 | } |
| 310 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 311 | static inline BidiRun* createRun(int start, int end, RenderObject* obj, InlineBidiResolver& resolver) |
| 312 | { |
| 313 | return new (obj->renderArena()) BidiRun(start, end, obj, resolver.context(), resolver.dir()); |
| 314 | } |
| 315 | |
| 316 | void RenderBlock::appendRunsForObject(BidiRunList<BidiRun>& runs, int start, int end, RenderObject* obj, InlineBidiResolver& resolver) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 317 | { |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 318 | if (start > end || obj->isFloating() || |
hyatt@apple.com | aa95610 | 2011-04-12 20:31:02 +0000 | [diff] [blame] | 319 | (obj->isPositioned() && !obj->style()->isOriginalDisplayInlineType() && !obj->container()->isRenderInline())) |
hyatt | eb003b8 | 2002-11-15 22:35:10 +0000 | [diff] [blame] | 320 | return; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 321 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 322 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 323 | bool haveNextMidpoint = (lineMidpointState.currentMidpoint < lineMidpointState.numMidpoints); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 324 | InlineIterator nextMidpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 325 | if (haveNextMidpoint) |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 326 | nextMidpoint = lineMidpointState.midpoints[lineMidpointState.currentMidpoint]; |
| 327 | if (lineMidpointState.betweenMidpoints) { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 328 | if (!(haveNextMidpoint && nextMidpoint.m_obj == obj)) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 329 | return; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 330 | // This is a new start point. Stop ignoring objects and |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 331 | // adjust our start. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 332 | lineMidpointState.betweenMidpoints = false; |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 333 | start = nextMidpoint.m_pos; |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 334 | lineMidpointState.currentMidpoint++; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 335 | if (start < end) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 336 | return appendRunsForObject(runs, start, end, obj, resolver); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 337 | } else { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 338 | if (!haveNextMidpoint || (obj != nextMidpoint.m_obj)) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 339 | runs.addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 340 | return; |
| 341 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 342 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 343 | // An end midpoint has been encountered within our object. We |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 344 | // need to go ahead and append a run with our endpoint. |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 345 | if (static_cast<int>(nextMidpoint.m_pos + 1) <= end) { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 346 | lineMidpointState.betweenMidpoints = true; |
| 347 | lineMidpointState.currentMidpoint++; |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 348 | if (nextMidpoint.m_pos != UINT_MAX) { // UINT_MAX means stop at the object and don't include any of it. |
| 349 | if (static_cast<int>(nextMidpoint.m_pos + 1) > start) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 350 | runs.addRun(createRun(start, nextMidpoint.m_pos + 1, obj, resolver)); |
| 351 | return appendRunsForObject(runs, nextMidpoint.m_pos + 1, end, obj, resolver); |
hyatt | c64f9fc | 2003-03-14 01:25:59 +0000 | [diff] [blame] | 352 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 353 | } else |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 354 | runs.addRun(createRun(start, end, obj, resolver)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 358 | static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false) |
| 359 | { |
| 360 | if (isRootLineBox) |
eric@webkit.org | 49b9d95 | 2009-07-03 01:29:07 +0000 | [diff] [blame] | 361 | return toRenderBlock(obj)->createAndAppendRootInlineBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 362 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 363 | if (obj->isText()) { |
| 364 | InlineTextBox* textBox = toRenderText(obj)->createInlineTextBox(); |
| 365 | // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode |
| 366 | // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.) |
| 367 | if (obj->isBR()) |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 368 | textBox->setIsText(isOnlyRun || obj->document()->inNoQuirksMode()); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 369 | return textBox; |
| 370 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 371 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 372 | if (obj->isBox()) |
| 373 | return toRenderBox(obj)->createInlineBox(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 374 | |
eric@webkit.org | 49b9d95 | 2009-07-03 01:29:07 +0000 | [diff] [blame] | 375 | return toRenderInline(obj)->createAndAppendInlineFlowBox(); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static inline void dirtyLineBoxesForRenderer(RenderObject* o, bool fullLayout) |
| 379 | { |
| 380 | if (o->isText()) { |
carol.szabo@nokia.com | eaaf199 | 2011-03-02 19:34:00 +0000 | [diff] [blame] | 381 | if (o->preferredLogicalWidthsDirty() && (o->isCounter() || o->isQuote())) |
hyatt@apple.com | 75dad74 | 2010-09-24 18:07:44 +0000 | [diff] [blame] | 382 | toRenderText(o)->computePreferredLogicalWidths(0); // FIXME: Counters depend on this hack. No clue why. Should be investigated and removed. |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 383 | toRenderText(o)->dirtyLineBoxes(fullLayout); |
| 384 | } else |
| 385 | toRenderInline(o)->dirtyLineBoxes(fullLayout); |
| 386 | } |
| 387 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 388 | static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox) |
| 389 | { |
| 390 | do { |
| 391 | if (parentBox->isConstructed() || parentBox->nextOnLine()) |
| 392 | return true; |
| 393 | parentBox = parentBox->parent(); |
| 394 | } while (parentBox); |
| 395 | return false; |
| 396 | } |
| 397 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 398 | InlineFlowBox* RenderBlock::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 399 | { |
| 400 | // See if we have an unconstructed line box for this object that is also |
| 401 | // the last item on the line. |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 402 | unsigned lineDepth = 1; |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 403 | InlineFlowBox* parentBox = 0; |
| 404 | InlineFlowBox* result = 0; |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 405 | bool hasDefaultLineBoxContain = style()->lineBoxContain() == RenderStyle::initialLineBoxContain(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 406 | do { |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 407 | ASSERT(obj->isRenderInline() || obj == this); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 408 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 409 | RenderInline* inlineFlow = (obj != this) ? toRenderInline(obj) : 0; |
| 410 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 411 | // Get the last box we made for this render object. |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 412 | parentBox = inlineFlow ? inlineFlow->lastLineBox() : toRenderBlock(obj)->lastLineBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 413 | |
xji@chromium.org | b0ad6eb82 | 2011-02-01 20:02:06 +0000 | [diff] [blame] | 414 | // If this box or its ancestor is constructed then it is from a previous line, and we need |
| 415 | // to make a new box for our line. If this box or its ancestor is unconstructed but it has |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 416 | // something following it on the line, then we know we have to make a new box |
| 417 | // as well. In this situation our inline has actually been split in two on |
| 418 | // the same line (this can happen with very fancy language mixtures). |
| 419 | bool constructedNewBox = false; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 420 | bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes(); |
| 421 | bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox); |
| 422 | if (allowedToConstructNewBox && !canUseExistingParentBox) { |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 423 | // We need to make a new box for this render object. Once |
| 424 | // made, we need to place it at the end of the current line. |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 425 | InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 426 | ASSERT(newBox->isInlineFlowBox()); |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 427 | parentBox = toInlineFlowBox(newBox); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 428 | parentBox->setFirstLineStyleBit(lineInfo.isFirstLine()); |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 429 | parentBox->setIsHorizontal(isHorizontalWritingMode()); |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 430 | if (!hasDefaultLineBoxContain) |
| 431 | parentBox->clearDescendantsHaveSameLineHeightAndBaseline(); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 432 | constructedNewBox = true; |
| 433 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 434 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 435 | if (constructedNewBox || canUseExistingParentBox) { |
| 436 | if (!result) |
| 437 | result = parentBox; |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 438 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 439 | // If we have hit the block itself, then |box| represents the root |
| 440 | // inline box for the line, and it doesn't have to be appended to any parent |
| 441 | // inline. |
| 442 | if (childBox) |
| 443 | parentBox->addToLine(childBox); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 444 | |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 445 | if (!constructedNewBox || obj == this) |
| 446 | break; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 447 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 448 | childBox = parentBox; |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 449 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 450 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 451 | // If we've exceeded our line depth, then jump straight to the root and skip all the remaining |
| 452 | // intermediate inline flows. |
| 453 | obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 454 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 455 | } while (true); |
| 456 | |
| 457 | return result; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 458 | } |
| 459 | |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 460 | static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 461 | { |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 462 | BidiRun* run = bidiRuns.logicallyLastRun(); |
| 463 | if (!run) |
| 464 | return true; |
| 465 | unsigned int pos = run->stop(); |
| 466 | RenderObject* r = run->m_object; |
| 467 | if (!r->isText() || r->isBR()) |
| 468 | return false; |
| 469 | RenderText* renderText = toRenderText(r); |
| 470 | if (pos >= renderText->textLength()) |
| 471 | return true; |
| 472 | |
| 473 | while (isASCIISpace(renderText->characters()[pos])) { |
| 474 | pos++; |
| 475 | if (pos >= renderText->textLength()) |
| 476 | return true; |
| 477 | } |
| 478 | return false; |
| 479 | } |
| 480 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 481 | RootInlineBox* RenderBlock::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 482 | { |
| 483 | ASSERT(bidiRuns.firstRun()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 484 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 485 | bool rootHasSelectedChildren = false; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 486 | InlineFlowBox* parentBox = 0; |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 487 | int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace(); |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 488 | for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 489 | // Create a box for our object. |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 490 | bool isOnlyRun = (runCount == 1); |
| 491 | if (runCount == 2 && !r->m_object->isListMarker()) |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 492 | isOnlyRun = (!style()->isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->m_object->isListMarker(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 493 | |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame^] | 494 | if (lineInfo.isEmpty()) |
| 495 | continue; |
| 496 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 497 | InlineBox* box = createInlineBoxForRenderer(r->m_object, false, isOnlyRun); |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 498 | r->m_box = box; |
| 499 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 500 | ASSERT(box); |
| 501 | if (!box) |
| 502 | continue; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 503 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 504 | if (!rootHasSelectedChildren && box->renderer()->selectionState() != RenderObject::SelectionNone) |
| 505 | rootHasSelectedChildren = true; |
| 506 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 507 | // If we have no parent box yet, or if the run is not simply a sibling, |
| 508 | // then we need to construct inline boxes as necessary to properly enclose the |
| 509 | // run's inline box. |
| 510 | if (!parentBox || parentBox->renderer() != r->m_object->parent()) |
| 511 | // Create new inline boxes all the way back to the appropriate insertion point. |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 512 | parentBox = createLineBoxes(r->m_object->parent(), lineInfo, box); |
hyatt@apple.com | 7d4066a | 2011-03-29 17:56:09 +0000 | [diff] [blame] | 513 | else { |
| 514 | // Append the inline box to this line. |
| 515 | parentBox->addToLine(box); |
| 516 | } |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 517 | |
macpherson@chromium.org | 258babf | 2011-06-10 06:20:58 +0000 | [diff] [blame] | 518 | bool visuallyOrdered = r->m_object->style()->rtlOrdering() == VisualOrder; |
xji@chromium.org | 6b0c017 | 2011-02-14 19:21:12 +0000 | [diff] [blame] | 519 | box->setBidiLevel(r->level()); |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 520 | |
| 521 | if (box->isInlineTextBox()) { |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 522 | InlineTextBox* text = toInlineTextBox(box); |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 523 | text->setStart(r->m_start); |
| 524 | text->setLen(r->m_stop - r->m_start); |
| 525 | text->m_dirOverride = r->dirOverride(visuallyOrdered); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 526 | if (r->m_hasHyphen) |
| 527 | text->setHasHyphen(true); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 528 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | // We should have a root inline box. It should be unconstructed and |
| 532 | // be the last continuation of our line list. |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 533 | ASSERT(lastLineBox() && !lastLineBox()->isConstructed()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 534 | |
inferno@chromium.org | e29694f | 2010-10-07 22:00:02 +0000 | [diff] [blame] | 535 | // Set the m_selectedChildren flag on the root inline box if one of the leaf inline box |
| 536 | // from the bidi runs walk above has a selection state. |
| 537 | if (rootHasSelectedChildren) |
| 538 | lastLineBox()->root()->setHasSelectedChildren(true); |
| 539 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 540 | // Set bits on our inline flow boxes that indicate which sides should |
| 541 | // paint borders/margins/padding. This knowledge will ultimately be used when |
| 542 | // we determine the horizontal positions and widths of all the inline boxes on |
| 543 | // the line. |
yael.aharon@nokia.com | 15c605d | 2011-04-14 05:35:54 +0000 | [diff] [blame] | 544 | bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->m_object && bidiRuns.logicallyLastRun()->m_object->isText() ? !reachedEndOfTextRenderer(bidiRuns) : true; |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 545 | lastLineBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, bidiRuns.logicallyLastRun()->m_object); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 546 | |
| 547 | // Now mark the line boxes as being constructed. |
| 548 | lastLineBox()->setConstructed(); |
| 549 | |
| 550 | // Return the last line. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 551 | return lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 552 | } |
| 553 | |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 554 | ETextAlign RenderBlock::textAlignmentForLine(bool endsWithSoftBreak) const |
| 555 | { |
| 556 | ETextAlign alignment = style()->textAlign(); |
| 557 | if (!endsWithSoftBreak && alignment == JUSTIFY) |
| 558 | alignment = TAAUTO; |
| 559 | |
| 560 | return alignment; |
| 561 | } |
| 562 | |
rniwa@webkit.org | cda6dbd | 2011-03-28 09:19:50 +0000 | [diff] [blame] | 563 | static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 564 | { |
| 565 | // The direction of the block should determine what happens with wide lines. |
| 566 | // In particular with RTL blocks, wide lines should still spill out to the left. |
| 567 | if (isLeftToRightDirection) { |
| 568 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) |
| 569 | trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); |
| 570 | return; |
| 571 | } |
| 572 | |
| 573 | if (trailingSpaceRun) |
| 574 | trailingSpaceRun->m_box->setLogicalWidth(0); |
| 575 | else if (totalLogicalWidth > availableLogicalWidth) |
| 576 | logicalLeft -= (totalLogicalWidth - availableLogicalWidth); |
| 577 | } |
| 578 | |
| 579 | static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 580 | { |
| 581 | // Wide lines spill out of the block based off direction. |
| 582 | // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right |
| 583 | // side of the block. |
| 584 | if (isLeftToRightDirection) { |
| 585 | if (trailingSpaceRun) { |
| 586 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 587 | trailingSpaceRun->m_box->setLogicalWidth(0); |
| 588 | } |
| 589 | if (totalLogicalWidth < availableLogicalWidth) |
| 590 | logicalLeft += availableLogicalWidth - totalLogicalWidth; |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) { |
| 595 | trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); |
| 596 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 597 | } else |
| 598 | logicalLeft += availableLogicalWidth - totalLogicalWidth; |
| 599 | } |
| 600 | |
| 601 | static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth) |
| 602 | { |
| 603 | float trailingSpaceWidth = 0; |
| 604 | if (trailingSpaceRun) { |
| 605 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 606 | trailingSpaceWidth = min(trailingSpaceRun->m_box->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2); |
| 607 | trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceWidth)); |
| 608 | } |
| 609 | if (isLeftToRightDirection) |
| 610 | logicalLeft += max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0); |
| 611 | else |
| 612 | logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth; |
| 613 | } |
| 614 | |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 615 | void RenderBlock::setMarginsForRubyRun(BidiRun* run, RenderRubyRun* renderer, RenderObject* previousObject, const LineInfo& lineInfo) |
| 616 | { |
| 617 | int startOverhang; |
| 618 | int endOverhang; |
| 619 | RenderObject* nextObject = 0; |
| 620 | for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) { |
| 621 | if (!runWithNextObject->m_object->isPositioned() && !runWithNextObject->m_box->isLineBreak()) { |
| 622 | nextObject = runWithNextObject->m_object; |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | renderer->getOverhang(lineInfo.isFirstLine(), renderer->style()->isLeftToRightDirection() ? previousObject : nextObject, renderer->style()->isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang); |
| 627 | setMarginStartForChild(renderer, -startOverhang); |
| 628 | setMarginEndForChild(renderer, -endOverhang); |
| 629 | } |
| 630 | |
commit-queue@webkit.org | e60bb90 | 2011-09-08 19:18:43 +0000 | [diff] [blame] | 631 | static inline float measureHyphenWidth(RenderText* renderer, const Font& font) |
| 632 | { |
| 633 | RenderStyle* style = renderer->style(); |
| 634 | return font.width(RenderBlock::constructTextRun(renderer, font, style->hyphenString().string(), style)); |
| 635 | } |
| 636 | |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 637 | static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo, |
| 638 | GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache) |
| 639 | { |
| 640 | HashSet<const SimpleFontData*> fallbackFonts; |
| 641 | GlyphOverflow glyphOverflow; |
| 642 | |
| 643 | // Always compute glyph overflow if the block's line-box-contain value is "glyphs". |
| 644 | if (lineBox->fitsToGlyphs()) { |
| 645 | // If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization |
| 646 | // will keep us from computing glyph bounds in nearly all cases. |
| 647 | bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading(); |
| 648 | int baselineShift = lineBox->verticalPositionForBox(run->m_box, verticalPositionCache); |
| 649 | int rootDescent = includeRootLine ? lineBox->renderer()->style(lineInfo.isFirstLine())->font().fontMetrics().descent() : 0; |
| 650 | int rootAscent = includeRootLine ? lineBox->renderer()->style(lineInfo.isFirstLine())->font().fontMetrics().ascent() : 0; |
| 651 | int boxAscent = renderer->style(lineInfo.isFirstLine())->font().fontMetrics().ascent() - baselineShift; |
| 652 | int boxDescent = renderer->style(lineInfo.isFirstLine())->font().fontMetrics().descent() + baselineShift; |
| 653 | if (boxAscent > rootDescent || boxDescent > rootAscent) |
| 654 | glyphOverflow.computeBounds = true; |
| 655 | } |
| 656 | |
| 657 | int hyphenWidth = 0; |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 658 | if (toInlineTextBox(run->m_box)->hasHyphen()) { |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 659 | const Font& font = renderer->style(lineInfo.isFirstLine())->font(); |
commit-queue@webkit.org | e60bb90 | 2011-09-08 19:18:43 +0000 | [diff] [blame] | 660 | hyphenWidth = measureHyphenWidth(renderer, font); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 661 | } |
| 662 | run->m_box->setLogicalWidth(renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow) + hyphenWidth); |
| 663 | if (!fallbackFonts.isEmpty()) { |
| 664 | ASSERT(run->m_box->isText()); |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 665 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 666 | ASSERT(it->second.first.isEmpty()); |
| 667 | copyToVector(fallbackFonts, it->second.first); |
| 668 | run->m_box->parent()->clearDescendantsHaveSameLineHeightAndBaseline(); |
| 669 | } |
| 670 | if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) { |
| 671 | ASSERT(run->m_box->isText()); |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 672 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(toInlineTextBox(run->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 673 | it->second.second = glyphOverflow; |
| 674 | run->m_box->clearKnownToHaveNoOverflow(); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | static inline void computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth) |
| 679 | { |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 680 | if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth) |
| 681 | return; |
| 682 | |
| 683 | size_t i = 0; |
| 684 | for (BidiRun* r = firstRun; r; r = r->next()) { |
| 685 | if (!r->m_box || r == trailingSpaceRun) |
| 686 | continue; |
| 687 | |
| 688 | if (r->m_object->isText()) { |
| 689 | unsigned opportunitiesInRun = expansionOpportunities[i++]; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 690 | |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 691 | ASSERT(opportunitiesInRun <= expansionOpportunityCount); |
| 692 | |
| 693 | // Only justify text if whitespace is collapsed. |
| 694 | if (r->m_object->style()->collapseWhiteSpace()) { |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 695 | InlineTextBox* textBox = toInlineTextBox(r->m_box); |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 696 | int expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount; |
| 697 | textBox->setExpansion(expansion); |
| 698 | totalLogicalWidth += expansion; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 699 | } |
mitz@apple.com | c7a1a51 | 2011-05-08 16:27:31 +0000 | [diff] [blame] | 700 | expansionOpportunityCount -= opportunitiesInRun; |
| 701 | if (!expansionOpportunityCount) |
| 702 | break; |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 707 | void RenderBlock::updateLogicalWidthForAlignment(const ETextAlign& textAlign, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount) |
| 708 | { |
| 709 | // Armed with the total width of the line (without justification), |
| 710 | // we now examine our text-align property in order to determine where to position the |
| 711 | // objects horizontally. The total width of the line can be increased if we end up |
| 712 | // justifying text. |
| 713 | switch (textAlign) { |
| 714 | case LEFT: |
| 715 | case WEBKIT_LEFT: |
| 716 | updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 717 | break; |
| 718 | case JUSTIFY: |
| 719 | adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth); |
| 720 | if (expansionOpportunityCount) { |
| 721 | if (trailingSpaceRun) { |
| 722 | totalLogicalWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 723 | trailingSpaceRun->m_box->setLogicalWidth(0); |
| 724 | } |
| 725 | break; |
| 726 | } |
| 727 | // fall through |
| 728 | case TAAUTO: |
| 729 | // for right to left fall through to right aligned |
| 730 | if (style()->isLeftToRightDirection()) { |
| 731 | if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) |
| 732 | trailingSpaceRun->m_box->setLogicalWidth(max<float>(0, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth)); |
| 733 | break; |
| 734 | } |
| 735 | case RIGHT: |
| 736 | case WEBKIT_RIGHT: |
| 737 | updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 738 | break; |
| 739 | case CENTER: |
| 740 | case WEBKIT_CENTER: |
| 741 | updateLogicalWidthForCenterAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 742 | break; |
| 743 | case TASTART: |
| 744 | if (style()->isLeftToRightDirection()) |
| 745 | updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 746 | else |
| 747 | updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 748 | break; |
| 749 | case TAEND: |
| 750 | if (style()->isLeftToRightDirection()) |
| 751 | updateLogicalWidthForRightAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 752 | else |
| 753 | updateLogicalWidthForLeftAlignedBlock(style()->isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth); |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 758 | void RenderBlock::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, |
hyatt@apple.com | 9bcbad6 | 2011-03-22 19:03:50 +0000 | [diff] [blame] | 759 | GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 760 | { |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 761 | ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak()); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 762 | float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), lineInfo.isFirstLine()); |
| 763 | float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), lineInfo.isFirstLine()) - logicalLeft; |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 764 | |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 765 | bool needsWordSpacing = false; |
mitz@apple.com | 390fa32 | 2011-02-24 23:07:06 +0000 | [diff] [blame] | 766 | float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth(); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 767 | unsigned expansionOpportunityCount = 0; |
| 768 | bool isAfterExpansion = true; |
| 769 | Vector<unsigned, 16> expansionOpportunities; |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 770 | RenderObject* previousObject = 0; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 771 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 772 | for (BidiRun* r = firstRun; r; r = r->next()) { |
| 773 | if (!r->m_box || r->m_object->isPositioned() || r->m_box->isLineBreak()) |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 774 | continue; // Positioned objects are only participating to figure out their |
| 775 | // correct static x position. They have no effect on the width. |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 776 | // Similarly, line break boxes have no effect on the width. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 777 | if (r->m_object->isText()) { |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 778 | RenderText* rt = toRenderText(r->m_object); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 779 | if (textAlign == JUSTIFY && r != trailingSpaceRun) { |
mitz@apple.com | 8096893 | 2011-03-26 00:46:26 +0000 | [diff] [blame] | 780 | if (!isAfterExpansion) |
jchaffraix@webkit.org | 8f1781d | 2011-06-24 21:22:54 +0000 | [diff] [blame] | 781 | toInlineTextBox(r->m_box)->setCanHaveLeadingExpansion(true); |
mitz@apple.com | 1b0578d | 2011-01-27 08:23:31 +0000 | [diff] [blame] | 782 | unsigned opportunitiesInRun = Font::expansionOpportunityCount(rt->characters() + r->m_start, r->m_stop - r->m_start, r->m_box->direction(), isAfterExpansion); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 783 | expansionOpportunities.append(opportunitiesInRun); |
| 784 | expansionOpportunityCount += opportunitiesInRun; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 785 | } |
| 786 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 787 | if (int length = rt->textLength()) { |
hyatt@apple.com | d0301a5 | 2009-01-26 21:50:57 +0000 | [diff] [blame] | 788 | if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt->characters()[r->m_start])) |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 789 | totalLogicalWidth += rt->style(lineInfo.isFirstLine())->font().wordSpacing(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 790 | needsWordSpacing = !isSpaceOrNewline(rt->characters()[r->m_stop - 1]) && r->m_stop == length; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 791 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 792 | |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 793 | setLogicalWidthForTextRun(lineBox, r, rt, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 794 | } else { |
| 795 | isAfterExpansion = false; |
| 796 | if (!r->m_object->isRenderInline()) { |
| 797 | RenderBox* renderBox = toRenderBox(r->m_object); |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 798 | if (renderBox->isRubyRun()) |
| 799 | setMarginsForRubyRun(r, toRenderRubyRun(renderBox), previousObject, lineInfo); |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 800 | r->m_box->setLogicalWidth(logicalWidthForChild(renderBox)); |
| 801 | totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox); |
| 802 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 803 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 804 | |
hyatt@apple.com | 546a248 | 2010-10-07 21:16:49 +0000 | [diff] [blame] | 805 | totalLogicalWidth += r->m_box->logicalWidth(); |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 806 | previousObject = r->m_object; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 807 | } |
| 808 | |
mitz@apple.com | 86470c8 | 2011-01-27 01:39:27 +0000 | [diff] [blame] | 809 | if (isAfterExpansion && !expansionOpportunities.isEmpty()) { |
| 810 | expansionOpportunities.last()--; |
| 811 | expansionOpportunityCount--; |
| 812 | } |
| 813 | |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 814 | updateLogicalWidthForAlignment(textAlign, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 815 | |
leviw@chromium.org | d70a007 | 2011-05-03 23:28:11 +0000 | [diff] [blame] | 816 | computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 817 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 818 | // The widths of all runs are now known. We can now place every inline box (and |
| 819 | // compute accurate widths for the inline flow boxes). |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 820 | needsWordSpacing = false; |
hyatt@apple.com | 546a248 | 2010-10-07 21:16:49 +0000 | [diff] [blame] | 821 | lineBox->placeBoxesInInlineDirection(logicalLeft, needsWordSpacing, textBoxDataMap); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 822 | } |
| 823 | |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 824 | void RenderBlock::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, |
| 825 | VerticalPositionCache& verticalPositionCache) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 826 | { |
hyatt@apple.com | 4a9c625a | 2010-11-17 20:55:40 +0000 | [diff] [blame] | 827 | setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache)); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 828 | |
| 829 | // Now make sure we place replaced render objects correctly. |
mitz@apple.com | 887f359 | 2008-02-25 22:03:08 +0000 | [diff] [blame] | 830 | for (BidiRun* r = firstRun; r; r = r->next()) { |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 831 | ASSERT(r->m_box); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 832 | if (!r->m_box) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 833 | continue; // Skip runs with no line boxes. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 834 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 835 | // Align positioned boxes with the top of the line box. This is |
| 836 | // a reasonable approximation of an appropriate y position. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 837 | if (r->m_object->isPositioned()) |
hyatt@apple.com | 35d2ad5 | 2010-10-20 18:17:36 +0000 | [diff] [blame] | 838 | r->m_box->setLogicalTop(logicalHeight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 839 | |
| 840 | // Position is used to properly position both replaced elements and |
| 841 | // to update the static normal flow x/y of positioned elements. |
hyatt@apple.com | 6a551ad | 2009-02-11 22:43:12 +0000 | [diff] [blame] | 842 | if (r->m_object->isText()) |
| 843 | toRenderText(r->m_object)->positionLineBox(r->m_box); |
| 844 | else if (r->m_object->isBox()) |
| 845 | toRenderBox(r->m_object)->positionLineBox(r->m_box); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 846 | } |
mitz@apple.com | a927be6 | 2008-03-21 05:30:19 +0000 | [diff] [blame] | 847 | // Positioned objects and zero-length text nodes destroy their boxes in |
| 848 | // position(), which unnecessarily dirties the line. |
| 849 | lineBox->markDirty(false); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 850 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 851 | |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 852 | static inline bool isCollapsibleSpace(UChar character, RenderText* renderer) |
| 853 | { |
| 854 | if (character == ' ' || character == '\t' || character == softHyphen) |
| 855 | return true; |
| 856 | if (character == '\n') |
| 857 | return !renderer->style()->preserveNewline(); |
| 858 | if (character == noBreakSpace) |
| 859 | return renderer->style()->nbspMode() == SPACE; |
| 860 | return false; |
| 861 | } |
| 862 | |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 863 | |
| 864 | static void setStaticPositions(RenderBlock* block, RenderBox* child) |
| 865 | { |
| 866 | // FIXME: The math here is actually not really right. It's a best-guess approximation that |
| 867 | // will work for the common cases |
| 868 | RenderObject* containerBlock = child->container(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 869 | LayoutUnit blockHeight = block->logicalHeight(); |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 870 | if (containerBlock->isRenderInline()) { |
| 871 | // A relative positioned inline encloses us. In this case, we also have to determine our |
| 872 | // position as though we were an inline. Set |staticInlinePosition| and |staticBlockPosition| on the relative positioned |
| 873 | // inline so that we can obtain the value later. |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 874 | toRenderInline(containerBlock)->layer()->setStaticInlinePosition(block->startAlignedOffsetForLine(child, blockHeight, false)); |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 875 | toRenderInline(containerBlock)->layer()->setStaticBlockPosition(blockHeight); |
| 876 | } |
| 877 | |
| 878 | if (child->style()->isOriginalDisplayInlineType()) |
hyatt@apple.com | a5cac3f | 2011-10-12 18:51:17 +0000 | [diff] [blame] | 879 | block->setStaticInlinePositionForChild(child, blockHeight, block->startAlignedOffsetForLine(child, blockHeight, false)); |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 880 | else |
hyatt@apple.com | a5cac3f | 2011-10-12 18:51:17 +0000 | [diff] [blame] | 881 | block->setStaticInlinePositionForChild(child, blockHeight, block->startOffsetForContent(blockHeight)); |
hyatt@apple.com | 14e332d | 2011-03-25 21:57:07 +0000 | [diff] [blame] | 882 | child->layer()->setStaticBlockPosition(blockHeight); |
| 883 | } |
| 884 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 885 | inline BidiRun* RenderBlock::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext) |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 886 | { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 887 | if (!bidiRuns.runCount() |
| 888 | || !bidiRuns.logicallyLastRun()->m_object->style()->breakOnlyAfterWhiteSpace() |
| 889 | || !bidiRuns.logicallyLastRun()->m_object->style()->autoWrap()) |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 890 | return 0; |
| 891 | |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 892 | BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun(); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 893 | RenderObject* lastObject = trailingSpaceRun->m_object; |
| 894 | if (!lastObject->isText()) |
| 895 | return 0; |
| 896 | |
| 897 | RenderText* lastText = toRenderText(lastObject); |
| 898 | const UChar* characters = lastText->characters(); |
| 899 | int firstSpace = trailingSpaceRun->stop(); |
| 900 | while (firstSpace > trailingSpaceRun->start()) { |
| 901 | UChar current = characters[firstSpace - 1]; |
| 902 | if (!isCollapsibleSpace(current, lastText)) |
| 903 | break; |
| 904 | firstSpace--; |
| 905 | } |
| 906 | if (firstSpace == trailingSpaceRun->stop()) |
| 907 | return 0; |
| 908 | |
| 909 | TextDirection direction = style()->direction(); |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 910 | bool shouldReorder = trailingSpaceRun != (direction == LTR ? bidiRuns.lastRun() : bidiRuns.firstRun()); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 911 | if (firstSpace != trailingSpaceRun->start()) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 912 | BidiContext* baseContext = currentContext; |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 913 | while (BidiContext* parent = baseContext->parent()) |
| 914 | baseContext = parent; |
| 915 | |
| 916 | BidiRun* newTrailingRun = new (renderArena()) BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->m_object, baseContext, OtherNeutral); |
| 917 | trailingSpaceRun->m_stop = firstSpace; |
| 918 | if (direction == LTR) |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 919 | bidiRuns.addRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 920 | else |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 921 | bidiRuns.prependRun(newTrailingRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 922 | trailingSpaceRun = newTrailingRun; |
| 923 | return trailingSpaceRun; |
| 924 | } |
| 925 | if (!shouldReorder) |
| 926 | return trailingSpaceRun; |
| 927 | |
| 928 | if (direction == LTR) { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 929 | bidiRuns.moveRunToEnd(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 930 | trailingSpaceRun->m_level = 0; |
| 931 | } else { |
eric@webkit.org | 5bee294 | 2011-04-08 02:12:31 +0000 | [diff] [blame] | 932 | bidiRuns.moveRunToBeginning(trailingSpaceRun); |
eric@webkit.org | 0894bb8 | 2011-04-03 08:29:40 +0000 | [diff] [blame] | 933 | trailingSpaceRun->m_level = 1; |
| 934 | } |
| 935 | return trailingSpaceRun; |
| 936 | } |
| 937 | |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 938 | void RenderBlock::appendFloatingObjectToLastLine(FloatingObject* floatingObject) |
| 939 | { |
mitz@apple.com | 0c4ce9f | 2011-05-04 02:20:02 +0000 | [diff] [blame] | 940 | ASSERT(!floatingObject->m_originatingLine); |
| 941 | floatingObject->m_originatingLine = lastRootBox(); |
mitz@apple.com | d17e8c0 | 2011-04-16 21:59:36 +0000 | [diff] [blame] | 942 | lastRootBox()->appendFloat(floatingObject->renderer()); |
| 943 | } |
| 944 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 945 | // FIXME: This should be a BidiStatus constructor or create method. |
| 946 | static inline BidiStatus statusWithDirection(TextDirection textDirection) |
| 947 | { |
| 948 | WTF::Unicode::Direction direction = textDirection == LTR ? LeftToRight : RightToLeft; |
| 949 | RefPtr<BidiContext> context = BidiContext::create(textDirection == LTR ? 0 : 1, direction, false, FromStyleOrDOM); |
| 950 | |
| 951 | // This copies BidiStatus and may churn the ref on BidiContext. I doubt it matters. |
| 952 | return BidiStatus(direction, direction, direction, context.release()); |
| 953 | } |
| 954 | |
| 955 | // FIXME: BidiResolver should have this logic. |
| 956 | static inline void constructBidiRuns(InlineBidiResolver& topResolver, BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine, VisualDirectionOverride override, bool previousLineBrokeCleanly) |
| 957 | { |
| 958 | // FIXME: We should pass a BidiRunList into createBidiRunsForLine instead |
| 959 | // of the resolver owning the runs. |
| 960 | ASSERT(&topResolver.runs() == &bidiRuns); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 961 | RenderObject* currentRoot = topResolver.position().root(); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 962 | topResolver.createBidiRunsForLine(endOfLine, override, previousLineBrokeCleanly); |
| 963 | |
| 964 | while (!topResolver.isolatedRuns().isEmpty()) { |
| 965 | // It does not matter which order we resolve the runs as long as we resolve them all. |
| 966 | BidiRun* isolatedRun = topResolver.isolatedRuns().last(); |
| 967 | topResolver.isolatedRuns().removeLast(); |
| 968 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 969 | RenderObject* startObj = isolatedRun->object(); |
| 970 | |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 971 | // Only inlines make sense with unicode-bidi: isolate (blocks are already isolated). |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 972 | // FIXME: Because enterIsolate is not passed a RenderObject, we have to crawl up the |
| 973 | // tree to see which parent inline is the isolate. We could change enterIsolate |
| 974 | // to take a RenderObject and do this logic there, but that would be a layering |
| 975 | // violation for BidiResolver (which knows nothing about RenderObject). |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 976 | RenderInline* isolatedInline = toRenderInline(containingIsolate(startObj, currentRoot)); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 977 | InlineBidiResolver isolatedResolver; |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 978 | EUnicodeBidi unicodeBidi = isolatedInline->style()->unicodeBidi(); |
| 979 | TextDirection direction; |
| 980 | if (unicodeBidi == Plaintext) |
| 981 | determineDirectionality(direction, InlineIterator(isolatedInline, isolatedRun->object(), 0)); |
| 982 | else { |
| 983 | ASSERT(unicodeBidi == Isolate); |
| 984 | direction = isolatedInline->style()->direction(); |
| 985 | } |
| 986 | isolatedResolver.setStatus(statusWithDirection(direction)); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 987 | |
| 988 | // FIXME: The fact that we have to construct an Iterator here |
| 989 | // currently prevents this code from moving into BidiResolver. |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 990 | if (!bidiFirstSkippingEmptyInlines(isolatedInline, &isolatedResolver)) |
rniwa@webkit.org | 2343fab | 2011-11-25 20:21:06 +0000 | [diff] [blame] | 991 | continue; |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 992 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 993 | // The starting position is the beginning of the first run within the isolate that was identified |
| 994 | // during the earlier call to createBidiRunsForLine. This can be but is not necessarily the |
| 995 | // first run within the isolate. |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 996 | InlineIterator iter = InlineIterator(isolatedInline, startObj, isolatedRun->m_start); |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 997 | isolatedResolver.setPositionIgnoringNestedIsolates(iter); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 998 | |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 999 | // We stop at the next end of line; we may re-enter this isolate in the next call to constructBidiRuns(). |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1000 | // FIXME: What should end and previousLineBrokeCleanly be? |
| 1001 | // rniwa says previousLineBrokeCleanly is just a WinIE hack and could always be false here? |
commit-queue@webkit.org | 30cc291 | 2011-12-15 04:19:24 +0000 | [diff] [blame] | 1002 | isolatedResolver.createBidiRunsForLine(endOfLine, NoVisualOverride, previousLineBrokeCleanly); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1003 | // Note that we do not delete the runs from the resolver. |
| 1004 | bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs()); |
| 1005 | |
| 1006 | // If we encountered any nested isolate runs, just move them |
| 1007 | // to the top resolver's list for later processing. |
| 1008 | if (!isolatedResolver.isolatedRuns().isEmpty()) { |
| 1009 | topResolver.isolatedRuns().append(isolatedResolver.isolatedRuns()); |
| 1010 | isolatedResolver.isolatedRuns().clear(); |
| 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1015 | // This function constructs line boxes for all of the text runs in the resolver and computes their position. |
| 1016 | RootInlineBox* RenderBlock::createLineBoxesFromBidiRuns(BidiRunList<BidiRun>& bidiRuns, const InlineIterator& end, LineInfo& lineInfo, VerticalPositionCache& verticalPositionCache, BidiRun* trailingSpaceRun) |
| 1017 | { |
| 1018 | if (!bidiRuns.runCount()) |
| 1019 | return 0; |
| 1020 | |
| 1021 | // FIXME: Why is this only done when we had runs? |
| 1022 | lineInfo.setLastLine(!end.m_obj); |
| 1023 | |
| 1024 | RootInlineBox* lineBox = constructLine(bidiRuns, lineInfo); |
| 1025 | if (!lineBox) |
| 1026 | return 0; |
| 1027 | |
| 1028 | lineBox->setEndsWithBreak(lineInfo.previousLineBrokeCleanly()); |
| 1029 | |
| 1030 | #if ENABLE(SVG) |
| 1031 | bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox(); |
| 1032 | #else |
| 1033 | bool isSVGRootInlineBox = false; |
| 1034 | #endif |
| 1035 | |
| 1036 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1037 | |
| 1038 | // Now we position all of our text runs horizontally. |
| 1039 | if (!isSVGRootInlineBox) |
| 1040 | computeInlineDirectionPositionsForLine(lineBox, lineInfo, bidiRuns.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap, verticalPositionCache); |
| 1041 | |
| 1042 | // Now position our text runs vertically. |
| 1043 | computeBlockDirectionPositionsForLine(lineBox, bidiRuns.firstRun(), textBoxDataMap, verticalPositionCache); |
| 1044 | |
| 1045 | #if ENABLE(SVG) |
| 1046 | // SVG text layout code computes vertical & horizontal positions on its own. |
| 1047 | // Note that we still need to execute computeVerticalPositionsForLine() as |
| 1048 | // it calls InlineTextBox::positionLineBox(), which tracks whether the box |
| 1049 | // contains reversed text or not. If we wouldn't do that editing and thus |
| 1050 | // text selection in RTL boxes would not work as expected. |
| 1051 | if (isSVGRootInlineBox) { |
| 1052 | ASSERT(isSVGText()); |
| 1053 | static_cast<SVGRootInlineBox*>(lineBox)->computePerCharacterLayoutInformation(); |
| 1054 | } |
| 1055 | #endif |
| 1056 | |
| 1057 | // Compute our overflow now. |
| 1058 | lineBox->computeOverflow(lineBox->lineTop(), lineBox->lineBottom(), textBoxDataMap); |
| 1059 | |
| 1060 | #if PLATFORM(MAC) |
| 1061 | // Highlight acts as an overflow inflation. |
| 1062 | if (style()->highlight() != nullAtom) |
| 1063 | lineBox->addHighlightOverflow(); |
| 1064 | #endif |
| 1065 | return lineBox; |
| 1066 | } |
| 1067 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1068 | // Like LayoutState for layout(), LineLayoutState keeps track of global information |
| 1069 | // during an entire linebox tree layout pass (aka layoutInlineChildren). |
| 1070 | class LineLayoutState { |
| 1071 | public: |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1072 | LineLayoutState(bool fullLayout, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1073 | : m_lastFloat(0) |
| 1074 | , m_endLine(0) |
| 1075 | , m_floatIndex(0) |
| 1076 | , m_endLineLogicalTop(0) |
| 1077 | , m_endLineMatched(false) |
| 1078 | , m_checkForFloatsFromLastLine(false) |
| 1079 | , m_isFullLayout(fullLayout) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1080 | , m_repaintLogicalTop(repaintLogicalTop) |
| 1081 | , m_repaintLogicalBottom(repaintLogicalBottom) |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1082 | , m_usesRepaintBounds(false) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1083 | { } |
| 1084 | |
| 1085 | void markForFullLayout() { m_isFullLayout = true; } |
| 1086 | bool isFullLayout() const { return m_isFullLayout; } |
| 1087 | |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1088 | bool usesRepaintBounds() const { return m_usesRepaintBounds; } |
| 1089 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1090 | void setRepaintRange(LayoutUnit logicalHeight) |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1091 | { |
| 1092 | m_usesRepaintBounds = true; |
| 1093 | m_repaintLogicalTop = m_repaintLogicalBottom = logicalHeight; |
| 1094 | } |
| 1095 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1096 | void updateRepaintRangeFromBox(RootInlineBox* box, LayoutUnit paginationDelta = 0) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1097 | { |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1098 | m_usesRepaintBounds = true; |
leviw@chromium.org | 6ff37a9 | 2012-02-16 04:49:03 +0000 | [diff] [blame] | 1099 | m_repaintLogicalTop = min(m_repaintLogicalTop, box->logicalTopVisualOverflow() + min(paginationDelta, zeroLayoutUnit)); |
| 1100 | m_repaintLogicalBottom = max(m_repaintLogicalBottom, box->logicalBottomVisualOverflow() + max(paginationDelta, zeroLayoutUnit)); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1101 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1102 | |
| 1103 | bool endLineMatched() const { return m_endLineMatched; } |
| 1104 | void setEndLineMatched(bool endLineMatched) { m_endLineMatched = endLineMatched; } |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1105 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1106 | bool checkForFloatsFromLastLine() const { return m_checkForFloatsFromLastLine; } |
| 1107 | void setCheckForFloatsFromLastLine(bool check) { m_checkForFloatsFromLastLine = check; } |
| 1108 | |
| 1109 | LineInfo& lineInfo() { return m_lineInfo; } |
| 1110 | const LineInfo& lineInfo() const { return m_lineInfo; } |
| 1111 | |
| 1112 | int endLineLogicalTop() const { return m_endLineLogicalTop; } |
| 1113 | void setEndLineLogicalTop(int logicalTop) { m_endLineLogicalTop = logicalTop; } |
| 1114 | |
| 1115 | RootInlineBox* endLine() const { return m_endLine; } |
| 1116 | void setEndLine(RootInlineBox* line) { m_endLine = line; } |
| 1117 | |
| 1118 | RenderBlock::FloatingObject* lastFloat() const { return m_lastFloat; } |
| 1119 | void setLastFloat(RenderBlock::FloatingObject* lastFloat) { m_lastFloat = lastFloat; } |
| 1120 | |
| 1121 | Vector<RenderBlock::FloatWithRect>& floats() { return m_floats; } |
| 1122 | |
| 1123 | unsigned floatIndex() const { return m_floatIndex; } |
| 1124 | void setFloatIndex(unsigned floatIndex) { m_floatIndex = floatIndex; } |
| 1125 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1126 | private: |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1127 | Vector<RenderBlock::FloatWithRect> m_floats; |
| 1128 | RenderBlock::FloatingObject* m_lastFloat; |
| 1129 | RootInlineBox* m_endLine; |
| 1130 | LineInfo m_lineInfo; |
| 1131 | unsigned m_floatIndex; |
| 1132 | int m_endLineLogicalTop; |
| 1133 | bool m_endLineMatched; |
| 1134 | bool m_checkForFloatsFromLastLine; |
| 1135 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1136 | bool m_isFullLayout; |
| 1137 | |
| 1138 | // FIXME: Should this be a range object instead of two ints? |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1139 | LayoutUnit& m_repaintLogicalTop; |
| 1140 | LayoutUnit& m_repaintLogicalBottom; |
| 1141 | |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1142 | bool m_usesRepaintBounds; |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1143 | }; |
| 1144 | |
| 1145 | static void deleteLineRange(LineLayoutState& layoutState, RenderArena* arena, RootInlineBox* startLine, RootInlineBox* stopLine = 0) |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1146 | { |
| 1147 | RootInlineBox* boxToDelete = startLine; |
| 1148 | while (boxToDelete && boxToDelete != stopLine) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1149 | layoutState.updateRepaintRangeFromBox(boxToDelete); |
eric@webkit.org | e2532d9 | 2011-05-16 23:10:49 +0000 | [diff] [blame] | 1150 | // Note: deleteLineRange(renderArena(), firstRootBox()) is not identical to deleteLineBoxTree(). |
| 1151 | // deleteLineBoxTree uses nextLineBox() instead of nextRootBox() when traversing. |
eric@webkit.org | 455d90e | 2011-05-09 22:27:27 +0000 | [diff] [blame] | 1152 | RootInlineBox* next = boxToDelete->nextRootBox(); |
| 1153 | boxToDelete->deleteLine(arena); |
| 1154 | boxToDelete = next; |
| 1155 | } |
| 1156 | } |
| 1157 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1158 | void RenderBlock::layoutRunsAndFloats(LineLayoutState& layoutState, bool hasInlineChild) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1159 | { |
| 1160 | // We want to skip ahead to the first dirty line |
| 1161 | InlineBidiResolver resolver; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1162 | RootInlineBox* startLine = determineStartPosition(layoutState, resolver); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1163 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1164 | unsigned consecutiveHyphenatedLines = 0; |
| 1165 | if (startLine) { |
| 1166 | for (RootInlineBox* line = startLine->prevRootBox(); line && line->isHyphenated(); line = line->prevRootBox()) |
| 1167 | consecutiveHyphenatedLines++; |
| 1168 | } |
| 1169 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1170 | // FIXME: This would make more sense outside of this function, but since |
| 1171 | // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call |
| 1172 | // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html. |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1173 | if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1174 | setNeedsLayout(true, false); // Mark ourselves as needing a full layout. This way we'll repaint like |
| 1175 | // we're supposed to. |
| 1176 | RenderView* v = view(); |
| 1177 | if (v && !v->doingFullRepaint() && hasLayer()) { |
| 1178 | // Because we waited until we were already inside layout to discover |
| 1179 | // that the block really needed a full layout, we missed our chance to repaint the layer |
| 1180 | // before layout started. Luckily the layer has cached the repaint rect for its original |
| 1181 | // position and size, and so we can use that to make a repaint happen now. |
| 1182 | repaintUsingContainer(containerForRepaint(), layer()->repaintRect()); |
| 1183 | } |
| 1184 | } |
| 1185 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1186 | if (m_floatingObjects && !m_floatingObjects->set().isEmpty()) |
| 1187 | layoutState.setLastFloat(m_floatingObjects->set().last()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1188 | |
| 1189 | // We also find the first clean line and extract these lines. We will add them back |
| 1190 | // if we determine that we're able to synchronize after handling all our dirty lines. |
| 1191 | InlineIterator cleanLineStart; |
| 1192 | BidiStatus cleanLineBidiStatus; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1193 | if (!layoutState.isFullLayout() && startLine) |
| 1194 | determineEndPosition(layoutState, startLine, cleanLineStart, cleanLineBidiStatus); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1195 | |
| 1196 | if (startLine) { |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1197 | if (!layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1198 | layoutState.setRepaintRange(logicalHeight()); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1199 | deleteLineRange(layoutState, renderArena(), startLine); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1202 | if (!layoutState.isFullLayout() && lastRootBox() && lastRootBox()->endsWithBreak()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1203 | // If the last line before the start line ends with a line break that clear floats, |
| 1204 | // adjust the height accordingly. |
| 1205 | // A line break can be either the first or the last object on a line, depending on its direction. |
| 1206 | if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) { |
| 1207 | RenderObject* lastObject = lastLeafChild->renderer(); |
| 1208 | if (!lastObject->isBR()) |
| 1209 | lastObject = lastRootBox()->firstLeafChild()->renderer(); |
| 1210 | if (lastObject->isBR()) { |
| 1211 | EClear clear = lastObject->style()->clear(); |
| 1212 | if (clear != CNONE) |
| 1213 | newLine(clear); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1218 | layoutRunsAndFloatsInRange(layoutState, resolver, cleanLineStart, cleanLineBidiStatus, consecutiveHyphenatedLines); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1219 | linkToEndLineIfNeeded(layoutState); |
| 1220 | repaintDirtyFloats(layoutState.floats()); |
| 1221 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1222 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1223 | void RenderBlock::layoutRunsAndFloatsInRange(LineLayoutState& layoutState, InlineBidiResolver& resolver, const InlineIterator& cleanLineStart, const BidiStatus& cleanLineBidiStatus, unsigned consecutiveHyphenatedLines) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1224 | { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 1225 | RenderStyle* styleToUse = style(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1226 | bool paginated = view()->layoutState() && view()->layoutState()->isPaginated(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1227 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
| 1228 | InlineIterator end = resolver.position(); |
| 1229 | bool checkForEndLineMatch = layoutState.endLine(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1230 | LineBreakIteratorInfo lineBreakIteratorInfo; |
| 1231 | VerticalPositionCache verticalPositionCache; |
| 1232 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1233 | LineBreaker lineBreaker(this); |
| 1234 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1235 | while (!end.atEnd()) { |
| 1236 | // FIXME: Is this check necessary before the first iteration or can it be moved to the end? |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1237 | if (checkForEndLineMatch) { |
| 1238 | layoutState.setEndLineMatched(matchedEndLine(layoutState, resolver, cleanLineStart, cleanLineBidiStatus)); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1239 | if (layoutState.endLineMatched()) { |
| 1240 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1241 | break; |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1242 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1243 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1244 | |
| 1245 | lineMidpointState.reset(); |
| 1246 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1247 | layoutState.lineInfo().setEmpty(true); |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 1248 | layoutState.lineInfo().resetRunsFromLeadingWhitespace(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1249 | |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1250 | const InlineIterator oldEnd = end; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1251 | bool isNewUBAParagraph = layoutState.lineInfo().previousLineBrokeCleanly(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1252 | FloatingObject* lastFloatFromPreviousLine = (m_floatingObjects && !m_floatingObjects->set().isEmpty()) ? m_floatingObjects->set().last() : 0; |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1253 | end = lineBreaker.nextLineBreak(resolver, layoutState.lineInfo(), lineBreakIteratorInfo, lastFloatFromPreviousLine, consecutiveHyphenatedLines); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1254 | if (resolver.position().atEnd()) { |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1255 | // FIXME: We shouldn't be creating any runs in nextLineBreak to begin with! |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1256 | // Once BidiRunList is separated from BidiResolver this will not be needed. |
| 1257 | resolver.runs().deleteRuns(); |
| 1258 | resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed). |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1259 | layoutState.setCheckForFloatsFromLastLine(true); |
rniwa@webkit.org | 7daa12d | 2011-12-02 02:39:14 +0000 | [diff] [blame] | 1260 | resolver.setPosition(InlineIterator(resolver.position().root(), 0, 0), 0); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1261 | break; |
| 1262 | } |
| 1263 | ASSERT(end != resolver.position()); |
| 1264 | |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1265 | // This is a short-cut for empty lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1266 | if (layoutState.lineInfo().isEmpty()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1267 | if (lastRootBox()) |
| 1268 | lastRootBox()->setLineBreakInfo(end.m_obj, end.m_pos, resolver.status()); |
| 1269 | } else { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 1270 | VisualDirectionOverride override = (styleToUse->rtlOrdering() == VisualOrder ? (styleToUse->direction() == LTR ? VisualLeftToRightOverride : VisualRightToLeftOverride) : NoVisualOverride); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1271 | |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 1272 | if (isNewUBAParagraph && styleToUse->unicodeBidi() == Plaintext && !resolver.context()->parent()) { |
| 1273 | TextDirection direction = styleToUse->direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1274 | determineDirectionality(direction, resolver.position()); |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 1275 | resolver.setStatus(BidiStatus(direction, styleToUse->unicodeBidi() == Override)); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1276 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1277 | // FIXME: This ownership is reversed. We should own the BidiRunList and pass it to createBidiRunsForLine. |
| 1278 | BidiRunList<BidiRun>& bidiRuns = resolver.runs(); |
eric@webkit.org | a26de04 | 2011-09-08 18:46:01 +0000 | [diff] [blame] | 1279 | constructBidiRuns(resolver, bidiRuns, end, override, layoutState.lineInfo().previousLineBrokeCleanly()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1280 | ASSERT(resolver.position() == end); |
| 1281 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1282 | BidiRun* trailingSpaceRun = !layoutState.lineInfo().previousLineBrokeCleanly() ? handleTrailingSpaces(bidiRuns, resolver.context()) : 0; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1283 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1284 | if (bidiRuns.runCount() && lineBreaker.lineWasHyphenated()) { |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1285 | bidiRuns.logicallyLastRun()->m_hasHyphen = true; |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1286 | consecutiveHyphenatedLines++; |
| 1287 | } else |
| 1288 | consecutiveHyphenatedLines = 0; |
eric@webkit.org | 45e33a5 | 2011-05-04 11:51:09 +0000 | [diff] [blame] | 1289 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1290 | // Now that the runs have been ordered, we create the line boxes. |
| 1291 | // At the same time we figure out where border/padding/margin should be applied for |
| 1292 | // inline flow boxes. |
| 1293 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1294 | LayoutUnit oldLogicalHeight = logicalHeight(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1295 | RootInlineBox* lineBox = createLineBoxesFromBidiRuns(bidiRuns, end, layoutState.lineInfo(), verticalPositionCache, trailingSpaceRun); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1296 | |
| 1297 | bidiRuns.deleteRuns(); |
| 1298 | resolver.markCurrentRunEmpty(); // FIXME: This can probably be replaced by an ASSERT (or just removed). |
| 1299 | |
| 1300 | if (lineBox) { |
| 1301 | lineBox->setLineBreakInfo(end.m_obj, end.m_pos, resolver.status()); |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1302 | if (layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1303 | layoutState.updateRepaintRangeFromBox(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1304 | |
| 1305 | if (paginated) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1306 | LayoutUnit adjustment = 0; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1307 | adjustLinePositionForPagination(lineBox, adjustment); |
| 1308 | if (adjustment) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1309 | LayoutUnit oldLineWidth = availableLogicalWidthForLine(oldLogicalHeight, layoutState.lineInfo().isFirstLine()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1310 | lineBox->adjustBlockDirectionPosition(adjustment); |
commit-queue@webkit.org | 49ad473 | 2011-07-15 07:23:01 +0000 | [diff] [blame] | 1311 | if (layoutState.usesRepaintBounds()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1312 | layoutState.updateRepaintRangeFromBox(lineBox); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1313 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1314 | if (availableLogicalWidthForLine(oldLogicalHeight + adjustment, layoutState.lineInfo().isFirstLine()) != oldLineWidth) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1315 | // We have to delete this line, remove all floats that got added, and let line layout re-run. |
| 1316 | lineBox->deleteLine(renderArena()); |
| 1317 | removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldLogicalHeight); |
| 1318 | setLogicalHeight(oldLogicalHeight + adjustment); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1319 | resolver.setPositionIgnoringNestedIsolates(oldEnd); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1320 | end = oldEnd; |
| 1321 | continue; |
| 1322 | } |
| 1323 | |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1324 | setLogicalHeight(lineBox->lineBottomWithLeading()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1329 | for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i) |
| 1330 | setStaticPositions(this, lineBreaker.positionedObjects()[i]); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1331 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1332 | layoutState.lineInfo().setFirstLine(false); |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1333 | newLine(lineBreaker.clear()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | if (m_floatingObjects && lastRootBox()) { |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1337 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1338 | FloatingObjectSetIterator it = floatingObjectSet.begin(); |
| 1339 | FloatingObjectSetIterator end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1340 | if (layoutState.lastFloat()) { |
| 1341 | FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find(layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1342 | ASSERT(lastFloatIterator != end); |
| 1343 | ++lastFloatIterator; |
| 1344 | it = lastFloatIterator; |
| 1345 | } |
| 1346 | for (; it != end; ++it) { |
| 1347 | FloatingObject* f = *it; |
| 1348 | appendFloatingObjectToLastLine(f); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1349 | ASSERT(f->m_renderer == layoutState.floats()[layoutState.floatIndex()].object); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1350 | // If a float's geometry has changed, give up on syncing with clean lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1351 | if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameRect()) |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1352 | checkForEndLineMatch = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1353 | layoutState.setFloatIndex(layoutState.floatIndex() + 1); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1354 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1355 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last() : 0); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | lineMidpointState.reset(); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1359 | resolver.setPosition(end, numberOfIsolateAncestors(end)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1360 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1361 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1362 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1363 | void RenderBlock::linkToEndLineIfNeeded(LineLayoutState& layoutState) |
| 1364 | { |
| 1365 | if (layoutState.endLine()) { |
| 1366 | if (layoutState.endLineMatched()) { |
| 1367 | bool paginated = view()->layoutState() && view()->layoutState()->isPaginated(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1368 | // Attach all the remaining lines, and then adjust their y-positions as needed. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1369 | LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1370 | for (RootInlineBox* line = layoutState.endLine(); line; line = line->nextRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1371 | line->attachLine(); |
| 1372 | if (paginated) { |
| 1373 | delta -= line->paginationStrut(); |
| 1374 | adjustLinePositionForPagination(line, delta); |
| 1375 | } |
| 1376 | if (delta) { |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1377 | layoutState.updateRepaintRangeFromBox(line, delta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1378 | line->adjustBlockDirectionPosition(delta); |
| 1379 | } |
| 1380 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
| 1381 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 1382 | for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
mitz@apple.com | 0c4ce9f | 2011-05-04 02:20:02 +0000 | [diff] [blame] | 1383 | FloatingObject* floatingObject = insertFloatingObject(*f); |
| 1384 | ASSERT(!floatingObject->m_originatingLine); |
| 1385 | floatingObject->m_originatingLine = line; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1386 | setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f) + delta); |
| 1387 | positionNewFloats(); |
| 1388 | } |
| 1389 | } |
| 1390 | } |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1391 | setLogicalHeight(lastRootBox()->lineBottomWithLeading()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1392 | } else { |
| 1393 | // Delete all the remaining lines. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1394 | deleteLineRange(layoutState, renderArena(), layoutState.endLine()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1395 | } |
| 1396 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1397 | |
| 1398 | if (m_floatingObjects && (layoutState.checkForFloatsFromLastLine() || positionNewFloats()) && lastRootBox()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1399 | // In case we have a float on the last line, it might not be positioned up to now. |
| 1400 | // This has to be done before adding in the bottom border/padding, or the float will |
| 1401 | // include the padding incorrectly. -dwh |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1402 | if (layoutState.checkForFloatsFromLastLine()) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1403 | int bottomVisualOverflow = lastRootBox()->logicalBottomVisualOverflow(); |
| 1404 | int bottomLayoutOverflow = lastRootBox()->logicalBottomLayoutOverflow(); |
| 1405 | TrailingFloatsRootInlineBox* trailingFloatsLineBox = new (renderArena()) TrailingFloatsRootInlineBox(this); |
| 1406 | m_lineBoxes.appendLineBox(trailingFloatsLineBox); |
| 1407 | trailingFloatsLineBox->setConstructed(); |
| 1408 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 1409 | VerticalPositionCache verticalPositionCache; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1410 | int blockLogicalHeight = logicalHeight(); |
hyatt@apple.com | a8b5b82 | 2011-09-07 18:48:07 +0000 | [diff] [blame] | 1411 | trailingFloatsLineBox->alignBoxesInBlockDirection(blockLogicalHeight, textBoxDataMap, verticalPositionCache); |
| 1412 | trailingFloatsLineBox->setLineTopBottomPositions(blockLogicalHeight, blockLogicalHeight, blockLogicalHeight, blockLogicalHeight); |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1413 | trailingFloatsLineBox->setPaginatedLineWidth(availableLogicalWidthForContent(blockLogicalHeight)); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1414 | IntRect logicalLayoutOverflow(0, blockLogicalHeight, 1, bottomLayoutOverflow - blockLogicalHeight); |
| 1415 | IntRect logicalVisualOverflow(0, blockLogicalHeight, 1, bottomVisualOverflow - blockLogicalHeight); |
| 1416 | trailingFloatsLineBox->setOverflowFromLogicalRects(logicalLayoutOverflow, logicalVisualOverflow, trailingFloatsLineBox->lineTop(), trailingFloatsLineBox->lineBottom()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 1419 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1420 | FloatingObjectSetIterator it = floatingObjectSet.begin(); |
| 1421 | FloatingObjectSetIterator end = floatingObjectSet.end(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1422 | if (layoutState.lastFloat()) { |
| 1423 | FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find(layoutState.lastFloat()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1424 | ASSERT(lastFloatIterator != end); |
| 1425 | ++lastFloatIterator; |
| 1426 | it = lastFloatIterator; |
| 1427 | } |
| 1428 | for (; it != end; ++it) |
| 1429 | appendFloatingObjectToLastLine(*it); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1430 | layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.last() : 0); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1431 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | void RenderBlock::repaintDirtyFloats(Vector<FloatWithRect>& floats) |
| 1435 | { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1436 | size_t floatCount = floats.size(); |
| 1437 | // Floats that did not have layout did not repaint when we laid them out. They would have |
| 1438 | // painted by now if they had moved, but if they stayed at (0, 0), they still need to be |
| 1439 | // painted. |
| 1440 | for (size_t i = 0; i < floatCount; ++i) { |
| 1441 | if (!floats[i].everHadLayout) { |
| 1442 | RenderBox* f = floats[i].object; |
| 1443 | if (!f->x() && !f->y() && f->checkForRepaintDuringLayout()) |
| 1444 | f->repaint(); |
| 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1449 | void RenderBlock::layoutInlineChildren(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) |
jamesr@google.com | 19548ad | 2010-04-02 23:21:35 +0000 | [diff] [blame] | 1450 | { |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 1451 | m_overflow.clear(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1452 | |
hyatt@apple.com | 81c1d74 | 2010-10-06 21:44:02 +0000 | [diff] [blame] | 1453 | setLogicalHeight(borderBefore() + paddingBefore()); |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1454 | |
| 1455 | // Lay out our hypothetical grid line as though it occurs at the top of the block. |
hyatt@apple.com | 989d217 | 2012-02-09 01:50:05 +0000 | [diff] [blame] | 1456 | if (view()->layoutState() && view()->layoutState()->lineGrid() == this) |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 1457 | layoutLineGridBox(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1458 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1459 | // Figure out if we should clear out our line boxes. |
| 1460 | // FIXME: Handle resize eventually! |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1461 | bool isFullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren; |
| 1462 | LineLayoutState layoutState(isFullLayout, repaintLogicalTop, repaintLogicalBottom); |
| 1463 | |
| 1464 | if (isFullLayout) |
hyatt@apple.com | b83de65 | 2009-01-28 20:48:04 +0000 | [diff] [blame] | 1465 | lineBoxes()->deleteLineBoxes(renderArena()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1466 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1467 | // Text truncation only kicks in if your overflow isn't visible and your text-overflow-mode isn't |
| 1468 | // clip. |
| 1469 | // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely |
| 1470 | // difficult to figure out (especially in the middle of doing layout), and is really an esoteric pile of nonsense |
| 1471 | // anyway, so we won't worry about following the draft here. |
igor.oliveira@openbossa.org | a132c62 | 2011-08-25 20:56:55 +0000 | [diff] [blame] | 1472 | bool hasTextOverflow = style()->textOverflow() && hasOverflowClip(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1473 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1474 | // Walk all the lines and delete our ellipsis line boxes if they exist. |
| 1475 | if (hasTextOverflow) |
| 1476 | deleteEllipsisLineBoxes(); |
| 1477 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1478 | if (firstChild()) { |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1479 | // layout replaced elements |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1480 | bool hasInlineChild = false; |
eric@webkit.org | 3351047 | 2011-06-04 19:34:29 +0000 | [diff] [blame] | 1481 | for (InlineWalker walker(this); !walker.atEnd(); walker.advance()) { |
| 1482 | RenderObject* o = walker.current(); |
commit-queue@webkit.org | cf45df9 | 2010-09-14 13:25:06 +0000 | [diff] [blame] | 1483 | if (!hasInlineChild && o->isInline()) |
| 1484 | hasInlineChild = true; |
| 1485 | |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1486 | if (o->isReplaced() || o->isFloating() || o->isPositioned()) { |
| 1487 | RenderBox* box = toRenderBox(o); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1488 | |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1489 | if (relayoutChildren || o->style()->width().isPercent() || o->style()->height().isPercent()) |
| 1490 | o->setChildNeedsLayout(true, false); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1491 | |
zimmermann@webkit.org | ac68af4 | 2011-06-15 08:02:37 +0000 | [diff] [blame] | 1492 | // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths. |
| 1493 | if (relayoutChildren && box->needsPreferredWidthsRecalculation()) |
hyatt@apple.com | 75dad74 | 2010-09-24 18:07:44 +0000 | [diff] [blame] | 1494 | o->setPreferredLogicalWidthsDirty(true, false); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1495 | |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1496 | if (o->isPositioned()) |
| 1497 | o->containingBlock()->insertPositionedObject(box); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1498 | else if (o->isFloating()) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1499 | layoutState.floats().append(FloatWithRect(box)); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1500 | else if (layoutState.isFullLayout() || o->needsLayout()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1501 | // Replaced elements |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1502 | toRenderBox(o)->dirtyLineBoxes(layoutState.isFullLayout()); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1503 | o->layoutIfNeeded(); |
| 1504 | } |
eric@webkit.org | 3351047 | 2011-06-04 19:34:29 +0000 | [diff] [blame] | 1505 | } else if (o->isText() || (o->isRenderInline() && !walker.atEndOfInline())) { |
hyatt@apple.com | a61b8a3 | 2011-04-06 18:20:52 +0000 | [diff] [blame] | 1506 | if (!o->isText()) |
inferno@chromium.org | 88a424d | 2011-08-09 18:18:36 +0000 | [diff] [blame] | 1507 | toRenderInline(o)->updateAlwaysCreateLineBoxes(layoutState.isFullLayout()); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1508 | if (layoutState.isFullLayout() || o->selfNeedsLayout()) |
| 1509 | dirtyLineBoxesForRenderer(o, layoutState.isFullLayout()); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1510 | o->setNeedsLayout(false); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1511 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1514 | layoutRunsAndFloats(layoutState, hasInlineChild); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1515 | } |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1516 | |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1517 | // Expand the last line to accommodate Ruby and emphasis marks. |
| 1518 | int lastLineAnnotationsAdjustment = 0; |
| 1519 | if (lastRootBox()) { |
hyatt@apple.com | 5e48ff5 | 2010-11-19 00:43:29 +0000 | [diff] [blame] | 1520 | int lowestAllowedPosition = max(lastRootBox()->lineBottom(), logicalHeight() + paddingAfter()); |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1521 | if (!style()->isFlippedLinesWritingMode()) |
| 1522 | lastLineAnnotationsAdjustment = lastRootBox()->computeUnderAnnotationAdjustment(lowestAllowedPosition); |
| 1523 | else |
| 1524 | lastLineAnnotationsAdjustment = lastRootBox()->computeOverAnnotationAdjustment(lowestAllowedPosition); |
hyatt@apple.com | 5e48ff5 | 2010-11-19 00:43:29 +0000 | [diff] [blame] | 1525 | } |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1526 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1527 | // Now add in the bottom border/padding. |
mitz@apple.com | 3672d9e | 2010-12-17 19:31:16 +0000 | [diff] [blame] | 1528 | setLogicalHeight(logicalHeight() + lastLineAnnotationsAdjustment + borderAfter() + paddingAfter() + scrollbarLogicalHeight()); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1529 | |
adele | 7a470a7 | 2006-04-20 22:22:14 +0000 | [diff] [blame] | 1530 | if (!firstLineBox() && hasLineIfEmpty()) |
hyatt@apple.com | 2a5eb21 | 2011-03-22 23:21:54 +0000 | [diff] [blame] | 1531 | setLogicalHeight(logicalHeight() + lineHeight(true, isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1532 | |
| 1533 | // See if we have any lines that spill out of our block. If we do, then we will possibly need to |
| 1534 | // truncate text. |
| 1535 | if (hasTextOverflow) |
| 1536 | checkLinesForTextOverflow(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1539 | void RenderBlock::checkFloatsInCleanLine(RootInlineBox* line, Vector<FloatWithRect>& floats, size_t& floatIndex, bool& encounteredNewFloat, bool& dirtiedByFloat) |
| 1540 | { |
| 1541 | Vector<RenderBox*>* cleanLineFloats = line->floatsPtr(); |
| 1542 | if (!cleanLineFloats) |
| 1543 | return; |
| 1544 | |
| 1545 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 1546 | for (Vector<RenderBox*>::iterator it = cleanLineFloats->begin(); it != end; ++it) { |
| 1547 | RenderBox* floatingBox = *it; |
| 1548 | floatingBox->layoutIfNeeded(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1549 | LayoutSize newSize(floatingBox->width() + floatingBox->marginLeft() + floatingBox->marginRight(), floatingBox->height() + floatingBox->marginTop() + floatingBox->marginBottom()); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1550 | ASSERT(floatIndex < floats.size()); |
| 1551 | if (floats[floatIndex].object != floatingBox) { |
| 1552 | encounteredNewFloat = true; |
| 1553 | return; |
| 1554 | } |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1555 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1556 | if (floats[floatIndex].rect.size() != newSize) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1557 | LayoutUnit floatTop = isHorizontalWritingMode() ? floats[floatIndex].rect.y() : floats[floatIndex].rect.x(); |
| 1558 | LayoutUnit floatHeight = isHorizontalWritingMode() ? max(floats[floatIndex].rect.height(), newSize.height()) |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1559 | : max(floats[floatIndex].rect.width(), newSize.width()); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1560 | floatHeight = min(floatHeight, numeric_limits<LayoutUnit>::max() - floatTop); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1561 | line->markDirty(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1562 | markLinesDirtyInBlockRange(line->lineBottomWithLeading(), floatTop + floatHeight, line); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1563 | floats[floatIndex].rect.setSize(newSize); |
| 1564 | dirtiedByFloat = true; |
| 1565 | } |
| 1566 | floatIndex++; |
| 1567 | } |
| 1568 | } |
| 1569 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1570 | RootInlineBox* RenderBlock::determineStartPosition(LineLayoutState& layoutState, InlineBidiResolver& resolver) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1571 | { |
| 1572 | RootInlineBox* curr = 0; |
| 1573 | RootInlineBox* last = 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1574 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1575 | // FIXME: This entire float-checking block needs to be broken into a new function. |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1576 | bool dirtiedByFloat = false; |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1577 | if (!layoutState.isFullLayout()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1578 | // Paginate all of the clean lines. |
| 1579 | bool paginated = view()->layoutState() && view()->layoutState()->isPaginated(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1580 | LayoutUnit paginationDelta = 0; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1581 | size_t floatIndex = 0; |
| 1582 | for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1583 | if (paginated) { |
hyatt@apple.com | 0c6cd7a | 2011-09-22 20:50:41 +0000 | [diff] [blame] | 1584 | if (lineWidthForPaginatedLineChanged(curr)) { |
| 1585 | curr->markDirty(); |
| 1586 | break; |
| 1587 | } |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1588 | paginationDelta -= curr->paginationStrut(); |
| 1589 | adjustLinePositionForPagination(curr, paginationDelta); |
| 1590 | if (paginationDelta) { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1591 | if (containsFloats() || !layoutState.floats().isEmpty()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1592 | // FIXME: Do better eventually. For now if we ever shift because of pagination and floats are present just go to a full layout. |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1593 | layoutState.markForFullLayout(); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1594 | break; |
| 1595 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1596 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1597 | layoutState.updateRepaintRangeFromBox(curr, paginationDelta); |
hyatt@apple.com | 61bbedf | 2011-01-26 23:10:57 +0000 | [diff] [blame] | 1598 | curr->adjustBlockDirectionPosition(paginationDelta); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1599 | } |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1600 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1601 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1602 | // If a new float has been inserted before this line or before its last known float, just do a full layout. |
| 1603 | bool encounteredNewFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1604 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1605 | if (encounteredNewFloat) |
| 1606 | layoutState.markForFullLayout(); |
| 1607 | |
| 1608 | if (dirtiedByFloat || layoutState.isFullLayout()) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1609 | break; |
| 1610 | } |
| 1611 | // Check if a new float has been inserted after the last known float. |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1612 | if (!curr && floatIndex < layoutState.floats().size()) |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1613 | layoutState.markForFullLayout(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
eric@webkit.org | 59c3c1e | 2011-05-17 19:45:24 +0000 | [diff] [blame] | 1616 | if (layoutState.isFullLayout()) { |
eric@webkit.org | e2532d9 | 2011-05-16 23:10:49 +0000 | [diff] [blame] | 1617 | // FIXME: This should just call deleteLineBoxTree, but that causes |
| 1618 | // crashes for fast/repaint tests. |
| 1619 | RenderArena* arena = renderArena(); |
| 1620 | curr = firstRootBox(); |
| 1621 | while (curr) { |
| 1622 | // Note: This uses nextRootBox() insted of nextLineBox() like deleteLineBoxTree does. |
| 1623 | RootInlineBox* next = curr->nextRootBox(); |
| 1624 | curr->deleteLine(arena); |
| 1625 | curr = next; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1626 | } |
eric@webkit.org | e2532d9 | 2011-05-16 23:10:49 +0000 | [diff] [blame] | 1627 | ASSERT(!firstLineBox() && !lastLineBox()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1628 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1629 | if (curr) { |
| 1630 | // We have a dirty line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1631 | if (RootInlineBox* prevRootBox = curr->prevRootBox()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1632 | // We have a previous line. |
staikos@webkit.org | 19d8c5f | 2009-03-26 14:24:15 +0000 | [diff] [blame] | 1633 | if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength()))) |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1634 | // The previous line didn't break cleanly or broke at a newline |
| 1635 | // that has been deleted, so treat it as dirty too. |
| 1636 | curr = prevRootBox; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1637 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1638 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1639 | // No dirty lines were found. |
| 1640 | // If the last line didn't break cleanly, treat it as dirty. |
| 1641 | if (lastRootBox() && !lastRootBox()->endsWithBreak()) |
| 1642 | curr = lastRootBox(); |
| 1643 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1644 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1645 | // If we have no dirty lines, then last is just the last root box. |
| 1646 | last = curr ? curr->prevRootBox() : lastRootBox(); |
| 1647 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1648 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1649 | unsigned numCleanFloats = 0; |
| 1650 | if (!layoutState.floats().isEmpty()) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1651 | LayoutUnit savedLogicalHeight = logicalHeight(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1652 | // Restore floats from clean lines. |
| 1653 | RootInlineBox* line = firstRootBox(); |
| 1654 | while (line != curr) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1655 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
| 1656 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 1657 | for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
mitz@apple.com | 0c4ce9f | 2011-05-04 02:20:02 +0000 | [diff] [blame] | 1658 | FloatingObject* floatingObject = insertFloatingObject(*f); |
| 1659 | ASSERT(!floatingObject->m_originatingLine); |
| 1660 | floatingObject->m_originatingLine = line; |
hyatt@apple.com | 9a2e7d2 | 2010-10-06 22:13:31 +0000 | [diff] [blame] | 1661 | setLogicalHeight(logicalTopForChild(*f) - marginBeforeForChild(*f)); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1662 | positionNewFloats(); |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1663 | ASSERT(layoutState.floats()[numCleanFloats].object == *f); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1664 | numCleanFloats++; |
| 1665 | } |
| 1666 | } |
| 1667 | line = line->nextRootBox(); |
| 1668 | } |
hyatt@apple.com | 9a2e7d2 | 2010-10-06 22:13:31 +0000 | [diff] [blame] | 1669 | setLogicalHeight(savedLogicalHeight); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1670 | } |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1671 | layoutState.setFloatIndex(numCleanFloats); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1672 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1673 | layoutState.lineInfo().setFirstLine(!last); |
| 1674 | layoutState.lineInfo().setPreviousLineBrokeCleanly(!last || last->endsWithBreak()); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1675 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1676 | if (last) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1677 | setLogicalHeight(last->lineBottomWithLeading()); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1678 | InlineIterator iter = InlineIterator(this, last->lineBreakObj(), last->lineBreakPos()); |
| 1679 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1680 | resolver.setStatus(last->lineBreakBidiStatus()); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1681 | } else { |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1682 | TextDirection direction = style()->direction(); |
leviw@chromium.org | e7812f3 | 2012-02-07 23:46:40 +0000 | [diff] [blame] | 1683 | if (style()->unicodeBidi() == Plaintext) |
| 1684 | determineDirectionality(direction, InlineIterator(this, bidiFirstSkippingEmptyInlines(this), 0)); |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 1685 | resolver.setStatus(BidiStatus(direction, style()->unicodeBidi() == Override)); |
rniwa@webkit.org | 53d106b | 2011-11-30 22:33:20 +0000 | [diff] [blame] | 1686 | InlineIterator iter = InlineIterator(this, bidiFirstSkippingEmptyInlines(this, &resolver), 0); |
| 1687 | resolver.setPosition(iter, numberOfIsolateAncestors(iter)); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1688 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1689 | return curr; |
| 1690 | } |
| 1691 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1692 | void RenderBlock::determineEndPosition(LineLayoutState& layoutState, RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1693 | { |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1694 | ASSERT(!layoutState.endLine()); |
| 1695 | size_t floatIndex = layoutState.floatIndex(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1696 | RootInlineBox* last = 0; |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1697 | for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) { |
| 1698 | if (!curr->isDirty()) { |
| 1699 | bool encounteredNewFloat = false; |
| 1700 | bool dirtiedByFloat = false; |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1701 | checkFloatsInCleanLine(curr, layoutState.floats(), floatIndex, encounteredNewFloat, dirtiedByFloat); |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1702 | if (encounteredNewFloat) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1703 | return; |
hyatt | 04420ca | 2004-07-16 00:05:42 +0000 | [diff] [blame] | 1704 | } |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1705 | if (curr->isDirty()) |
| 1706 | last = 0; |
| 1707 | else if (!last) |
| 1708 | last = curr; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1709 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1710 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1711 | if (!last) |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1712 | return; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1713 | |
mitz@apple.com | d9ccfeb | 2011-03-10 01:56:27 +0000 | [diff] [blame] | 1714 | // At this point, |last| is the first line in a run of clean lines that ends with the last line |
| 1715 | // in the block. |
| 1716 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1717 | RootInlineBox* prev = last->prevRootBox(); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1718 | cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1719 | cleanLineBidiStatus = prev->lineBreakBidiStatus(); |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1720 | layoutState.setEndLineLogicalTop(prev->lineBottomWithLeading()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1721 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1722 | for (RootInlineBox* line = last; line; line = line->nextRootBox()) |
| 1723 | line->extractLine(); // Disconnect all line boxes from their render objects while preserving |
| 1724 | // their connections to one another. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1725 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1726 | layoutState.setEndLine(last); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1729 | bool RenderBlock::checkPaginationAndFloatsAtEndLine(LineLayoutState& layoutState) |
| 1730 | { |
| 1731 | LayoutUnit lineDelta = logicalHeight() - layoutState.endLineLogicalTop(); |
| 1732 | |
| 1733 | bool paginated = view()->layoutState() && view()->layoutState()->isPaginated(); |
hyatt@apple.com | d4d3bcf | 2011-10-04 18:17:04 +0000 | [diff] [blame] | 1734 | if (paginated && inRenderFlowThread()) { |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1735 | // Check all lines from here to the end, and see if the hypothetical new position for the lines will result |
| 1736 | // in a different available line width. |
| 1737 | for (RootInlineBox* lineBox = layoutState.endLine(); lineBox; lineBox = lineBox->nextRootBox()) { |
| 1738 | if (paginated) { |
| 1739 | // This isn't the real move we're going to do, so don't update the line box's pagination |
| 1740 | // strut yet. |
| 1741 | LayoutUnit oldPaginationStrut = lineBox->paginationStrut(); |
| 1742 | lineDelta -= oldPaginationStrut; |
| 1743 | adjustLinePositionForPagination(lineBox, lineDelta); |
| 1744 | lineBox->setPaginationStrut(oldPaginationStrut); |
| 1745 | } |
| 1746 | if (lineWidthForPaginatedLineChanged(lineBox, lineDelta)) |
| 1747 | return false; |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | if (!lineDelta || !m_floatingObjects) |
| 1752 | return true; |
| 1753 | |
| 1754 | // See if any floats end in the range along which we want to shift the lines vertically. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1755 | LayoutUnit logicalTop = min(logicalHeight(), layoutState.endLineLogicalTop()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1756 | |
| 1757 | RootInlineBox* lastLine = layoutState.endLine(); |
| 1758 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 1759 | lastLine = nextLine; |
| 1760 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 1761 | LayoutUnit logicalBottom = lastLine->lineBottomWithLeading() + abs(lineDelta); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1762 | |
| 1763 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 1764 | FloatingObjectSetIterator end = floatingObjectSet.end(); |
| 1765 | for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) { |
| 1766 | FloatingObject* f = *it; |
| 1767 | if (logicalBottomForFloat(f) >= logicalTop && logicalBottomForFloat(f) < logicalBottom) |
| 1768 | return false; |
| 1769 | } |
| 1770 | |
| 1771 | return true; |
| 1772 | } |
| 1773 | |
commit-queue@webkit.org | c979afb | 2011-08-02 18:07:32 +0000 | [diff] [blame] | 1774 | bool RenderBlock::matchedEndLine(LineLayoutState& layoutState, const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1775 | { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1776 | if (resolver.position() == endLineStart) { |
| 1777 | if (resolver.status() != endLineStatus) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1778 | return false; |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1779 | return checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1780 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1781 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1782 | // The first clean line doesn't match, but we can check a handful of following lines to try |
| 1783 | // to match back up. |
| 1784 | static int numLines = 8; // The # of lines we're willing to match against. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1785 | RootInlineBox* originalEndLine = layoutState.endLine(); |
| 1786 | RootInlineBox* line = originalEndLine; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1787 | for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) { |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 1788 | if (line->lineBreakObj() == resolver.position().m_obj && line->lineBreakPos() == resolver.position().m_pos) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1789 | // We have a match. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1790 | if (line->lineBreakBidiStatus() != resolver.status()) |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1791 | return false; // ...but the bidi state doesn't match. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1792 | |
| 1793 | bool matched = false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1794 | RootInlineBox* result = line->nextRootBox(); |
hyatt@apple.com | 1fb7d58 | 2011-09-23 20:25:11 +0000 | [diff] [blame] | 1795 | layoutState.setEndLine(result); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1796 | if (result) { |
hyatt@apple.com | 7ce0d42 | 2011-08-30 16:57:37 +0000 | [diff] [blame] | 1797 | layoutState.setEndLineLogicalTop(line->lineBottomWithLeading()); |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1798 | matched = checkPaginationAndFloatsAtEndLine(layoutState); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1801 | // Now delete the lines that we failed to sync. |
hyatt@apple.com | a10d30e | 2011-09-22 22:28:21 +0000 | [diff] [blame] | 1802 | deleteLineRange(layoutState, renderArena(), originalEndLine, result); |
| 1803 | return matched; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1804 | } |
| 1805 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1806 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1807 | return false; |
| 1808 | } |
| 1809 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 1810 | static inline bool skipNonBreakingSpace(const InlineIterator& it, const LineInfo& lineInfo) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1811 | { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 1812 | if (it.m_obj->style()->nbspMode() != SPACE || it.current() != noBreakSpace) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1813 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1814 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1815 | // FIXME: This is bad. It makes nbsp inconsistent with space and won't work correctly |
| 1816 | // with m_minWidth/m_maxWidth. |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1817 | // Do not skip a non-breaking space if it is the first character |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1818 | // on a line after a clean line break (or on the first line, since previousLineBrokeCleanly starts off |
| 1819 | // |true|). |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 1820 | if (lineInfo.isEmpty() && lineInfo.previousLineBrokeCleanly()) |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1821 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1822 | |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1823 | return true; |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1826 | enum WhitespacePosition { LeadingWhitespace, TrailingWhitespace }; |
| 1827 | static inline bool shouldCollapseWhiteSpace(const RenderStyle* style, const LineInfo& lineInfo, WhitespacePosition whitespacePosition) |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 1828 | { |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1829 | // CSS2 16.6.1 |
| 1830 | // If a space (U+0020) at the beginning of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is removed. |
| 1831 | // 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. |
| 1832 | // If spaces (U+0020) or tabs (U+0009) at the end of a line have 'white-space' set to 'pre-wrap', UAs may visually collapse them. |
| 1833 | return style->collapseWhiteSpace() |
| 1834 | || (whitespacePosition == TrailingWhitespace && style->whiteSpace() == PRE_WRAP && (!lineInfo.isEmpty() || !lineInfo.previousLineBrokeCleanly())); |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame^] | 1837 | static bool requiresLineBoxForContent(RenderInline* flow, const LineInfo& lineInfo) |
| 1838 | { |
| 1839 | RenderObject* parent = flow->parent(); |
| 1840 | if (flow->document()->inNoQuirksMode() |
| 1841 | && (flow->style(lineInfo.isFirstLine())->lineHeight() != parent->style(lineInfo.isFirstLine())->lineHeight() |
| 1842 | || flow->style()->verticalAlign() != parent->style()->verticalAlign() |
| 1843 | || !parent->style()->font().fontMetrics().hasIdenticalAscentDescentAndLineGap(flow->style()->font().fontMetrics()))) |
| 1844 | return true; |
| 1845 | return false; |
| 1846 | } |
| 1847 | |
| 1848 | static bool alwaysRequiresLineBox(RenderInline* flow, const LineInfo& lineInfo) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1849 | { |
| 1850 | // FIXME: Right now, we only allow line boxes for inlines that are truly empty. |
hyatt@apple.com | eb66ef4 | 2008-01-18 22:59:29 +0000 | [diff] [blame] | 1851 | // We need to fix this, though, because at the very least, inlines containing only |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1852 | // ignorable whitespace should should also have line boxes. |
hyatt@apple.com | 0415e5d | 2010-10-07 17:40:25 +0000 | [diff] [blame] | 1853 | return !flow->firstChild() && flow->hasInlineDirectionBordersPaddingOrMargin(); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1856 | static bool requiresLineBox(const InlineIterator& it, const LineInfo& lineInfo = LineInfo(), WhitespacePosition whitespacePosition = LeadingWhitespace) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1857 | { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 1858 | if (it.m_obj->isFloatingOrPositioned()) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1859 | return false; |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1860 | |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame^] | 1861 | if (it.m_obj->isRenderInline() && !alwaysRequiresLineBox(toRenderInline(it.m_obj), lineInfo) && !requiresLineBoxForContent(toRenderInline(it.m_obj), lineInfo)) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1862 | return false; |
| 1863 | |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1864 | if (!shouldCollapseWhiteSpace(it.m_obj->style(), lineInfo, whitespacePosition) || it.m_obj->isBR()) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1865 | return true; |
| 1866 | |
| 1867 | UChar current = it.current(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1868 | return current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || it.m_obj->preservesNewline()) |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 1869 | && !skipNonBreakingSpace(it, lineInfo); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 1872 | bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1873 | { |
| 1874 | ASSERT(inlineObj->parent() == this); |
| 1875 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1876 | InlineIterator it(this, inlineObj, 0); |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1877 | // FIXME: We should pass correct value for WhitespacePosition. |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 1878 | while (!it.atEnd() && !requiresLineBox(it)) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1879 | it.increment(); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1880 | |
| 1881 | return !it.atEnd(); |
| 1882 | } |
| 1883 | |
mitz@apple.com | bf6e8d3 | 2008-07-25 20:21:06 +0000 | [diff] [blame] | 1884 | // FIXME: The entire concept of the skipTrailingWhitespace function is flawed, since we really need to be building |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1885 | // line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned |
| 1886 | // elements quite right. In other words, we need to build this function's work into the normal line |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1887 | // object iteration process. |
mitz@apple.com | bf6e8d3 | 2008-07-25 20:21:06 +0000 | [diff] [blame] | 1888 | // NB. this function will insert any floating elements that would otherwise |
| 1889 | // be skipped but it will not position them. |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1890 | void RenderBlock::LineBreaker::skipTrailingWhitespace(InlineIterator& iterator, const LineInfo& lineInfo) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1891 | { |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1892 | while (!iterator.atEnd() && !requiresLineBox(iterator, lineInfo, TrailingWhitespace)) { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 1893 | RenderObject* object = iterator.m_obj; |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 1894 | if (object->isPositioned()) |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1895 | setStaticPositions(m_block, toRenderBox(object)); |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 1896 | else if (object->isFloating()) |
| 1897 | m_block->insertFloatingObject(toRenderBox(object)); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1898 | iterator.increment(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1899 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1900 | } |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1901 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 1902 | void RenderBlock::LineBreaker::skipLeadingWhitespace(InlineBidiResolver& resolver, LineInfo& lineInfo, |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1903 | FloatingObject* lastFloatFromPreviousLine, LineWidth& width) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1904 | { |
rniwa@webkit.org | 4024842 | 2011-06-15 00:19:39 +0000 | [diff] [blame] | 1905 | while (!resolver.position().atEnd() && !requiresLineBox(resolver.position(), lineInfo, LeadingWhitespace)) { |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 1906 | RenderObject* object = resolver.position().m_obj; |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 1907 | if (object->isPositioned()) { |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 1908 | setStaticPositions(m_block, toRenderBox(object)); |
robert@webkit.org | 8cbab14 | 2011-12-30 20:58:29 +0000 | [diff] [blame] | 1909 | if (object->style()->isOriginalDisplayInlineType()) { |
| 1910 | resolver.runs().addRun(createRun(0, 1, object, resolver)); |
| 1911 | lineInfo.incrementRunsFromLeadingWhitespace(); |
| 1912 | } |
| 1913 | } else if (object->isFloating()) |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 1914 | m_block->positionNewFloatOnLine(m_block->insertFloatingObject(toRenderBox(object)), lastFloatFromPreviousLine, lineInfo, width); |
commit-queue@webkit.org | 8e277fd | 2012-01-19 18:05:33 +0000 | [diff] [blame] | 1915 | else if (object->isText() && object->style()->hasTextCombine() && object->isCombineText() && !toRenderCombineText(object)->isCombined()) { |
commit-queue@webkit.org | f6c35c0 | 2012-01-06 20:30:15 +0000 | [diff] [blame] | 1916 | toRenderCombineText(object)->combineText(); |
commit-queue@webkit.org | 8e277fd | 2012-01-19 18:05:33 +0000 | [diff] [blame] | 1917 | if (toRenderCombineText(object)->isCombined()) |
| 1918 | continue; |
commit-queue@webkit.org | f6c35c0 | 2012-01-06 20:30:15 +0000 | [diff] [blame] | 1919 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1920 | resolver.increment(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1921 | } |
mitz@apple.com | 83d2e87 | 2008-10-23 21:56:03 +0000 | [diff] [blame] | 1922 | resolver.commitExplicitEmbedding(); |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 1925 | // This is currently just used for list markers and inline flows that have line boxes. Neither should |
| 1926 | // have an effect on whitespace at the start of the line. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1927 | static bool shouldSkipWhitespaceAfterStartObject(RenderBlock* block, RenderObject* o, LineMidpointState& lineMidpointState) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1928 | { |
eric@webkit.org | d4b9d77 | 2011-08-22 23:34:31 +0000 | [diff] [blame] | 1929 | RenderObject* next = bidiNextSkippingEmptyInlines(block, o); |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 1930 | if (next && !next->isBR() && next->isText() && toRenderText(next)->textLength() > 0) { |
| 1931 | RenderText* nextText = toRenderText(next); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1932 | UChar nextChar = nextText->characters()[0]; |
| 1933 | if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) { |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1934 | addMidpoint(lineMidpointState, InlineIterator(0, o, 0)); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1935 | return true; |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | return false; |
| 1940 | } |
| 1941 | |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 1942 | static inline float textWidth(RenderText* text, unsigned from, unsigned len, const Font& font, float xPos, bool isFixedPitch, bool collapseWhiteSpace) |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1943 | { |
hyatt@apple.com | 4d046b7 | 2011-01-31 20:39:09 +0000 | [diff] [blame] | 1944 | if (isFixedPitch || (!from && len == text->textLength()) || text->style()->hasTextCombine()) |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1945 | return text->width(from, len, font, xPos); |
zimmermann@webkit.org | 544abde | 2011-06-12 12:40:40 +0000 | [diff] [blame] | 1946 | |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 1947 | TextRun run = RenderBlock::constructTextRun(text, font, text->characters() + from, len, text->style()); |
zimmermann@webkit.org | 544abde | 2011-06-12 12:40:40 +0000 | [diff] [blame] | 1948 | run.setCharactersLength(text->textLength() - from); |
| 1949 | ASSERT(run.charactersLength() >= run.length()); |
| 1950 | |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 1951 | run.setAllowTabs(!collapseWhiteSpace); |
| 1952 | run.setXPos(xPos); |
| 1953 | return font.width(run); |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1956 | static void tryHyphenating(RenderText* text, const Font& font, const AtomicString& localeIdentifier, unsigned consecutiveHyphenatedLines, int consecutiveHyphenatedLinesLimit, int minimumPrefixLength, int minimumSuffixLength, int lastSpace, int pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, int nextBreakable, bool& hyphenated) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1957 | { |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 1958 | // Map 'hyphenate-limit-{before,after}: auto;' to 2. |
| 1959 | if (minimumPrefixLength < 0) |
| 1960 | minimumPrefixLength = 2; |
| 1961 | |
| 1962 | if (minimumSuffixLength < 0) |
| 1963 | minimumSuffixLength = 2; |
| 1964 | |
| 1965 | if (pos - lastSpace <= minimumSuffixLength) |
| 1966 | return; |
| 1967 | |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 1968 | if (consecutiveHyphenatedLinesLimit >= 0 && consecutiveHyphenatedLines >= static_cast<unsigned>(consecutiveHyphenatedLinesLimit)) |
| 1969 | return; |
| 1970 | |
commit-queue@webkit.org | e60bb90 | 2011-09-08 19:18:43 +0000 | [diff] [blame] | 1971 | int hyphenWidth = measureHyphenWidth(text, font); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1972 | |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 1973 | float maxPrefixWidth = availableWidth - xPos - hyphenWidth - lastSpaceWordSpacing; |
mitz@apple.com | 7c67b29 | 2010-09-12 23:04:16 +0000 | [diff] [blame] | 1974 | // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely |
| 1975 | // that an hyphenation opportunity exists, so do not bother to look for it. |
| 1976 | if (maxPrefixWidth <= font.pixelSize() * 5 / 4) |
| 1977 | return; |
| 1978 | |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 1979 | TextRun run = RenderBlock::constructTextRun(text, font, text->characters() + lastSpace, pos - lastSpace, text->style()); |
zimmermann@webkit.org | 544abde | 2011-06-12 12:40:40 +0000 | [diff] [blame] | 1980 | run.setCharactersLength(text->textLength() - lastSpace); |
| 1981 | ASSERT(run.charactersLength() >= run.length()); |
| 1982 | |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 1983 | run.setAllowTabs(!collapseWhiteSpace); |
| 1984 | run.setXPos(xPos + lastSpaceWordSpacing); |
| 1985 | |
| 1986 | unsigned prefixLength = font.offsetForPosition(run, maxPrefixWidth, false); |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 1987 | if (prefixLength < static_cast<unsigned>(minimumPrefixLength)) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1988 | return; |
| 1989 | |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 1990 | prefixLength = lastHyphenLocation(text->characters() + lastSpace, pos - lastSpace, min(prefixLength, static_cast<unsigned>(pos - lastSpace - minimumSuffixLength)) + 1, localeIdentifier); |
mitz@apple.com | 348878a | 2011-12-11 19:06:56 +0000 | [diff] [blame] | 1991 | if (!prefixLength || prefixLength < static_cast<unsigned>(minimumPrefixLength)) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1992 | return; |
| 1993 | |
mitz@apple.com | 348878a | 2011-12-11 19:06:56 +0000 | [diff] [blame] | 1994 | // When lastSapce is a space, which it always is except sometimes at the beginning of a line or after collapsed |
| 1995 | // space, it should not count towards hyphenate-limit-before. |
| 1996 | if (prefixLength == static_cast<unsigned>(minimumPrefixLength)) { |
| 1997 | UChar characterAtLastSpace = text->characters()[lastSpace]; |
| 1998 | if (characterAtLastSpace == ' ' || characterAtLastSpace == '\n' || characterAtLastSpace == '\t' || characterAtLastSpace == noBreakSpace) |
| 1999 | return; |
| 2000 | } |
| 2001 | |
mitz@apple.com | d56f108 | 2011-03-06 22:44:48 +0000 | [diff] [blame] | 2002 | ASSERT(pos - lastSpace - prefixLength >= static_cast<unsigned>(minimumSuffixLength)); |
| 2003 | |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2004 | #if !ASSERT_DISABLED |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2005 | float prefixWidth = hyphenWidth + textWidth(text, lastSpace, prefixLength, font, xPos, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing; |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2006 | ASSERT(xPos + prefixWidth <= availableWidth); |
mitz@apple.com | 34b43c7 | 2010-06-21 17:21:22 +0000 | [diff] [blame] | 2007 | #else |
| 2008 | UNUSED_PARAM(isFixedPitch); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2009 | #endif |
| 2010 | |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2011 | lineBreak.moveTo(text, lastSpace + prefixLength, nextBreakable); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2012 | hyphenated = true; |
| 2013 | } |
| 2014 | |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2015 | class TrailingObjects { |
| 2016 | public: |
| 2017 | TrailingObjects(); |
| 2018 | void setTrailingWhitespace(RenderText*); |
| 2019 | void clear(); |
| 2020 | void appendBoxIfNeeded(RenderBox*); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2021 | |
| 2022 | enum CollapseFirstSpaceOrNot { DoNotCollapseFirstSpace, CollapseFirstSpace }; |
| 2023 | |
| 2024 | void updateMidpointsForTrailingBoxes(LineMidpointState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2025 | |
| 2026 | private: |
| 2027 | RenderText* m_whitespace; |
| 2028 | Vector<RenderBox*, 4> m_boxes; |
| 2029 | }; |
| 2030 | |
| 2031 | TrailingObjects::TrailingObjects() |
| 2032 | : m_whitespace(0) |
| 2033 | { |
| 2034 | } |
| 2035 | |
| 2036 | inline void TrailingObjects::setTrailingWhitespace(RenderText* whitespace) |
| 2037 | { |
| 2038 | ASSERT(whitespace); |
| 2039 | m_whitespace = whitespace; |
| 2040 | } |
| 2041 | |
| 2042 | inline void TrailingObjects::clear() |
| 2043 | { |
| 2044 | m_whitespace = 0; |
| 2045 | m_boxes.clear(); |
| 2046 | } |
| 2047 | |
| 2048 | inline void TrailingObjects::appendBoxIfNeeded(RenderBox* box) |
| 2049 | { |
| 2050 | if (m_whitespace) |
| 2051 | m_boxes.append(box); |
| 2052 | } |
| 2053 | |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2054 | void TrailingObjects::updateMidpointsForTrailingBoxes(LineMidpointState& lineMidpointState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace) |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2055 | { |
| 2056 | if (!m_whitespace) |
| 2057 | return; |
| 2058 | |
| 2059 | // This object is either going to be part of the last midpoint, or it is going to be the actual endpoint. |
| 2060 | // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline. |
| 2061 | if (lineMidpointState.numMidpoints % 2) { |
| 2062 | // Find the trailing space object's midpoint. |
| 2063 | int trailingSpaceMidpoint = lineMidpointState.numMidpoints - 1; |
inferno@chromium.org | 92ca04e | 2011-08-01 18:03:03 +0000 | [diff] [blame] | 2064 | for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints[trailingSpaceMidpoint].m_obj != m_whitespace; --trailingSpaceMidpoint) { } |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2065 | ASSERT(trailingSpaceMidpoint >= 0); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2066 | if (collapseFirstSpace == CollapseFirstSpace) |
| 2067 | lineMidpointState.midpoints[trailingSpaceMidpoint].m_pos--; |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2068 | |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2069 | // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2070 | // ignoring spaces. |
| 2071 | size_t currentMidpoint = trailingSpaceMidpoint + 1; |
| 2072 | for (size_t i = 0; i < m_boxes.size(); ++i) { |
| 2073 | if (currentMidpoint >= lineMidpointState.numMidpoints) { |
| 2074 | // We don't have a midpoint for this box yet. |
| 2075 | InlineIterator ignoreStart(0, m_boxes[i], 0); |
| 2076 | addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring. |
| 2077 | addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again. |
| 2078 | } else { |
| 2079 | ASSERT(lineMidpointState.midpoints[currentMidpoint].m_obj == m_boxes[i]); |
| 2080 | ASSERT(lineMidpointState.midpoints[currentMidpoint + 1].m_obj == m_boxes[i]); |
| 2081 | } |
| 2082 | currentMidpoint += 2; |
| 2083 | } |
| 2084 | } else if (!lBreak.m_obj) { |
| 2085 | ASSERT(m_whitespace->isText()); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2086 | ASSERT(collapseFirstSpace == CollapseFirstSpace); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2087 | // Add a new end midpoint that stops right at the very end. |
| 2088 | unsigned length = m_whitespace->textLength(); |
| 2089 | unsigned pos = length >= 2 ? length - 2 : UINT_MAX; |
| 2090 | InlineIterator endMid(0, m_whitespace, pos); |
| 2091 | addMidpoint(lineMidpointState, endMid); |
| 2092 | for (size_t i = 0; i < m_boxes.size(); ++i) { |
| 2093 | InlineIterator ignoreStart(0, m_boxes[i], 0); |
| 2094 | addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring spaces. |
| 2095 | addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again. |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2100 | void RenderBlock::LineBreaker::reset() |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2101 | { |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2102 | m_positionedObjects.clear(); |
| 2103 | m_hyphenated = false; |
| 2104 | m_clear = CNONE; |
| 2105 | } |
| 2106 | |
| 2107 | InlineIterator RenderBlock::LineBreaker::nextLineBreak(InlineBidiResolver& resolver, LineInfo& lineInfo, |
mitz@apple.com | 10ed3cb | 2011-09-07 20:59:39 +0000 | [diff] [blame] | 2108 | LineBreakIteratorInfo& lineBreakIteratorInfo, FloatingObject* lastFloatFromPreviousLine, unsigned consecutiveHyphenatedLines) |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2109 | { |
| 2110 | reset(); |
| 2111 | |
| 2112 | ASSERT(resolver.position().root() == m_block); |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 2113 | |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 2114 | bool appliedStartWidth = resolver.position().m_pos > 0; |
yael.aharon@nokia.com | 1cfbceb | 2011-06-06 18:32:54 +0000 | [diff] [blame] | 2115 | bool includeEndWidth = true; |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2116 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2117 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2118 | LineWidth width(m_block, lineInfo.isFirstLine()); |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2119 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2120 | skipLeadingWhitespace(resolver, lineInfo, lastFloatFromPreviousLine, width); |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2121 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2122 | if (resolver.position().atEnd()) |
| 2123 | return resolver.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2124 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2125 | // This variable is used only if whitespace isn't set to PRE, and it tells us whether |
| 2126 | // or not we are currently ignoring whitespace. |
| 2127 | bool ignoringSpaces = false; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2128 | InlineIterator ignoreStart; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2129 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2130 | // This variable tracks whether the very last character we saw was a space. We use |
| 2131 | // this to detect when we encounter a second space so we know we have to terminate |
| 2132 | // a run. |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2133 | bool currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2134 | bool currentCharacterIsWS = false; |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2135 | TrailingObjects trailingObjects; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2136 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2137 | InlineIterator lBreak = resolver.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2138 | |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2139 | // FIXME: It is error-prone to split the position object out like this. |
| 2140 | // Teach this code to work with objects instead of this split tuple. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2141 | InlineIterator current = resolver.position(); |
| 2142 | RenderObject* last = current.m_obj; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 2143 | bool atStart = true; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2144 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2145 | bool startingNewParagraph = lineInfo.previousLineBrokeCleanly(); |
| 2146 | lineInfo.setPreviousLineBrokeCleanly(false); |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 2147 | |
| 2148 | bool autoWrapWasEverTrueOnLine = false; |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 2149 | bool floatsFitOnLine = true; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2150 | |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 2151 | // Firefox and Opera will allow a table cell to grow to fit an image inside it under |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2152 | // very specific circumstances (in order to match common WinIE renderings). |
| 2153 | // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.) |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2154 | RenderStyle* blockStyle = m_block->style(); |
| 2155 | bool allowImagesToBreak = !m_block->document()->inQuirksMode() || !m_block->isTableCell() || !blockStyle->logicalWidth().isIntrinsicOrAuto(); |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 2156 | |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2157 | EWhiteSpace currWS = blockStyle->whiteSpace(); |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2158 | EWhiteSpace lastWS = currWS; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2159 | while (current.m_obj) { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2160 | RenderStyle* currentStyle = current.m_obj->style(); |
eric@webkit.org | d4b9d77 | 2011-08-22 23:34:31 +0000 | [diff] [blame] | 2161 | RenderObject* next = bidiNextSkippingEmptyInlines(m_block, current.m_obj); |
yael.aharon@nokia.com | 1cfbceb | 2011-06-06 18:32:54 +0000 | [diff] [blame] | 2162 | if (next && next->parent() && !next->parent()->isDescendantOf(current.m_obj->parent())) |
| 2163 | includeEndWidth = true; |
mitz@apple.com | ddb5987 | 2011-04-05 05:21:16 +0000 | [diff] [blame] | 2164 | |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2165 | currWS = current.m_obj->isReplaced() ? current.m_obj->parent()->style()->whiteSpace() : currentStyle->whiteSpace(); |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2166 | lastWS = last->isReplaced() ? last->parent()->style()->whiteSpace() : last->style()->whiteSpace(); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2167 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2168 | bool autoWrap = RenderStyle::autoWrap(currWS); |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 2169 | autoWrapWasEverTrueOnLine = autoWrapWasEverTrueOnLine || autoWrap; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2170 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 2171 | #if ENABLE(SVG) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2172 | bool preserveNewline = current.m_obj->isSVGInlineText() ? false : RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2173 | #else |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2174 | bool preserveNewline = RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2175 | #endif |
| 2176 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2177 | bool collapseWhiteSpace = RenderStyle::collapseWhiteSpace(currWS); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2178 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2179 | if (current.m_obj->isBR()) { |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2180 | if (width.fitsOnLine()) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2181 | lBreak.moveToStartOf(current.m_obj); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2182 | lBreak.increment(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2183 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2184 | // A <br> always breaks a line, so don't let the line be collapsed |
| 2185 | // away. Also, the space at the end of a line with a <br> does not |
hyatt | 01eff98 | 2003-03-14 20:13:23 +0000 | [diff] [blame] | 2186 | // get collapsed away. It only does this if the previous line broke |
| 2187 | // cleanly. Otherwise the <br> has no effect on whether the line is |
| 2188 | // empty or not. |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2189 | if (startingNewParagraph) |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2190 | lineInfo.setEmpty(false, m_block, &width); |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2191 | trailingObjects.clear(); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2192 | lineInfo.setPreviousLineBrokeCleanly(true); |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 2193 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2194 | if (!lineInfo.isEmpty()) |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2195 | m_clear = currentStyle->clear(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2196 | } |
| 2197 | goto end; |
| 2198 | } |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2199 | |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 2200 | if (current.m_obj->isPositioned()) { |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2201 | // If our original display wasn't an inline type, then we can |
| 2202 | // go ahead and determine our static inline position now. |
| 2203 | RenderBox* box = toRenderBox(current.m_obj); |
| 2204 | bool isInlineType = box->style()->isOriginalDisplayInlineType(); |
| 2205 | if (!isInlineType) |
hyatt@apple.com | a5cac3f | 2011-10-12 18:51:17 +0000 | [diff] [blame] | 2206 | m_block->setStaticInlinePositionForChild(box, m_block->logicalHeight(), m_block->startOffsetForContent(m_block->logicalHeight())); |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2207 | else { |
| 2208 | // If our original display was an INLINE type, then we can go ahead |
| 2209 | // and determine our static y position now. |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2210 | box->layer()->setStaticBlockPosition(m_block->logicalHeight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2211 | } |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2212 | |
| 2213 | // If we're ignoring spaces, we have to stop and include this object and |
| 2214 | // then start ignoring spaces again. |
| 2215 | if (isInlineType || current.m_obj->container()->isRenderInline()) { |
| 2216 | if (ignoringSpaces) { |
| 2217 | ignoreStart.m_obj = current.m_obj; |
| 2218 | ignoreStart.m_pos = 0; |
| 2219 | addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring spaces. |
| 2220 | addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again. |
| 2221 | } |
| 2222 | trailingObjects.appendBoxIfNeeded(box); |
| 2223 | } else |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2224 | m_positionedObjects.append(box); |
mitz@apple.com | d67fb21 | 2011-12-19 02:51:46 +0000 | [diff] [blame] | 2225 | } else if (current.m_obj->isFloating()) { |
| 2226 | RenderBox* floatBox = toRenderBox(current.m_obj); |
| 2227 | FloatingObject* f = m_block->insertFloatingObject(floatBox); |
| 2228 | // check if it fits in the current line. |
| 2229 | // If it does, position it now, otherwise, position |
| 2230 | // it after moving to next line (in newLine() func) |
| 2231 | if (floatsFitOnLine && width.fitsOnLine(m_block->logicalWidthForFloat(f))) { |
| 2232 | m_block->positionNewFloatOnLine(f, lastFloatFromPreviousLine, lineInfo, width); |
| 2233 | if (lBreak.m_obj == current.m_obj) { |
| 2234 | ASSERT(!lBreak.m_pos); |
| 2235 | lBreak.increment(); |
| 2236 | } |
| 2237 | } else |
| 2238 | floatsFitOnLine = false; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2239 | } else if (current.m_obj->isRenderInline()) { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2240 | // Right now, we should only encounter empty inlines here. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2241 | ASSERT(!current.m_obj->firstChild()); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2242 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2243 | RenderInline* flowBox = toRenderInline(current.m_obj); |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2244 | |
| 2245 | // Now that some inline flows have line boxes, if we are already ignoring spaces, we need |
| 2246 | // to make sure that we stop to include this object and then start ignoring spaces again. |
| 2247 | // If this object is at the start of the line, we need to behave like list markers and |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2248 | // start ignoring spaces. |
robert@webkit.org | 56e5a9f | 2012-02-17 21:10:42 +0000 | [diff] [blame^] | 2249 | bool requiresLineBox = alwaysRequiresLineBox(flowBox, lineInfo); |
| 2250 | if (requiresLineBox || requiresLineBoxForContent(flowBox, lineInfo)) { |
| 2251 | // An empty inline that only has line-height, vertical-align or font-metrics will only get a |
| 2252 | // line box to affect the height of the line if the rest of the line is not empty. |
| 2253 | if (requiresLineBox) |
| 2254 | lineInfo.setEmpty(false, m_block, &width); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2255 | if (ignoringSpaces) { |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2256 | trailingObjects.clear(); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2257 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0)); // Stop ignoring spaces. |
| 2258 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0)); // Start ignoring again. |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2259 | } else if (blockStyle->collapseWhiteSpace() && resolver.position().m_obj == current.m_obj |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2260 | && shouldSkipWhitespaceAfterStartObject(m_block, current.m_obj, lineMidpointState)) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2261 | // Like with list markers, we start ignoring spaces to make sure that any |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2262 | // additional spaces we see will be discarded. |
| 2263 | currentCharacterIsSpace = true; |
| 2264 | currentCharacterIsWS = true; |
| 2265 | ignoringSpaces = true; |
| 2266 | } |
| 2267 | } |
| 2268 | |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2269 | width.addUncommittedWidth(borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox)); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2270 | } else if (current.m_obj->isReplaced()) { |
| 2271 | RenderBox* replacedBox = toRenderBox(current.m_obj); |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 2272 | |
hyatt | de39634 | 2003-10-29 08:57:20 +0000 | [diff] [blame] | 2273 | // Break on replaced elements if either has normal white-space. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2274 | if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!current.m_obj->isImage() || allowImagesToBreak)) { |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2275 | width.commit(); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2276 | lBreak.moveToStartOf(current.m_obj); |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 2279 | if (ignoringSpaces) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2280 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, 0)); |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 2281 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2282 | lineInfo.setEmpty(false, m_block, &width); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2283 | ignoringSpaces = false; |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2284 | currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2285 | currentCharacterIsWS = false; |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2286 | trailingObjects.clear(); |
hamaji@chromium.org | 382642b | 2009-12-01 07:37:14 +0000 | [diff] [blame] | 2287 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2288 | // Optimize for a common case. If we can't find whitespace after the list |
hyatt@apple.com | 0415e5d | 2010-10-07 17:40:25 +0000 | [diff] [blame] | 2289 | // item, then this is all moot. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2290 | LayoutUnit replacedLogicalWidth = m_block->logicalWidthForChild(replacedBox) + m_block->marginStartForChild(replacedBox) + m_block->marginEndForChild(replacedBox) + inlineLogicalWidth(current.m_obj); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2291 | if (current.m_obj->isListMarker()) { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2292 | if (blockStyle->collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(m_block, current.m_obj, lineMidpointState)) { |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2293 | // Like with inline flows, we start ignoring spaces to make sure that any |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 2294 | // additional spaces we see will be discarded. |
| 2295 | currentCharacterIsSpace = true; |
| 2296 | currentCharacterIsWS = true; |
| 2297 | ignoringSpaces = true; |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 2298 | } |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2299 | if (toRenderListMarker(current.m_obj)->isInside()) |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2300 | width.addUncommittedWidth(replacedLogicalWidth); |
justing | 244d3a3 | 2006-04-13 01:31:24 +0000 | [diff] [blame] | 2301 | } else |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2302 | width.addUncommittedWidth(replacedLogicalWidth); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2303 | if (current.m_obj->isRubyRun()) |
| 2304 | width.applyOverhang(toRenderRubyRun(current.m_obj), last, next); |
| 2305 | } else if (current.m_obj->isText()) { |
| 2306 | if (!current.m_pos) |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 2307 | appliedStartWidth = false; |
| 2308 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2309 | RenderText* t = toRenderText(current.m_obj); |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 2310 | |
zimmermann@webkit.org | 6e96afd | 2010-09-10 15:35:50 +0000 | [diff] [blame] | 2311 | #if ENABLE(SVG) |
| 2312 | bool isSVGText = t->isSVGInlineText(); |
| 2313 | #endif |
| 2314 | |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2315 | RenderStyle* style = t->style(lineInfo.isFirstLine()); |
commit-queue@webkit.org | f6c35c0 | 2012-01-06 20:30:15 +0000 | [diff] [blame] | 2316 | if (style->hasTextCombine() && current.m_obj->isCombineText() && !toRenderCombineText(current.m_obj)->isCombined()) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2317 | toRenderCombineText(current.m_obj)->combineText(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2318 | |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2319 | const Font& f = style->font(); |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 2320 | bool isFixedPitch = f.isFixedPitch(); |
mitz@apple.com | 6ae8861 | 2011-03-03 23:09:11 +0000 | [diff] [blame] | 2321 | bool canHyphenate = style->hyphens() == HyphensAuto && WebCore::canHyphenate(style->locale()); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2322 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2323 | int lastSpace = current.m_pos; |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2324 | float wordSpacing = currentStyle->wordSpacing(); |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2325 | float lastSpaceWordSpacing = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2326 | |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 2327 | // Non-zero only when kerning is enabled, in which case we measure words with their trailing |
| 2328 | // space, then subtract its width. |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 2329 | float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(constructTextRun(t, f, &space, 1, style)) + wordSpacing : 0; |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 2330 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2331 | float wrapW = width.uncommittedWidth() + inlineLogicalWidth(current.m_obj, !appliedStartWidth, true); |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2332 | float charWidth = 0; |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2333 | bool breakNBSP = autoWrap && currentStyle->nbspMode() == SPACE; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2334 | // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word, |
| 2335 | // which is only possible if the word is the first thing on the line, that is, if |w| is zero. |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2336 | bool breakWords = currentStyle->breakWords() && ((autoWrap && !width.committedWidth()) || currWS == PRE); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2337 | bool midWordBreak = false; |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2338 | bool breakAll = currentStyle->wordBreak() == BreakAllWordBreak && autoWrap; |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2339 | float hyphenWidth = 0; |
hyatt | ea474f7 | 2007-04-20 05:02:19 +0000 | [diff] [blame] | 2340 | |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 2341 | if (t->isWordBreak()) { |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2342 | width.commit(); |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2343 | lBreak.moveToStartOf(current.m_obj); |
| 2344 | ASSERT(current.m_pos == t->textLength()); |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2347 | for (; current.m_pos < t->textLength(); current.fastIncrementInTextNode()) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2348 | bool previousCharacterIsSpace = currentCharacterIsSpace; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2349 | bool previousCharacterIsWS = currentCharacterIsWS; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2350 | UChar c = current.current(); |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2351 | currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNewline && (c == '\n')); |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 2352 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2353 | if (!collapseWhiteSpace || !currentCharacterIsSpace) |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2354 | lineInfo.setEmpty(false, m_block, &width); |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 2355 | |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 2356 | if (c == softHyphen && autoWrap && !hyphenWidth && style->hyphens() != HyphensNone) { |
commit-queue@webkit.org | e60bb90 | 2011-09-08 19:18:43 +0000 | [diff] [blame] | 2357 | hyphenWidth = measureHyphenWidth(t, f); |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2358 | width.addUncommittedWidth(hyphenWidth); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2359 | } |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 2360 | |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 2361 | bool applyWordSpacing = false; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2362 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 2363 | currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace); |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2364 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 2365 | if ((breakAll || breakWords) && !midWordBreak) { |
| 2366 | wrapW += charWidth; |
mitz@apple.com | 880d8e1 | 2011-08-17 20:52:31 +0000 | [diff] [blame] | 2367 | bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && current.m_pos + 1 < t->textLength() && U16_IS_TRAIL(t->characters()[current.m_pos + 1]); |
mitz@apple.com | fe520be | 2011-06-26 16:09:33 +0000 | [diff] [blame] | 2368 | charWidth = textWidth(t, current.m_pos, midWordBreakIsBeforeSurrogatePair ? 2 : 1, f, width.committedWidth() + wrapW, isFixedPitch, collapseWhiteSpace); |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2369 | midWordBreak = width.committedWidth() + wrapW + charWidth > width.availableWidth(); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2370 | } |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 2371 | |
commit-queue@webkit.org | b01957a | 2012-02-14 22:02:05 +0000 | [diff] [blame] | 2372 | if ((lineBreakIteratorInfo.first != t) || (lineBreakIteratorInfo.second.string() != t->characters())) { |
mitz@apple.com | 44fc513 | 2011-02-25 18:34:15 +0000 | [diff] [blame] | 2373 | lineBreakIteratorInfo.first = t; |
mitz@apple.com | df9281d | 2011-06-23 18:02:45 +0000 | [diff] [blame] | 2374 | lineBreakIteratorInfo.second.reset(t->characters(), t->textLength(), style->locale()); |
mitz@apple.com | 44fc513 | 2011-02-25 18:34:15 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2377 | bool betweenWords = c == '\n' || (currWS != PRE && !atStart && isBreakable(lineBreakIteratorInfo.second, current.m_pos, current.m_nextBreakablePosition, breakNBSP) |
| 2378 | && (style->hyphens() != HyphensNone || (current.previousInSameNode() != softHyphen))); |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 2379 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 2380 | if (betweenWords || midWordBreak) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2381 | bool stoppedIgnoringSpaces = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2382 | if (ignoringSpaces) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2383 | if (!currentCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2384 | // Stop ignoring spaces and begin at this |
| 2385 | // new point. |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 2386 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2387 | lastSpaceWordSpacing = 0; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2388 | lastSpace = current.m_pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
| 2389 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2390 | stoppedIgnoringSpaces = true; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2391 | } else { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2392 | // Just keep ignoring these spaces. |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2393 | continue; |
| 2394 | } |
| 2395 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2396 | |
hyatt@apple.com | 0acc935 | 2011-02-17 19:19:07 +0000 | [diff] [blame] | 2397 | float additionalTmpW; |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 2398 | if (wordTrailingSpaceWidth && currentCharacterIsSpace) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2399 | additionalTmpW = textWidth(t, lastSpace, current.m_pos + 1 - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) - wordTrailingSpaceWidth + lastSpaceWordSpacing; |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 2400 | else |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2401 | additionalTmpW = textWidth(t, lastSpace, current.m_pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing; |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2402 | width.addUncommittedWidth(additionalTmpW); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2403 | if (!appliedStartWidth) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2404 | width.addUncommittedWidth(inlineLogicalWidth(current.m_obj, true, false)); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2405 | appliedStartWidth = true; |
| 2406 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2407 | |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2408 | applyWordSpacing = wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 2409 | |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2410 | if (!width.committedWidth() && autoWrap && !width.fitsOnLine()) |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 2411 | width.fitBelowFloats(); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 2412 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2413 | if (autoWrap || breakWords) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2414 | // If we break only after white-space, consider the current character |
kocienda | e413424 | 2004-10-25 18:48:44 +0000 | [diff] [blame] | 2415 | // as candidate width for this line. |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2416 | bool lineWasTooWide = false; |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2417 | if (width.fitsOnLine() && currentCharacterIsWS && currentStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2418 | float charWidth = textWidth(t, current.m_pos, 1, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) + (applyWordSpacing ? wordSpacing : 0); |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2419 | // Check if line is too big even without the extra space |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2420 | // at the end of the line. If it is not, do nothing. |
| 2421 | // If the line needs the extra whitespace to be too long, |
| 2422 | // then move the line break to the space and skip all |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2423 | // additional whitespace. |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2424 | if (!width.fitsOnLine(charWidth)) { |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2425 | lineWasTooWide = true; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2426 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2427 | skipTrailingWhitespace(lBreak, lineInfo); |
kocienda | 9dbe9b1 | 2004-10-22 20:07:05 +0000 | [diff] [blame] | 2428 | } |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2429 | } |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2430 | if (lineWasTooWide || !width.fitsOnLine()) { |
| 2431 | if (canHyphenate && !width.fitsOnLine()) { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2432 | tryHyphenating(t, f, style->locale(), consecutiveHyphenatedLines, blockStyle->hyphenationLimitLines(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated); |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2433 | if (m_hyphenated) |
mitz@apple.com | 67ed70a | 2010-06-22 22:10:10 +0000 | [diff] [blame] | 2434 | goto end; |
| 2435 | } |
leviw@chromium.org | cee2051 | 2011-04-06 12:12:58 +0000 | [diff] [blame] | 2436 | if (lBreak.atTextParagraphSeparator()) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2437 | if (!stoppedIgnoringSpaces && current.m_pos > 0) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2438 | // We need to stop right before the newline and then start up again. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2439 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos - 1)); // Stop |
| 2440 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); // Start |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2441 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2442 | lBreak.increment(); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2443 | lineInfo.setPreviousLineBrokeCleanly(true); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 2444 | } |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 2445 | if (lBreak.m_obj && lBreak.m_pos && lBreak.m_obj->isText() && toRenderText(lBreak.m_obj)->textLength() && toRenderText(lBreak.m_obj)->characters()[lBreak.m_pos - 1] == softHyphen && style->hyphens() != HyphensNone) |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2446 | m_hyphenated = true; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2447 | goto end; // Didn't fit. Jump to the end. |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2448 | } else { |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 2449 | if (!betweenWords || (midWordBreak && !autoWrap)) |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2450 | width.addUncommittedWidth(-additionalTmpW); |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 2451 | if (hyphenWidth) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2452 | // Subtract the width of the soft hyphen out since we fit on a line. |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2453 | width.addUncommittedWidth(-hyphenWidth); |
mitz@apple.com | 20e3445 | 2010-09-28 19:38:15 +0000 | [diff] [blame] | 2454 | hyphenWidth = 0; |
| 2455 | } |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2456 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2457 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2458 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2459 | if (c == '\n' && preserveNewline) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2460 | if (!stoppedIgnoringSpaces && current.m_pos > 0) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2461 | // We need to stop right before the newline and then start up again. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2462 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos - 1)); // Stop |
| 2463 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); // Start |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2464 | } |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2465 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2466 | lBreak.increment(); |
leviw@chromium.org | f009c8e | 2011-05-03 20:49:15 +0000 | [diff] [blame] | 2467 | lineInfo.setPreviousLineBrokeCleanly(true); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2468 | return lBreak; |
| 2469 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2470 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2471 | if (autoWrap && betweenWords) { |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2472 | width.commit(); |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 2473 | wrapW = 0; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2474 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2475 | // Auto-wrapping text should not wrap in the middle of a word once it has had an |
| 2476 | // opportunity to break after a word. |
| 2477 | breakWords = false; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2478 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2479 | |
mitz@apple.com | 8687772 | 2011-08-19 16:29:32 +0000 | [diff] [blame] | 2480 | if (midWordBreak && !U16_IS_TRAIL(c) && !(category(c) & (Mark_NonSpacing | Mark_Enclosing | Mark_SpacingCombining))) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2481 | // Remember this as a breakable position in case |
| 2482 | // adding the end width forces a break. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2483 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 2484 | midWordBreak &= (breakWords || breakAll); |
| 2485 | } |
| 2486 | |
| 2487 | if (betweenWords) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2488 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2489 | lastSpace = current.m_pos; |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2490 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2491 | |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2492 | if (!ignoringSpaces && currentStyle->collapseWhiteSpace()) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2493 | // If we encounter a newline, or if we encounter a |
| 2494 | // second space, we need to go ahead and break up this |
| 2495 | // run and enter a mode where we start collapsing spaces. |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2496 | if (currentCharacterIsSpace && previousCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2497 | ignoringSpaces = true; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2498 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2499 | // We just entered a mode where we are ignoring |
| 2500 | // spaces. Create a midpoint to terminate the run |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2501 | // before the second space. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2502 | addMidpoint(lineMidpointState, ignoreStart); |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2503 | trailingObjects.updateMidpointsForTrailingBoxes(lineMidpointState, InlineIterator(), TrailingObjects::DoNotCollapseFirstSpace); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2504 | } |
| 2505 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2506 | } else if (ignoringSpaces) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2507 | // Stop ignoring spaces and begin at this |
| 2508 | // new point. |
| 2509 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2510 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2511 | lastSpace = current.m_pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
| 2512 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2513 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2514 | |
zimmermann@webkit.org | cea31466 | 2011-04-05 16:38:10 +0000 | [diff] [blame] | 2515 | #if ENABLE(SVG) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2516 | if (isSVGText && current.m_pos > 0) { |
zimmermann@webkit.org | cea31466 | 2011-04-05 16:38:10 +0000 | [diff] [blame] | 2517 | // Force creation of new InlineBoxes for each absolute positioned character (those that start new text chunks). |
jchaffraix@webkit.org | 3e44dfa | 2011-06-20 23:14:23 +0000 | [diff] [blame] | 2518 | if (toRenderSVGInlineText(t)->characterStartsNewTextChunk(current.m_pos)) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2519 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos - 1)); |
| 2520 | addMidpoint(lineMidpointState, InlineIterator(0, current.m_obj, current.m_pos)); |
zimmermann@webkit.org | cea31466 | 2011-04-05 16:38:10 +0000 | [diff] [blame] | 2521 | } |
| 2522 | } |
| 2523 | #endif |
| 2524 | |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2525 | if (currentCharacterIsSpace && !previousCharacterIsSpace) { |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2526 | ignoreStart.m_obj = current.m_obj; |
| 2527 | ignoreStart.m_pos = current.m_pos; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2528 | } |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2529 | |
| 2530 | if (!currentCharacterIsWS && previousCharacterIsWS) { |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2531 | if (autoWrap && currentStyle->breakOnlyAfterWhiteSpace()) |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2532 | lBreak.moveTo(current.m_obj, current.m_pos, current.m_nextBreakablePosition); |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2533 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2534 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2535 | if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSpaces) |
jchaffraix@webkit.org | 3e44dfa | 2011-06-20 23:14:23 +0000 | [diff] [blame] | 2536 | trailingObjects.setTrailingWhitespace(toRenderText(current.m_obj)); |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2537 | else if (!currentStyle->collapseWhiteSpace() || !currentCharacterIsSpace) |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2538 | trailingObjects.clear(); |
| 2539 | |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 2540 | atStart = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2541 | } |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 2542 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2543 | // IMPORTANT: current.m_pos is > length here! |
| 2544 | float additionalTmpW = ignoringSpaces ? 0 : textWidth(t, lastSpace, current.m_pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing; |
yael.aharon@nokia.com | 1cfbceb | 2011-06-06 18:32:54 +0000 | [diff] [blame] | 2545 | width.addUncommittedWidth(additionalTmpW + inlineLogicalWidth(current.m_obj, !appliedStartWidth, includeEndWidth)); |
| 2546 | includeEndWidth = false; |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2547 | |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2548 | if (!width.fitsOnLine()) { |
mitz@apple.com | 96cf46d | 2011-03-14 01:09:26 +0000 | [diff] [blame] | 2549 | if (canHyphenate) |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2550 | tryHyphenating(t, f, style->locale(), consecutiveHyphenatedLines, blockStyle->hyphenationLimitLines(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, current.m_pos, width.currentWidth() - additionalTmpW, width.availableWidth(), isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, current.m_nextBreakablePosition, m_hyphenated); |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2551 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2552 | if (!m_hyphenated && lBreak.previousInSameNode() == softHyphen && style->hyphens() != HyphensNone) |
| 2553 | m_hyphenated = true; |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2554 | |
leviw@chromium.org | 1a50869 | 2011-05-05 00:01:11 +0000 | [diff] [blame] | 2555 | if (m_hyphenated) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 2556 | goto end; |
| 2557 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2558 | } else |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2559 | ASSERT_NOT_REACHED(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2560 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2561 | bool checkForBreak = autoWrap; |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2562 | if (width.committedWidth() && !width.fitsOnLine() && lBreak.m_obj && currWS == NOWRAP) |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 2563 | checkForBreak = true; |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2564 | else if (next && current.m_obj->isText() && next->isText() && !next->isBR() && (autoWrap || (next->style()->autoWrap()))) { |
| 2565 | if (currentCharacterIsSpace) |
| 2566 | checkForBreak = true; |
| 2567 | else { |
| 2568 | RenderText* nextText = toRenderText(next); |
| 2569 | if (nextText->textLength()) { |
| 2570 | UChar c = nextText->characters()[0]; |
| 2571 | checkForBreak = (c == ' ' || c == '\t' || (c == '\n' && !next->preservesNewline())); |
| 2572 | // If the next item on the line is text, and if we did not end with |
| 2573 | // a space, then the next text run continues our word (and so it needs to |
| 2574 | // keep adding to |tmpW|. Just update and continue. |
| 2575 | } else if (nextText->isWordBreak()) |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2576 | checkForBreak = true; |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2577 | |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2578 | if (!width.fitsOnLine() && !width.committedWidth()) |
| 2579 | width.fitBelowFloats(); |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2580 | |
rniwa@webkit.org | 76aa522 | 2011-05-04 13:03:32 +0000 | [diff] [blame] | 2581 | bool canPlaceOnLine = width.fitsOnLine() || !autoWrapWasEverTrueOnLine; |
| 2582 | if (canPlaceOnLine && checkForBreak) { |
| 2583 | width.commit(); |
| 2584 | lBreak.moveToStartOf(next); |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | } |
| 2588 | |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2589 | if (checkForBreak && !width.fitsOnLine()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2590 | // if we have floats, try to get below them. |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2591 | if (currentCharacterIsSpace && !ignoringSpaces && currentStyle->collapseWhiteSpace()) |
rniwa@webkit.org | 105350c | 2011-05-03 20:33:25 +0000 | [diff] [blame] | 2592 | trailingObjects.clear(); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 2593 | |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2594 | if (width.committedWidth()) |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 2595 | goto end; |
| 2596 | |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 2597 | width.fitBelowFloats(); |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 2598 | |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 2599 | // |width| may have been adjusted because we got shoved down past a float (thus |
| 2600 | // giving us more room), so we need to retest, and only jump to |
| 2601 | // the end label if we still don't fit on the line. -dwh |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2602 | if (!width.fitsOnLine()) |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 2603 | goto end; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2604 | } |
hyatt | 1d9e29b | 2003-04-10 01:48:53 +0000 | [diff] [blame] | 2605 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2606 | if (!current.m_obj->isFloatingOrPositioned()) { |
| 2607 | last = current.m_obj; |
darin@apple.com | b6cb256 | 2009-08-05 21:25:09 +0000 | [diff] [blame] | 2608 | if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || toRenderListMarker(last)->isInside())) { |
rniwa@webkit.org | 58925e8 | 2011-04-12 21:32:58 +0000 | [diff] [blame] | 2609 | width.commit(); |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2610 | lBreak.moveToStartOf(next); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2611 | } |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2614 | // Clear out our character space bool, since inline <pre>s don't collapse whitespace |
| 2615 | // with adjacent inline normal/nowrap spans. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2616 | if (!collapseWhiteSpace) |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2617 | currentCharacterIsSpace = false; |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2618 | |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2619 | current.moveToStartOf(next); |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 2620 | atStart = false; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2621 | } |
eric@webkit.org | 060caf6 | 2011-05-03 22:11:39 +0000 | [diff] [blame] | 2622 | |
rniwa@webkit.org | 5eb8d16 | 2011-04-13 02:13:33 +0000 | [diff] [blame] | 2623 | if (width.fitsOnLine() || lastWS == NOWRAP) |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2624 | lBreak.clear(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2625 | |
| 2626 | end: |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 2627 | if (lBreak == resolver.position() && (!lBreak.m_obj || !lBreak.m_obj->isBR())) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2628 | // we just add as much as possible |
mihnea@adobe.com | 3bebbf2 | 2012-01-19 09:22:59 +0000 | [diff] [blame] | 2629 | if (blockStyle->whiteSpace() == PRE) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2630 | // FIXME: Don't really understand this case. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2631 | if (current.m_pos) { |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2632 | // FIXME: This should call moveTo which would clear m_nextBreakablePosition |
| 2633 | // this code as-is is likely wrong. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2634 | lBreak.m_obj = current.m_obj; |
| 2635 | lBreak.m_pos = current.m_pos - 1; |
eric@webkit.org | bd14359 | 2011-03-29 17:44:41 +0000 | [diff] [blame] | 2636 | } else |
| 2637 | lBreak.moveTo(last, last->isText() ? last->length() : 0); |
eric@webkit.org | 8c25a59 | 2011-03-29 13:18:11 +0000 | [diff] [blame] | 2638 | } else if (lBreak.m_obj) { |
yuzo@google.com | c25f62f | 2010-02-09 09:16:36 +0000 | [diff] [blame] | 2639 | // Don't ever break in the middle of a word if we can help it. |
| 2640 | // There's no room at all. We just have to be on this line, |
| 2641 | // even though we'll spill out. |
rniwa@webkit.org | 15b9152 | 2011-05-04 00:38:05 +0000 | [diff] [blame] | 2642 | lBreak.moveTo(current.m_obj, current.m_pos); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | // make sure we consume at least one char/object. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2647 | if (lBreak == resolver.position()) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2648 | lBreak.increment(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2649 | |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 2650 | // Sanity check our midpoints. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2651 | checkMidpoints(lineMidpointState, lBreak); |
hyatt@apple.com | 63a8df3 | 2011-03-28 19:44:19 +0000 | [diff] [blame] | 2652 | |
mitz@apple.com | e98acc9 | 2011-05-22 04:44:27 +0000 | [diff] [blame] | 2653 | trailingObjects.updateMidpointsForTrailingBoxes(lineMidpointState, lBreak, TrailingObjects::CollapseFirstSpace); |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2654 | |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2655 | // We might have made lBreak an iterator that points past the end |
| 2656 | // of the object. Do this adjustment to make it point to the start |
| 2657 | // of the next object instead to avoid confusing the rest of the |
| 2658 | // code. |
eric@webkit.org | 86a865a | 2011-03-29 15:30:41 +0000 | [diff] [blame] | 2659 | if (lBreak.m_pos > 0) { |
| 2660 | lBreak.m_pos--; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2661 | lBreak.increment(); |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2664 | return lBreak; |
| 2665 | } |
| 2666 | |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 2667 | void RenderBlock::addOverflowFromInlineChildren() |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2668 | { |
leviw@chromium.org | 6ff37a9 | 2012-02-16 04:49:03 +0000 | [diff] [blame] | 2669 | LayoutUnit endPadding = hasOverflowClip() ? paddingEnd() : zeroLayoutUnit; |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 2670 | // FIXME: Need to find another way to do this, since scrollbars could show when we don't want them to. |
commit-queue@webkit.org | 595681f | 2011-03-25 16:21:30 +0000 | [diff] [blame] | 2671 | if (hasOverflowClip() && !endPadding && node() && node()->rendererIsEditable() && node() == node()->rootEditableElement() && style()->isLeftToRightDirection()) |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 2672 | endPadding = 1; |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2673 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
hyatt@apple.com | 592848f | 2010-12-06 20:03:43 +0000 | [diff] [blame] | 2674 | addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding)); |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 2675 | if (!hasOverflowClip()) |
hyatt@apple.com | 61f2532 | 2011-03-31 20:40:48 +0000 | [diff] [blame] | 2676 | addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom())); |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2677 | } |
| 2678 | } |
| 2679 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2680 | void RenderBlock::deleteEllipsisLineBoxes() |
| 2681 | { |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2682 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 2683 | curr->clearTruncation(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | void RenderBlock::checkLinesForTextOverflow() |
| 2687 | { |
| 2688 | // Determine the width of the ellipsis using the current font. |
darin | dbba2bb | 2007-01-11 12:23:49 +0000 | [diff] [blame] | 2689 | // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable" |
zimmermann@webkit.org | 8a7e7ff | 2011-05-24 15:27:36 +0000 | [diff] [blame] | 2690 | const Font& font = style()->font(); |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 2691 | DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1)); |
hyatt | 3e99d1c | 2006-02-24 21:13:08 +0000 | [diff] [blame] | 2692 | const Font& firstLineFont = firstLineStyle()->font(); |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2693 | LayoutUnit firstLineEllipsisWidth = firstLineFont.width(constructTextRun(this, firstLineFont, &horizontalEllipsis, 1, firstLineStyle())); |
| 2694 | LayoutUnit ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(constructTextRun(this, font, &horizontalEllipsis, 1, style())); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2695 | |
| 2696 | // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see |
| 2697 | // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and |
| 2698 | // check the left edge of the line box to see if it is less |
| 2699 | // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()" |
hyatt@apple.com | c0fa163 | 2010-09-30 20:01:33 +0000 | [diff] [blame] | 2700 | bool ltr = style()->isLeftToRightDirection(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2701 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2702 | LayoutUnit blockRightEdge = logicalRightOffsetForLine(curr->y(), curr == firstRootBox()); |
| 2703 | LayoutUnit blockLeftEdge = logicalLeftOffsetForLine(curr->y(), curr == firstRootBox()); |
| 2704 | LayoutUnit lineBoxEdge = ltr ? curr->x() + curr->logicalWidth() : curr->x(); |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 2705 | if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) { |
hyatt | f918d2d | 2004-06-15 07:24:11 +0000 | [diff] [blame] | 2706 | // This line spills out of our box in the appropriate direction. Now we need to see if the line |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2707 | // can be truncated. In order for truncation to be possible, the line must have sufficient space to |
| 2708 | // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis |
| 2709 | // space. |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2710 | LayoutUnit width = curr == firstRootBox() ? firstLineEllipsisWidth : ellipsisWidth; |
| 2711 | LayoutUnit blockEdge = ltr ? blockRightEdge : blockLeftEdge; |
thakis@chromium.org | a4fcdf3 | 2011-02-22 05:51:51 +0000 | [diff] [blame] | 2712 | if (curr->lineCanAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 2713 | curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2714 | } |
| 2715 | } |
| 2716 | } |
| 2717 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2718 | bool RenderBlock::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, LineInfo& lineInfo, LineWidth& width) |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2719 | { |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2720 | if (!positionNewFloats()) |
| 2721 | return false; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2722 | |
rniwa@webkit.org | 4442475 | 2011-04-14 00:58:40 +0000 | [diff] [blame] | 2723 | width.shrinkAvailableWidthForNewFloatIfNeeded(newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2724 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 2725 | // We only connect floats to lines for pagination purposes if the floats occur at the start of |
| 2726 | // the line and the previous line had a hard break (so this line is either the first in the block |
| 2727 | // or follows a <br>). |
| 2728 | if (!newFloat->m_paginationStrut || !lineInfo.previousLineBrokeCleanly() || !lineInfo.isEmpty()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2729 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2730 | |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 2731 | const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2732 | ASSERT(floatingObjectSet.last() == newFloat); |
| 2733 | |
eae@chromium.org | ee8613e | 2011-11-12 01:12:58 +0000 | [diff] [blame] | 2734 | LayoutUnit floatLogicalTop = logicalTopForFloat(newFloat); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2735 | int paginationStrut = newFloat->m_paginationStrut; |
| 2736 | |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2737 | if (floatLogicalTop - paginationStrut != logicalHeight() + lineInfo.floatPaginationStrut()) |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2738 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2739 | |
| 2740 | FloatingObjectSetIterator it = floatingObjectSet.end(); |
| 2741 | --it; // Last float is newFloat, skip that one. |
| 2742 | FloatingObjectSetIterator begin = floatingObjectSet.begin(); |
| 2743 | while (it != begin) { |
| 2744 | --it; |
| 2745 | FloatingObject* f = *it; |
| 2746 | if (f == lastFloatFromPreviousLine) |
| 2747 | break; |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2748 | if (logicalTopForFloat(f) == logicalHeight() + lineInfo.floatPaginationStrut()) { |
| 2749 | f->m_paginationStrut += paginationStrut; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2750 | RenderBox* o = f->m_renderer; |
| 2751 | setLogicalTopForChild(o, logicalTopForChild(o) + marginBeforeForChild(o) + paginationStrut); |
| 2752 | if (o->isRenderBlock()) |
| 2753 | toRenderBlock(o)->setChildNeedsLayout(true, false); |
| 2754 | o->layoutIfNeeded(); |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 2755 | // Save the old logical top before calling removePlacedObject which will set |
| 2756 | // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat. |
| 2757 | LayoutUnit oldLogicalTop = logicalTopForFloat(f); |
| 2758 | m_floatingObjects->removePlacedObject(f); |
hyatt@apple.com | 5950bd4 | 2011-09-27 20:39:57 +0000 | [diff] [blame] | 2759 | setLogicalTopForFloat(f, oldLogicalTop + paginationStrut); |
hyatt@apple.com | 46c65b3 | 2011-08-09 19:13:45 +0000 | [diff] [blame] | 2760 | m_floatingObjects->addPlacedObject(f); |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2761 | } |
| 2762 | } |
| 2763 | |
hyatt@apple.com | dd78df8 | 2011-09-27 22:11:41 +0000 | [diff] [blame] | 2764 | // Just update the line info's pagination strut without altering our logical height yet. If the line ends up containing |
| 2765 | // no content, then we don't want to improperly grow the height of the block. |
| 2766 | lineInfo.setFloatPaginationStrut(lineInfo.floatPaginationStrut() + paginationStrut); |
rniwa@webkit.org | 7881ad0 | 2011-04-07 13:05:35 +0000 | [diff] [blame] | 2767 | return true; |
rniwa@webkit.org | 73ce42a | 2011-04-06 14:10:02 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2770 | LayoutUnit RenderBlock::startAlignedOffsetForLine(RenderBox* child, LayoutUnit position, bool firstLine) |
| 2771 | { |
| 2772 | ETextAlign textAlign = style()->textAlign(); |
| 2773 | |
| 2774 | if (textAlign == TAAUTO) |
| 2775 | return startOffsetForLine(position, firstLine); |
| 2776 | |
| 2777 | // updateLogicalWidthForAlignment() handles the direction of the block so no need to consider it here |
| 2778 | float logicalLeft; |
| 2779 | float availableLogicalWidth; |
| 2780 | logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false); |
| 2781 | availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), false) - logicalLeft; |
| 2782 | float totalLogicalWidth = logicalWidthForChild(child); |
| 2783 | updateLogicalWidthForAlignment(textAlign, 0l, logicalLeft, totalLogicalWidth, availableLogicalWidth, 0); |
robert@webkit.org | 7861a10 | 2011-09-22 17:16:47 +0000 | [diff] [blame] | 2784 | |
| 2785 | if (!style()->isLeftToRightDirection()) |
hyatt@apple.com | 0f06023 | 2011-10-01 03:07:46 +0000 | [diff] [blame] | 2786 | return logicalWidth() - (logicalLeft + totalLogicalWidth); |
robert@webkit.org | fc7763c | 2011-09-03 18:28:57 +0000 | [diff] [blame] | 2787 | return logicalLeft; |
| 2788 | } |
| 2789 | |
hyatt@apple.com | ee7af1d | 2012-01-17 19:16:24 +0000 | [diff] [blame] | 2790 | |
| 2791 | void RenderBlock::layoutLineGridBox() |
| 2792 | { |
| 2793 | if (style()->lineGrid() == RenderStyle::initialLineGrid()) { |
| 2794 | setLineGridBox(0); |
| 2795 | return; |
| 2796 | } |
| 2797 | |
| 2798 | setLineGridBox(0); |
| 2799 | |
| 2800 | RootInlineBox* lineGridBox = new (renderArena()) RootInlineBox(this); |
| 2801 | lineGridBox->setHasTextChildren(); // Needed to make the line ascent/descent actually be honored in quirks mode. |
| 2802 | lineGridBox->setConstructed(); |
| 2803 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
| 2804 | VerticalPositionCache verticalPositionCache; |
| 2805 | lineGridBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache); |
| 2806 | |
| 2807 | setLineGridBox(lineGridBox); |
| 2808 | |
| 2809 | // FIXME: If any of the characteristics of the box change compared to the old one, then we need to do a deep dirtying |
| 2810 | // (similar to what happens when the page height changes). Ideally, though, we only do this if someone is actually snapping |
| 2811 | // to this grid. |
| 2812 | } |
| 2813 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2814 | } |