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