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