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