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