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 | 1d4e953 | 2010-01-18 20:55:25 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010 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" |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 26 | #include "CharacterNames.h" |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 27 | #include "Hyphenation.h" |
hyatt@apple.com | 71eeb44 | 2010-02-11 20:05:51 +0000 | [diff] [blame] | 28 | #include "InlineIterator.h" |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 29 | #include "InlineTextBox.h" |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 30 | #include "Logging.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 31 | #include "RenderArena.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" |
hyatt | d804834 | 2006-05-31 01:48:18 +0000 | [diff] [blame] | 35 | #include "RenderView.h" |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 36 | #include "Settings.h" |
dbates@webkit.org | f6f05a9 | 2010-05-17 04:58:25 +0000 | [diff] [blame] | 37 | #include "TrailingFloatsRootInlineBox.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 38 | #include "break_lines.h" |
mjs | bb86351 | 2006-05-09 09:27:55 +0000 | [diff] [blame] | 39 | #include <wtf/AlwaysInline.h> |
slewis@apple.com | a7615ca | 2008-07-12 05:51:33 +0000 | [diff] [blame] | 40 | #include <wtf/RefCountedLeakCounter.h> |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 41 | #include <wtf/StdLibExtras.h> |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 42 | #include <wtf/Vector.h> |
hyatt | 8c371e5 | 2004-06-16 01:19:26 +0000 | [diff] [blame] | 43 | |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 44 | #if ENABLE(SVG) |
zimmermann@webkit.org | 6e96afd | 2010-09-10 15:35:50 +0000 | [diff] [blame] | 45 | #include "RenderSVGInlineText.h" |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 46 | #include "SVGRootInlineBox.h" |
| 47 | #endif |
| 48 | |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 49 | using namespace std; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 50 | using namespace WTF; |
| 51 | using namespace Unicode; |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 52 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 53 | namespace WebCore { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 54 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 55 | // We don't let our line box tree for a single line get any deeper than this. |
| 56 | const unsigned cMaxLineDepth = 200; |
| 57 | |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 58 | static int getBorderPaddingMargin(RenderBoxModelObject* child, bool endOfInline) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 59 | { |
hyatt@apple.com | 21cc37a | 2008-02-26 23:17:03 +0000 | [diff] [blame] | 60 | bool leftSide = (child->style()->direction() == LTR) ? !endOfInline : endOfInline; |
| 61 | if (leftSide) |
| 62 | return child->marginLeft() + child->paddingLeft() + child->borderLeft(); |
| 63 | return child->marginRight() + child->paddingRight() + child->borderRight(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static int inlineWidth(RenderObject* child, bool start = true, bool end = true) |
| 67 | { |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 68 | unsigned lineDepth = 1; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 69 | int extraWidth = 0; |
| 70 | RenderObject* parent = child->parent(); |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 71 | while (parent->isInline() && !parent->isInlineBlockOrInlineTable() && lineDepth++ < cMaxLineDepth) { |
hyatt@apple.com | 40232f8 | 2009-02-04 04:26:08 +0000 | [diff] [blame] | 72 | if (start && !child->previousSibling()) |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 73 | extraWidth += getBorderPaddingMargin(toRenderBoxModelObject(parent), false); |
hyatt@apple.com | 40232f8 | 2009-02-04 04:26:08 +0000 | [diff] [blame] | 74 | if (end && !child->nextSibling()) |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 75 | extraWidth += getBorderPaddingMargin(toRenderBoxModelObject(parent), true); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 76 | child = parent; |
| 77 | parent = child->parent(); |
| 78 | } |
| 79 | return extraWidth; |
| 80 | } |
| 81 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 82 | static void chopMidpointsAt(LineMidpointState& lineMidpointState, RenderObject* obj, unsigned pos) |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 83 | { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 84 | if (!lineMidpointState.numMidpoints) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 85 | return; |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 86 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 87 | for (int i = lineMidpointState.numMidpoints - 1; i >= 0; i--) { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 88 | const InlineIterator& point = midpoints[i]; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 89 | if (point.obj == obj && point.pos == pos) { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 90 | lineMidpointState.numMidpoints = i; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 91 | break; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 96 | static void checkMidpoints(LineMidpointState& lineMidpointState, InlineIterator& lBreak) |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 97 | { |
| 98 | // 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] | 99 | // shave it off the list, and shave off a trailing space if the previous end point doesn't |
| 100 | // preserve whitespace. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 101 | if (lBreak.obj && lineMidpointState.numMidpoints && !(lineMidpointState.numMidpoints % 2)) { |
| 102 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 103 | InlineIterator& endpoint = midpoints[lineMidpointState.numMidpoints - 2]; |
| 104 | const InlineIterator& startpoint = midpoints[lineMidpointState.numMidpoints - 1]; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 105 | InlineIterator currpoint = endpoint; |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 106 | while (!currpoint.atEnd() && currpoint != startpoint && currpoint != lBreak) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 107 | currpoint.increment(); |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 108 | if (currpoint == lBreak) { |
| 109 | // 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] | 110 | lineMidpointState.numMidpoints--; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 111 | if (endpoint.obj->style()->collapseWhiteSpace()) { |
hyatt | ee1bcae | 2004-03-29 21:36:04 +0000 | [diff] [blame] | 112 | if (endpoint.obj->isText()) { |
harrison | a4d6cdc | 2006-10-02 15:32:17 +0000 | [diff] [blame] | 113 | // Don't shave a character off the endpoint if it was from a soft hyphen. |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 114 | RenderText* textObj = toRenderText(endpoint.obj); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 115 | if (endpoint.pos + 1 < textObj->textLength()) { |
| 116 | if (textObj->characters()[endpoint.pos+1] == softHyphen) |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 117 | return; |
| 118 | } else if (startpoint.obj->isText()) { |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 119 | RenderText *startText = toRenderText(startpoint.obj); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 120 | if (startText->textLength() && startText->characters()[0] == softHyphen) |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 121 | return; |
| 122 | } |
hyatt | ee1bcae | 2004-03-29 21:36:04 +0000 | [diff] [blame] | 123 | } |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 124 | endpoint.pos--; |
hyatt | ee1bcae | 2004-03-29 21:36:04 +0000 | [diff] [blame] | 125 | } |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 130 | static void addMidpoint(LineMidpointState& lineMidpointState, const InlineIterator& midpoint) |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 131 | { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 132 | if (lineMidpointState.midpoints.size() <= lineMidpointState.numMidpoints) |
| 133 | lineMidpointState.midpoints.grow(lineMidpointState.numMidpoints + 10); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 134 | |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 135 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 136 | midpoints[lineMidpointState.numMidpoints++] = midpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 137 | } |
| 138 | |
hyatt@apple.com | 71eeb44 | 2010-02-11 20:05:51 +0000 | [diff] [blame] | 139 | void RenderBlock::appendRunsForObject(int start, int end, RenderObject* obj, InlineBidiResolver& resolver) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 140 | { |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 141 | if (start > end || obj->isFloating() || |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 142 | (obj->isPositioned() && !obj->style()->hasStaticX() && !obj->style()->hasStaticY() && !obj->container()->isRenderInline())) |
hyatt | eb003b8 | 2002-11-15 22:35:10 +0000 | [diff] [blame] | 143 | return; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 144 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 145 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 146 | bool haveNextMidpoint = (lineMidpointState.currentMidpoint < lineMidpointState.numMidpoints); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 147 | InlineIterator nextMidpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 148 | if (haveNextMidpoint) |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 149 | nextMidpoint = lineMidpointState.midpoints[lineMidpointState.currentMidpoint]; |
| 150 | if (lineMidpointState.betweenMidpoints) { |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 151 | if (!(haveNextMidpoint && nextMidpoint.obj == obj)) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 152 | return; |
| 153 | // This is a new start point. Stop ignoring objects and |
| 154 | // adjust our start. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 155 | lineMidpointState.betweenMidpoints = false; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 156 | start = nextMidpoint.pos; |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 157 | lineMidpointState.currentMidpoint++; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 158 | if (start < end) |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 159 | return appendRunsForObject(start, end, obj, resolver); |
| 160 | } else { |
mitz@apple.com | 5c2e0e0 | 2008-03-13 00:25:55 +0000 | [diff] [blame] | 161 | if (!haveNextMidpoint || (obj != nextMidpoint.obj)) { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 162 | resolver.addRun(new (obj->renderArena()) BidiRun(start, end, obj, resolver.context(), resolver.dir())); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 163 | return; |
| 164 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 165 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 166 | // An end midpoint has been encountered within our object. We |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 167 | // need to go ahead and append a run with our endpoint. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 168 | if (static_cast<int>(nextMidpoint.pos + 1) <= end) { |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 169 | lineMidpointState.betweenMidpoints = true; |
| 170 | lineMidpointState.currentMidpoint++; |
hyatt | c64f9fc | 2003-03-14 01:25:59 +0000 | [diff] [blame] | 171 | if (nextMidpoint.pos != UINT_MAX) { // UINT_MAX means stop at the object and don't include any of it. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 172 | if (static_cast<int>(nextMidpoint.pos + 1) > start) |
| 173 | resolver.addRun(new (obj->renderArena()) |
| 174 | BidiRun(start, nextMidpoint.pos + 1, obj, resolver.context(), resolver.dir())); |
| 175 | return appendRunsForObject(nextMidpoint.pos + 1, end, obj, resolver); |
hyatt | c64f9fc | 2003-03-14 01:25:59 +0000 | [diff] [blame] | 176 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 177 | } else |
| 178 | resolver.addRun(new (obj->renderArena()) BidiRun(start, end, obj, resolver.context(), resolver.dir())); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 182 | static inline InlineBox* createInlineBoxForRenderer(RenderObject* obj, bool isRootLineBox, bool isOnlyRun = false) |
| 183 | { |
| 184 | if (isRootLineBox) |
eric@webkit.org | 49b9d95 | 2009-07-03 01:29:07 +0000 | [diff] [blame] | 185 | return toRenderBlock(obj)->createAndAppendRootInlineBox(); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 186 | |
| 187 | if (obj->isText()) { |
| 188 | InlineTextBox* textBox = toRenderText(obj)->createInlineTextBox(); |
| 189 | // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode |
| 190 | // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.) |
| 191 | if (obj->isBR()) |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 192 | textBox->setIsText(isOnlyRun || obj->document()->inNoQuirksMode()); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 193 | return textBox; |
| 194 | } |
| 195 | |
| 196 | if (obj->isBox()) |
| 197 | return toRenderBox(obj)->createInlineBox(); |
| 198 | |
eric@webkit.org | 49b9d95 | 2009-07-03 01:29:07 +0000 | [diff] [blame] | 199 | return toRenderInline(obj)->createAndAppendInlineFlowBox(); |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static inline void dirtyLineBoxesForRenderer(RenderObject* o, bool fullLayout) |
| 203 | { |
| 204 | if (o->isText()) { |
hyatt@apple.com | 75dad74 | 2010-09-24 18:07:44 +0000 | [diff] [blame] | 205 | if (o->preferredLogicalWidthsDirty() && o->isCounter()) |
| 206 | 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] | 207 | toRenderText(o)->dirtyLineBoxes(fullLayout); |
| 208 | } else |
| 209 | toRenderInline(o)->dirtyLineBoxes(fullLayout); |
| 210 | } |
| 211 | |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 212 | InlineFlowBox* RenderBlock::createLineBoxes(RenderObject* obj, bool firstLine) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 213 | { |
| 214 | // See if we have an unconstructed line box for this object that is also |
| 215 | // the last item on the line. |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 216 | unsigned lineDepth = 1; |
| 217 | InlineFlowBox* childBox = 0; |
| 218 | InlineFlowBox* parentBox = 0; |
| 219 | InlineFlowBox* result = 0; |
| 220 | do { |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 221 | ASSERT(obj->isRenderInline() || obj == this); |
hyatt@apple.com | 76dbdb5 | 2009-01-29 22:49:13 +0000 | [diff] [blame] | 222 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 223 | // Get the last box we made for this render object. |
weinig@apple.com | 7c50a3b | 2009-01-30 19:55:45 +0000 | [diff] [blame] | 224 | parentBox = obj->isRenderInline() ? toRenderInline(obj)->lastLineBox() : toRenderBlock(obj)->lastLineBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 225 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 226 | // If this box is constructed then it is from a previous line, and we need |
| 227 | // to make a new box for our line. If this box is unconstructed but it has |
| 228 | // something following it on the line, then we know we have to make a new box |
| 229 | // as well. In this situation our inline has actually been split in two on |
| 230 | // the same line (this can happen with very fancy language mixtures). |
| 231 | bool constructedNewBox = false; |
| 232 | if (!parentBox || parentBox->isConstructed() || parentBox->nextOnLine()) { |
| 233 | // We need to make a new box for this render object. Once |
| 234 | // 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] | 235 | InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 236 | ASSERT(newBox->isInlineFlowBox()); |
| 237 | parentBox = static_cast<InlineFlowBox*>(newBox); |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 238 | parentBox->setFirstLineStyleBit(firstLine); |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 239 | constructedNewBox = true; |
| 240 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 241 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 242 | if (!result) |
| 243 | result = parentBox; |
| 244 | |
| 245 | // If we have hit the block itself, then |box| represents the root |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 246 | // inline box for the line, and it doesn't have to be appended to any parent |
| 247 | // inline. |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 248 | if (childBox) |
| 249 | parentBox->addToLine(childBox); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 250 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 251 | if (!constructedNewBox || obj == this) |
| 252 | break; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 253 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 254 | childBox = parentBox; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 255 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 256 | // If we've exceeded our line depth, then jump straight to the root and skip all the remaining |
| 257 | // intermediate inline flows. |
| 258 | obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 259 | |
hyatt | 1d5d87b | 2007-04-24 04:55:54 +0000 | [diff] [blame] | 260 | } while (true); |
| 261 | |
| 262 | return result; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 263 | } |
| 264 | |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 265 | RootInlineBox* RenderBlock::constructLine(unsigned runCount, BidiRun* firstRun, BidiRun* lastRun, bool firstLine, bool lastLine, RenderObject* endObject) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 266 | { |
mitz@apple.com | 887f359 | 2008-02-25 22:03:08 +0000 | [diff] [blame] | 267 | ASSERT(firstRun); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 268 | |
| 269 | InlineFlowBox* parentBox = 0; |
mitz@apple.com | 887f359 | 2008-02-25 22:03:08 +0000 | [diff] [blame] | 270 | for (BidiRun* r = firstRun; r; r = r->next()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 271 | // Create a box for our object. |
mitz@apple.com | 887f359 | 2008-02-25 22:03:08 +0000 | [diff] [blame] | 272 | bool isOnlyRun = (runCount == 1); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 273 | if (runCount == 2 && !r->m_object->isListMarker()) |
| 274 | isOnlyRun = ((style()->direction() == RTL) ? lastRun : firstRun)->m_object->isListMarker(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 275 | |
hyatt@apple.com | c92b735 | 2009-02-12 01:35:08 +0000 | [diff] [blame] | 276 | InlineBox* box = createInlineBoxForRenderer(r->m_object, false, isOnlyRun); |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 277 | r->m_box = box; |
| 278 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 279 | ASSERT(box); |
| 280 | if (!box) |
| 281 | continue; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 282 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 283 | // If we have no parent box yet, or if the run is not simply a sibling, |
| 284 | // then we need to construct inline boxes as necessary to properly enclose the |
| 285 | // run's inline box. |
| 286 | if (!parentBox || parentBox->renderer() != r->m_object->parent()) |
| 287 | // Create new inline boxes all the way back to the appropriate insertion point. |
| 288 | parentBox = createLineBoxes(r->m_object->parent(), firstLine); |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 289 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 290 | // Append the inline box to this line. |
| 291 | parentBox->addToLine(box); |
mitz@apple.com | 576e84e | 2008-04-24 19:09:48 +0000 | [diff] [blame] | 292 | |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 293 | bool visuallyOrdered = r->m_object->style()->visuallyOrdered(); |
| 294 | box->setBidiLevel(visuallyOrdered ? 0 : r->level()); |
| 295 | |
| 296 | if (box->isInlineTextBox()) { |
| 297 | InlineTextBox* text = static_cast<InlineTextBox*>(box); |
| 298 | text->setStart(r->m_start); |
| 299 | text->setLen(r->m_stop - r->m_start); |
| 300 | text->m_dirOverride = r->dirOverride(visuallyOrdered); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 301 | if (r->m_hasHyphen) |
| 302 | text->setHasHyphen(true); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 303 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | // We should have a root inline box. It should be unconstructed and |
| 307 | // be the last continuation of our line list. |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 308 | ASSERT(lastLineBox() && !lastLineBox()->isConstructed()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 309 | |
| 310 | // Set bits on our inline flow boxes that indicate which sides should |
| 311 | // paint borders/margins/padding. This knowledge will ultimately be used when |
| 312 | // we determine the horizontal positions and widths of all the inline boxes on |
| 313 | // the line. |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 314 | lastLineBox()->determineSpacingForFlowBoxes(lastLine, endObject); |
| 315 | |
| 316 | // Now mark the line boxes as being constructed. |
| 317 | lastLineBox()->setConstructed(); |
| 318 | |
| 319 | // Return the last line. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 320 | return lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 321 | } |
| 322 | |
hyatt@apple.com | 44e83c0 | 2010-09-23 22:21:30 +0000 | [diff] [blame] | 323 | void RenderBlock::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, bool firstLine, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap& textBoxDataMap) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 324 | { |
| 325 | // First determine our total width. |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 326 | int availableWidth = lineWidth(height(), firstLine); |
hyatt@apple.com | 39cee96 | 2010-09-23 21:47:13 +0000 | [diff] [blame] | 327 | int totWidth = lineBox->getFlowSpacingLogicalWidth(); |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 328 | bool needsWordSpacing = false; |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 329 | unsigned numSpaces = 0; |
| 330 | ETextAlign textAlign = style()->textAlign(); |
| 331 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 332 | for (BidiRun* r = firstRun; r; r = r->next()) { |
| 333 | if (!r->m_box || r->m_object->isPositioned() || r->m_box->isLineBreak()) |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 334 | continue; // Positioned objects are only participating to figure out their |
| 335 | // correct static x position. They have no effect on the width. |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 336 | // Similarly, line break boxes have no effect on the width. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 337 | if (r->m_object->isText()) { |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 338 | RenderText* rt = toRenderText(r->m_object); |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 339 | |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 340 | if (textAlign == JUSTIFY && r != trailingSpaceRun) { |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 341 | const UChar* characters = rt->characters(); |
| 342 | for (int i = r->m_start; i < r->m_stop; i++) { |
| 343 | UChar c = characters[i]; |
| 344 | if (c == ' ' || c == '\n' || c == '\t') |
| 345 | numSpaces++; |
| 346 | } |
| 347 | } |
| 348 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 349 | if (int length = rt->textLength()) { |
hyatt@apple.com | d0301a5 | 2009-01-26 21:50:57 +0000 | [diff] [blame] | 350 | if (!r->m_start && needsWordSpacing && isSpaceOrNewline(rt->characters()[r->m_start])) |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 351 | totWidth += rt->style(firstLine)->font().wordSpacing(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 352 | needsWordSpacing = !isSpaceOrNewline(rt->characters()[r->m_stop - 1]) && r->m_stop == length; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 353 | } |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 354 | HashSet<const SimpleFontData*> fallbackFonts; |
enrica@apple.com | b9050ed | 2010-04-07 17:01:52 +0000 | [diff] [blame] | 355 | GlyphOverflow glyphOverflow; |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 356 | int hyphenWidth = 0; |
| 357 | if (static_cast<InlineTextBox*>(r->m_box)->hasHyphen()) { |
| 358 | const AtomicString& hyphenString = rt->style()->hyphenString(); |
| 359 | hyphenWidth = rt->style(firstLine)->font().width(TextRun(hyphenString.characters(), hyphenString.length())); |
| 360 | } |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 361 | r->m_box->setLogicalWidth(rt->width(r->m_start, r->m_stop - r->m_start, totWidth, firstLine, &fallbackFonts, &glyphOverflow) + hyphenWidth); |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 362 | if (!fallbackFonts.isEmpty()) { |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 363 | ASSERT(r->m_box->isText()); |
mitz@apple.com | 0cc7bed | 2010-05-17 01:43:49 +0000 | [diff] [blame] | 364 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(static_cast<InlineTextBox*>(r->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first; |
| 365 | ASSERT(it->second.first.isEmpty()); |
| 366 | copyToVector(fallbackFonts, it->second.first); |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 367 | } |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 368 | if ((glyphOverflow.top || glyphOverflow.bottom || glyphOverflow.left || glyphOverflow.right)) { |
enrica@apple.com | b9050ed | 2010-04-07 17:01:52 +0000 | [diff] [blame] | 369 | ASSERT(r->m_box->isText()); |
mitz@apple.com | 0cc7bed | 2010-05-17 01:43:49 +0000 | [diff] [blame] | 370 | GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(static_cast<InlineTextBox*>(r->m_box), make_pair(Vector<const SimpleFontData*>(), GlyphOverflow())).first; |
| 371 | it->second.second = glyphOverflow; |
enrica@apple.com | b9050ed | 2010-04-07 17:01:52 +0000 | [diff] [blame] | 372 | } |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 373 | } else if (!r->m_object->isRenderInline()) { |
hyatt@apple.com | 0c30563 | 2009-01-23 23:25:07 +0000 | [diff] [blame] | 374 | RenderBox* renderBox = toRenderBox(r->m_object); |
hyatt@apple.com | 5f4fae0 | 2010-09-24 06:45:16 +0000 | [diff] [blame] | 375 | renderBox->computeLogicalWidth(); |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 376 | r->m_box->setLogicalWidth(renderBox->width()); |
hyatt@apple.com | d0301a5 | 2009-01-26 21:50:57 +0000 | [diff] [blame] | 377 | totWidth += renderBox->marginLeft() + renderBox->marginRight(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 378 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 379 | |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 380 | totWidth += r->m_box->logicalWidth(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // Armed with the total width of the line (without justification), |
| 384 | // we now examine our text-align property in order to determine where to position the |
| 385 | // objects horizontally. The total width of the line can be increased if we end up |
| 386 | // justifying text. |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 387 | int x = leftOffset(height(), firstLine); |
ddkilzer@apple.com | dfdc3fd | 2009-07-08 13:55:55 +0000 | [diff] [blame] | 388 | switch (textAlign) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 389 | case LEFT: |
ddkilzer | 95d2be0 | 2007-04-14 01:26:07 +0000 | [diff] [blame] | 390 | case WEBKIT_LEFT: |
hyatt | 959a54e | 2004-09-27 17:52:18 +0000 | [diff] [blame] | 391 | // The direction of the block should determine what happens with wide lines. In |
| 392 | // particular with RTL blocks, wide lines should still spill out to the left. |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 393 | if (style()->direction() == LTR) { |
| 394 | if (totWidth > availableWidth && trailingSpaceRun) |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 395 | trailingSpaceRun->m_box->setLogicalWidth(max(0, trailingSpaceRun->m_box->logicalWidth() - totWidth + availableWidth)); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 396 | } else { |
| 397 | if (trailingSpaceRun) |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 398 | trailingSpaceRun->m_box->setLogicalWidth(0); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 399 | else if (totWidth > availableWidth) |
| 400 | x -= (totWidth - availableWidth); |
| 401 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 402 | break; |
| 403 | case JUSTIFY: |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 404 | if (numSpaces && !reachedEnd && !lineBox->endsWithBreak()) { |
| 405 | if (trailingSpaceRun) { |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 406 | totWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 407 | trailingSpaceRun->m_box->setLogicalWidth(0); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 408 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 409 | break; |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 410 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 411 | // fall through |
| 412 | case TAAUTO: |
| 413 | numSpaces = 0; |
| 414 | // for right to left fall through to right aligned |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 415 | if (style()->direction() == LTR) { |
| 416 | if (totWidth > availableWidth && trailingSpaceRun) |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 417 | trailingSpaceRun->m_box->setLogicalWidth(max(0, trailingSpaceRun->m_box->logicalWidth() - totWidth + availableWidth)); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 418 | break; |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 419 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 420 | case RIGHT: |
ddkilzer | 95d2be0 | 2007-04-14 01:26:07 +0000 | [diff] [blame] | 421 | case WEBKIT_RIGHT: |
hyatt | 959a54e | 2004-09-27 17:52:18 +0000 | [diff] [blame] | 422 | // Wide lines spill out of the block based off direction. |
| 423 | // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right |
| 424 | // side of the block. |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 425 | if (style()->direction() == LTR) { |
| 426 | if (trailingSpaceRun) { |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 427 | totWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 428 | trailingSpaceRun->m_box->setLogicalWidth(0); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 429 | } |
| 430 | if (totWidth < availableWidth) |
| 431 | x += availableWidth - totWidth; |
| 432 | } else { |
| 433 | if (totWidth > availableWidth && trailingSpaceRun) { |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 434 | trailingSpaceRun->m_box->setLogicalWidth(max(0, trailingSpaceRun->m_box->logicalWidth() - totWidth + availableWidth)); |
| 435 | totWidth -= trailingSpaceRun->m_box->logicalWidth(); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 436 | } else |
| 437 | x += availableWidth - totWidth; |
| 438 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 439 | break; |
| 440 | case CENTER: |
ddkilzer | 95d2be0 | 2007-04-14 01:26:07 +0000 | [diff] [blame] | 441 | case WEBKIT_CENTER: |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 442 | int trailingSpaceWidth = 0; |
| 443 | if (trailingSpaceRun) { |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 444 | totWidth -= trailingSpaceRun->m_box->logicalWidth(); |
| 445 | trailingSpaceWidth = min(trailingSpaceRun->m_box->logicalWidth(), (availableWidth - totWidth + 1) / 2); |
| 446 | trailingSpaceRun->m_box->setLogicalWidth(max(0, trailingSpaceWidth)); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 447 | } |
mitz@apple.com | 37717da | 2008-02-28 02:23:22 +0000 | [diff] [blame] | 448 | if (style()->direction() == LTR) |
| 449 | x += max((availableWidth - totWidth) / 2, 0); |
| 450 | else |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 451 | x += totWidth > availableWidth ? (availableWidth - totWidth) : (availableWidth - totWidth) / 2 - trailingSpaceWidth; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 452 | break; |
| 453 | } |
| 454 | |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 455 | if (numSpaces) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 456 | for (BidiRun* r = firstRun; r; r = r->next()) { |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 457 | if (!r->m_box || r == trailingSpaceRun) |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 458 | continue; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 459 | |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 460 | int spaceAdd = 0; |
hyatt@apple.com | d0301a5 | 2009-01-26 21:50:57 +0000 | [diff] [blame] | 461 | if (r->m_object->isText()) { |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 462 | unsigned spaces = 0; |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 463 | const UChar* characters = toRenderText(r->m_object)->characters(); |
pewtermoose | cf72e2d | 2007-07-20 19:01:55 +0000 | [diff] [blame] | 464 | for (int i = r->m_start; i < r->m_stop; i++) { |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 465 | UChar c = characters[i]; |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 466 | if (c == ' ' || c == '\n' || c == '\t') |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 467 | spaces++; |
darin | a3c4828 | 2003-10-07 15:49:30 +0000 | [diff] [blame] | 468 | } |
hyatt | 870bdda | 2003-05-21 23:37:33 +0000 | [diff] [blame] | 469 | |
darin | b53ebdc | 2006-07-09 15:10:21 +0000 | [diff] [blame] | 470 | ASSERT(spaces <= numSpaces); |
hyatt | 870bdda | 2003-05-21 23:37:33 +0000 | [diff] [blame] | 471 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 472 | // Only justify text if whitespace is collapsed. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 473 | if (r->m_object->style()->collapseWhiteSpace()) { |
mitz@apple.com | 815ef2f | 2008-02-25 17:11:56 +0000 | [diff] [blame] | 474 | spaceAdd = (availableWidth - totWidth) * spaces / numSpaces; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 475 | static_cast<InlineTextBox*>(r->m_box)->setSpaceAdd(spaceAdd); |
hyatt | 870bdda | 2003-05-21 23:37:33 +0000 | [diff] [blame] | 476 | totWidth += spaceAdd; |
| 477 | } |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 478 | numSpaces -= spaces; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 479 | if (!numSpaces) |
| 480 | break; |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 481 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 482 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 483 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 484 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 485 | // The widths of all runs are now known. We can now place every inline box (and |
| 486 | // compute accurate widths for the inline flow boxes). |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 487 | needsWordSpacing = false; |
hyatt@apple.com | 44e83c0 | 2010-09-23 22:21:30 +0000 | [diff] [blame] | 488 | lineBox->placeBoxesInInlineDirection(x, needsWordSpacing, textBoxDataMap); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 489 | } |
| 490 | |
hyatt@apple.com | 44e83c0 | 2010-09-23 22:21:30 +0000 | [diff] [blame] | 491 | void RenderBlock::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 492 | { |
hyatt@apple.com | 44e83c0 | 2010-09-23 22:21:30 +0000 | [diff] [blame] | 493 | setHeight(lineBox->alignBoxesInBlockDirection(height(), textBoxDataMap)); |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 494 | lineBox->setBlockHeight(height()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 495 | |
| 496 | // Now make sure we place replaced render objects correctly. |
mitz@apple.com | 887f359 | 2008-02-25 22:03:08 +0000 | [diff] [blame] | 497 | for (BidiRun* r = firstRun; r; r = r->next()) { |
mitz@apple.com | aa6ce3d | 2009-04-10 01:00:20 +0000 | [diff] [blame] | 498 | ASSERT(r->m_box); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 499 | if (!r->m_box) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 500 | continue; // Skip runs with no line boxes. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 501 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 502 | // Align positioned boxes with the top of the line box. This is |
| 503 | // a reasonable approximation of an appropriate y position. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 504 | if (r->m_object->isPositioned()) |
hyatt@apple.com | 5631f11 | 2009-02-11 01:36:45 +0000 | [diff] [blame] | 505 | r->m_box->setY(height()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 506 | |
| 507 | // Position is used to properly position both replaced elements and |
| 508 | // to update the static normal flow x/y of positioned elements. |
hyatt@apple.com | 6a551ad | 2009-02-11 22:43:12 +0000 | [diff] [blame] | 509 | if (r->m_object->isText()) |
| 510 | toRenderText(r->m_object)->positionLineBox(r->m_box); |
| 511 | else if (r->m_object->isBox()) |
| 512 | toRenderBox(r->m_object)->positionLineBox(r->m_box); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 513 | } |
mitz@apple.com | a927be6 | 2008-03-21 05:30:19 +0000 | [diff] [blame] | 514 | // Positioned objects and zero-length text nodes destroy their boxes in |
| 515 | // position(), which unnecessarily dirties the line. |
| 516 | lineBox->markDirty(false); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 517 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 518 | |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 519 | static inline bool isCollapsibleSpace(UChar character, RenderText* renderer) |
| 520 | { |
| 521 | if (character == ' ' || character == '\t' || character == softHyphen) |
| 522 | return true; |
| 523 | if (character == '\n') |
| 524 | return !renderer->style()->preserveNewline(); |
| 525 | if (character == noBreakSpace) |
| 526 | return renderer->style()->nbspMode() == SPACE; |
| 527 | return false; |
| 528 | } |
| 529 | |
jamesr@google.com | 19548ad | 2010-04-02 23:21:35 +0000 | [diff] [blame] | 530 | void RenderBlock::layoutInlineChildren(bool relayoutChildren, int& repaintTop, int& repaintBottom) |
| 531 | { |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 532 | bool useRepaintBounds = false; |
| 533 | |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 534 | m_overflow.clear(); |
hyatt | 7b41b9d | 2007-05-30 05:32:40 +0000 | [diff] [blame] | 535 | |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 536 | setHeight(borderTop() + paddingTop()); |
hyatt | f9f247b | 2007-01-12 22:53:40 +0000 | [diff] [blame] | 537 | int toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 538 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 539 | // Figure out if we should clear out our line boxes. |
| 540 | // FIXME: Handle resize eventually! |
eric@webkit.org | c024942 | 2010-01-06 00:07:56 +0000 | [diff] [blame] | 541 | bool fullLayout = !firstLineBox() || selfNeedsLayout() || relayoutChildren; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 542 | if (fullLayout) |
hyatt@apple.com | b83de65 | 2009-01-28 20:48:04 +0000 | [diff] [blame] | 543 | lineBoxes()->deleteLineBoxes(renderArena()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 544 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 545 | // Text truncation only kicks in if your overflow isn't visible and your text-overflow-mode isn't |
| 546 | // clip. |
| 547 | // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely |
| 548 | // difficult to figure out (especially in the middle of doing layout), and is really an esoteric pile of nonsense |
| 549 | // anyway, so we won't worry about following the draft here. |
| 550 | bool hasTextOverflow = style()->textOverflow() && hasOverflowClip(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 551 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 552 | // Walk all the lines and delete our ellipsis line boxes if they exist. |
| 553 | if (hasTextOverflow) |
| 554 | deleteEllipsisLineBoxes(); |
| 555 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 556 | if (firstChild()) { |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 557 | // layout replaced elements |
| 558 | bool endOfInline = false; |
| 559 | RenderObject* o = bidiFirst(this, 0, false); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 560 | Vector<FloatWithRect> floats; |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 561 | bool hasInlineChild = false; |
| 562 | while (o) { |
commit-queue@webkit.org | cf45df9 | 2010-09-14 13:25:06 +0000 | [diff] [blame] | 563 | if (!hasInlineChild && o->isInline()) |
| 564 | hasInlineChild = true; |
| 565 | |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 566 | if (o->isReplaced() || o->isFloating() || o->isPositioned()) { |
| 567 | RenderBox* box = toRenderBox(o); |
| 568 | |
| 569 | if (relayoutChildren || o->style()->width().isPercent() || o->style()->height().isPercent()) |
| 570 | o->setChildNeedsLayout(true, false); |
| 571 | |
| 572 | // If relayoutChildren is set and we have percentage padding, we also need to invalidate the child's pref widths. |
| 573 | if (relayoutChildren && (o->style()->paddingLeft().isPercent() || o->style()->paddingRight().isPercent())) |
hyatt@apple.com | 75dad74 | 2010-09-24 18:07:44 +0000 | [diff] [blame] | 574 | o->setPreferredLogicalWidthsDirty(true, false); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 575 | |
| 576 | if (o->isPositioned()) |
| 577 | o->containingBlock()->insertPositionedObject(box); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 578 | else if (o->isFloating()) |
| 579 | floats.append(FloatWithRect(box)); |
| 580 | else if (fullLayout || o->needsLayout()) { |
| 581 | // Replaced elements |
| 582 | toRenderBox(o)->dirtyLineBoxes(fullLayout); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 583 | o->layoutIfNeeded(); |
| 584 | } |
| 585 | } else if (o->isText() || (o->isRenderInline() && !endOfInline)) { |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 586 | if (fullLayout || o->selfNeedsLayout()) |
| 587 | dirtyLineBoxesForRenderer(o, fullLayout); |
| 588 | o->setNeedsLayout(false); |
| 589 | if (!o->isText()) |
| 590 | toRenderInline(o)->invalidateVerticalPosition(); // FIXME: Should do better here and not always invalidate everything. |
| 591 | } |
| 592 | o = bidiNext(this, o, 0, false, &endOfInline); |
| 593 | } |
| 594 | |
| 595 | // We want to skip ahead to the first dirty line |
| 596 | InlineBidiResolver resolver; |
| 597 | unsigned floatIndex; |
| 598 | bool firstLine = true; |
| 599 | bool previousLineBrokeCleanly = true; |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 600 | RootInlineBox* startLine = determineStartPosition(firstLine, fullLayout, previousLineBrokeCleanly, resolver, floats, floatIndex, |
| 601 | useRepaintBounds, repaintTop, repaintBottom); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 602 | |
eric@webkit.org | ddbec0aa | 2010-01-06 01:13:11 +0000 | [diff] [blame] | 603 | if (fullLayout && hasInlineChild && !selfNeedsLayout()) { |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 604 | setNeedsLayout(true, false); // Mark ourselves as needing a full layout. This way we'll repaint like |
| 605 | // we're supposed to. |
simon.fraser@apple.com | 6528b50 | 2009-01-12 21:42:25 +0000 | [diff] [blame] | 606 | RenderView* v = view(); |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 607 | if (v && !v->doingFullRepaint() && hasLayer()) { |
hyatt | 837eb36 | 2004-05-21 22:17:10 +0000 | [diff] [blame] | 608 | // Because we waited until we were already inside layout to discover |
| 609 | // that the block really needed a full layout, we missed our chance to repaint the layer |
| 610 | // before layout started. Luckily the layer has cached the repaint rect for its original |
| 611 | // position and size, and so we can use that to make a repaint happen now. |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 612 | repaintUsingContainer(containerForRepaint(), layer()->repaintRect()); |
hyatt | 837eb36 | 2004-05-21 22:17:10 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 615 | |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 616 | FloatingObject* lastFloat = m_floatingObjects ? m_floatingObjects->last() : 0; |
| 617 | |
| 618 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
| 619 | |
| 620 | // We also find the first clean line and extract these lines. We will add them back |
| 621 | // if we determine that we're able to synchronize after handling all our dirty lines. |
| 622 | InlineIterator cleanLineStart; |
| 623 | BidiStatus cleanLineBidiStatus; |
| 624 | int endLineYPos = 0; |
| 625 | RootInlineBox* endLine = (fullLayout || !startLine) ? |
| 626 | 0 : determineEndPosition(startLine, cleanLineStart, cleanLineBidiStatus, endLineYPos); |
| 627 | |
| 628 | if (startLine) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 629 | if (!useRepaintBounds) { |
| 630 | useRepaintBounds = true; |
| 631 | repaintTop = height(); |
| 632 | repaintBottom = height(); |
| 633 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 634 | RenderArena* arena = renderArena(); |
| 635 | RootInlineBox* box = startLine; |
| 636 | while (box) { |
| 637 | repaintTop = min(repaintTop, box->topVisibleOverflow()); |
| 638 | repaintBottom = max(repaintBottom, box->bottomVisibleOverflow()); |
| 639 | RootInlineBox* next = box->nextRootBox(); |
| 640 | box->deleteLine(arena); |
| 641 | box = next; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | InlineIterator end = resolver.position(); |
| 646 | |
| 647 | if (!fullLayout && lastRootBox() && lastRootBox()->endsWithBreak()) { |
| 648 | // If the last line before the start line ends with a line break that clear floats, |
| 649 | // adjust the height accordingly. |
| 650 | // A line break can be either the first or the last object on a line, depending on its direction. |
| 651 | if (InlineBox* lastLeafChild = lastRootBox()->lastLeafChild()) { |
| 652 | RenderObject* lastObject = lastLeafChild->renderer(); |
| 653 | if (!lastObject->isBR()) |
| 654 | lastObject = lastRootBox()->firstLeafChild()->renderer(); |
| 655 | if (lastObject->isBR()) { |
| 656 | EClear clear = lastObject->style()->clear(); |
| 657 | if (clear != CNONE) |
| 658 | newLine(clear); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | bool endLineMatched = false; |
| 664 | bool checkForEndLineMatch = endLine; |
| 665 | bool checkForFloatsFromLastLine = false; |
| 666 | |
| 667 | bool isLineEmpty = true; |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 668 | bool paginated = view()->layoutState() && view()->layoutState()->isPaginated(); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 669 | |
| 670 | while (!end.atEnd()) { |
| 671 | // FIXME: Is this check necessary before the first iteration or can it be moved to the end? |
| 672 | if (checkForEndLineMatch && (endLineMatched = matchedEndLine(resolver, cleanLineStart, cleanLineBidiStatus, endLine, endLineYPos, repaintBottom, repaintTop))) |
| 673 | break; |
| 674 | |
| 675 | lineMidpointState.reset(); |
| 676 | |
| 677 | isLineEmpty = true; |
| 678 | |
| 679 | EClear clear = CNONE; |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 680 | bool hyphenated; |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 681 | |
| 682 | InlineIterator oldEnd = end; |
| 683 | FloatingObject* lastFloatFromPreviousLine = m_floatingObjects ? m_floatingObjects->last() : 0; |
| 684 | end = findNextLineBreak(resolver, firstLine, isLineEmpty, previousLineBrokeCleanly, hyphenated, &clear, lastFloatFromPreviousLine); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 685 | if (resolver.position().atEnd()) { |
| 686 | resolver.deleteRuns(); |
| 687 | checkForFloatsFromLastLine = true; |
| 688 | break; |
| 689 | } |
| 690 | ASSERT(end != resolver.position()); |
| 691 | |
| 692 | if (!isLineEmpty) { |
mitz@apple.com | 62d5bbd | 2010-06-25 18:07:01 +0000 | [diff] [blame] | 693 | resolver.createBidiRunsForLine(end, style()->visuallyOrdered(), previousLineBrokeCleanly); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 694 | ASSERT(resolver.position() == end); |
| 695 | |
| 696 | BidiRun* trailingSpaceRun = 0; |
| 697 | if (!previousLineBrokeCleanly && resolver.runCount() && resolver.logicallyLastRun()->m_object->style()->breakOnlyAfterWhiteSpace() |
| 698 | && resolver.logicallyLastRun()->m_object->style()->autoWrap()) { |
| 699 | trailingSpaceRun = resolver.logicallyLastRun(); |
| 700 | RenderObject* lastObject = trailingSpaceRun->m_object; |
| 701 | if (lastObject->isText()) { |
| 702 | RenderText* lastText = toRenderText(lastObject); |
| 703 | const UChar* characters = lastText->characters(); |
| 704 | int firstSpace = trailingSpaceRun->stop(); |
| 705 | while (firstSpace > trailingSpaceRun->start()) { |
| 706 | UChar current = characters[firstSpace - 1]; |
| 707 | if (!isCollapsibleSpace(current, lastText)) |
| 708 | break; |
| 709 | firstSpace--; |
| 710 | } |
| 711 | if (firstSpace == trailingSpaceRun->stop()) |
| 712 | trailingSpaceRun = 0; |
| 713 | else { |
| 714 | TextDirection direction = style()->direction(); |
| 715 | bool shouldReorder = trailingSpaceRun != (direction == LTR ? resolver.lastRun() : resolver.firstRun()); |
| 716 | if (firstSpace != trailingSpaceRun->start()) { |
| 717 | BidiContext* baseContext = resolver.context(); |
| 718 | while (BidiContext* parent = baseContext->parent()) |
| 719 | baseContext = parent; |
| 720 | |
| 721 | BidiRun* newTrailingRun = new (renderArena()) BidiRun(firstSpace, trailingSpaceRun->m_stop, trailingSpaceRun->m_object, baseContext, OtherNeutral); |
| 722 | trailingSpaceRun->m_stop = firstSpace; |
| 723 | if (direction == LTR) |
| 724 | resolver.addRun(newTrailingRun); |
| 725 | else |
| 726 | resolver.prependRun(newTrailingRun); |
| 727 | trailingSpaceRun = newTrailingRun; |
| 728 | shouldReorder = false; |
| 729 | } |
| 730 | if (shouldReorder) { |
| 731 | if (direction == LTR) { |
| 732 | resolver.moveRunToEnd(trailingSpaceRun); |
| 733 | trailingSpaceRun->m_level = 0; |
| 734 | } else { |
| 735 | resolver.moveRunToBeginning(trailingSpaceRun); |
| 736 | trailingSpaceRun->m_level = 1; |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } else |
| 741 | trailingSpaceRun = 0; |
| 742 | } |
| 743 | |
| 744 | // Now that the runs have been ordered, we create the line boxes. |
| 745 | // At the same time we figure out where border/padding/margin should be applied for |
| 746 | // inline flow boxes. |
| 747 | |
| 748 | RootInlineBox* lineBox = 0; |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 749 | int oldHeight = height(); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 750 | if (resolver.runCount()) { |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 751 | if (hyphenated) |
| 752 | resolver.logicallyLastRun()->m_hasHyphen = true; |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 753 | lineBox = constructLine(resolver.runCount(), resolver.firstRun(), resolver.lastRun(), firstLine, !end.obj, end.obj && !end.pos ? end.obj : 0); |
| 754 | if (lineBox) { |
| 755 | lineBox->setEndsWithBreak(previousLineBrokeCleanly); |
| 756 | |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 757 | #if ENABLE(SVG) |
| 758 | bool isSVGRootInlineBox = lineBox->isSVGRootInlineBox(); |
| 759 | #else |
| 760 | bool isSVGRootInlineBox = false; |
| 761 | #endif |
| 762 | |
mitz@apple.com | 0cc7bed | 2010-05-17 01:43:49 +0000 | [diff] [blame] | 763 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 764 | |
| 765 | // Now we position all of our text runs horizontally. |
| 766 | if (!isSVGRootInlineBox) |
hyatt@apple.com | 44e83c0 | 2010-09-23 22:21:30 +0000 | [diff] [blame] | 767 | computeInlineDirectionPositionsForLine(lineBox, firstLine, resolver.firstRun(), trailingSpaceRun, end.atEnd(), textBoxDataMap); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 768 | |
| 769 | // Now position our text runs vertically. |
hyatt@apple.com | 44e83c0 | 2010-09-23 22:21:30 +0000 | [diff] [blame] | 770 | computeBlockDirectionPositionsForLine(lineBox, resolver.firstRun(), textBoxDataMap); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 771 | |
| 772 | #if ENABLE(SVG) |
zimmermann@webkit.org | b40815c | 2010-06-18 11:18:44 +0000 | [diff] [blame] | 773 | // SVG text layout code computes vertical & horizontal positions on its own. |
| 774 | // Note that we still need to execute computeVerticalPositionsForLine() as |
| 775 | // it calls InlineTextBox::positionLineBox(), which tracks whether the box |
| 776 | // contains reversed text or not. If we wouldn't do that editing and thus |
| 777 | // text selection in RTL boxes would not work as expected. |
| 778 | if (isSVGRootInlineBox) { |
| 779 | ASSERT(isSVGText()); |
| 780 | static_cast<SVGRootInlineBox*>(lineBox)->computePerCharacterLayoutInformation(); |
| 781 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 782 | #endif |
| 783 | |
| 784 | #if PLATFORM(MAC) |
| 785 | // Highlight acts as an overflow inflation. |
| 786 | if (style()->highlight() != nullAtom) |
| 787 | lineBox->addHighlightOverflow(); |
| 788 | #endif |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | resolver.deleteRuns(); |
| 793 | |
| 794 | if (lineBox) { |
| 795 | lineBox->setLineBreakInfo(end.obj, end.pos, resolver.status()); |
| 796 | if (useRepaintBounds) { |
| 797 | repaintTop = min(repaintTop, lineBox->topVisibleOverflow()); |
| 798 | repaintBottom = max(repaintBottom, lineBox->bottomVisibleOverflow()); |
| 799 | } |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 800 | |
| 801 | if (paginated) { |
| 802 | int adjustment = 0; |
| 803 | adjustLinePositionForPagination(lineBox, adjustment); |
| 804 | if (adjustment) { |
| 805 | int oldLineWidth = lineWidth(oldHeight, firstLine); |
| 806 | lineBox->adjustPosition(0, adjustment); |
| 807 | if (useRepaintBounds) // This can only be a positive adjustment, so no need to update repaintTop. |
| 808 | repaintBottom = max(repaintBottom, lineBox->bottomVisibleOverflow()); |
| 809 | |
| 810 | if (lineWidth(oldHeight + adjustment, firstLine) != oldLineWidth) { |
| 811 | // We have to delete this line, remove all floats that got added, and let line layout re-run. |
| 812 | lineBox->deleteLine(renderArena()); |
| 813 | removeFloatingObjectsBelow(lastFloatFromPreviousLine, oldHeight); |
| 814 | setHeight(oldHeight + adjustment); |
| 815 | resolver.setPosition(oldEnd); |
| 816 | end = oldEnd; |
| 817 | continue; |
| 818 | } |
| 819 | |
| 820 | setHeight(lineBox->blockHeight()); |
| 821 | } |
| 822 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | firstLine = false; |
| 826 | newLine(clear); |
| 827 | } |
| 828 | |
| 829 | if (m_floatingObjects && lastRootBox()) { |
| 830 | if (lastFloat) { |
| 831 | for (FloatingObject* f = m_floatingObjects->last(); f != lastFloat; f = m_floatingObjects->prev()) { |
| 832 | } |
| 833 | m_floatingObjects->next(); |
| 834 | } else |
| 835 | m_floatingObjects->first(); |
| 836 | for (FloatingObject* f = m_floatingObjects->current(); f; f = m_floatingObjects->next()) { |
| 837 | lastRootBox()->floats().append(f->m_renderer); |
| 838 | ASSERT(f->m_renderer == floats[floatIndex].object); |
| 839 | // If a float's geometry has changed, give up on syncing with clean lines. |
| 840 | if (floats[floatIndex].rect != IntRect(f->m_left, f->m_top, f->m_width, f->m_bottom - f->m_top)) |
| 841 | checkForEndLineMatch = false; |
| 842 | floatIndex++; |
| 843 | } |
| 844 | lastFloat = m_floatingObjects->last(); |
| 845 | } |
| 846 | |
| 847 | lineMidpointState.reset(); |
| 848 | resolver.setPosition(end); |
| 849 | } |
| 850 | |
| 851 | if (endLine) { |
| 852 | if (endLineMatched) { |
| 853 | // Attach all the remaining lines, and then adjust their y-positions as needed. |
| 854 | int delta = height() - endLineYPos; |
| 855 | for (RootInlineBox* line = endLine; line; line = line->nextRootBox()) { |
| 856 | line->attachLine(); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 857 | if (paginated) { |
| 858 | delta -= line->paginationStrut(); |
| 859 | adjustLinePositionForPagination(line, delta); |
| 860 | } |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 861 | if (delta) { |
| 862 | repaintTop = min(repaintTop, line->topVisibleOverflow() + min(delta, 0)); |
| 863 | repaintBottom = max(repaintBottom, line->bottomVisibleOverflow() + max(delta, 0)); |
| 864 | line->adjustPosition(0, delta); |
| 865 | } |
| 866 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
| 867 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 868 | for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
| 869 | int floatTop = (*f)->y() - (*f)->marginTop(); |
| 870 | insertFloatingObject(*f); |
| 871 | setHeight(floatTop + delta); |
| 872 | positionNewFloats(); |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | setHeight(lastRootBox()->blockHeight()); |
| 877 | } else { |
| 878 | // Delete all the remaining lines. |
| 879 | RootInlineBox* line = endLine; |
| 880 | RenderArena* arena = renderArena(); |
| 881 | while (line) { |
| 882 | repaintTop = min(repaintTop, line->topVisibleOverflow()); |
| 883 | repaintBottom = max(repaintBottom, line->bottomVisibleOverflow()); |
| 884 | RootInlineBox* next = line->nextRootBox(); |
| 885 | line->deleteLine(arena); |
| 886 | line = next; |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | if (m_floatingObjects && (checkForFloatsFromLastLine || positionNewFloats()) && lastRootBox()) { |
| 891 | // In case we have a float on the last line, it might not be positioned up to now. |
| 892 | // This has to be done before adding in the bottom border/padding, or the float will |
| 893 | // include the padding incorrectly. -dwh |
| 894 | if (checkForFloatsFromLastLine) { |
| 895 | int bottomVisualOverflow = lastRootBox()->bottomVisualOverflow(); |
| 896 | int bottomLayoutOverflow = lastRootBox()->bottomLayoutOverflow(); |
dbates@webkit.org | f6f05a9 | 2010-05-17 04:58:25 +0000 | [diff] [blame] | 897 | TrailingFloatsRootInlineBox* trailingFloatsLineBox = new (renderArena()) TrailingFloatsRootInlineBox(this); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 898 | m_lineBoxes.appendLineBox(trailingFloatsLineBox); |
| 899 | trailingFloatsLineBox->setConstructed(); |
mitz@apple.com | 0cc7bed | 2010-05-17 01:43:49 +0000 | [diff] [blame] | 900 | GlyphOverflowAndFallbackFontsMap textBoxDataMap; |
hyatt@apple.com | 44e83c0 | 2010-09-23 22:21:30 +0000 | [diff] [blame] | 901 | trailingFloatsLineBox->alignBoxesInBlockDirection(height(), textBoxDataMap); |
| 902 | trailingFloatsLineBox->setBlockDirectionOverflowPositions(height(), bottomLayoutOverflow, height(), bottomVisualOverflow, 0); |
abarth@webkit.org | 31d23df | 2010-04-05 21:52:09 +0000 | [diff] [blame] | 903 | trailingFloatsLineBox->setBlockHeight(height()); |
| 904 | } |
| 905 | if (lastFloat) { |
| 906 | for (FloatingObject* f = m_floatingObjects->last(); f != lastFloat; f = m_floatingObjects->prev()) { |
| 907 | } |
| 908 | m_floatingObjects->next(); |
| 909 | } else |
| 910 | m_floatingObjects->first(); |
| 911 | for (FloatingObject* f = m_floatingObjects->current(); f; f = m_floatingObjects->next()) |
| 912 | lastRootBox()->floats().append(f->m_renderer); |
| 913 | lastFloat = m_floatingObjects->last(); |
| 914 | } |
| 915 | size_t floatCount = floats.size(); |
| 916 | // Floats that did not have layout did not repaint when we laid them out. They would have |
| 917 | // painted by now if they had moved, but if they stayed at (0, 0), they still need to be |
| 918 | // painted. |
| 919 | for (size_t i = 0; i < floatCount; ++i) { |
| 920 | if (!floats[i].everHadLayout) { |
| 921 | RenderBox* f = floats[i].object; |
| 922 | if (!f->x() && !f->y() && f->checkForRepaintDuringLayout()) |
| 923 | f->repaint(); |
| 924 | } |
| 925 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 926 | } |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 927 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 928 | // Now add in the bottom border/padding. |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 929 | setHeight(height() + toAdd); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 930 | |
adele | 7a470a7 | 2006-04-20 22:22:14 +0000 | [diff] [blame] | 931 | if (!firstLineBox() && hasLineIfEmpty()) |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 932 | setHeight(height() + lineHeight(true, true)); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 933 | |
| 934 | // See if we have any lines that spill out of our block. If we do, then we will possibly need to |
| 935 | // truncate text. |
| 936 | if (hasTextOverflow) |
| 937 | checkLinesForTextOverflow(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 938 | } |
| 939 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 940 | RootInlineBox* RenderBlock::determineStartPosition(bool& firstLine, bool& fullLayout, bool& previousLineBrokeCleanly, |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 941 | InlineBidiResolver& resolver, Vector<FloatWithRect>& floats, unsigned& numCleanFloats, |
| 942 | bool& useRepaintBounds, int& repaintTop, int& repaintBottom) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 943 | { |
| 944 | RootInlineBox* curr = 0; |
| 945 | RootInlineBox* last = 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 946 | |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 947 | bool dirtiedByFloat = false; |
| 948 | if (!fullLayout) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 949 | // Paginate all of the clean lines. |
| 950 | bool paginated = view()->layoutState() && view()->layoutState()->isPaginated(); |
| 951 | int paginationDelta = 0; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 952 | size_t floatIndex = 0; |
| 953 | for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 954 | if (paginated) { |
| 955 | paginationDelta -= curr->paginationStrut(); |
| 956 | adjustLinePositionForPagination(curr, paginationDelta); |
| 957 | if (paginationDelta) { |
| 958 | if (containsFloats() || !floats.isEmpty()) { |
| 959 | // FIXME: Do better eventually. For now if we ever shift because of pagination and floats are present just go to a full layout. |
| 960 | fullLayout = true; |
| 961 | break; |
| 962 | } |
| 963 | |
| 964 | if (!useRepaintBounds) |
| 965 | useRepaintBounds = true; |
| 966 | |
| 967 | repaintTop = min(repaintTop, curr->topVisibleOverflow() + min(paginationDelta, 0)); |
| 968 | repaintBottom = max(repaintBottom, curr->bottomVisibleOverflow() + max(paginationDelta, 0)); |
| 969 | curr->adjustPosition(0, paginationDelta); |
| 970 | } |
| 971 | } |
| 972 | |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 973 | if (Vector<RenderBox*>* cleanLineFloats = curr->floatsPtr()) { |
| 974 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 975 | for (Vector<RenderBox*>::iterator o = cleanLineFloats->begin(); o != end; ++o) { |
| 976 | RenderBox* f = *o; |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 977 | f->layoutIfNeeded(); |
| 978 | IntSize newSize(f->width() + f->marginLeft() + f->marginRight(), f->height() + f->marginTop() + f->marginBottom()); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 979 | ASSERT(floatIndex < floats.size()); |
| 980 | if (floats[floatIndex].object != f) { |
| 981 | // A new float has been inserted before this line or before its last known float. |
| 982 | // Just do a full layout. |
| 983 | fullLayout = true; |
| 984 | break; |
| 985 | } |
| 986 | if (floats[floatIndex].rect.size() != newSize) { |
mitz@apple.com | 070a7de | 2008-03-19 18:40:52 +0000 | [diff] [blame] | 987 | int floatTop = floats[floatIndex].rect.y(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 988 | curr->markDirty(); |
mitz@apple.com | 1d4e953 | 2010-01-18 20:55:25 +0000 | [diff] [blame] | 989 | markLinesDirtyInVerticalRange(curr->blockHeight(), floatTop + max(floats[floatIndex].rect.height(), newSize.height()), curr); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 990 | floats[floatIndex].rect.setSize(newSize); |
| 991 | dirtiedByFloat = true; |
| 992 | } |
| 993 | floatIndex++; |
| 994 | } |
| 995 | } |
| 996 | if (dirtiedByFloat || fullLayout) |
| 997 | break; |
| 998 | } |
| 999 | // Check if a new float has been inserted after the last known float. |
| 1000 | if (!curr && floatIndex < floats.size()) |
| 1001 | fullLayout = true; |
| 1002 | } |
| 1003 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1004 | if (fullLayout) { |
| 1005 | // Nuke all our lines. |
| 1006 | if (firstRootBox()) { |
| 1007 | RenderArena* arena = renderArena(); |
| 1008 | curr = firstRootBox(); |
| 1009 | while (curr) { |
| 1010 | RootInlineBox* next = curr->nextRootBox(); |
| 1011 | curr->deleteLine(arena); |
| 1012 | curr = next; |
| 1013 | } |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 1014 | ASSERT(!firstLineBox() && !lastLineBox()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1015 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1016 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1017 | if (curr) { |
| 1018 | // We have a dirty line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1019 | if (RootInlineBox* prevRootBox = curr->prevRootBox()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1020 | // We have a previous line. |
staikos@webkit.org | 19d8c5f | 2009-03-26 14:24:15 +0000 | [diff] [blame] | 1021 | if (!dirtiedByFloat && (!prevRootBox->endsWithBreak() || (prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= toRenderText(prevRootBox->lineBreakObj())->textLength()))) |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1022 | // The previous line didn't break cleanly or broke at a newline |
| 1023 | // that has been deleted, so treat it as dirty too. |
| 1024 | curr = prevRootBox; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1025 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1026 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1027 | // No dirty lines were found. |
| 1028 | // If the last line didn't break cleanly, treat it as dirty. |
| 1029 | if (lastRootBox() && !lastRootBox()->endsWithBreak()) |
| 1030 | curr = lastRootBox(); |
| 1031 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1032 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1033 | // If we have no dirty lines, then last is just the last root box. |
| 1034 | last = curr ? curr->prevRootBox() : lastRootBox(); |
| 1035 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1036 | |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1037 | numCleanFloats = 0; |
| 1038 | if (!floats.isEmpty()) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1039 | int savedHeight = height(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1040 | // Restore floats from clean lines. |
| 1041 | RootInlineBox* line = firstRootBox(); |
| 1042 | while (line != curr) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1043 | if (Vector<RenderBox*>* cleanLineFloats = line->floatsPtr()) { |
| 1044 | Vector<RenderBox*>::iterator end = cleanLineFloats->end(); |
| 1045 | for (Vector<RenderBox*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1046 | insertFloatingObject(*f); |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1047 | setHeight((*f)->y() - (*f)->marginTop()); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1048 | positionNewFloats(); |
| 1049 | ASSERT(floats[numCleanFloats].object == *f); |
| 1050 | numCleanFloats++; |
| 1051 | } |
| 1052 | } |
| 1053 | line = line->nextRootBox(); |
| 1054 | } |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1055 | setHeight(savedHeight); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1058 | firstLine = !last; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1059 | previousLineBrokeCleanly = !last || last->endsWithBreak(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1060 | |
| 1061 | RenderObject* startObj; |
| 1062 | int pos = 0; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1063 | if (last) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1064 | setHeight(last->blockHeight()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1065 | startObj = last->lineBreakObj(); |
| 1066 | pos = last->lineBreakPos(); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1067 | resolver.setStatus(last->lineBreakBidiStatus()); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1068 | } else { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1069 | bool ltr = style()->direction() == LTR |
| 1070 | #if ENABLE(SVG) |
| 1071 | || (style()->unicodeBidi() == UBNormal && isSVGText()) |
| 1072 | #endif |
| 1073 | ; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1074 | |
mitz@apple.com | 45d9e10 | 2009-04-27 16:24:55 +0000 | [diff] [blame] | 1075 | Direction direction = ltr ? LeftToRight : RightToLeft; |
| 1076 | resolver.setLastStrongDir(direction); |
| 1077 | resolver.setLastDir(direction); |
| 1078 | resolver.setEorDir(direction); |
| 1079 | resolver.setContext(BidiContext::create(ltr ? 0 : 1, direction, style()->unicodeBidi() == Override)); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1080 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1081 | startObj = bidiFirst(this, &resolver); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1082 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1083 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1084 | resolver.setPosition(InlineIterator(this, startObj, pos)); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1085 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1086 | return curr; |
| 1087 | } |
| 1088 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1089 | RootInlineBox* RenderBlock::determineEndPosition(RootInlineBox* startLine, InlineIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus, int& yPos) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1090 | { |
| 1091 | RootInlineBox* last = 0; |
hyatt | a6960b1 | 2004-12-07 02:09:10 +0000 | [diff] [blame] | 1092 | if (!startLine) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1093 | last = 0; |
| 1094 | else { |
hyatt | 04420ca | 2004-07-16 00:05:42 +0000 | [diff] [blame] | 1095 | for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) { |
| 1096 | if (curr->isDirty()) |
| 1097 | last = 0; |
| 1098 | else if (!last) |
| 1099 | last = curr; |
| 1100 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1101 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1102 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1103 | if (!last) |
| 1104 | return 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1105 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1106 | RootInlineBox* prev = last->prevRootBox(); |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1107 | cleanLineStart = InlineIterator(this, prev->lineBreakObj(), prev->lineBreakPos()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1108 | cleanLineBidiStatus = prev->lineBreakBidiStatus(); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1109 | yPos = prev->blockHeight(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1110 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1111 | for (RootInlineBox* line = last; line; line = line->nextRootBox()) |
| 1112 | line->extractLine(); // Disconnect all line boxes from their render objects while preserving |
| 1113 | // their connections to one another. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1114 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1115 | return last; |
| 1116 | } |
| 1117 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1118 | bool RenderBlock::matchedEndLine(const InlineBidiResolver& resolver, const InlineIterator& endLineStart, const BidiStatus& endLineStatus, RootInlineBox*& endLine, int& endYPos, int& repaintBottom, int& repaintTop) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1119 | { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1120 | if (resolver.position() == endLineStart) { |
| 1121 | if (resolver.status() != endLineStatus) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1122 | return false; |
| 1123 | |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1124 | int delta = height() - endYPos; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1125 | if (!delta || !m_floatingObjects) |
| 1126 | return true; |
| 1127 | |
| 1128 | // See if any floats end in the range along which we want to shift the lines vertically. |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1129 | int top = min(height(), endYPos); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1130 | |
| 1131 | RootInlineBox* lastLine = endLine; |
| 1132 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 1133 | lastLine = nextLine; |
| 1134 | |
| 1135 | int bottom = lastLine->blockHeight() + abs(delta); |
| 1136 | |
| 1137 | for (FloatingObject* f = m_floatingObjects->first(); f; f = m_floatingObjects->next()) { |
mitz@apple.com | 9352659 | 2008-03-18 04:36:51 +0000 | [diff] [blame] | 1138 | if (f->m_bottom >= top && f->m_bottom < bottom) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1139 | return false; |
| 1140 | } |
| 1141 | |
| 1142 | return true; |
| 1143 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1144 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1145 | // The first clean line doesn't match, but we can check a handful of following lines to try |
| 1146 | // to match back up. |
| 1147 | static int numLines = 8; // The # of lines we're willing to match against. |
| 1148 | RootInlineBox* line = endLine; |
| 1149 | for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1150 | if (line->lineBreakObj() == resolver.position().obj && line->lineBreakPos() == resolver.position().pos) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1151 | // We have a match. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1152 | if (line->lineBreakBidiStatus() != resolver.status()) |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1153 | return false; // ...but the bidi state doesn't match. |
| 1154 | RootInlineBox* result = line->nextRootBox(); |
| 1155 | |
| 1156 | // Set our yPos to be the block height of endLine. |
| 1157 | if (result) |
| 1158 | endYPos = line->blockHeight(); |
| 1159 | |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1160 | int delta = height() - endYPos; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1161 | if (delta && m_floatingObjects) { |
| 1162 | // See if any floats end in the range along which we want to shift the lines vertically. |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1163 | int top = min(height(), endYPos); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1164 | |
| 1165 | RootInlineBox* lastLine = endLine; |
| 1166 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 1167 | lastLine = nextLine; |
| 1168 | |
| 1169 | int bottom = lastLine->blockHeight() + abs(delta); |
| 1170 | |
| 1171 | for (FloatingObject* f = m_floatingObjects->first(); f; f = m_floatingObjects->next()) { |
mitz@apple.com | 9352659 | 2008-03-18 04:36:51 +0000 | [diff] [blame] | 1172 | if (f->m_bottom >= top && f->m_bottom < bottom) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1173 | return false; |
| 1174 | } |
| 1175 | } |
| 1176 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1177 | // Now delete the lines that we failed to sync. |
| 1178 | RootInlineBox* boxToDelete = endLine; |
| 1179 | RenderArena* arena = renderArena(); |
| 1180 | while (boxToDelete && boxToDelete != result) { |
hyatt@apple.com | c37b4bb | 2009-08-19 19:26:32 +0000 | [diff] [blame] | 1181 | repaintTop = min(repaintTop, boxToDelete->topVisibleOverflow()); |
| 1182 | repaintBottom = max(repaintBottom, boxToDelete->bottomVisibleOverflow()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1183 | RootInlineBox* next = boxToDelete->nextRootBox(); |
| 1184 | boxToDelete->deleteLine(arena); |
| 1185 | boxToDelete = next; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1186 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1187 | |
| 1188 | endLine = result; |
| 1189 | return result; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1190 | } |
| 1191 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1192 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1193 | return false; |
| 1194 | } |
| 1195 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1196 | static inline bool skipNonBreakingSpace(const InlineIterator& it, bool isLineEmpty, bool previousLineBrokeCleanly) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1197 | { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1198 | if (it.obj->style()->nbspMode() != SPACE || it.current() != noBreakSpace) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1199 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1200 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1201 | // FIXME: This is bad. It makes nbsp inconsistent with space and won't work correctly |
| 1202 | // with m_minWidth/m_maxWidth. |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1203 | // Do not skip a non-breaking space if it is the first character |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1204 | // on a line after a clean line break (or on the first line, since previousLineBrokeCleanly starts off |
| 1205 | // |true|). |
| 1206 | if (isLineEmpty && previousLineBrokeCleanly) |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1207 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1208 | |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1209 | return true; |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1212 | static inline bool shouldCollapseWhiteSpace(const RenderStyle* style, bool isLineEmpty, bool previousLineBrokeCleanly) |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 1213 | { |
| 1214 | return style->collapseWhiteSpace() || (style->whiteSpace() == PRE_WRAP && (!isLineEmpty || !previousLineBrokeCleanly)); |
| 1215 | } |
| 1216 | |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1217 | static inline bool shouldPreserveNewline(RenderObject* object) |
| 1218 | { |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 1219 | #if ENABLE(SVG) |
zimmermann@webkit.org | e943aaa | 2010-06-25 10:03:33 +0000 | [diff] [blame] | 1220 | if (object->isSVGInlineText()) |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1221 | return false; |
| 1222 | #endif |
| 1223 | |
| 1224 | return object->style()->preserveNewline(); |
| 1225 | } |
| 1226 | |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 1227 | static bool inlineFlowRequiresLineBox(RenderInline* flow) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1228 | { |
| 1229 | // 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] | 1230 | // We need to fix this, though, because at the very least, inlines containing only |
| 1231 | // ignorable whitespace should should also have line boxes. |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 1232 | return !flow->firstChild() && flow->hasHorizontalBordersPaddingOrMargin(); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
hyatt@apple.com | 71eeb44 | 2010-02-11 20:05:51 +0000 | [diff] [blame] | 1235 | bool RenderBlock::requiresLineBox(const InlineIterator& it, bool isLineEmpty, bool previousLineBrokeCleanly) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1236 | { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1237 | if (it.obj->isFloatingOrPositioned()) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1238 | return false; |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1239 | |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 1240 | if (it.obj->isRenderInline() && !inlineFlowRequiresLineBox(toRenderInline(it.obj))) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1241 | return false; |
| 1242 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1243 | if (!shouldCollapseWhiteSpace(it.obj->style(), isLineEmpty, previousLineBrokeCleanly) || it.obj->isBR()) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1244 | return true; |
| 1245 | |
| 1246 | UChar current = it.current(); |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1247 | return current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || shouldPreserveNewline(it.obj)) |
| 1248 | && !skipNonBreakingSpace(it, isLineEmpty, previousLineBrokeCleanly); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1251 | bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj, bool isLineEmpty, bool previousLineBrokeCleanly) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1252 | { |
| 1253 | ASSERT(inlineObj->parent() == this); |
| 1254 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1255 | InlineIterator it(this, inlineObj, 0); |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1256 | while (!it.atEnd() && !requiresLineBox(it, isLineEmpty, previousLineBrokeCleanly)) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1257 | it.increment(); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1258 | |
| 1259 | return !it.atEnd(); |
| 1260 | } |
| 1261 | |
mitz@apple.com | bf6e8d3 | 2008-07-25 20:21:06 +0000 | [diff] [blame] | 1262 | // FIXME: The entire concept of the skipTrailingWhitespace function is flawed, since we really need to be building |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1263 | // line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned |
| 1264 | // elements quite right. In other words, we need to build this function's work into the normal line |
| 1265 | // object iteration process. |
mitz@apple.com | bf6e8d3 | 2008-07-25 20:21:06 +0000 | [diff] [blame] | 1266 | // NB. this function will insert any floating elements that would otherwise |
| 1267 | // be skipped but it will not position them. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1268 | void RenderBlock::skipTrailingWhitespace(InlineIterator& iterator, bool isLineEmpty, bool previousLineBrokeCleanly) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1269 | { |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1270 | while (!iterator.atEnd() && !requiresLineBox(iterator, isLineEmpty, previousLineBrokeCleanly)) { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1271 | RenderObject* object = iterator.obj; |
| 1272 | if (object->isFloating()) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1273 | insertFloatingObject(toRenderBox(object)); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1274 | } else if (object->isPositioned()) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1275 | // FIXME: The math here is actually not really right. It's a best-guess approximation that |
| 1276 | // will work for the common cases |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1277 | RenderObject* c = object->container(); |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 1278 | if (c->isRenderInline()) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1279 | // A relative positioned inline encloses us. In this case, we also have to determine our |
| 1280 | // position as though we were an inline. Set |staticX| and |staticY| on the relative positioned |
| 1281 | // inline so that we can obtain the value later. |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1282 | toRenderInline(c)->layer()->setStaticX(style()->direction() == LTR ? leftOffset(height(), false) : rightOffset(height(), false)); |
| 1283 | toRenderInline(c)->layer()->setStaticY(height()); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1284 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1285 | |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1286 | RenderBox* box = toRenderBox(object); |
| 1287 | if (box->style()->hasStaticX()) { |
| 1288 | if (box->style()->isOriginalDisplayInlineType()) |
| 1289 | box->layer()->setStaticX(style()->direction() == LTR ? leftOffset(height(), false) : width() - rightOffset(height(), false)); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1290 | else |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1291 | box->layer()->setStaticX(style()->direction() == LTR ? borderLeft() + paddingLeft() : borderRight() + paddingRight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1292 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1293 | |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1294 | if (box->style()->hasStaticY()) |
| 1295 | box->layer()->setStaticY(height()); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1296 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1297 | iterator.increment(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1298 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1299 | } |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1300 | |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1301 | int RenderBlock::skipLeadingWhitespace(InlineBidiResolver& resolver, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly, |
| 1302 | FloatingObject* lastFloatFromPreviousLine) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1303 | { |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1304 | int availableWidth = lineWidth(height(), firstLine); |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1305 | while (!resolver.position().atEnd() && !requiresLineBox(resolver.position(), isLineEmpty, previousLineBrokeCleanly)) { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1306 | RenderObject* object = resolver.position().obj; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1307 | if (object->isFloating()) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1308 | positionNewFloatOnLine(insertFloatingObject(toRenderBox(object)), lastFloatFromPreviousLine); |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1309 | availableWidth = lineWidth(height(), firstLine); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1310 | } else if (object->isPositioned()) { |
| 1311 | // FIXME: The math here is actually not really right. It's a best-guess approximation that |
| 1312 | // will work for the common cases |
| 1313 | RenderObject* c = object->container(); |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 1314 | if (c->isRenderInline()) { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1315 | // A relative positioned inline encloses us. In this case, we also have to determine our |
| 1316 | // position as though we were an inline. Set |staticX| and |staticY| on the relative positioned |
| 1317 | // inline so that we can obtain the value later. |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1318 | toRenderInline(c)->layer()->setStaticX(style()->direction() == LTR ? leftOffset(height(), firstLine) : rightOffset(height(), firstLine)); |
| 1319 | toRenderInline(c)->layer()->setStaticY(height()); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1322 | RenderBox* box = toRenderBox(object); |
| 1323 | if (box->style()->hasStaticX()) { |
bfulgham@webkit.org | a519d8a | 2009-02-08 02:10:55 +0000 | [diff] [blame] | 1324 | if (box->style()->isOriginalDisplayInlineType()) |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1325 | box->layer()->setStaticX(style()->direction() == LTR ? leftOffset(height(), firstLine) : width() - rightOffset(height(), firstLine)); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1326 | else |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1327 | box->layer()->setStaticX(style()->direction() == LTR ? borderLeft() + paddingLeft() : borderRight() + paddingRight()); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1330 | if (box->style()->hasStaticY()) |
| 1331 | box->layer()->setStaticY(height()); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1332 | } |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1333 | resolver.increment(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1334 | } |
mitz@apple.com | 83d2e87 | 2008-10-23 21:56:03 +0000 | [diff] [blame] | 1335 | resolver.commitExplicitEmbedding(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1336 | return availableWidth; |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1339 | // This is currently just used for list markers and inline flows that have line boxes. Neither should |
| 1340 | // have an effect on whitespace at the start of the line. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1341 | static bool shouldSkipWhitespaceAfterStartObject(RenderBlock* block, RenderObject* o, LineMidpointState& lineMidpointState) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1342 | { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1343 | RenderObject* next = bidiNext(block, o); |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 1344 | if (next && !next->isBR() && next->isText() && toRenderText(next)->textLength() > 0) { |
| 1345 | RenderText* nextText = toRenderText(next); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1346 | UChar nextChar = nextText->characters()[0]; |
| 1347 | if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) { |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1348 | addMidpoint(lineMidpointState, InlineIterator(0, o, 0)); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1349 | return true; |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | return false; |
| 1354 | } |
| 1355 | |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1356 | void RenderBlock::fitBelowFloats(int widthToFit, bool firstLine, int& availableWidth) |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1357 | { |
| 1358 | ASSERT(widthToFit > availableWidth); |
| 1359 | |
| 1360 | int floatBottom; |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1361 | int lastFloatBottom = height(); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1362 | int newLineWidth = availableWidth; |
| 1363 | while (true) { |
| 1364 | floatBottom = nextFloatBottomBelow(lastFloatBottom); |
| 1365 | if (!floatBottom) |
| 1366 | break; |
| 1367 | |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1368 | newLineWidth = lineWidth(floatBottom, firstLine); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1369 | lastFloatBottom = floatBottom; |
| 1370 | if (newLineWidth >= widthToFit) |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | if (newLineWidth > availableWidth) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1375 | setHeight(lastFloatBottom); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1376 | availableWidth = newLineWidth; |
| 1377 | } |
| 1378 | } |
| 1379 | |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1380 | static inline unsigned textWidth(RenderText* text, unsigned from, unsigned len, const Font& font, int xPos, bool isFixedPitch, bool collapseWhiteSpace) |
| 1381 | { |
staikos@webkit.org | 19d8c5f | 2009-03-26 14:24:15 +0000 | [diff] [blame] | 1382 | if (isFixedPitch || (!from && len == text->textLength())) |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1383 | return text->width(from, len, font, xPos); |
| 1384 | return font.width(TextRun(text->characters() + from, len, !collapseWhiteSpace, xPos)); |
| 1385 | } |
| 1386 | |
mitz@apple.com | 73eb8c9 | 2010-08-04 21:22:24 +0000 | [diff] [blame] | 1387 | static void tryHyphenating(RenderText* text, const Font& font, const AtomicString& localeIdentifier, int lastSpace, int pos, int 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] | 1388 | { |
| 1389 | const AtomicString& hyphenString = text->style()->hyphenString(); |
| 1390 | int hyphenWidth = font.width(TextRun(hyphenString.characters(), hyphenString.length())); |
| 1391 | |
mitz@apple.com | 7c67b29 | 2010-09-12 23:04:16 +0000 | [diff] [blame] | 1392 | int maxPrefixWidth = availableWidth - xPos - hyphenWidth - lastSpaceWordSpacing; |
| 1393 | // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely |
| 1394 | // that an hyphenation opportunity exists, so do not bother to look for it. |
| 1395 | if (maxPrefixWidth <= font.pixelSize() * 5 / 4) |
| 1396 | return; |
| 1397 | |
| 1398 | unsigned prefixLength = font.offsetForPosition(TextRun(text->characters() + lastSpace, pos - lastSpace, !collapseWhiteSpace, xPos + lastSpaceWordSpacing), maxPrefixWidth, false); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1399 | if (!prefixLength) |
| 1400 | return; |
| 1401 | |
mitz@apple.com | 2ef4491 | 2010-08-07 21:41:06 +0000 | [diff] [blame] | 1402 | prefixLength = lastHyphenLocation(text->characters() + lastSpace, pos - lastSpace, prefixLength + 1, localeIdentifier); |
| 1403 | if (!prefixLength) |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1404 | return; |
| 1405 | |
| 1406 | #if !ASSERT_DISABLED |
| 1407 | int prefixWidth = hyphenWidth + textWidth(text, lastSpace, prefixLength, font, xPos, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing; |
| 1408 | ASSERT(xPos + prefixWidth <= availableWidth); |
mitz@apple.com | 34b43c7 | 2010-06-21 17:21:22 +0000 | [diff] [blame] | 1409 | #else |
| 1410 | UNUSED_PARAM(isFixedPitch); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1411 | #endif |
| 1412 | |
| 1413 | lineBreak.obj = text; |
| 1414 | lineBreak.pos = lastSpace + prefixLength; |
| 1415 | lineBreak.nextBreakablePosition = nextBreakable; |
| 1416 | hyphenated = true; |
| 1417 | } |
| 1418 | |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1419 | InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool firstLine, bool& isLineEmpty, bool& previousLineBrokeCleanly, |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1420 | bool& hyphenated, EClear* clear, FloatingObject* lastFloatFromPreviousLine) |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1421 | { |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1422 | ASSERT(resolver.position().block == this); |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 1423 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1424 | bool appliedStartWidth = resolver.position().pos > 0; |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1425 | LineMidpointState& lineMidpointState = resolver.midpointState(); |
| 1426 | |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1427 | int width = skipLeadingWhitespace(resolver, firstLine, isLineEmpty, previousLineBrokeCleanly, lastFloatFromPreviousLine); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1428 | |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1429 | int w = 0; |
| 1430 | int tmpW = 0; |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1431 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1432 | if (resolver.position().atEnd()) |
| 1433 | return resolver.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1434 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1435 | // This variable is used only if whitespace isn't set to PRE, and it tells us whether |
| 1436 | // or not we are currently ignoring whitespace. |
| 1437 | bool ignoringSpaces = false; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1438 | InlineIterator ignoreStart; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1439 | |
| 1440 | // This variable tracks whether the very last character we saw was a space. We use |
| 1441 | // this to detect when we encounter a second space so we know we have to terminate |
| 1442 | // a run. |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1443 | bool currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1444 | bool currentCharacterIsWS = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1445 | RenderObject* trailingSpaceObject = 0; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1446 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1447 | InlineIterator lBreak = resolver.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1448 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1449 | RenderObject *o = resolver.position().obj; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1450 | RenderObject *last = o; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1451 | unsigned pos = resolver.position().pos; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1452 | int nextBreakable = resolver.position().nextBreakablePosition; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1453 | bool atStart = true; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1454 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1455 | bool prevLineBrokeCleanly = previousLineBrokeCleanly; |
| 1456 | previousLineBrokeCleanly = false; |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 1457 | |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1458 | hyphenated = false; |
| 1459 | |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 1460 | bool autoWrapWasEverTrueOnLine = false; |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 1461 | bool floatsFitOnLine = true; |
hyatt | 01eff98 | 2003-03-14 20:13:23 +0000 | [diff] [blame] | 1462 | |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 1463 | // Firefox and Opera will allow a table cell to grow to fit an image inside it under |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 1464 | // very specific circumstances (in order to match common WinIE renderings). |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 1465 | // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.) |
hyatt@apple.com | ce8ee2a | 2010-08-27 20:29:34 +0000 | [diff] [blame] | 1466 | bool allowImagesToBreak = !document()->inQuirksMode() || !isTableCell() || !style()->width().isIntrinsicOrAuto(); |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 1467 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1468 | EWhiteSpace currWS = style()->whiteSpace(); |
| 1469 | EWhiteSpace lastWS = currWS; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1470 | while (o) { |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1471 | currWS = o->isReplaced() ? o->parent()->style()->whiteSpace() : o->style()->whiteSpace(); |
| 1472 | lastWS = last->isReplaced() ? last->parent()->style()->whiteSpace() : last->style()->whiteSpace(); |
| 1473 | |
| 1474 | bool autoWrap = RenderStyle::autoWrap(currWS); |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 1475 | autoWrapWasEverTrueOnLine = autoWrapWasEverTrueOnLine || autoWrap; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1476 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 1477 | #if ENABLE(SVG) |
zimmermann@webkit.org | e943aaa | 2010-06-25 10:03:33 +0000 | [diff] [blame] | 1478 | bool preserveNewline = o->isSVGInlineText() ? false : RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1479 | #else |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1480 | bool preserveNewline = RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1481 | #endif |
| 1482 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1483 | bool collapseWhiteSpace = RenderStyle::collapseWhiteSpace(currWS); |
| 1484 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1485 | if (o->isBR()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1486 | if (w + tmpW <= width) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1487 | lBreak.obj = o; |
| 1488 | lBreak.pos = 0; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1489 | lBreak.nextBreakablePosition = -1; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1490 | lBreak.increment(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1491 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1492 | // A <br> always breaks a line, so don't let the line be collapsed |
| 1493 | // 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] | 1494 | // get collapsed away. It only does this if the previous line broke |
| 1495 | // cleanly. Otherwise the <br> has no effect on whether the line is |
| 1496 | // empty or not. |
| 1497 | if (prevLineBrokeCleanly) |
| 1498 | isLineEmpty = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1499 | trailingSpaceObject = 0; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1500 | previousLineBrokeCleanly = true; |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 1501 | |
mitz@apple.com | 71e3084 | 2008-03-18 16:13:31 +0000 | [diff] [blame] | 1502 | if (!isLineEmpty && clear) |
| 1503 | *clear = o->style()->clear(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1504 | } |
| 1505 | goto end; |
| 1506 | } |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1507 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1508 | if (o->isFloatingOrPositioned()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1509 | // add to special objects... |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1510 | if (o->isFloating()) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1511 | RenderBox* floatBox = toRenderBox(o); |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1512 | FloatingObject* f = insertFloatingObject(floatBox); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1513 | // check if it fits in the current line. |
| 1514 | // If it does, position it now, otherwise, position |
| 1515 | // it after moving to next line (in newLine() func) |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1516 | if (floatsFitOnLine && floatBox->width() + floatBox->marginLeft() + floatBox->marginRight() + w + tmpW <= width) { |
hyatt@apple.com | cc1737c | 2010-09-16 20:20:02 +0000 | [diff] [blame] | 1517 | positionNewFloatOnLine(f, lastFloatFromPreviousLine); |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1518 | width = lineWidth(height(), firstLine); |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 1519 | } else |
| 1520 | floatsFitOnLine = false; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1521 | } else if (o->isPositioned()) { |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 1522 | // If our original display wasn't an inline type, then we can |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1523 | // go ahead and determine our static x position now. |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1524 | RenderBox* box = toRenderBox(o); |
| 1525 | bool isInlineType = box->style()->isOriginalDisplayInlineType(); |
| 1526 | bool needToSetStaticX = box->style()->hasStaticX(); |
| 1527 | if (box->style()->hasStaticX() && !isInlineType) { |
| 1528 | box->layer()->setStaticX(o->parent()->style()->direction() == LTR ? |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1529 | borderLeft() + paddingLeft() : |
| 1530 | borderRight() + paddingRight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1531 | needToSetStaticX = false; |
| 1532 | } |
| 1533 | |
| 1534 | // If our original display was an INLINE type, then we can go ahead |
| 1535 | // and determine our static y position now. |
hyatt@apple.com | 0de4d64 | 2009-02-05 22:26:53 +0000 | [diff] [blame] | 1536 | bool needToSetStaticY = box->style()->hasStaticY(); |
| 1537 | if (box->style()->hasStaticY() && isInlineType) { |
| 1538 | box->layer()->setStaticY(height()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1539 | needToSetStaticY = false; |
| 1540 | } |
| 1541 | |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 1542 | bool needToCreateLineBox = needToSetStaticX || needToSetStaticY; |
| 1543 | RenderObject* c = o->container(); |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 1544 | if (c->isRenderInline() && (!needToSetStaticX || !needToSetStaticY)) |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 1545 | needToCreateLineBox = true; |
| 1546 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1547 | // If we're ignoring spaces, we have to stop and include this object and |
| 1548 | // then start ignoring spaces again. |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 1549 | if (needToCreateLineBox) { |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 1550 | trailingSpaceObject = 0; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1551 | ignoreStart.obj = o; |
| 1552 | ignoreStart.pos = 0; |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 1553 | if (ignoringSpaces) { |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1554 | addMidpoint(lineMidpointState, ignoreStart); // Stop ignoring spaces. |
| 1555 | addMidpoint(lineMidpointState, ignoreStart); // Start ignoring again. |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 1556 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1557 | |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 1558 | } |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1559 | } |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 1560 | } else if (o->isRenderInline()) { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1561 | // Right now, we should only encounter empty inlines here. |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 1562 | ASSERT(!o->firstChild()); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1563 | |
hyatt@apple.com | 0d4818f | 2009-02-08 05:39:22 +0000 | [diff] [blame] | 1564 | RenderInline* flowBox = toRenderInline(o); |
hyatt@apple.com | 774bbed | 2009-01-23 05:13:22 +0000 | [diff] [blame] | 1565 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1566 | // Now that some inline flows have line boxes, if we are already ignoring spaces, we need |
| 1567 | // to make sure that we stop to include this object and then start ignoring spaces again. |
| 1568 | // If this object is at the start of the line, we need to behave like list markers and |
| 1569 | // start ignoring spaces. |
hyatt@apple.com | 774bbed | 2009-01-23 05:13:22 +0000 | [diff] [blame] | 1570 | if (inlineFlowRequiresLineBox(flowBox)) { |
hyatt@apple.com | eb66ef4 | 2008-01-18 22:59:29 +0000 | [diff] [blame] | 1571 | isLineEmpty = false; |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1572 | if (ignoringSpaces) { |
| 1573 | trailingSpaceObject = 0; |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1574 | addMidpoint(lineMidpointState, InlineIterator(0, o, 0)); // Stop ignoring spaces. |
| 1575 | addMidpoint(lineMidpointState, InlineIterator(0, o, 0)); // Start ignoring again. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1576 | } else if (style()->collapseWhiteSpace() && resolver.position().obj == o |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1577 | && shouldSkipWhitespaceAfterStartObject(this, o, lineMidpointState)) { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1578 | // Like with list markers, we start ignoring spaces to make sure that any |
| 1579 | // additional spaces we see will be discarded. |
| 1580 | currentCharacterIsSpace = true; |
| 1581 | currentCharacterIsWS = true; |
| 1582 | ignoringSpaces = true; |
| 1583 | } |
| 1584 | } |
| 1585 | |
hyatt@apple.com | 774bbed | 2009-01-23 05:13:22 +0000 | [diff] [blame] | 1586 | tmpW += flowBox->marginLeft() + flowBox->borderLeft() + flowBox->paddingLeft() + |
| 1587 | flowBox->marginRight() + flowBox->borderRight() + flowBox->paddingRight(); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1588 | } else if (o->isReplaced()) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1589 | RenderBox* replacedBox = toRenderBox(o); |
| 1590 | |
hyatt | de39634 | 2003-10-29 08:57:20 +0000 | [diff] [blame] | 1591 | // Break on replaced elements if either has normal white-space. |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 1592 | if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!o->isImage() || allowImagesToBreak)) { |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 1593 | w += tmpW; |
| 1594 | tmpW = 0; |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 1595 | lBreak.obj = o; |
| 1596 | lBreak.pos = 0; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1597 | lBreak.nextBreakablePosition = -1; |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 1600 | if (ignoringSpaces) |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1601 | addMidpoint(lineMidpointState, InlineIterator(0, o, 0)); |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 1602 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1603 | isLineEmpty = false; |
| 1604 | ignoringSpaces = false; |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1605 | currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1606 | currentCharacterIsWS = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1607 | trailingSpaceObject = 0; |
hamaji@chromium.org | 382642b | 2009-12-01 07:37:14 +0000 | [diff] [blame] | 1608 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1609 | // Optimize for a common case. If we can't find whitespace after the list |
| 1610 | // item, then this is all moot. -dwh |
hamaji@chromium.org | 382642b | 2009-12-01 07:37:14 +0000 | [diff] [blame] | 1611 | if (o->isListMarker()) { |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1612 | if (style()->collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(this, o, lineMidpointState)) { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1613 | // Like with inline flows, we start ignoring spaces to make sure that any |
| 1614 | // additional spaces we see will be discarded. |
| 1615 | currentCharacterIsSpace = true; |
| 1616 | currentCharacterIsWS = true; |
| 1617 | ignoringSpaces = true; |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 1618 | } |
hamaji@chromium.org | 382642b | 2009-12-01 07:37:14 +0000 | [diff] [blame] | 1619 | if (toRenderListMarker(o)->isInside()) |
| 1620 | tmpW += replacedBox->width() + replacedBox->marginLeft() + replacedBox->marginRight() + inlineWidth(o); |
justing | 244d3a3 | 2006-04-13 01:31:24 +0000 | [diff] [blame] | 1621 | } else |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 1622 | tmpW += replacedBox->width() + replacedBox->marginLeft() + replacedBox->marginRight() + inlineWidth(o); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1623 | } else if (o->isText()) { |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 1624 | if (!pos) |
| 1625 | appliedStartWidth = false; |
| 1626 | |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 1627 | RenderText* t = toRenderText(o); |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1628 | |
zimmermann@webkit.org | 6e96afd | 2010-09-10 15:35:50 +0000 | [diff] [blame] | 1629 | #if ENABLE(SVG) |
| 1630 | bool isSVGText = t->isSVGInlineText(); |
| 1631 | #endif |
| 1632 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1633 | int strlen = t->textLength(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1634 | int len = strlen - pos; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1635 | const UChar* str = t->characters(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1636 | |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1637 | RenderStyle* style = t->style(firstLine); |
| 1638 | const Font& f = style->font(); |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1639 | bool isFixedPitch = f.isFixedPitch(); |
mitz@apple.com | 73eb8c9 | 2010-08-04 21:22:24 +0000 | [diff] [blame] | 1640 | bool canHyphenate = style->hyphens() == HyphensAuto && WebCore::canHyphenate(style->hyphenationLocale()); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1641 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1642 | int lastSpace = pos; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1643 | int wordSpacing = o->style()->wordSpacing(); |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1644 | int lastSpaceWordSpacing = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1645 | |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 1646 | // Non-zero only when kerning is enabled, in which case we measure words with their trailing |
| 1647 | // space, then subtract its width. |
mitz@apple.com | 6ff116d | 2010-07-06 00:11:08 +0000 | [diff] [blame] | 1648 | int wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(TextRun(&space, 1)) + wordSpacing : 0; |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 1649 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1650 | int wrapW = tmpW + inlineWidth(o, !appliedStartWidth, true); |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1651 | int charWidth = 0; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1652 | bool breakNBSP = autoWrap && o->style()->nbspMode() == SPACE; |
| 1653 | // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word, |
| 1654 | // which is only possible if the word is the first thing on the line, that is, if |w| is zero. |
hyatt | ea474f7 | 2007-04-20 05:02:19 +0000 | [diff] [blame] | 1655 | bool breakWords = o->style()->breakWords() && ((autoWrap && !w) || currWS == PRE); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1656 | bool midWordBreak = false; |
hyatt | ea474f7 | 2007-04-20 05:02:19 +0000 | [diff] [blame] | 1657 | bool breakAll = o->style()->wordBreak() == BreakAllWordBreak && autoWrap; |
| 1658 | |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1659 | if (t->isWordBreak()) { |
| 1660 | w += tmpW; |
| 1661 | tmpW = 0; |
| 1662 | lBreak.obj = o; |
| 1663 | lBreak.pos = 0; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1664 | lBreak.nextBreakablePosition = -1; |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1665 | ASSERT(!len); |
| 1666 | } |
| 1667 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1668 | while (len) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1669 | bool previousCharacterIsSpace = currentCharacterIsSpace; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1670 | bool previousCharacterIsWS = currentCharacterIsWS; |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 1671 | UChar c = str[pos]; |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1672 | currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNewline && (c == '\n')); |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 1673 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1674 | if (!collapseWhiteSpace || !currentCharacterIsSpace) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1675 | isLineEmpty = false; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1676 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1677 | // Check for soft hyphens. Go ahead and ignore them. |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1678 | if (c == softHyphen) { |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1679 | if (!ignoringSpaces) { |
| 1680 | // Ignore soft hyphens |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1681 | InlineIterator beforeSoftHyphen; |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1682 | if (pos) |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1683 | beforeSoftHyphen = InlineIterator(0, o, pos - 1); |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 1684 | else |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 1685 | beforeSoftHyphen = InlineIterator(0, last, last->isText() ? toRenderText(last)->textLength() - 1 : 0); |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 1686 | // Two consecutive soft hyphens. Avoid overlapping midpoints. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 1687 | if (lineMidpointState.numMidpoints && lineMidpointState.midpoints[lineMidpointState.numMidpoints - 1].obj == o && |
| 1688 | lineMidpointState.midpoints[lineMidpointState.numMidpoints - 1].pos == pos) |
| 1689 | lineMidpointState.numMidpoints--; |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 1690 | else |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1691 | addMidpoint(lineMidpointState, beforeSoftHyphen); |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1692 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1693 | // Add the width up to but not including the hyphen. |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1694 | tmpW += textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing; |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1695 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1696 | // For wrapping text only, include the hyphen. We need to ensure it will fit |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1697 | // on the line if it shows when we break. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1698 | if (autoWrap) |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1699 | tmpW += textWidth(t, pos, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace); |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1700 | |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 1701 | InlineIterator afterSoftHyphen(0, o, pos); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1702 | afterSoftHyphen.increment(); |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1703 | addMidpoint(lineMidpointState, afterSoftHyphen); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1704 | } |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1705 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1706 | pos++; |
| 1707 | len--; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1708 | lastSpaceWordSpacing = 0; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1709 | lastSpace = pos; // Cheesy hack to prevent adding in widths of the run twice. |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1710 | if (style->hyphens() == HyphensNone) { |
| 1711 | // Prevent a line break at the soft hyphen by ensuring that betweenWords is false |
| 1712 | // in the next iteration. |
| 1713 | atStart = true; |
| 1714 | } |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1715 | continue; |
| 1716 | } |
zimmermann@webkit.org | 6e96afd | 2010-09-10 15:35:50 +0000 | [diff] [blame] | 1717 | |
| 1718 | #if ENABLE(SVG) |
| 1719 | if (isSVGText) { |
| 1720 | RenderSVGInlineText* svgInlineText = static_cast<RenderSVGInlineText*>(t); |
| 1721 | if (pos > 0) { |
| 1722 | if (svgInlineText->characterStartsNewTextChunk(pos)) { |
| 1723 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos - 1)); |
| 1724 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos)); |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | #endif |
| 1729 | |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1730 | bool applyWordSpacing = false; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1731 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1732 | currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace); |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1733 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1734 | if ((breakAll || breakWords) && !midWordBreak) { |
| 1735 | wrapW += charWidth; |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1736 | charWidth = textWidth(t, pos, 1, f, w + wrapW, isFixedPitch, collapseWhiteSpace); |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1737 | midWordBreak = w + wrapW + charWidth > width; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1738 | } |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 1739 | |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1740 | bool betweenWords = c == '\n' || (currWS != PRE && !atStart && isBreakable(str, pos, strlen, nextBreakable, breakNBSP)); |
hyatt | ea474f7 | 2007-04-20 05:02:19 +0000 | [diff] [blame] | 1741 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1742 | if (betweenWords || midWordBreak) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1743 | bool stoppedIgnoringSpaces = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1744 | if (ignoringSpaces) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1745 | if (!currentCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1746 | // Stop ignoring spaces and begin at this |
| 1747 | // new point. |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 1748 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1749 | lastSpaceWordSpacing = 0; |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 1750 | lastSpace = pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1751 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos)); |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1752 | stoppedIgnoringSpaces = true; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1753 | } else { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1754 | // Just keep ignoring these spaces. |
| 1755 | pos++; |
| 1756 | len--; |
| 1757 | continue; |
| 1758 | } |
| 1759 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1760 | |
mitz@apple.com | fa13fcc | 2010-01-07 01:41:32 +0000 | [diff] [blame] | 1761 | int additionalTmpW; |
| 1762 | if (wordTrailingSpaceWidth && currentCharacterIsSpace) |
| 1763 | additionalTmpW = textWidth(t, lastSpace, pos + 1 - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) - wordTrailingSpaceWidth + lastSpaceWordSpacing; |
| 1764 | else |
| 1765 | additionalTmpW = textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing; |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1766 | tmpW += additionalTmpW; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1767 | if (!appliedStartWidth) { |
| 1768 | tmpW += inlineWidth(o, true, false); |
| 1769 | appliedStartWidth = true; |
| 1770 | } |
| 1771 | |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1772 | applyWordSpacing = wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1773 | |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1774 | if (!w && autoWrap && tmpW > width) |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1775 | fitBelowFloats(tmpW, firstLine, width); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1776 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1777 | if (autoWrap || breakWords) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1778 | // If we break only after white-space, consider the current character |
kocienda | e413424 | 2004-10-25 18:48:44 +0000 | [diff] [blame] | 1779 | // as candidate width for this line. |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 1780 | bool lineWasTooWide = false; |
| 1781 | if (w + tmpW <= width && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) { |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1782 | int charWidth = textWidth(t, pos, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + (applyWordSpacing ? wordSpacing : 0); |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 1783 | // Check if line is too big even without the extra space |
| 1784 | // at the end of the line. If it is not, do nothing. |
| 1785 | // If the line needs the extra whitespace to be too long, |
| 1786 | // then move the line break to the space and skip all |
| 1787 | // additional whitespace. |
| 1788 | if (w + tmpW + charWidth > width) { |
| 1789 | lineWasTooWide = true; |
| 1790 | lBreak.obj = o; |
| 1791 | lBreak.pos = pos; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1792 | lBreak.nextBreakablePosition = nextBreakable; |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1793 | skipTrailingWhitespace(lBreak, isLineEmpty, previousLineBrokeCleanly); |
kocienda | 9dbe9b1 | 2004-10-22 20:07:05 +0000 | [diff] [blame] | 1794 | } |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 1795 | } |
| 1796 | if (lineWasTooWide || w + tmpW > width) { |
mitz@apple.com | 67ed70a | 2010-06-22 22:10:10 +0000 | [diff] [blame] | 1797 | if (canHyphenate && w + tmpW > width) { |
mitz@apple.com | 73eb8c9 | 2010-08-04 21:22:24 +0000 | [diff] [blame] | 1798 | tryHyphenating(t, f, style->hyphenationLocale(), lastSpace, pos, w + tmpW - additionalTmpW, width, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated); |
mitz@apple.com | 67ed70a | 2010-06-22 22:10:10 +0000 | [diff] [blame] | 1799 | if (hyphenated) |
| 1800 | goto end; |
| 1801 | } |
eric@webkit.org | 1cb4440 | 2009-12-29 06:25:16 +0000 | [diff] [blame] | 1802 | if (lBreak.obj && shouldPreserveNewline(lBreak.obj) && lBreak.obj->isText() && toRenderText(lBreak.obj)->textLength() && !toRenderText(lBreak.obj)->isWordBreak() && toRenderText(lBreak.obj)->characters()[lBreak.pos] == '\n') { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1803 | if (!stoppedIgnoringSpaces && pos > 0) { |
| 1804 | // We need to stop right before the newline and then start up again. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1805 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos - 1)); // Stop |
| 1806 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos)); // Start |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1807 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1808 | lBreak.increment(); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1809 | previousLineBrokeCleanly = true; |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1810 | } |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1811 | goto end; // Didn't fit. Jump to the end. |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1812 | } else { |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1813 | if (!betweenWords || (midWordBreak && !autoWrap)) |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1814 | tmpW -= additionalTmpW; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1815 | if (pos > 0 && str[pos-1] == softHyphen) |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1816 | // Subtract the width of the soft hyphen out since we fit on a line. |
mitz@apple.com | 3410644 | 2009-02-01 06:23:39 +0000 | [diff] [blame] | 1817 | tmpW -= textWidth(t, pos - 1, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace); |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1818 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1819 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1820 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1821 | if (c == '\n' && preserveNewline) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1822 | if (!stoppedIgnoringSpaces && pos > 0) { |
| 1823 | // We need to stop right before the newline and then start up again. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1824 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos - 1)); // Stop |
| 1825 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos)); // Start |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1826 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1827 | lBreak.obj = o; |
| 1828 | lBreak.pos = pos; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1829 | lBreak.nextBreakablePosition = nextBreakable; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1830 | lBreak.increment(); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1831 | previousLineBrokeCleanly = true; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1832 | return lBreak; |
| 1833 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1834 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1835 | if (autoWrap && betweenWords) { |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1836 | w += tmpW; |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1837 | wrapW = 0; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1838 | tmpW = 0; |
| 1839 | lBreak.obj = o; |
| 1840 | lBreak.pos = pos; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1841 | lBreak.nextBreakablePosition = nextBreakable; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1842 | // Auto-wrapping text should not wrap in the middle of a word once it has had an |
| 1843 | // opportunity to break after a word. |
| 1844 | breakWords = false; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1845 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1846 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1847 | if (midWordBreak) { |
| 1848 | // Remember this as a breakable position in case |
| 1849 | // adding the end width forces a break. |
| 1850 | lBreak.obj = o; |
| 1851 | lBreak.pos = pos; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1852 | lBreak.nextBreakablePosition = nextBreakable; |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1853 | midWordBreak &= (breakWords || breakAll); |
| 1854 | } |
| 1855 | |
| 1856 | if (betweenWords) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1857 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
| 1858 | lastSpace = pos; |
| 1859 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1860 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1861 | if (!ignoringSpaces && o->style()->collapseWhiteSpace()) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1862 | // If we encounter a newline, or if we encounter a |
| 1863 | // second space, we need to go ahead and break up this |
| 1864 | // run and enter a mode where we start collapsing spaces. |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1865 | if (currentCharacterIsSpace && previousCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1866 | ignoringSpaces = true; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1867 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1868 | // We just entered a mode where we are ignoring |
| 1869 | // spaces. Create a midpoint to terminate the run |
| 1870 | // before the second space. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1871 | addMidpoint(lineMidpointState, ignoreStart); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1872 | } |
| 1873 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1874 | } else if (ignoringSpaces) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1875 | // Stop ignoring spaces and begin at this |
| 1876 | // new point. |
| 1877 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1878 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1879 | lastSpace = pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 1880 | addMidpoint(lineMidpointState, InlineIterator(0, o, pos)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1881 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1882 | |
| 1883 | if (currentCharacterIsSpace && !previousCharacterIsSpace) { |
| 1884 | ignoreStart.obj = o; |
| 1885 | ignoreStart.pos = pos; |
| 1886 | } |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1887 | |
| 1888 | if (!currentCharacterIsWS && previousCharacterIsWS) { |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1889 | if (autoWrap && o->style()->breakOnlyAfterWhiteSpace()) { |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1890 | lBreak.obj = o; |
| 1891 | lBreak.pos = pos; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1892 | lBreak.nextBreakablePosition = nextBreakable; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1893 | } |
| 1894 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1895 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1896 | if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSpaces) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1897 | trailingSpaceObject = o; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1898 | else if (!o->style()->collapseWhiteSpace() || !currentCharacterIsSpace) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1899 | trailingSpaceObject = 0; |
| 1900 | |
| 1901 | pos++; |
| 1902 | len--; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1903 | atStart = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1904 | } |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1905 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1906 | // IMPORTANT: pos is > length here! |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1907 | int additionalTmpW = ignoringSpaces ? 0 : textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing; |
| 1908 | tmpW += additionalTmpW; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1909 | tmpW += inlineWidth(o, !appliedStartWidth, true); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1910 | |
| 1911 | if (canHyphenate && w + tmpW > width) { |
mitz@apple.com | 73eb8c9 | 2010-08-04 21:22:24 +0000 | [diff] [blame] | 1912 | tryHyphenating(t, f, style->hyphenationLocale(), lastSpace, pos, w + tmpW - additionalTmpW, width, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated); |
mitz@apple.com | b210765 | 2010-06-21 16:54:52 +0000 | [diff] [blame] | 1913 | if (hyphenated) |
| 1914 | goto end; |
| 1915 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1916 | } else |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1917 | ASSERT_NOT_REACHED(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1918 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1919 | RenderObject* next = bidiNext(this, o); |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1920 | bool checkForBreak = autoWrap; |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1921 | if (w && w + tmpW > width && lBreak.obj && currWS == NOWRAP) |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 1922 | checkForBreak = true; |
| 1923 | else if (next && o->isText() && next->isText() && !next->isBR()) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1924 | if (autoWrap || (next->style()->autoWrap())) { |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1925 | if (currentCharacterIsSpace) |
| 1926 | checkForBreak = true; |
| 1927 | else { |
harrison | 07b5e58 | 2005-08-15 23:31:16 +0000 | [diff] [blame] | 1928 | checkForBreak = false; |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 1929 | RenderText* nextText = toRenderText(next); |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1930 | if (nextText->textLength()) { |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1931 | UChar c = nextText->characters()[0]; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1932 | if (c == ' ' || c == '\t' || (c == '\n' && !shouldPreserveNewline(next))) |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1933 | // If the next item on the line is text, and if we did not end with |
| 1934 | // a space, then the next text run continues our word (and so it needs to |
| 1935 | // keep adding to |tmpW|. Just update and continue. |
| 1936 | checkForBreak = true; |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1937 | } else if (nextText->isWordBreak()) |
| 1938 | checkForBreak = true; |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1939 | bool willFitOnLine = w + tmpW <= width; |
| 1940 | if (!willFitOnLine && !w) { |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1941 | fitBelowFloats(tmpW, firstLine, width); |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1942 | willFitOnLine = tmpW <= width; |
| 1943 | } |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1944 | bool canPlaceOnLine = willFitOnLine || !autoWrapWasEverTrueOnLine; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1945 | if (canPlaceOnLine && checkForBreak) { |
| 1946 | w += tmpW; |
| 1947 | tmpW = 0; |
| 1948 | lBreak.obj = next; |
| 1949 | lBreak.pos = 0; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1950 | lBreak.nextBreakablePosition = -1; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | } |
| 1955 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1956 | if (checkForBreak && (w + tmpW > width)) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1957 | // if we have floats, try to get below them. |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1958 | if (currentCharacterIsSpace && !ignoringSpaces && o->style()->collapseWhiteSpace()) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1959 | trailingSpaceObject = 0; |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1960 | |
| 1961 | if (w) |
| 1962 | goto end; |
| 1963 | |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 1964 | fitBelowFloats(tmpW, firstLine, width); |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 1965 | |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 1966 | // |width| may have been adjusted because we got shoved down past a float (thus |
| 1967 | // giving us more room), so we need to retest, and only jump to |
| 1968 | // the end label if we still don't fit on the line. -dwh |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1969 | if (w + tmpW > width) |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 1970 | goto end; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1971 | } |
hyatt | 1d9e29b | 2003-04-10 01:48:53 +0000 | [diff] [blame] | 1972 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1973 | if (!o->isFloatingOrPositioned()) { |
| 1974 | last = o; |
darin@apple.com | b6cb256 | 2009-08-05 21:25:09 +0000 | [diff] [blame] | 1975 | if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || toRenderListMarker(last)->isInside())) { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1976 | w += tmpW; |
| 1977 | tmpW = 0; |
| 1978 | lBreak.obj = next; |
| 1979 | lBreak.pos = 0; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1980 | lBreak.nextBreakablePosition = -1; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1981 | } |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1984 | o = next; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 1985 | nextBreakable = -1; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1986 | |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1987 | // Clear out our character space bool, since inline <pre>s don't collapse whitespace |
| 1988 | // with adjacent inline normal/nowrap spans. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1989 | if (!collapseWhiteSpace) |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1990 | currentCharacterIsSpace = false; |
| 1991 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1992 | pos = 0; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1993 | atStart = false; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1996 | |
| 1997 | if (w + tmpW <= width || lastWS == NOWRAP) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1998 | lBreak.obj = 0; |
| 1999 | lBreak.pos = 0; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 2000 | lBreak.nextBreakablePosition = -1; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | end: |
eric@webkit.org | ee76f4f | 2009-03-25 22:14:46 +0000 | [diff] [blame] | 2004 | if (lBreak == resolver.position() && (!lBreak.obj || !lBreak.obj->isBR())) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2005 | // we just add as much as possible |
weinig | 98726da | 2007-03-15 01:22:19 +0000 | [diff] [blame] | 2006 | if (style()->whiteSpace() == PRE) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2007 | // FIXME: Don't really understand this case. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2008 | if (pos != 0) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2009 | lBreak.obj = o; |
| 2010 | lBreak.pos = pos - 1; |
| 2011 | } else { |
| 2012 | lBreak.obj = last; |
hyatt | c3731d4 | 2002-12-12 06:20:22 +0000 | [diff] [blame] | 2013 | lBreak.pos = last->isText() ? last->length() : 0; |
mitz@apple.com | d17dc39 | 2008-09-15 18:48:20 +0000 | [diff] [blame] | 2014 | lBreak.nextBreakablePosition = -1; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2015 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2016 | } else if (lBreak.obj) { |
yuzo@google.com | c25f62f | 2010-02-09 09:16:36 +0000 | [diff] [blame] | 2017 | // Don't ever break in the middle of a word if we can help it. |
| 2018 | // There's no room at all. We just have to be on this line, |
| 2019 | // even though we'll spill out. |
| 2020 | lBreak.obj = o; |
| 2021 | lBreak.pos = pos; |
| 2022 | lBreak.nextBreakablePosition = -1; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | // make sure we consume at least one char/object. |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2027 | if (lBreak == resolver.position()) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2028 | lBreak.increment(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2029 | |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 2030 | // Sanity check our midpoints. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2031 | checkMidpoints(lineMidpointState, lBreak); |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 2032 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2033 | if (trailingSpaceObject) { |
| 2034 | // This object is either going to be part of the last midpoint, or it is going |
| 2035 | // to be the actual endpoint. In both cases we just decrease our pos by 1 level to |
| 2036 | // exclude the space, allowing it to - in effect - collapse into the newline. |
hyatt@apple.com | 1a5ffd8 | 2009-06-13 17:20:30 +0000 | [diff] [blame] | 2037 | if (lineMidpointState.numMidpoints % 2) { |
| 2038 | InlineIterator* midpoints = lineMidpointState.midpoints.data(); |
| 2039 | midpoints[lineMidpointState.numMidpoints - 1].pos--; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2040 | } |
| 2041 | //else if (lBreak.pos > 0) |
| 2042 | // lBreak.pos--; |
| 2043 | else if (lBreak.obj == 0 && trailingSpaceObject->isText()) { |
hyatt | d20075d | 2002-11-16 02:23:32 +0000 | [diff] [blame] | 2044 | // Add a new end midpoint that stops right at the very end. |
darin@apple.com | 36744d6 | 2009-01-25 20:23:04 +0000 | [diff] [blame] | 2045 | RenderText* text = toRenderText(trailingSpaceObject); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2046 | unsigned length = text->textLength(); |
| 2047 | unsigned pos = length >= 2 ? length - 2 : UINT_MAX; |
mitz@apple.com | 15035e6 | 2008-07-05 20:44:44 +0000 | [diff] [blame] | 2048 | InlineIterator endMid(0, trailingSpaceObject, pos); |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2049 | addMidpoint(lineMidpointState, endMid); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2050 | } |
| 2051 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2052 | |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2053 | // We might have made lBreak an iterator that points past the end |
| 2054 | // of the object. Do this adjustment to make it point to the start |
| 2055 | // of the next object instead to avoid confusing the rest of the |
| 2056 | // code. |
| 2057 | if (lBreak.pos > 0) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2058 | lBreak.pos--; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2059 | lBreak.increment(); |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2062 | if (lBreak.obj && lBreak.pos >= 2 && lBreak.obj->isText()) { |
| 2063 | // For soft hyphens on line breaks, we have to chop out the midpoints that made us |
| 2064 | // ignore the hyphen so that it will render at the end of the line. |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2065 | UChar c = toRenderText(lBreak.obj)->characters()[lBreak.pos - 1]; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2066 | if (c == softHyphen) |
hyatt@apple.com | b3466af | 2009-06-13 06:04:40 +0000 | [diff] [blame] | 2067 | chopMidpointsAt(lineMidpointState, lBreak.obj, lBreak.pos - 2); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2070 | return lBreak; |
| 2071 | } |
| 2072 | |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 2073 | void RenderBlock::addOverflowFromInlineChildren() |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2074 | { |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2075 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 2076 | addLayoutOverflow(curr->layoutOverflowRect()); |
| 2077 | if (!hasOverflowClip()) |
| 2078 | addVisualOverflow(curr->visualOverflowRect()); |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2082 | void RenderBlock::deleteEllipsisLineBoxes() |
| 2083 | { |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2084 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 2085 | curr->clearTruncation(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | void RenderBlock::checkLinesForTextOverflow() |
| 2089 | { |
| 2090 | // Determine the width of the ellipsis using the current font. |
darin | dbba2bb | 2007-01-11 12:23:49 +0000 | [diff] [blame] | 2091 | // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable" |
| 2092 | TextRun ellipsisRun(&horizontalEllipsis, 1); |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 2093 | DEFINE_STATIC_LOCAL(AtomicString, ellipsisStr, (&horizontalEllipsis, 1)); |
hyatt | 3e99d1c | 2006-02-24 21:13:08 +0000 | [diff] [blame] | 2094 | const Font& firstLineFont = firstLineStyle()->font(); |
| 2095 | const Font& font = style()->font(); |
hyatt | 43d6c79 | 2006-05-11 10:19:34 +0000 | [diff] [blame] | 2096 | int firstLineEllipsisWidth = firstLineFont.width(ellipsisRun); |
| 2097 | int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(ellipsisRun); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2098 | |
| 2099 | // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see |
| 2100 | // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and |
| 2101 | // check the left edge of the line box to see if it is less |
| 2102 | // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()" |
| 2103 | bool ltr = style()->direction() == LTR; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2104 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 2105 | int blockRightEdge = rightOffset(curr->y(), curr == firstRootBox()); |
| 2106 | int blockLeftEdge = leftOffset(curr->y(), curr == firstRootBox()); |
hyatt@apple.com | c01df9e | 2010-09-23 19:17:33 +0000 | [diff] [blame] | 2107 | int lineBoxEdge = ltr ? curr->x() + curr->logicalWidth() : curr->x(); |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 2108 | if ((ltr && lineBoxEdge > blockRightEdge) || (!ltr && lineBoxEdge < blockLeftEdge)) { |
hyatt | f918d2d | 2004-06-15 07:24:11 +0000 | [diff] [blame] | 2109 | // 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] | 2110 | // can be truncated. In order for truncation to be possible, the line must have sufficient space to |
| 2111 | // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis |
| 2112 | // space. |
| 2113 | int width = curr == firstRootBox() ? firstLineEllipsisWidth : ellipsisWidth; |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 2114 | int blockEdge = ltr ? blockRightEdge : blockLeftEdge; |
hyatt | 1a8d251 | 2004-06-17 01:38:30 +0000 | [diff] [blame] | 2115 | if (curr->canAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) |
dglazkov@chromium.org | 28434e6 | 2009-05-13 22:30:10 +0000 | [diff] [blame] | 2116 | curr->placeEllipsis(ellipsisStr, ltr, blockLeftEdge, blockRightEdge, width); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2121 | } |