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) { |
| 994 | if (direction == LTR) |
| 995 | start.moveRunToEnd(trailingSpaceRun); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 996 | else |
mitz@apple.com | 3a43c71 | 2008-04-20 04:26:28 +0000 | [diff] [blame^] | 997 | start.moveRunToBeginning(trailingSpaceRun); |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | } else |
| 1001 | trailingSpaceRun = 0; |
| 1002 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1003 | |
| 1004 | // Now that the runs have been ordered, we create the line boxes. |
| 1005 | // At the same time we figure out where border/padding/margin should be applied for |
| 1006 | // inline flow boxes. |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1007 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1008 | RootInlineBox* lineBox = 0; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1009 | if (start.runCount()) { |
| 1010 | 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] | 1011 | if (lineBox) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1012 | lineBox->setEndsWithBreak(previousLineBrokeCleanly); |
pewtermoose | cf72e2d | 2007-07-20 19:01:55 +0000 | [diff] [blame] | 1013 | |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1014 | // Now we position all of our text runs horizontally. |
mitz@apple.com | c13ea5f | 2008-04-18 21:18:26 +0000 | [diff] [blame] | 1015 | computeHorizontalPositionsForLine(lineBox, start.firstRun(), trailingSpaceRun, end.atEnd()); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1016 | |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1017 | // Now position our text runs vertically. |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1018 | computeVerticalPositionsForLine(lineBox, start.firstRun()); |
hyatt | bddcc61 | 2006-07-24 23:16:15 +0000 | [diff] [blame] | 1019 | |
oliver | 98d5238 | 2007-10-12 10:47:18 +0000 | [diff] [blame] | 1020 | #if ENABLE(SVG) |
| 1021 | // Special SVG text layout code |
| 1022 | lineBox->computePerCharacterLayoutInformation(); |
| 1023 | #endif |
| 1024 | |
hyatt | bddcc61 | 2006-07-24 23:16:15 +0000 | [diff] [blame] | 1025 | #if PLATFORM(MAC) |
| 1026 | // Highlight acts as an overflow inflation. |
| 1027 | if (style()->highlight() != nullAtom) |
| 1028 | lineBox->addHighlightOverflow(); |
| 1029 | #endif |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1030 | } |
| 1031 | } |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 1032 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1033 | start.deleteRuns(); |
hyatt | 35a85e5 | 2003-02-14 19:43:07 +0000 | [diff] [blame] | 1034 | |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1035 | if (lineBox) { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1036 | lineBox->setLineBreakInfo(end.obj, end.pos, start.status()); |
ap | ddd2ff4 | 2007-03-31 08:26:24 +0000 | [diff] [blame] | 1037 | if (useRepaintBounds) { |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1038 | repaintTop = min(repaintTop, lineBox->topOverflow()); |
| 1039 | repaintBottom = max(repaintBottom, lineBox->bottomOverflow()); |
| 1040 | } |
| 1041 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1042 | |
hyatt | 35a85e5 | 2003-02-14 19:43:07 +0000 | [diff] [blame] | 1043 | m_firstLine = false; |
mitz@apple.com | 71e3084 | 2008-03-18 16:13:31 +0000 | [diff] [blame] | 1044 | newLine(clear); |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1045 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1046 | |
mitz@apple.com | 7b08984 | 2008-03-22 06:57:28 +0000 | [diff] [blame] | 1047 | if (m_floatingObjects && lastRootBox()) { |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1048 | if (lastFloat) { |
| 1049 | for (FloatingObject* f = m_floatingObjects->last(); f != lastFloat; f = m_floatingObjects->prev()) { |
| 1050 | } |
| 1051 | m_floatingObjects->next(); |
| 1052 | } else |
| 1053 | m_floatingObjects->first(); |
| 1054 | for (FloatingObject* f = m_floatingObjects->current(); f; f = m_floatingObjects->next()) { |
mitz@apple.com | 9352659 | 2008-03-18 04:36:51 +0000 | [diff] [blame] | 1055 | lastRootBox()->floats().append(f->m_renderer); |
| 1056 | ASSERT(f->m_renderer == floats[floatIndex].object); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1057 | // 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] | 1058 | 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] | 1059 | checkForEndLineMatch = false; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1060 | floatIndex++; |
| 1061 | } |
| 1062 | lastFloat = m_floatingObjects->last(); |
| 1063 | } |
| 1064 | |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1065 | sNumMidpoints = 0; |
| 1066 | sCurrMidpoint = 0; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1067 | start.setPosition(end); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1068 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1069 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1070 | if (endLine) { |
| 1071 | if (endLineMatched) { |
| 1072 | // Attach all the remaining lines, and then adjust their y-positions as needed. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1073 | int delta = m_height - endLineYPos; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1074 | for (RootInlineBox* line = endLine; line; line = line->nextRootBox()) { |
| 1075 | line->attachLine(); |
| 1076 | if (delta) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1077 | repaintTop = min(repaintTop, line->topOverflow() + min(delta, 0)); |
| 1078 | repaintBottom = max(repaintBottom, line->bottomOverflow() + max(delta, 0)); |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 1079 | line->adjustPosition(0, delta); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1080 | } |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1081 | if (Vector<RenderObject*>* cleanLineFloats = line->floatsPtr()) { |
| 1082 | Vector<RenderObject*>::iterator end = cleanLineFloats->end(); |
| 1083 | for (Vector<RenderObject*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
| 1084 | int floatTop = (*f)->yPos() - (*f)->marginTop(); |
| 1085 | insertFloatingObject(*f); |
| 1086 | m_height = floatTop + delta; |
| 1087 | positionNewFloats(); |
| 1088 | } |
| 1089 | } |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 1090 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1091 | m_height = lastRootBox()->blockHeight(); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1092 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1093 | // Delete all the remaining lines. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1094 | InlineRunBox* line = endLine; |
| 1095 | RenderArena* arena = renderArena(); |
| 1096 | while (line) { |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1097 | repaintTop = min(repaintTop, line->topOverflow()); |
| 1098 | repaintBottom = max(repaintBottom, line->bottomOverflow()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1099 | InlineRunBox* next = line->nextLineBox(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1100 | line->deleteLine(arena); |
| 1101 | line = next; |
| 1102 | } |
| 1103 | } |
| 1104 | } |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1105 | if (m_floatingObjects) { |
| 1106 | // In case we have a float on the last line, it might not be positioned up to now. |
| 1107 | // This has to be done before adding in the bottom border/padding, or the float will |
| 1108 | // include the padding incorrectly. -dwh |
| 1109 | if (positionNewFloats() && lastRootBox()) { |
| 1110 | if (lastFloat) { |
| 1111 | for (FloatingObject* f = m_floatingObjects->last(); f != lastFloat; f = m_floatingObjects->prev()) { |
| 1112 | } |
| 1113 | m_floatingObjects->next(); |
| 1114 | } else |
| 1115 | m_floatingObjects->first(); |
| 1116 | for (FloatingObject* f = m_floatingObjects->current(); f; f = m_floatingObjects->next()) |
mitz@apple.com | 9352659 | 2008-03-18 04:36:51 +0000 | [diff] [blame] | 1117 | lastRootBox()->floats().append(f->m_renderer); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1118 | lastFloat = m_floatingObjects->last(); |
| 1119 | } |
| 1120 | } |
| 1121 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1122 | } |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1123 | |
| 1124 | sNumMidpoints = 0; |
| 1125 | sCurrMidpoint = 0; |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1126 | |
| 1127 | // Now add in the bottom border/padding. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1128 | m_height += toAdd; |
| 1129 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1130 | // Always make sure this is at least our height. |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 1131 | m_overflowHeight = max(m_height, m_overflowHeight); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1132 | |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 1133 | // See if any lines spill out of the block. If so, we need to update our overflow width. |
| 1134 | checkLinesForOverflow(); |
| 1135 | |
adele | 7a470a7 | 2006-04-20 22:22:14 +0000 | [diff] [blame] | 1136 | if (!firstLineBox() && hasLineIfEmpty()) |
adele | 05abee3 | 2006-08-25 23:44:05 +0000 | [diff] [blame] | 1137 | m_height += lineHeight(true, true); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1138 | |
| 1139 | // See if we have any lines that spill out of our block. If we do, then we will possibly need to |
| 1140 | // truncate text. |
| 1141 | if (hasTextOverflow) |
| 1142 | checkLinesForTextOverflow(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1145 | RootInlineBox* RenderBlock::determineStartPosition(bool& fullLayout, BidiState& start, Vector<FloatWithRect>& floats, unsigned& numCleanFloats) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1146 | { |
| 1147 | RootInlineBox* curr = 0; |
| 1148 | RootInlineBox* last = 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1149 | |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1150 | bool dirtiedByFloat = false; |
| 1151 | if (!fullLayout) { |
| 1152 | size_t floatIndex = 0; |
| 1153 | for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()) { |
| 1154 | if (Vector<RenderObject*>* cleanLineFloats = curr->floatsPtr()) { |
| 1155 | Vector<RenderObject*>::iterator end = cleanLineFloats->end(); |
| 1156 | for (Vector<RenderObject*>::iterator o = cleanLineFloats->begin(); o != end; ++o) { |
| 1157 | RenderObject* f = *o; |
| 1158 | IntSize newSize(f->width() + f->marginLeft() +f->marginRight(), f->height() + f->marginTop() + f->marginBottom()); |
| 1159 | ASSERT(floatIndex < floats.size()); |
| 1160 | if (floats[floatIndex].object != f) { |
| 1161 | // A new float has been inserted before this line or before its last known float. |
| 1162 | // Just do a full layout. |
| 1163 | fullLayout = true; |
| 1164 | break; |
| 1165 | } |
| 1166 | if (floats[floatIndex].rect.size() != newSize) { |
mitz@apple.com | 070a7de | 2008-03-19 18:40:52 +0000 | [diff] [blame] | 1167 | int floatTop = floats[floatIndex].rect.y(); |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1168 | curr->markDirty(); |
| 1169 | markLinesDirtyInVerticalRange(curr->blockHeight(), floatTop + max(floats[floatIndex].rect.height(), newSize.height())); |
| 1170 | floats[floatIndex].rect.setSize(newSize); |
| 1171 | dirtiedByFloat = true; |
| 1172 | } |
| 1173 | floatIndex++; |
| 1174 | } |
| 1175 | } |
| 1176 | if (dirtiedByFloat || fullLayout) |
| 1177 | break; |
| 1178 | } |
| 1179 | // Check if a new float has been inserted after the last known float. |
| 1180 | if (!curr && floatIndex < floats.size()) |
| 1181 | fullLayout = true; |
| 1182 | } |
| 1183 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1184 | if (fullLayout) { |
| 1185 | // Nuke all our lines. |
| 1186 | if (firstRootBox()) { |
| 1187 | RenderArena* arena = renderArena(); |
| 1188 | curr = firstRootBox(); |
| 1189 | while (curr) { |
| 1190 | RootInlineBox* next = curr->nextRootBox(); |
| 1191 | curr->deleteLine(arena); |
| 1192 | curr = next; |
| 1193 | } |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 1194 | ASSERT(!firstLineBox() && !lastLineBox()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1195 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1196 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1197 | if (curr) { |
| 1198 | // We have a dirty line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1199 | if (RootInlineBox* prevRootBox = curr->prevRootBox()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1200 | // We have a previous line. |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1201 | 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] | 1202 | // The previous line didn't break cleanly or broke at a newline |
| 1203 | // that has been deleted, so treat it as dirty too. |
| 1204 | curr = prevRootBox; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1205 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1206 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1207 | // No dirty lines were found. |
| 1208 | // If the last line didn't break cleanly, treat it as dirty. |
| 1209 | if (lastRootBox() && !lastRootBox()->endsWithBreak()) |
| 1210 | curr = lastRootBox(); |
| 1211 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1212 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1213 | // If we have no dirty lines, then last is just the last root box. |
| 1214 | last = curr ? curr->prevRootBox() : lastRootBox(); |
| 1215 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1216 | |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1217 | numCleanFloats = 0; |
| 1218 | if (!floats.isEmpty()) { |
| 1219 | int savedHeight = m_height; |
| 1220 | // Restore floats from clean lines. |
| 1221 | RootInlineBox* line = firstRootBox(); |
| 1222 | while (line != curr) { |
| 1223 | if (Vector<RenderObject*>* cleanLineFloats = line->floatsPtr()) { |
| 1224 | Vector<RenderObject*>::iterator end = cleanLineFloats->end(); |
| 1225 | for (Vector<RenderObject*>::iterator f = cleanLineFloats->begin(); f != end; ++f) { |
| 1226 | insertFloatingObject(*f); |
| 1227 | m_height = (*f)->yPos() - (*f)->marginTop(); |
| 1228 | positionNewFloats(); |
| 1229 | ASSERT(floats[numCleanFloats].object == *f); |
| 1230 | numCleanFloats++; |
| 1231 | } |
| 1232 | } |
| 1233 | line = line->nextRootBox(); |
| 1234 | } |
| 1235 | m_height = savedHeight; |
| 1236 | } |
| 1237 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1238 | m_firstLine = !last; |
| 1239 | previousLineBrokeCleanly = !last || last->endsWithBreak(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1240 | |
| 1241 | RenderObject* startObj; |
| 1242 | int pos = 0; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1243 | if (last) { |
| 1244 | m_height = last->blockHeight(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1245 | startObj = last->lineBreakObj(); |
| 1246 | pos = last->lineBreakPos(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1247 | start.setStatus(last->lineBreakBidiStatus()); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1248 | } else { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1249 | bool ltr = style()->direction() == LTR |
| 1250 | #if ENABLE(SVG) |
| 1251 | || (style()->unicodeBidi() == UBNormal && isSVGText()) |
| 1252 | #endif |
| 1253 | ; |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1254 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1255 | BidiContext* context = new BidiContext(ltr ? 0 : 1, ltr ? LeftToRight : RightToLeft, style()->unicodeBidi() == Override); |
| 1256 | |
| 1257 | start.setLastStrongDir(context->dir()); |
| 1258 | start.setLastDir(context->dir()); |
| 1259 | start.setEorDir(context->dir()); |
| 1260 | start.setContext(context); |
| 1261 | startObj = bidiFirst(this, &start); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1262 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1263 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1264 | start.setPosition(BidiIterator(this, startObj, pos)); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1265 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1266 | return curr; |
| 1267 | } |
| 1268 | |
pewtermoose | cf72e2d | 2007-07-20 19:01:55 +0000 | [diff] [blame] | 1269 | RootInlineBox* RenderBlock::determineEndPosition(RootInlineBox* startLine, BidiIterator& cleanLineStart, BidiStatus& cleanLineBidiStatus, int& yPos) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1270 | { |
| 1271 | RootInlineBox* last = 0; |
hyatt | a6960b1 | 2004-12-07 02:09:10 +0000 | [diff] [blame] | 1272 | if (!startLine) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1273 | last = 0; |
| 1274 | else { |
hyatt | 04420ca | 2004-07-16 00:05:42 +0000 | [diff] [blame] | 1275 | for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) { |
| 1276 | if (curr->isDirty()) |
| 1277 | last = 0; |
| 1278 | else if (!last) |
| 1279 | last = curr; |
| 1280 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1281 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1282 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1283 | if (!last) |
| 1284 | return 0; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1285 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1286 | RootInlineBox* prev = last->prevRootBox(); |
| 1287 | cleanLineStart = BidiIterator(this, prev->lineBreakObj(), prev->lineBreakPos()); |
| 1288 | cleanLineBidiStatus = prev->lineBreakBidiStatus(); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1289 | yPos = prev->blockHeight(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1290 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1291 | for (RootInlineBox* line = last; line; line = line->nextRootBox()) |
| 1292 | line->extractLine(); // Disconnect all line boxes from their render objects while preserving |
| 1293 | // their connections to one another. |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1294 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1295 | return last; |
| 1296 | } |
| 1297 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1298 | 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] | 1299 | { |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1300 | if (start.position() == endLineStart) { |
| 1301 | if (start.status() != endLineStatus) |
| 1302 | return false; |
| 1303 | |
| 1304 | int delta = m_height - endYPos; |
| 1305 | if (!delta || !m_floatingObjects) |
| 1306 | return true; |
| 1307 | |
| 1308 | // See if any floats end in the range along which we want to shift the lines vertically. |
| 1309 | int top = min(m_height, endYPos); |
| 1310 | |
| 1311 | RootInlineBox* lastLine = endLine; |
| 1312 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 1313 | lastLine = nextLine; |
| 1314 | |
| 1315 | int bottom = lastLine->blockHeight() + abs(delta); |
| 1316 | |
| 1317 | for (FloatingObject* f = m_floatingObjects->first(); f; f = m_floatingObjects->next()) { |
mitz@apple.com | 9352659 | 2008-03-18 04:36:51 +0000 | [diff] [blame] | 1318 | if (f->m_bottom >= top && f->m_bottom < bottom) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1319 | return false; |
| 1320 | } |
| 1321 | |
| 1322 | return true; |
| 1323 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1324 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1325 | // The first clean line doesn't match, but we can check a handful of following lines to try |
| 1326 | // to match back up. |
| 1327 | static int numLines = 8; // The # of lines we're willing to match against. |
| 1328 | RootInlineBox* line = endLine; |
| 1329 | for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1330 | if (line->lineBreakObj() == start.position().obj && line->lineBreakPos() == start.position().pos) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1331 | // We have a match. |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1332 | if (line->lineBreakBidiStatus() != start.status()) |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1333 | return false; // ...but the bidi state doesn't match. |
| 1334 | RootInlineBox* result = line->nextRootBox(); |
| 1335 | |
| 1336 | // Set our yPos to be the block height of endLine. |
| 1337 | if (result) |
| 1338 | endYPos = line->blockHeight(); |
| 1339 | |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1340 | int delta = m_height - endYPos; |
| 1341 | if (delta && m_floatingObjects) { |
| 1342 | // See if any floats end in the range along which we want to shift the lines vertically. |
| 1343 | int top = min(m_height, endYPos); |
| 1344 | |
| 1345 | RootInlineBox* lastLine = endLine; |
| 1346 | while (RootInlineBox* nextLine = lastLine->nextRootBox()) |
| 1347 | lastLine = nextLine; |
| 1348 | |
| 1349 | int bottom = lastLine->blockHeight() + abs(delta); |
| 1350 | |
| 1351 | for (FloatingObject* f = m_floatingObjects->first(); f; f = m_floatingObjects->next()) { |
mitz@apple.com | 9352659 | 2008-03-18 04:36:51 +0000 | [diff] [blame] | 1352 | if (f->m_bottom >= top && f->m_bottom < bottom) |
mitz@apple.com | 40547b3 | 2008-03-18 04:04:34 +0000 | [diff] [blame] | 1353 | return false; |
| 1354 | } |
| 1355 | } |
| 1356 | |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1357 | // Now delete the lines that we failed to sync. |
| 1358 | RootInlineBox* boxToDelete = endLine; |
| 1359 | RenderArena* arena = renderArena(); |
| 1360 | while (boxToDelete && boxToDelete != result) { |
| 1361 | repaintTop = min(repaintTop, boxToDelete->topOverflow()); |
| 1362 | repaintBottom = max(repaintBottom, boxToDelete->bottomOverflow()); |
| 1363 | RootInlineBox* next = boxToDelete->nextRootBox(); |
| 1364 | boxToDelete->deleteLine(arena); |
| 1365 | boxToDelete = next; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1366 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1367 | |
| 1368 | endLine = result; |
| 1369 | return result; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1370 | } |
| 1371 | } |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1372 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1373 | return false; |
| 1374 | } |
| 1375 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1376 | static inline bool skipNonBreakingSpace(const BidiIterator& it) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1377 | { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1378 | if (it.obj->style()->nbspMode() != SPACE || it.current() != noBreakSpace) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1379 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1380 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1381 | // FIXME: This is bad. It makes nbsp inconsistent with space and won't work correctly |
| 1382 | // with m_minWidth/m_maxWidth. |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1383 | // Do not skip a non-breaking space if it is the first character |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1384 | // on a line after a clean line break (or on the first line, since previousLineBrokeCleanly starts off |
| 1385 | // |true|). |
| 1386 | if (isLineEmpty && previousLineBrokeCleanly) |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1387 | return false; |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1388 | |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1389 | return true; |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 1392 | static inline bool shouldCollapseWhiteSpace(const RenderStyle* style) |
| 1393 | { |
| 1394 | return style->collapseWhiteSpace() || (style->whiteSpace() == PRE_WRAP && (!isLineEmpty || !previousLineBrokeCleanly)); |
| 1395 | } |
| 1396 | |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1397 | static inline bool shouldPreserveNewline(RenderObject* object) |
| 1398 | { |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 1399 | #if ENABLE(SVG) |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1400 | if (object->isSVGText()) |
| 1401 | return false; |
| 1402 | #endif |
| 1403 | |
| 1404 | return object->style()->preserveNewline(); |
| 1405 | } |
| 1406 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1407 | static bool inlineFlowRequiresLineBox(RenderObject* flow) |
| 1408 | { |
| 1409 | // 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] | 1410 | // We need to fix this, though, because at the very least, inlines containing only |
| 1411 | // ignorable whitespace should should also have line boxes. |
hyatt@apple.com | 21cc37a | 2008-02-26 23:17:03 +0000 | [diff] [blame] | 1412 | return flow->isInlineFlow() && !flow->firstChild() && flow->hasHorizontalBordersPaddingOrMargin(); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1415 | static inline bool requiresLineBox(const BidiIterator& it) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1416 | { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1417 | if (it.obj->isFloatingOrPositioned()) |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1418 | return false; |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1419 | |
| 1420 | if (it.obj->isInlineFlow() && !inlineFlowRequiresLineBox(it.obj)) |
| 1421 | return false; |
| 1422 | |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1423 | if (!shouldCollapseWhiteSpace(it.obj->style()) || it.obj->isBR()) |
| 1424 | return true; |
| 1425 | |
| 1426 | UChar current = it.current(); |
| 1427 | return current != ' ' && current != '\t' && current != softHyphen && (current != '\n' || shouldPreserveNewline(it.obj)) && !skipNonBreakingSpace(it); |
| 1428 | } |
| 1429 | |
| 1430 | bool RenderBlock::generatesLineBoxesForInlineChild(RenderObject* inlineObj) |
| 1431 | { |
| 1432 | ASSERT(inlineObj->parent() == this); |
| 1433 | |
| 1434 | BidiIterator it(this, inlineObj, 0); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1435 | while (!it.atEnd() && !requiresLineBox(it)) |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1436 | it.increment(); |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1437 | |
| 1438 | return !it.atEnd(); |
| 1439 | } |
| 1440 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1441 | // FIXME: The entire concept of the skipWhitespace function is flawed, since we really need to be building |
| 1442 | // line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned |
| 1443 | // elements quite right. In other words, we need to build this function's work into the normal line |
| 1444 | // object iteration process. |
| 1445 | int RenderBlock::skipWhitespace(BidiIterator& iterator) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1446 | { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1447 | int availableWidth = lineWidth(m_height); |
| 1448 | while (!iterator.atEnd() && !requiresLineBox(iterator)) { |
| 1449 | RenderObject* object = iterator.obj; |
| 1450 | if (object->isFloating()) { |
| 1451 | insertFloatingObject(object); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1452 | positionNewFloats(); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1453 | availableWidth = lineWidth(m_height); |
| 1454 | } else if (object->isPositioned()) { |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1455 | // FIXME: The math here is actually not really right. It's a best-guess approximation that |
| 1456 | // will work for the common cases |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1457 | RenderObject* c = object->container(); |
mitz@apple.com | e136420 | 2008-02-28 01:06:41 +0000 | [diff] [blame] | 1458 | if (c->isInlineFlow()) { |
| 1459 | // A relative positioned inline encloses us. In this case, we also have to determine our |
| 1460 | // position as though we were an inline. Set |staticX| and |staticY| on the relative positioned |
| 1461 | // inline so that we can obtain the value later. |
| 1462 | c->setStaticX(style()->direction() == LTR ? leftOffset(m_height) : rightOffset(m_height)); |
| 1463 | c->setStaticY(m_height); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1464 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1465 | |
| 1466 | if (object->hasStaticX()) { |
| 1467 | if (object->style()->isOriginalDisplayInlineType()) |
| 1468 | 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] | 1469 | else |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1470 | object->setStaticX(style()->direction() == LTR ? borderLeft() + paddingLeft() : borderRight() + paddingRight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1471 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1472 | |
| 1473 | if (object->hasStaticY()) |
| 1474 | object->setStaticY(m_height); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1475 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1476 | iterator.increment(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1477 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1478 | return availableWidth; |
| 1479 | } |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 1480 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1481 | int RenderBlock::skipWhitespace(BidiState& iterator) |
| 1482 | { |
| 1483 | int availableWidth = lineWidth(m_height); |
| 1484 | while (!iterator.position().atEnd() && !requiresLineBox(iterator.position())) { |
| 1485 | RenderObject* object = iterator.position().obj; |
| 1486 | if (object->isFloating()) { |
| 1487 | insertFloatingObject(object); |
| 1488 | positionNewFloats(); |
| 1489 | availableWidth = lineWidth(m_height); |
| 1490 | } else if (object->isPositioned()) { |
| 1491 | // FIXME: The math here is actually not really right. It's a best-guess approximation that |
| 1492 | // will work for the common cases |
| 1493 | RenderObject* c = object->container(); |
| 1494 | if (c->isInlineFlow()) { |
| 1495 | // A relative positioned inline encloses us. In this case, we also have to determine our |
| 1496 | // position as though we were an inline. Set |staticX| and |staticY| on the relative positioned |
| 1497 | // inline so that we can obtain the value later. |
| 1498 | c->setStaticX(style()->direction() == LTR ? leftOffset(m_height) : rightOffset(m_height)); |
| 1499 | c->setStaticY(m_height); |
| 1500 | } |
| 1501 | |
| 1502 | if (object->hasStaticX()) { |
| 1503 | if (object->style()->isOriginalDisplayInlineType()) |
| 1504 | object->setStaticX(style()->direction() == LTR ? leftOffset(m_height) : width() - rightOffset(m_height)); |
| 1505 | else |
| 1506 | object->setStaticX(style()->direction() == LTR ? borderLeft() + paddingLeft() : borderRight() + paddingRight()); |
| 1507 | } |
| 1508 | |
| 1509 | if (object->hasStaticY()) |
| 1510 | object->setStaticY(m_height); |
| 1511 | } |
| 1512 | iterator.increment(); |
| 1513 | } |
| 1514 | return availableWidth; |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1517 | // This is currently just used for list markers and inline flows that have line boxes. Neither should |
| 1518 | // have an effect on whitespace at the start of the line. |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1519 | static bool shouldSkipWhitespaceAfterStartObject(RenderBlock* block, RenderObject* o) |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1520 | { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1521 | RenderObject* next = bidiNext(block, o); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1522 | if (next && !next->isBR() && next->isText() && static_cast<RenderText*>(next)->textLength() > 0) { |
| 1523 | RenderText* nextText = static_cast<RenderText*>(next); |
| 1524 | UChar nextChar = nextText->characters()[0]; |
| 1525 | if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) { |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 1526 | addMidpoint(BidiIterator(0, o, 0)); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1527 | return true; |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | return false; |
| 1532 | } |
| 1533 | |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1534 | void RenderBlock::fitBelowFloats(int widthToFit, int& availableWidth) |
| 1535 | { |
| 1536 | ASSERT(widthToFit > availableWidth); |
| 1537 | |
| 1538 | int floatBottom; |
| 1539 | int lastFloatBottom = m_height; |
| 1540 | int newLineWidth = availableWidth; |
| 1541 | while (true) { |
| 1542 | floatBottom = nextFloatBottomBelow(lastFloatBottom); |
| 1543 | if (!floatBottom) |
| 1544 | break; |
| 1545 | |
| 1546 | newLineWidth = lineWidth(floatBottom); |
| 1547 | lastFloatBottom = floatBottom; |
| 1548 | if (newLineWidth >= widthToFit) |
| 1549 | break; |
| 1550 | } |
| 1551 | |
| 1552 | if (newLineWidth > availableWidth) { |
| 1553 | m_height = lastFloatBottom; |
| 1554 | availableWidth = newLineWidth; |
| 1555 | } |
| 1556 | } |
| 1557 | |
mitz@apple.com | 71e3084 | 2008-03-18 16:13:31 +0000 | [diff] [blame] | 1558 | BidiIterator RenderBlock::findNextLineBreak(BidiState& start, EClear* clear) |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1559 | { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1560 | ASSERT(start.position().block == this); |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 1561 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1562 | bool appliedStartWidth = start.position().pos > 0; |
| 1563 | |
| 1564 | int width = skipWhitespace(start); |
| 1565 | |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1566 | int w = 0; |
| 1567 | int tmpW = 0; |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 1568 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1569 | if (start.position().atEnd()) |
| 1570 | return start.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1571 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1572 | // This variable is used only if whitespace isn't set to PRE, and it tells us whether |
| 1573 | // or not we are currently ignoring whitespace. |
| 1574 | bool ignoringSpaces = false; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1575 | BidiIterator ignoreStart; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1576 | |
| 1577 | // This variable tracks whether the very last character we saw was a space. We use |
| 1578 | // this to detect when we encounter a second space so we know we have to terminate |
| 1579 | // a run. |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1580 | bool currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1581 | bool currentCharacterIsWS = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1582 | RenderObject* trailingSpaceObject = 0; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1583 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1584 | BidiIterator lBreak = start.position(); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1585 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1586 | RenderObject *o = start.position().obj; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1587 | RenderObject *last = o; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1588 | unsigned pos = start.position().pos; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1589 | bool atStart = true; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1590 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1591 | bool prevLineBrokeCleanly = previousLineBrokeCleanly; |
| 1592 | previousLineBrokeCleanly = false; |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 1593 | |
| 1594 | bool autoWrapWasEverTrueOnLine = false; |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 1595 | bool floatsFitOnLine = true; |
hyatt | 01eff98 | 2003-03-14 20:13:23 +0000 | [diff] [blame] | 1596 | |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 1597 | // 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] | 1598 | // very specific circumstances (in order to match common WinIE renderings). |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 1599 | // Not supporting the quirk has caused us to mis-render some real sites. (See Bugzilla 10517.) |
| 1600 | bool allowImagesToBreak = !style()->htmlHacks() || !isTableCell() || !style()->width().isIntrinsicOrAuto(); |
| 1601 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1602 | EWhiteSpace currWS = style()->whiteSpace(); |
| 1603 | EWhiteSpace lastWS = currWS; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1604 | while (o) { |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1605 | currWS = o->isReplaced() ? o->parent()->style()->whiteSpace() : o->style()->whiteSpace(); |
| 1606 | lastWS = last->isReplaced() ? last->parent()->style()->whiteSpace() : last->style()->whiteSpace(); |
| 1607 | |
| 1608 | bool autoWrap = RenderStyle::autoWrap(currWS); |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 1609 | autoWrapWasEverTrueOnLine = autoWrapWasEverTrueOnLine || autoWrap; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1610 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 1611 | #if ENABLE(SVG) |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1612 | bool preserveNewline = o->isSVGText() ? false : RenderStyle::preserveNewline(currWS); |
| 1613 | #else |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1614 | bool preserveNewline = RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 1615 | #endif |
| 1616 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1617 | bool collapseWhiteSpace = RenderStyle::collapseWhiteSpace(currWS); |
| 1618 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1619 | if (o->isBR()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1620 | if (w + tmpW <= width) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1621 | lBreak.obj = o; |
| 1622 | lBreak.pos = 0; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1623 | lBreak.increment(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1624 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1625 | // A <br> always breaks a line, so don't let the line be collapsed |
| 1626 | // 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] | 1627 | // get collapsed away. It only does this if the previous line broke |
| 1628 | // cleanly. Otherwise the <br> has no effect on whether the line is |
| 1629 | // empty or not. |
| 1630 | if (prevLineBrokeCleanly) |
| 1631 | isLineEmpty = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1632 | trailingSpaceObject = 0; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1633 | previousLineBrokeCleanly = true; |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 1634 | |
mitz@apple.com | 71e3084 | 2008-03-18 16:13:31 +0000 | [diff] [blame] | 1635 | if (!isLineEmpty && clear) |
| 1636 | *clear = o->style()->clear(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1637 | } |
| 1638 | goto end; |
| 1639 | } |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1640 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1641 | if (o->isFloatingOrPositioned()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1642 | // add to special objects... |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1643 | if (o->isFloating()) { |
hyatt | 3ac0135 | 2003-03-22 01:37:33 +0000 | [diff] [blame] | 1644 | insertFloatingObject(o); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1645 | // check if it fits in the current line. |
| 1646 | // If it does, position it now, otherwise, position |
| 1647 | // it after moving to next line (in newLine() func) |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 1648 | if (floatsFitOnLine && o->width() + o->marginLeft() + o->marginRight() + w + tmpW <= width) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1649 | positionNewFloats(); |
| 1650 | width = lineWidth(m_height); |
mitz@apple.com | 25beac6 | 2008-02-24 18:48:27 +0000 | [diff] [blame] | 1651 | } else |
| 1652 | floatsFitOnLine = false; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1653 | } else if (o->isPositioned()) { |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 1654 | // If our original display wasn't an inline type, then we can |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1655 | // go ahead and determine our static x position now. |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 1656 | bool isInlineType = o->style()->isOriginalDisplayInlineType(); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1657 | bool needToSetStaticX = o->hasStaticX(); |
| 1658 | if (o->hasStaticX() && !isInlineType) { |
| 1659 | o->setStaticX(o->parent()->style()->direction() == LTR ? |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1660 | borderLeft() + paddingLeft() : |
| 1661 | borderRight() + paddingRight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1662 | needToSetStaticX = false; |
| 1663 | } |
| 1664 | |
| 1665 | // If our original display was an INLINE type, then we can go ahead |
| 1666 | // and determine our static y position now. |
| 1667 | bool needToSetStaticY = o->hasStaticY(); |
| 1668 | if (o->hasStaticY() && isInlineType) { |
| 1669 | o->setStaticY(m_height); |
| 1670 | needToSetStaticY = false; |
| 1671 | } |
| 1672 | |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 1673 | bool needToCreateLineBox = needToSetStaticX || needToSetStaticY; |
| 1674 | RenderObject* c = o->container(); |
| 1675 | if (c->isInlineFlow() && (!needToSetStaticX || !needToSetStaticY)) |
| 1676 | needToCreateLineBox = true; |
| 1677 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1678 | // If we're ignoring spaces, we have to stop and include this object and |
| 1679 | // then start ignoring spaces again. |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 1680 | if (needToCreateLineBox) { |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 1681 | trailingSpaceObject = 0; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1682 | ignoreStart.obj = o; |
| 1683 | ignoreStart.pos = 0; |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 1684 | if (ignoringSpaces) { |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1685 | addMidpoint(ignoreStart); // Stop ignoring spaces. |
| 1686 | addMidpoint(ignoreStart); // Start ignoring again. |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 1687 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1688 | |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 1689 | } |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1690 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1691 | } else if (o->isInlineFlow()) { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1692 | // Right now, we should only encounter empty inlines here. |
ggaren | f9f32ae | 2007-03-26 20:08:53 +0000 | [diff] [blame] | 1693 | ASSERT(!o->firstChild()); |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1694 | |
| 1695 | // Now that some inline flows have line boxes, if we are already ignoring spaces, we need |
| 1696 | // to make sure that we stop to include this object and then start ignoring spaces again. |
| 1697 | // If this object is at the start of the line, we need to behave like list markers and |
| 1698 | // start ignoring spaces. |
| 1699 | if (inlineFlowRequiresLineBox(o)) { |
hyatt@apple.com | eb66ef4 | 2008-01-18 22:59:29 +0000 | [diff] [blame] | 1700 | isLineEmpty = false; |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1701 | if (ignoringSpaces) { |
| 1702 | trailingSpaceObject = 0; |
| 1703 | addMidpoint(BidiIterator(0, o, 0)); // Stop ignoring spaces. |
| 1704 | addMidpoint(BidiIterator(0, o, 0)); // Start ignoring again. |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1705 | } else if (style()->collapseWhiteSpace() && start.position().obj == o |
| 1706 | && shouldSkipWhitespaceAfterStartObject(this, o)) { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1707 | // Like with list markers, we start ignoring spaces to make sure that any |
| 1708 | // additional spaces we see will be discarded. |
| 1709 | currentCharacterIsSpace = true; |
| 1710 | currentCharacterIsWS = true; |
| 1711 | ignoringSpaces = true; |
| 1712 | } |
| 1713 | } |
| 1714 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1715 | tmpW += o->marginLeft() + o->borderLeft() + o->paddingLeft() + |
| 1716 | o->marginRight() + o->borderRight() + o->paddingRight(); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1717 | } else if (o->isReplaced()) { |
hyatt | de39634 | 2003-10-29 08:57:20 +0000 | [diff] [blame] | 1718 | // Break on replaced elements if either has normal white-space. |
hyatt@apple.com | 6934090 | 2008-01-16 21:24:21 +0000 | [diff] [blame] | 1719 | if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!o->isImage() || allowImagesToBreak)) { |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 1720 | w += tmpW; |
| 1721 | tmpW = 0; |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 1722 | lBreak.obj = o; |
| 1723 | lBreak.pos = 0; |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
mitz@apple.com | bfdc911 | 2008-02-21 19:59:40 +0000 | [diff] [blame] | 1726 | if (ignoringSpaces) |
| 1727 | addMidpoint(BidiIterator(0, o, 0)); |
| 1728 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1729 | isLineEmpty = false; |
| 1730 | ignoringSpaces = false; |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1731 | currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1732 | currentCharacterIsWS = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1733 | trailingSpaceObject = 0; |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 1734 | |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1735 | // Optimize for a common case. If we can't find whitespace after the list |
| 1736 | // item, then this is all moot. -dwh |
mjs | d26b297 | 2007-02-13 13:09:04 +0000 | [diff] [blame] | 1737 | if (o->isListMarker() && !static_cast<RenderListMarker*>(o)->isInside()) { |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1738 | if (style()->collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(this, o)) { |
bdakin | f876bee | 2007-10-30 05:27:09 +0000 | [diff] [blame] | 1739 | // Like with inline flows, we start ignoring spaces to make sure that any |
| 1740 | // additional spaces we see will be discarded. |
| 1741 | currentCharacterIsSpace = true; |
| 1742 | currentCharacterIsWS = true; |
| 1743 | ignoringSpaces = true; |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 1744 | } |
justing | 244d3a3 | 2006-04-13 01:31:24 +0000 | [diff] [blame] | 1745 | } else |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1746 | tmpW += o->width() + o->marginLeft() + o->marginRight() + inlineWidth(o); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1747 | } else if (o->isText()) { |
mitz@apple.com | 5101732 | 2008-02-26 06:47:43 +0000 | [diff] [blame] | 1748 | if (!pos) |
| 1749 | appliedStartWidth = false; |
| 1750 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1751 | RenderText* t = static_cast<RenderText*>(o); |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1752 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1753 | int strlen = t->textLength(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1754 | int len = strlen - pos; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1755 | const UChar* str = t->characters(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1756 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1757 | const Font& f = t->style(m_firstLine)->font(); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1758 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1759 | int lastSpace = pos; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1760 | int wordSpacing = o->style()->wordSpacing(); |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1761 | int lastSpaceWordSpacing = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1762 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1763 | int wrapW = tmpW + inlineWidth(o, !appliedStartWidth, true); |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1764 | int charWidth = 0; |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 1765 | int nextBreakable = -1; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1766 | bool breakNBSP = autoWrap && o->style()->nbspMode() == SPACE; |
| 1767 | // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word, |
| 1768 | // 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] | 1769 | bool breakWords = o->style()->breakWords() && ((autoWrap && !w) || currWS == PRE); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1770 | bool midWordBreak = false; |
hyatt | ea474f7 | 2007-04-20 05:02:19 +0000 | [diff] [blame] | 1771 | bool breakAll = o->style()->wordBreak() == BreakAllWordBreak && autoWrap; |
| 1772 | |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1773 | if (t->isWordBreak()) { |
| 1774 | w += tmpW; |
| 1775 | tmpW = 0; |
| 1776 | lBreak.obj = o; |
| 1777 | lBreak.pos = 0; |
| 1778 | ASSERT(!len); |
| 1779 | } |
| 1780 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1781 | while (len) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1782 | bool previousCharacterIsSpace = currentCharacterIsSpace; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1783 | bool previousCharacterIsWS = currentCharacterIsWS; |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 1784 | UChar c = str[pos]; |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1785 | currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNewline && (c == '\n')); |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 1786 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1787 | if (!collapseWhiteSpace || !currentCharacterIsSpace) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1788 | isLineEmpty = false; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1789 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1790 | // Check for soft hyphens. Go ahead and ignore them. |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1791 | if (c == softHyphen) { |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1792 | if (!ignoringSpaces) { |
| 1793 | // Ignore soft hyphens |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1794 | BidiIterator beforeSoftHyphen; |
| 1795 | if (pos) |
| 1796 | beforeSoftHyphen = BidiIterator(0, o, pos - 1); |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 1797 | else |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1798 | beforeSoftHyphen = BidiIterator(0, last, last->isText() ? static_cast<RenderText*>(last)->textLength() - 1 : 0); |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 1799 | // Two consecutive soft hyphens. Avoid overlapping midpoints. |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1800 | 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] | 1801 | sNumMidpoints--; |
| 1802 | else |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1803 | addMidpoint(beforeSoftHyphen); |
| 1804 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1805 | // Add the width up to but not including the hyphen. |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1806 | tmpW += t->width(lastSpace, pos - lastSpace, f, w + tmpW) + lastSpaceWordSpacing; |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1807 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1808 | // 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] | 1809 | // on the line if it shows when we break. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1810 | if (autoWrap) |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1811 | tmpW += t->width(pos, 1, f, w + tmpW); |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1812 | |
| 1813 | BidiIterator afterSoftHyphen(0, o, pos); |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1814 | afterSoftHyphen.increment(); |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1815 | addMidpoint(afterSoftHyphen); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1816 | } |
mitz@apple.com | be42956 | 2008-03-07 01:09:51 +0000 | [diff] [blame] | 1817 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1818 | pos++; |
| 1819 | len--; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1820 | lastSpaceWordSpacing = 0; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1821 | lastSpace = pos; // Cheesy hack to prevent adding in widths of the run twice. |
| 1822 | continue; |
| 1823 | } |
| 1824 | |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1825 | bool applyWordSpacing = false; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1826 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1827 | currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace); |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1828 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1829 | if ((breakAll || breakWords) && !midWordBreak) { |
| 1830 | wrapW += charWidth; |
| 1831 | charWidth = t->width(pos, 1, f, w + wrapW); |
| 1832 | midWordBreak = w + wrapW + charWidth > width; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1833 | } |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 1834 | |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1835 | bool betweenWords = c == '\n' || (currWS != PRE && !atStart && isBreakable(str, pos, strlen, nextBreakable, breakNBSP)); |
hyatt | ea474f7 | 2007-04-20 05:02:19 +0000 | [diff] [blame] | 1836 | |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1837 | if (betweenWords || midWordBreak) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1838 | bool stoppedIgnoringSpaces = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1839 | if (ignoringSpaces) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1840 | if (!currentCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1841 | // Stop ignoring spaces and begin at this |
| 1842 | // new point. |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 1843 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1844 | lastSpaceWordSpacing = 0; |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 1845 | 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] | 1846 | addMidpoint(BidiIterator(0, o, pos)); |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1847 | stoppedIgnoringSpaces = true; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1848 | } else { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1849 | // Just keep ignoring these spaces. |
| 1850 | pos++; |
| 1851 | len--; |
| 1852 | continue; |
| 1853 | } |
| 1854 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1855 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1856 | int additionalTmpW = t->width(lastSpace, pos - lastSpace, f, w+tmpW) + lastSpaceWordSpacing; |
| 1857 | tmpW += additionalTmpW; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1858 | if (!appliedStartWidth) { |
| 1859 | tmpW += inlineWidth(o, true, false); |
| 1860 | appliedStartWidth = true; |
| 1861 | } |
| 1862 | |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1863 | applyWordSpacing = wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 1864 | |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 1865 | if (!w && autoWrap && tmpW > width) |
| 1866 | fitBelowFloats(tmpW, width); |
| 1867 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1868 | if (autoWrap || breakWords) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1869 | // If we break only after white-space, consider the current character |
kocienda | e413424 | 2004-10-25 18:48:44 +0000 | [diff] [blame] | 1870 | // as candidate width for this line. |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 1871 | bool lineWasTooWide = false; |
| 1872 | if (w + tmpW <= width && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) { |
| 1873 | int charWidth = t->width(pos, 1, f, w + tmpW) + (applyWordSpacing ? wordSpacing : 0); |
| 1874 | // Check if line is too big even without the extra space |
| 1875 | // at the end of the line. If it is not, do nothing. |
| 1876 | // If the line needs the extra whitespace to be too long, |
| 1877 | // then move the line break to the space and skip all |
| 1878 | // additional whitespace. |
| 1879 | if (w + tmpW + charWidth > width) { |
| 1880 | lineWasTooWide = true; |
| 1881 | lBreak.obj = o; |
| 1882 | lBreak.pos = pos; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1883 | skipWhitespace(lBreak); |
kocienda | 9dbe9b1 | 2004-10-22 20:07:05 +0000 | [diff] [blame] | 1884 | } |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 1885 | } |
| 1886 | if (lineWasTooWide || w + tmpW > width) { |
mitz@apple.com | 3d3d92b | 2008-02-21 05:00:10 +0000 | [diff] [blame] | 1887 | 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] | 1888 | if (!stoppedIgnoringSpaces && pos > 0) { |
| 1889 | // 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] | 1890 | addMidpoint(BidiIterator(0, o, pos - 1)); // Stop |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1891 | addMidpoint(BidiIterator(0, o, pos)); // Start |
| 1892 | } |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1893 | lBreak.increment(); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1894 | previousLineBrokeCleanly = true; |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1895 | } |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 1896 | goto end; // Didn't fit. Jump to the end. |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1897 | } else { |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1898 | if (!betweenWords || (midWordBreak && !autoWrap)) |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1899 | tmpW -= additionalTmpW; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1900 | if (pos > 0 && str[pos-1] == softHyphen) |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1901 | // Subtract the width of the soft hyphen out since we fit on a line. |
| 1902 | tmpW -= t->width(pos-1, 1, f, w+tmpW); |
| 1903 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 1904 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1905 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1906 | if (c == '\n' && preserveNewline) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1907 | if (!stoppedIgnoringSpaces && pos > 0) { |
| 1908 | // 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] | 1909 | addMidpoint(BidiIterator(0, o, pos - 1)); // Stop |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1910 | addMidpoint(BidiIterator(0, o, pos)); // Start |
| 1911 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1912 | lBreak.obj = o; |
| 1913 | lBreak.pos = pos; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1914 | lBreak.increment(); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1915 | previousLineBrokeCleanly = true; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1916 | return lBreak; |
| 1917 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1918 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1919 | if (autoWrap && betweenWords) { |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1920 | w += tmpW; |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1921 | wrapW = 0; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1922 | tmpW = 0; |
| 1923 | lBreak.obj = o; |
| 1924 | lBreak.pos = pos; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1925 | // Auto-wrapping text should not wrap in the middle of a word once it has had an |
| 1926 | // opportunity to break after a word. |
| 1927 | breakWords = false; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 1928 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1929 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1930 | if (midWordBreak) { |
| 1931 | // Remember this as a breakable position in case |
| 1932 | // adding the end width forces a break. |
| 1933 | lBreak.obj = o; |
| 1934 | lBreak.pos = pos; |
weinig | ed111c1 | 2007-07-13 22:45:11 +0000 | [diff] [blame] | 1935 | midWordBreak &= (breakWords || breakAll); |
| 1936 | } |
| 1937 | |
| 1938 | if (betweenWords) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1939 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
| 1940 | lastSpace = pos; |
| 1941 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1942 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1943 | if (!ignoringSpaces && o->style()->collapseWhiteSpace()) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1944 | // If we encounter a newline, or if we encounter a |
| 1945 | // second space, we need to go ahead and break up this |
| 1946 | // run and enter a mode where we start collapsing spaces. |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1947 | if (currentCharacterIsSpace && previousCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1948 | ignoringSpaces = true; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1949 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1950 | // We just entered a mode where we are ignoring |
| 1951 | // spaces. Create a midpoint to terminate the run |
| 1952 | // before the second space. |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1953 | addMidpoint(ignoreStart); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1954 | } |
| 1955 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1956 | } else if (ignoringSpaces) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1957 | // Stop ignoring spaces and begin at this |
| 1958 | // new point. |
| 1959 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1960 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1961 | 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] | 1962 | addMidpoint(BidiIterator(0, o, pos)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1963 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 1964 | |
| 1965 | if (currentCharacterIsSpace && !previousCharacterIsSpace) { |
| 1966 | ignoreStart.obj = o; |
| 1967 | ignoreStart.pos = pos; |
| 1968 | } |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1969 | |
| 1970 | if (!currentCharacterIsWS && previousCharacterIsWS) { |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1971 | if (autoWrap && o->style()->breakOnlyAfterWhiteSpace()) { |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 1972 | lBreak.obj = o; |
| 1973 | lBreak.pos = pos; |
| 1974 | } |
| 1975 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1976 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1977 | if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSpaces) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1978 | trailingSpaceObject = o; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1979 | else if (!o->style()->collapseWhiteSpace() || !currentCharacterIsSpace) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1980 | trailingSpaceObject = 0; |
| 1981 | |
| 1982 | pos++; |
| 1983 | len--; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 1984 | atStart = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1985 | } |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 1986 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1987 | // IMPORTANT: pos is > length here! |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1988 | if (!ignoringSpaces) |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 1989 | tmpW += t->width(lastSpace, pos - lastSpace, f, w+tmpW) + lastSpaceWordSpacing; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1990 | tmpW += inlineWidth(o, !appliedStartWidth, true); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1991 | } else |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 1992 | ASSERT_NOT_REACHED(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1993 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 1994 | RenderObject* next = bidiNext(this, o); |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1995 | bool checkForBreak = autoWrap; |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 1996 | if (w && w + tmpW > width && lBreak.obj && currWS == NOWRAP) |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 1997 | checkForBreak = true; |
| 1998 | else if (next && o->isText() && next->isText() && !next->isBR()) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1999 | if (autoWrap || (next->style()->autoWrap())) { |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2000 | if (currentCharacterIsSpace) |
| 2001 | checkForBreak = true; |
| 2002 | else { |
harrison | 07b5e58 | 2005-08-15 23:31:16 +0000 | [diff] [blame] | 2003 | checkForBreak = false; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2004 | RenderText* nextText = static_cast<RenderText*>(next); |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 2005 | if (nextText->textLength()) { |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2006 | UChar c = nextText->characters()[0]; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2007 | if (c == ' ' || c == '\t' || (c == '\n' && !shouldPreserveNewline(next))) |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2008 | // If the next item on the line is text, and if we did not end with |
| 2009 | // a space, then the next text run continues our word (and so it needs to |
| 2010 | // keep adding to |tmpW|. Just update and continue. |
| 2011 | checkForBreak = true; |
mitz@apple.com | fb8da4e | 2008-02-19 21:13:19 +0000 | [diff] [blame] | 2012 | } else if (nextText->isWordBreak()) |
| 2013 | checkForBreak = true; |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 2014 | bool willFitOnLine = w + tmpW <= width; |
| 2015 | if (!willFitOnLine && !w) { |
| 2016 | fitBelowFloats(tmpW, width); |
| 2017 | willFitOnLine = tmpW <= width; |
| 2018 | } |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 2019 | bool canPlaceOnLine = willFitOnLine || !autoWrapWasEverTrueOnLine; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2020 | if (canPlaceOnLine && checkForBreak) { |
| 2021 | w += tmpW; |
| 2022 | tmpW = 0; |
| 2023 | lBreak.obj = next; |
| 2024 | lBreak.pos = 0; |
| 2025 | } |
| 2026 | } |
| 2027 | } |
| 2028 | } |
| 2029 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2030 | if (checkForBreak && (w + tmpW > width)) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2031 | // if we have floats, try to get below them. |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2032 | if (currentCharacterIsSpace && !ignoringSpaces && o->style()->collapseWhiteSpace()) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2033 | trailingSpaceObject = 0; |
mitz@apple.com | cfd9b7b | 2008-02-24 04:00:21 +0000 | [diff] [blame] | 2034 | |
| 2035 | if (w) |
| 2036 | goto end; |
| 2037 | |
| 2038 | fitBelowFloats(tmpW, width); |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 2039 | |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 2040 | // |width| may have been adjusted because we got shoved down past a float (thus |
| 2041 | // giving us more room), so we need to retest, and only jump to |
| 2042 | // the end label if we still don't fit on the line. -dwh |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2043 | if (w + tmpW > width) |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 2044 | goto end; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2045 | } |
hyatt | 1d9e29b | 2003-04-10 01:48:53 +0000 | [diff] [blame] | 2046 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2047 | if (!o->isFloatingOrPositioned()) { |
| 2048 | last = o; |
| 2049 | if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || static_cast<RenderListMarker*>(last)->isInside())) { |
| 2050 | w += tmpW; |
| 2051 | tmpW = 0; |
| 2052 | lBreak.obj = next; |
| 2053 | lBreak.pos = 0; |
| 2054 | } |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2057 | o = next; |
| 2058 | |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2059 | // Clear out our character space bool, since inline <pre>s don't collapse whitespace |
| 2060 | // with adjacent inline normal/nowrap spans. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2061 | if (!collapseWhiteSpace) |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2062 | currentCharacterIsSpace = false; |
| 2063 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2064 | pos = 0; |
ddkilzer | e8759ef | 2007-03-25 06:28:19 +0000 | [diff] [blame] | 2065 | atStart = false; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2068 | |
| 2069 | if (w + tmpW <= width || lastWS == NOWRAP) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2070 | lBreak.obj = 0; |
| 2071 | lBreak.pos = 0; |
| 2072 | } |
| 2073 | |
| 2074 | end: |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2075 | |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2076 | if (lBreak == start.position() && !lBreak.obj->isBR()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2077 | // we just add as much as possible |
weinig | 98726da | 2007-03-15 01:22:19 +0000 | [diff] [blame] | 2078 | if (style()->whiteSpace() == PRE) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2079 | // FIXME: Don't really understand this case. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2080 | if (pos != 0) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2081 | lBreak.obj = o; |
| 2082 | lBreak.pos = pos - 1; |
| 2083 | } else { |
| 2084 | lBreak.obj = last; |
hyatt | c3731d4 | 2002-12-12 06:20:22 +0000 | [diff] [blame] | 2085 | lBreak.pos = last->isText() ? last->length() : 0; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2086 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2087 | } else if (lBreak.obj) { |
| 2088 | if (last != o && !last->isListMarker()) { |
bdakin | a964eb3 | 2005-10-24 17:47:26 +0000 | [diff] [blame] | 2089 | // 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] | 2090 | lBreak.obj = o; |
| 2091 | lBreak.pos = 0; |
| 2092 | } else { |
hyatt | dda1d1b | 2002-12-13 09:44:17 +0000 | [diff] [blame] | 2093 | // Don't ever break in the middle of a word if we can help it. |
| 2094 | // There's no room at all. We just have to be on this line, |
| 2095 | // even though we'll spill out. |
| 2096 | lBreak.obj = o; |
| 2097 | lBreak.pos = pos; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2098 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | // make sure we consume at least one char/object. |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2103 | if (lBreak == start.position()) |
| 2104 | lBreak.increment(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2105 | |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 2106 | // Sanity check our midpoints. |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2107 | checkMidpoints(lBreak); |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 2108 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2109 | if (trailingSpaceObject) { |
| 2110 | // This object is either going to be part of the last midpoint, or it is going |
| 2111 | // to be the actual endpoint. In both cases we just decrease our pos by 1 level to |
| 2112 | // exclude the space, allowing it to - in effect - collapse into the newline. |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 2113 | if (sNumMidpoints%2==1) { |
| 2114 | BidiIterator* midpoints = smidpoints->data(); |
| 2115 | midpoints[sNumMidpoints-1].pos--; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2116 | } |
| 2117 | //else if (lBreak.pos > 0) |
| 2118 | // lBreak.pos--; |
| 2119 | else if (lBreak.obj == 0 && trailingSpaceObject->isText()) { |
hyatt | d20075d | 2002-11-16 02:23:32 +0000 | [diff] [blame] | 2120 | // Add a new end midpoint that stops right at the very end. |
hyatt | d20075d | 2002-11-16 02:23:32 +0000 | [diff] [blame] | 2121 | RenderText* text = static_cast<RenderText *>(trailingSpaceObject); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2122 | unsigned length = text->textLength(); |
| 2123 | unsigned pos = length >= 2 ? length - 2 : UINT_MAX; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2124 | BidiIterator endMid(0, trailingSpaceObject, pos); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 2125 | addMidpoint(endMid); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2126 | } |
| 2127 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2128 | |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2129 | // We might have made lBreak an iterator that points past the end |
| 2130 | // of the object. Do this adjustment to make it point to the start |
| 2131 | // of the next object instead to avoid confusing the rest of the |
| 2132 | // code. |
| 2133 | if (lBreak.pos > 0) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2134 | lBreak.pos--; |
mitz@apple.com | 1a30177 | 2008-03-11 18:30:36 +0000 | [diff] [blame] | 2135 | lBreak.increment(); |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2138 | if (lBreak.obj && lBreak.pos >= 2 && lBreak.obj->isText()) { |
| 2139 | // For soft hyphens on line breaks, we have to chop out the midpoints that made us |
| 2140 | // 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] | 2141 | UChar c = static_cast<RenderText*>(lBreak.obj)->characters()[lBreak.pos-1]; |
| 2142 | if (c == softHyphen) |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2143 | chopMidpointsAt(lBreak.obj, lBreak.pos-2); |
| 2144 | } |
| 2145 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2146 | return lBreak; |
| 2147 | } |
| 2148 | |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2149 | void RenderBlock::checkLinesForOverflow() |
| 2150 | { |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2151 | m_overflowWidth = m_width; |
| 2152 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 2153 | m_overflowLeft = min(curr->leftOverflow(), m_overflowLeft); |
| 2154 | m_overflowTop = min(curr->topOverflow(), m_overflowTop); |
| 2155 | m_overflowWidth = max(curr->rightOverflow(), m_overflowWidth); |
| 2156 | m_overflowHeight = max(curr->bottomOverflow(), m_overflowHeight); |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2160 | void RenderBlock::deleteEllipsisLineBoxes() |
| 2161 | { |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2162 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 2163 | curr->clearTruncation(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | void RenderBlock::checkLinesForTextOverflow() |
| 2167 | { |
| 2168 | // Determine the width of the ellipsis using the current font. |
darin | dbba2bb | 2007-01-11 12:23:49 +0000 | [diff] [blame] | 2169 | // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable" |
| 2170 | TextRun ellipsisRun(&horizontalEllipsis, 1); |
| 2171 | static AtomicString ellipsisStr(&horizontalEllipsis, 1); |
hyatt | 3e99d1c | 2006-02-24 21:13:08 +0000 | [diff] [blame] | 2172 | const Font& firstLineFont = firstLineStyle()->font(); |
| 2173 | const Font& font = style()->font(); |
hyatt | 43d6c79 | 2006-05-11 10:19:34 +0000 | [diff] [blame] | 2174 | int firstLineEllipsisWidth = firstLineFont.width(ellipsisRun); |
| 2175 | int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(ellipsisRun); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2176 | |
| 2177 | // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see |
| 2178 | // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and |
| 2179 | // check the left edge of the line box to see if it is less |
| 2180 | // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()" |
| 2181 | bool ltr = style()->direction() == LTR; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2182 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 2183 | int blockEdge = ltr ? rightOffset(curr->yPos()) : leftOffset(curr->yPos()); |
hyatt | 1a8d251 | 2004-06-17 01:38:30 +0000 | [diff] [blame] | 2184 | int lineBoxEdge = ltr ? curr->xPos() + curr->width() : curr->xPos(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2185 | if ((ltr && lineBoxEdge > blockEdge) || (!ltr && lineBoxEdge < blockEdge)) { |
hyatt | f918d2d | 2004-06-15 07:24:11 +0000 | [diff] [blame] | 2186 | // 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] | 2187 | // can be truncated. In order for truncation to be possible, the line must have sufficient space to |
| 2188 | // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis |
| 2189 | // space. |
| 2190 | int width = curr == firstRootBox() ? firstLineEllipsisWidth : ellipsisWidth; |
hyatt | 1a8d251 | 2004-06-17 01:38:30 +0000 | [diff] [blame] | 2191 | if (curr->canAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) |
| 2192 | curr->placeEllipsis(ellipsisStr, ltr, blockEdge, width); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2193 | } |
| 2194 | } |
| 2195 | } |
| 2196 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2197 | } |