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