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