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