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