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