kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1 | /** |
| 2 | * This file is part of the html renderer for KDE. |
| 3 | * |
| 4 | * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 5 | * Copyright (C) 2004, 2006 Apple Computer, Inc. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this library; see the file COPYING.LIB. If not, write to |
| 19 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | * |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 22 | */ |
darin | be4c67d | 2005-12-19 19:53:12 +0000 | [diff] [blame] | 23 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 24 | #include "config.h" |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 25 | #include "bidi.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 26 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 27 | #include "CharacterNames.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 28 | #include "Document.h" |
eseidel | 40eb1b9 | 2006-03-25 22:20:36 +0000 | [diff] [blame] | 29 | #include "Element.h" |
mjs | d4145d1 | 2006-01-11 09:36:47 +0000 | [diff] [blame] | 30 | #include "FrameView.h" |
eseidel | 3a6d132 | 2006-01-09 03:14:50 +0000 | [diff] [blame] | 31 | #include "InlineTextBox.h" |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 32 | #include "Logging.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 33 | #include "RenderArena.h" |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 34 | #include "RenderLayer.h" |
mjs | d26b297 | 2007-02-13 13:09:04 +0000 | [diff] [blame] | 35 | #include "RenderListMarker.h" |
hyatt | d804834 | 2006-05-31 01:48:18 +0000 | [diff] [blame] | 36 | #include "RenderView.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 37 | #include "break_lines.h" |
mjs | bb86351 | 2006-05-09 09:27:55 +0000 | [diff] [blame] | 38 | #include <wtf/AlwaysInline.h> |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 39 | #include <wtf/Vector.h> |
hyatt | 8c371e5 | 2004-06-16 01:19:26 +0000 | [diff] [blame] | 40 | |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 41 | using namespace std; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 42 | using namespace WTF; |
| 43 | using namespace Unicode; |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 44 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 45 | namespace WebCore { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 46 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 47 | // an iterator which traverses all the objects within a block |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 48 | struct BidiIterator { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 49 | BidiIterator() : block(0), obj(0), pos(0) {} |
| 50 | BidiIterator(RenderBlock* b, RenderObject* o, unsigned int p) |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 51 | : block(b), obj(o), pos(p) {} |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 52 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 53 | void increment(BidiState& state); |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 54 | bool atEnd() const; |
| 55 | |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 56 | UChar current() const; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 57 | Direction direction() const; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 58 | |
| 59 | RenderBlock* block; |
| 60 | RenderObject* obj; |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 61 | unsigned int pos; |
| 62 | }; |
| 63 | |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 64 | struct BidiState { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 65 | BidiState() : context(0), dir(OtherNeutral), adjustEmbedding(false), reachedEndOfLine(false) {} |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 66 | |
| 67 | BidiIterator sor; |
| 68 | BidiIterator eor; |
| 69 | BidiIterator last; |
| 70 | BidiIterator current; |
mjs | bb3d15c | 2005-12-01 10:32:32 +0000 | [diff] [blame] | 71 | RefPtr<BidiContext> context; |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 72 | BidiStatus status; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 73 | Direction dir; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 74 | bool adjustEmbedding; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 75 | BidiIterator endOfLine; |
| 76 | bool reachedEndOfLine; |
darin | e4fa9e2 | 2005-12-16 18:18:50 +0000 | [diff] [blame] | 77 | BidiIterator lastBeforeET; |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 78 | }; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 79 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 80 | inline bool operator==(const BidiStatus& status1, const BidiStatus& status2) |
| 81 | { |
| 82 | return status1.eor == status2.eor && status1.last == status2.last && status1.lastStrong == status2.lastStrong; |
| 83 | } |
| 84 | |
| 85 | inline bool operator!=(const BidiStatus& status1, const BidiStatus& status2) |
| 86 | { |
| 87 | return !(status1 == status2); |
| 88 | } |
| 89 | |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 90 | // Used to track a list of chained bidi runs. |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 91 | static BidiRun* sFirstBidiRun; |
| 92 | static BidiRun* sLastBidiRun; |
ddkilzer | fe11506 | 2006-07-14 04:42:01 +0000 | [diff] [blame] | 93 | static BidiRun* sLogicallyLastBidiRun; |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 94 | static int sBidiRunCount; |
| 95 | static BidiRun* sCompactFirstBidiRun; |
| 96 | static BidiRun* sCompactLastBidiRun; |
| 97 | static int sCompactBidiRunCount; |
| 98 | static bool sBuildingCompactRuns; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 99 | |
| 100 | // Midpoint globals. The goal is not to do any allocation when dealing with |
| 101 | // these midpoints, so we just keep an array around and never clear it. We track |
| 102 | // the number of items and position using the two other variables. |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 103 | static Vector<BidiIterator>* smidpoints; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 104 | static unsigned sNumMidpoints; |
| 105 | static unsigned sCurrMidpoint; |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 106 | static bool betweenMidpoints; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 107 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 108 | static bool isLineEmpty = true; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 109 | static bool previousLineBrokeCleanly = true; |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 110 | static bool emptyRun = true; |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 111 | static int numSpaces; |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 112 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 113 | static void embed(Direction, BidiState&); |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 114 | static void appendRun(BidiState&); |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 115 | static void deleteBidiRuns(RenderArena*); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 116 | |
adele | 68afa0b | 2007-02-05 23:25:44 +0000 | [diff] [blame] | 117 | void RenderBlock::bidiReorderCharacters(Document* document, RenderStyle* style, CharacterBuffer& characterBuffer) |
| 118 | { |
| 119 | unsigned bufferLength = characterBuffer.size(); |
| 120 | // Create a local copy of the buffer. |
| 121 | String string(characterBuffer.data(), bufferLength); |
| 122 | |
| 123 | // Create anonymous RenderBlock |
| 124 | RenderStyle* blockStyle = new (document->renderArena()) RenderStyle(); |
| 125 | blockStyle->inheritFrom(style); |
| 126 | blockStyle->setDisplay(BLOCK); |
| 127 | blockStyle->setWhiteSpace(PRE); |
| 128 | RenderBlock* block = new (document->renderArena()) RenderBlock(document); |
| 129 | block->setStyle(blockStyle); |
| 130 | |
| 131 | // Create RenderText |
| 132 | RenderText* text = new (document->renderArena()) RenderText(document, string.impl()); |
| 133 | text->setStyle(blockStyle); |
| 134 | block->addChild(text); |
| 135 | |
| 136 | // Call bidiReorderLine |
| 137 | BidiState bidi; |
adele | fcfff3d | 2007-02-06 02:12:26 +0000 | [diff] [blame] | 138 | PassRefPtr<BidiContext> startEmbed; |
adele | 68afa0b | 2007-02-05 23:25:44 +0000 | [diff] [blame] | 139 | if (style->direction() == LTR) { |
| 140 | startEmbed = new BidiContext(0, LeftToRight, NULL, style->unicodeBidi() == Override); |
| 141 | bidi.status.eor = LeftToRight; |
| 142 | } else { |
| 143 | startEmbed = new BidiContext(1, RightToLeft, NULL, style->unicodeBidi() == Override); |
| 144 | bidi.status.eor = RightToLeft; |
| 145 | } |
| 146 | bidi.status.lastStrong = startEmbed->dir(); |
| 147 | bidi.status.last = startEmbed->dir(); |
| 148 | bidi.status.eor = startEmbed->dir(); |
| 149 | bidi.context = startEmbed; |
| 150 | bidi.dir = OtherNeutral; |
| 151 | betweenMidpoints = false; |
| 152 | |
| 153 | block->bidiReorderLine(BidiIterator(block, text, 0), BidiIterator(block, text, bufferLength), bidi); |
| 154 | |
| 155 | // Fill the characterBuffer. |
| 156 | int index = 0; |
| 157 | BidiRun* r = sFirstBidiRun; |
| 158 | while (r) { |
| 159 | bool reversed = r->reversed(style->visuallyOrdered()); |
| 160 | // If there's only one run, and it doesn't need to be reversed, return early |
| 161 | if (sBidiRunCount == 1 && !reversed) |
| 162 | break; |
| 163 | for (int i = r->start; i < r->stop; ++i) { |
| 164 | if (reversed) |
| 165 | characterBuffer[index] = string[r->stop + r->start - i - 1]; |
| 166 | else |
| 167 | characterBuffer[index] = string[i]; |
| 168 | ++index; |
| 169 | } |
| 170 | r = r->nextRun; |
| 171 | } |
| 172 | |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 173 | // Tear down temporary RenderBlock, RenderText, and BidiRuns |
adele | 68afa0b | 2007-02-05 23:25:44 +0000 | [diff] [blame] | 174 | block->removeChild(text); |
| 175 | text->destroy(); |
| 176 | block->destroy(); |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 177 | deleteBidiRuns(document->renderArena()); |
adele | 68afa0b | 2007-02-05 23:25:44 +0000 | [diff] [blame] | 178 | } |
| 179 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 180 | static int getBPMWidth(int childValue, Length cssUnit) |
| 181 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 182 | if (!cssUnit.isIntrinsicOrAuto()) |
darin | 947a31b | 2006-02-24 03:08:41 +0000 | [diff] [blame] | 183 | return (cssUnit.isFixed() ? cssUnit.value() : childValue); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static int getBorderPaddingMargin(RenderObject* child, bool endOfInline) |
| 188 | { |
| 189 | RenderStyle* cstyle = child->style(); |
| 190 | int result = 0; |
| 191 | bool leftSide = (cstyle->direction() == LTR) ? !endOfInline : endOfInline; |
| 192 | result += getBPMWidth((leftSide ? child->marginLeft() : child->marginRight()), |
| 193 | (leftSide ? cstyle->marginLeft() : |
| 194 | cstyle->marginRight())); |
| 195 | result += getBPMWidth((leftSide ? child->paddingLeft() : child->paddingRight()), |
| 196 | (leftSide ? cstyle->paddingLeft() : |
| 197 | cstyle->paddingRight())); |
| 198 | result += leftSide ? child->borderLeft() : child->borderRight(); |
| 199 | return result; |
| 200 | } |
| 201 | |
| 202 | static int inlineWidth(RenderObject* child, bool start = true, bool end = true) |
| 203 | { |
| 204 | int extraWidth = 0; |
| 205 | RenderObject* parent = child->parent(); |
hyatt | 450813d | 2003-07-25 20:22:34 +0000 | [diff] [blame] | 206 | while (parent->isInline() && !parent->isInlineBlockOrInlineTable()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 207 | if (start && parent->firstChild() == child) |
| 208 | extraWidth += getBorderPaddingMargin(parent, false); |
| 209 | if (end && parent->lastChild() == child) |
| 210 | extraWidth += getBorderPaddingMargin(parent, true); |
| 211 | child = parent; |
| 212 | parent = child->parent(); |
| 213 | } |
| 214 | return extraWidth; |
| 215 | } |
| 216 | |
darin | 35355e5 | 2002-12-20 09:19:00 +0000 | [diff] [blame] | 217 | #ifndef NDEBUG |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 218 | WTFLogChannel LogWebCoreBidiRunLeaks = { 0x00000000, "", WTFLogChannelOn }; |
| 219 | |
| 220 | struct BidiRunCounter { |
| 221 | static int count; |
| 222 | ~BidiRunCounter() |
| 223 | { |
| 224 | if (count) |
| 225 | LOG(WebCoreBidiRunLeaks, "LEAK: %d BidiRun\n", count); |
| 226 | } |
| 227 | }; |
| 228 | int BidiRunCounter::count = 0; |
| 229 | static BidiRunCounter bidiRunCounter; |
| 230 | |
harrison | 0012ced | 2005-10-06 18:37:42 +0000 | [diff] [blame] | 231 | static bool inBidiRunDestroy; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 232 | #endif |
| 233 | |
harrison | e8363b4 | 2005-10-06 00:54:06 +0000 | [diff] [blame] | 234 | void BidiRun::destroy(RenderArena* renderArena) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 235 | { |
| 236 | #ifndef NDEBUG |
harrison | 0012ced | 2005-10-06 18:37:42 +0000 | [diff] [blame] | 237 | inBidiRunDestroy = true; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 238 | #endif |
| 239 | delete this; |
| 240 | #ifndef NDEBUG |
harrison | 0012ced | 2005-10-06 18:37:42 +0000 | [diff] [blame] | 241 | inBidiRunDestroy = false; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 242 | #endif |
| 243 | |
| 244 | // Recover the size left there for us by operator delete and free the memory. |
| 245 | renderArena->free(*(size_t *)this, this); |
| 246 | } |
| 247 | |
| 248 | void* BidiRun::operator new(size_t sz, RenderArena* renderArena) throw() |
| 249 | { |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 250 | #ifndef NDEBUG |
| 251 | ++BidiRunCounter::count; |
| 252 | #endif |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 253 | return renderArena->allocate(sz); |
| 254 | } |
| 255 | |
| 256 | void BidiRun::operator delete(void* ptr, size_t sz) |
| 257 | { |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 258 | #ifndef NDEBUG |
| 259 | --BidiRunCounter::count; |
| 260 | #endif |
harrison | 0012ced | 2005-10-06 18:37:42 +0000 | [diff] [blame] | 261 | assert(inBidiRunDestroy); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 262 | |
harrison | e8363b4 | 2005-10-06 00:54:06 +0000 | [diff] [blame] | 263 | // Stash size where destroy() can find it. |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 264 | *(size_t*)ptr = sz; |
| 265 | } |
| 266 | |
| 267 | static void deleteBidiRuns(RenderArena* arena) |
| 268 | { |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 269 | emptyRun = true; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 270 | if (!sFirstBidiRun) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 271 | return; |
| 272 | |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 273 | BidiRun* curr = sFirstBidiRun; |
| 274 | while (curr) { |
| 275 | BidiRun* s = curr->nextRun; |
harrison | e8363b4 | 2005-10-06 00:54:06 +0000 | [diff] [blame] | 276 | curr->destroy(arena); |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 277 | curr = s; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 278 | } |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 279 | |
| 280 | sFirstBidiRun = 0; |
| 281 | sLastBidiRun = 0; |
| 282 | sBidiRunCount = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 283 | } |
| 284 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 285 | // --------------------------------------------------------------------- |
| 286 | |
| 287 | /* a small helper class used internally to resolve Bidi embedding levels. |
| 288 | Each line of text caches the embedding level at the start of the line for faster |
| 289 | relayouting |
| 290 | */ |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 291 | BidiContext::BidiContext(unsigned char l, Direction e, BidiContext *p, bool o) |
mjs | 08191d5 | 2006-03-06 02:53:41 +0000 | [diff] [blame] | 292 | : level(l), override(o), m_dir(e) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 293 | { |
| 294 | parent = p; |
weinig | da22cda | 2006-12-27 21:19:02 +0000 | [diff] [blame] | 295 | if (p) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 296 | p->ref(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 297 | count = 0; |
| 298 | } |
| 299 | |
| 300 | BidiContext::~BidiContext() |
| 301 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 302 | if (parent) |
| 303 | parent->deref(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void BidiContext::ref() const |
| 307 | { |
| 308 | count++; |
| 309 | } |
| 310 | |
| 311 | void BidiContext::deref() const |
| 312 | { |
| 313 | count--; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 314 | if (count <= 0) |
| 315 | delete this; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 316 | } |
| 317 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 318 | bool operator==(const BidiContext& c1, const BidiContext& c2) |
| 319 | { |
| 320 | if (&c1 == &c2) |
| 321 | return true; |
weinig | da22cda | 2006-12-27 21:19:02 +0000 | [diff] [blame] | 322 | if (c1.level != c2.level || c1.override != c2.override || c1.dir() != c2.dir()) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 323 | return false; |
eseidel | 6465a0f | 2006-01-10 13:35:45 +0000 | [diff] [blame] | 324 | if (!c1.parent) |
| 325 | return !c2.parent; |
| 326 | return c2.parent && *c1.parent == *c2.parent; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | inline bool operator!=(const BidiContext& c1, const BidiContext& c2) |
| 330 | { |
| 331 | return !(c1 == c2); |
| 332 | } |
| 333 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 334 | // --------------------------------------------------------------------- |
| 335 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 336 | inline bool operator==(const BidiIterator& it1, const BidiIterator& it2) |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 337 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 338 | if (it1.pos != it2.pos) |
| 339 | return false; |
| 340 | if (it1.obj != it2.obj) |
| 341 | return false; |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 342 | return true; |
| 343 | } |
| 344 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 345 | inline bool operator!=(const BidiIterator& it1, const BidiIterator& it2) |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 346 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 347 | if (it1.pos != it2.pos) |
| 348 | return true; |
| 349 | if (it1.obj != it2.obj) |
| 350 | return true; |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 351 | return false; |
| 352 | } |
| 353 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 354 | static inline RenderObject* bidiNext(RenderBlock* block, RenderObject* current, BidiState& bidi, |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 355 | bool skipInlines = true, bool* endOfInline = 0) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 356 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 357 | RenderObject* next = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 358 | bool oldEndOfInline = endOfInline ? *endOfInline : false; |
| 359 | if (endOfInline) |
| 360 | *endOfInline = false; |
| 361 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 362 | while (current) { |
sullivan | abd4d03 | 2007-02-09 22:51:41 +0000 | [diff] [blame] | 363 | next = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 364 | if (!oldEndOfInline && !current->isFloating() && !current->isReplaced() && !current->isPositioned()) { |
| 365 | next = current->firstChild(); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 366 | if (next && bidi.adjustEmbedding && next->isInlineFlow()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 367 | EUnicodeBidi ub = next->style()->unicodeBidi(); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 368 | if (ub != UBNormal) { |
darin | 9d0a628 | 2006-03-01 07:49:33 +0000 | [diff] [blame] | 369 | TextDirection dir = next->style()->direction(); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 370 | Direction d = (ub == Embed |
| 371 | ? (dir == RTL ? RightToLeftEmbedding : LeftToRightEmbedding) |
| 372 | : (dir == RTL ? RightToLeftOverride : LeftToRightOverride)); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 373 | embed(d, bidi); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 377 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 378 | if (!next) { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 379 | if (!skipInlines && !oldEndOfInline && current->isInlineFlow()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 380 | next = current; |
| 381 | if (endOfInline) |
| 382 | *endOfInline = true; |
| 383 | break; |
| 384 | } |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 385 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 386 | while (current && current != block) { |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 387 | if (bidi.adjustEmbedding && current->isInlineFlow() && current->style()->unicodeBidi() != UBNormal) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 388 | embed(PopDirectionalFormat, bidi); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 389 | |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 390 | next = current->nextSibling(); |
| 391 | if (next) { |
| 392 | if (bidi.adjustEmbedding && next->isInlineFlow()) { |
| 393 | EUnicodeBidi ub = next->style()->unicodeBidi(); |
| 394 | if (ub != UBNormal) { |
darin | 9d0a628 | 2006-03-01 07:49:33 +0000 | [diff] [blame] | 395 | TextDirection dir = next->style()->direction(); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 396 | Direction d = (ub == Embed |
| 397 | ? (dir == RTL ? RightToLeftEmbedding: LeftToRightEmbedding) |
| 398 | : (dir == RTL ? RightToLeftOverride : LeftToRightOverride)); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 399 | embed(d, bidi); |
| 400 | } |
| 401 | } |
| 402 | break; |
| 403 | } |
| 404 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 405 | current = current->parent(); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 406 | if (!skipInlines && current && current != block && current->isInlineFlow()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 407 | next = current; |
| 408 | if (endOfInline) |
| 409 | *endOfInline = true; |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | } |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 414 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 415 | if (!next) |
| 416 | break; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 417 | |
| 418 | if (next->isText() || next->isBR() || next->isFloating() || next->isReplaced() || next->isPositioned() |
| 419 | || ((!skipInlines || !next->firstChild()) // Always return EMPTY inlines. |
| 420 | && next->isInlineFlow())) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 421 | break; |
| 422 | current = next; |
| 423 | } |
| 424 | return next; |
| 425 | } |
| 426 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 427 | static RenderObject* bidiFirst(RenderBlock* block, BidiState& bidi, bool skipInlines = true ) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 428 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 429 | if (!block->firstChild()) |
| 430 | return 0; |
| 431 | |
| 432 | RenderObject* o = block->firstChild(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 433 | if (o->isInlineFlow()) { |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 434 | if (bidi.adjustEmbedding) { |
| 435 | EUnicodeBidi ub = o->style()->unicodeBidi(); |
| 436 | if (ub != UBNormal) { |
darin | 9d0a628 | 2006-03-01 07:49:33 +0000 | [diff] [blame] | 437 | TextDirection dir = o->style()->direction(); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 438 | Direction d = (ub == Embed |
| 439 | ? (dir == RTL ? RightToLeftEmbedding : LeftToRightEmbedding) |
| 440 | : (dir == RTL ? RightToLeftOverride : LeftToRightOverride)); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 441 | embed(d, bidi); |
| 442 | } |
| 443 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 444 | if (skipInlines && o->firstChild()) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 445 | o = bidiNext(block, o, bidi, skipInlines); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 446 | else |
| 447 | return o; // Never skip empty inlines. |
| 448 | } |
hyatt | c5334f1 | 2003-08-08 22:26:08 +0000 | [diff] [blame] | 449 | |
| 450 | if (o && !o->isText() && !o->isBR() && !o->isReplaced() && !o->isFloating() && !o->isPositioned()) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 451 | o = bidiNext(block, o, bidi, skipInlines); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 452 | return o; |
| 453 | } |
| 454 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 455 | inline void BidiIterator::increment(BidiState& bidi) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 456 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 457 | if (!obj) |
| 458 | return; |
| 459 | if (obj->isText()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 460 | pos++; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 461 | if (pos >= static_cast<RenderText *>(obj)->textLength()) { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 462 | obj = bidiNext(block, obj, bidi); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 463 | pos = 0; |
| 464 | } |
| 465 | } else { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 466 | obj = bidiNext(block, obj, bidi); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 467 | pos = 0; |
| 468 | } |
| 469 | } |
| 470 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 471 | inline bool BidiIterator::atEnd() const |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 472 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 473 | return !obj; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 474 | } |
| 475 | |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 476 | UChar BidiIterator::current() const |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 477 | { |
hyatt | 30586b4 | 2003-12-02 23:19:11 +0000 | [diff] [blame] | 478 | if (!obj || !obj->isText()) |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 479 | return 0; |
hyatt | 30586b4 | 2003-12-02 23:19:11 +0000 | [diff] [blame] | 480 | |
| 481 | RenderText* text = static_cast<RenderText*>(obj); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 482 | if (!text->characters()) |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 483 | return 0; |
hyatt | 30586b4 | 2003-12-02 23:19:11 +0000 | [diff] [blame] | 484 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 485 | return text->characters()[pos]; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 486 | } |
| 487 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 488 | ALWAYS_INLINE Direction BidiIterator::direction() const |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 489 | { |
hyatt | 5c18e1a | 2004-09-28 18:32:47 +0000 | [diff] [blame] | 490 | if (!obj) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 491 | return OtherNeutral; |
hyatt | 5c18e1a | 2004-09-28 18:32:47 +0000 | [diff] [blame] | 492 | if (obj->isListMarker()) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 493 | return obj->style()->direction() == LTR ? LeftToRight : RightToLeft; |
hyatt | 5c18e1a | 2004-09-28 18:32:47 +0000 | [diff] [blame] | 494 | if (!obj->isText()) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 495 | return OtherNeutral; |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 496 | RenderText* renderTxt = static_cast<RenderText*>(obj); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 497 | if (pos >= renderTxt->textLength()) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 498 | return OtherNeutral; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 499 | return Unicode::direction(renderTxt->characters()[pos]); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 500 | } |
| 501 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 502 | // ------------------------------------------------------------------------------------------------- |
| 503 | |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 504 | static void addRun(BidiRun* bidiRun) |
| 505 | { |
| 506 | if (!sFirstBidiRun) |
| 507 | sFirstBidiRun = sLastBidiRun = bidiRun; |
| 508 | else { |
| 509 | sLastBidiRun->nextRun = bidiRun; |
| 510 | sLastBidiRun = bidiRun; |
| 511 | } |
| 512 | sBidiRunCount++; |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 513 | bidiRun->compact = sBuildingCompactRuns; |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 514 | |
| 515 | // Compute the number of spaces in this run, |
| 516 | if (bidiRun->obj && bidiRun->obj->isText()) { |
| 517 | RenderText* text = static_cast<RenderText*>(bidiRun->obj); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 518 | if (text->characters()) { |
hyatt | efebbdd | 2003-12-02 22:25:31 +0000 | [diff] [blame] | 519 | for (int i = bidiRun->start; i < bidiRun->stop; i++) { |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 520 | UChar c = text->characters()[i]; |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 521 | if (c == ' ' || c == '\n' || c == '\t') |
hyatt | efebbdd | 2003-12-02 22:25:31 +0000 | [diff] [blame] | 522 | numSpaces++; |
| 523 | } |
darin | a3c4828 | 2003-10-07 15:49:30 +0000 | [diff] [blame] | 524 | } |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 525 | } |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | static void reverseRuns(int start, int end) |
| 529 | { |
| 530 | if (start >= end) |
| 531 | return; |
| 532 | |
| 533 | assert(start >= 0 && end < sBidiRunCount); |
| 534 | |
| 535 | // Get the item before the start of the runs to reverse and put it in |
| 536 | // |beforeStart|. |curr| should point to the first run to reverse. |
| 537 | BidiRun* curr = sFirstBidiRun; |
| 538 | BidiRun* beforeStart = 0; |
| 539 | int i = 0; |
| 540 | while (i < start) { |
| 541 | i++; |
| 542 | beforeStart = curr; |
| 543 | curr = curr->nextRun; |
| 544 | } |
| 545 | |
hyatt | 793fbbc | 2003-02-26 02:38:01 +0000 | [diff] [blame] | 546 | BidiRun* startRun = curr; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 547 | while (i < end) { |
hyatt | 793fbbc | 2003-02-26 02:38:01 +0000 | [diff] [blame] | 548 | i++; |
| 549 | curr = curr->nextRun; |
| 550 | } |
| 551 | BidiRun* endRun = curr; |
| 552 | BidiRun* afterEnd = curr->nextRun; |
| 553 | |
| 554 | i = start; |
| 555 | curr = startRun; |
| 556 | BidiRun* newNext = afterEnd; |
| 557 | while (i <= end) { |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 558 | // Do the reversal. |
| 559 | BidiRun* next = curr->nextRun; |
hyatt | 793fbbc | 2003-02-26 02:38:01 +0000 | [diff] [blame] | 560 | curr->nextRun = newNext; |
| 561 | newNext = curr; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 562 | curr = next; |
| 563 | i++; |
| 564 | } |
| 565 | |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 566 | // Now hook up beforeStart and afterEnd to the newStart and newEnd. |
| 567 | if (beforeStart) |
hyatt | 793fbbc | 2003-02-26 02:38:01 +0000 | [diff] [blame] | 568 | beforeStart->nextRun = endRun; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 569 | else |
hyatt | 793fbbc | 2003-02-26 02:38:01 +0000 | [diff] [blame] | 570 | sFirstBidiRun = endRun; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 571 | |
hyatt | 793fbbc | 2003-02-26 02:38:01 +0000 | [diff] [blame] | 572 | startRun->nextRun = afterEnd; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 573 | if (!afterEnd) |
hyatt | 793fbbc | 2003-02-26 02:38:01 +0000 | [diff] [blame] | 574 | sLastBidiRun = startRun; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 575 | } |
| 576 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 577 | static void chopMidpointsAt(RenderObject* obj, unsigned pos) |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 578 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 579 | if (!sNumMidpoints) |
| 580 | return; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 581 | BidiIterator* midpoints = smidpoints->data(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 582 | for (unsigned i = 0; i < sNumMidpoints; i++) { |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 583 | const BidiIterator& point = midpoints[i]; |
| 584 | if (point.obj == obj && point.pos == pos) { |
| 585 | sNumMidpoints = i; |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 591 | static void checkMidpoints(BidiIterator& lBreak, BidiState& bidi) |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 592 | { |
| 593 | // 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] | 594 | // shave it off the list, and shave off a trailing space if the previous end point doesn't |
| 595 | // preserve whitespace. |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 596 | if (lBreak.obj && sNumMidpoints && sNumMidpoints%2 == 0) { |
| 597 | BidiIterator* midpoints = smidpoints->data(); |
| 598 | BidiIterator& endpoint = midpoints[sNumMidpoints-2]; |
| 599 | const BidiIterator& startpoint = midpoints[sNumMidpoints-1]; |
| 600 | BidiIterator currpoint = endpoint; |
| 601 | while (!currpoint.atEnd() && currpoint != startpoint && currpoint != lBreak) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 602 | currpoint.increment(bidi); |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 603 | if (currpoint == lBreak) { |
| 604 | // We hit the line break before the start point. Shave off the start point. |
| 605 | sNumMidpoints--; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 606 | if (endpoint.obj->style()->collapseWhiteSpace()) { |
hyatt | ee1bcae | 2004-03-29 21:36:04 +0000 | [diff] [blame] | 607 | if (endpoint.obj->isText()) { |
harrison | a4d6cdc | 2006-10-02 15:32:17 +0000 | [diff] [blame] | 608 | // 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] | 609 | RenderText* textObj = static_cast<RenderText*>(endpoint.obj); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 610 | if (endpoint.pos + 1 < textObj->textLength()) { |
| 611 | if (textObj->characters()[endpoint.pos+1] == softHyphen) |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 612 | return; |
| 613 | } else if (startpoint.obj->isText()) { |
| 614 | RenderText *startText = static_cast<RenderText*>(startpoint.obj); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 615 | if (startText->textLength() && startText->characters()[0] == softHyphen) |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 616 | return; |
| 617 | } |
hyatt | ee1bcae | 2004-03-29 21:36:04 +0000 | [diff] [blame] | 618 | } |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 619 | endpoint.pos--; |
hyatt | ee1bcae | 2004-03-29 21:36:04 +0000 | [diff] [blame] | 620 | } |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 625 | static void addMidpoint(const BidiIterator& midpoint) |
| 626 | { |
| 627 | if (!smidpoints) |
| 628 | return; |
| 629 | |
| 630 | if (smidpoints->size() <= sNumMidpoints) |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 631 | smidpoints->resize(sNumMidpoints + 10); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 632 | |
| 633 | BidiIterator* midpoints = smidpoints->data(); |
| 634 | midpoints[sNumMidpoints++] = midpoint; |
| 635 | } |
| 636 | |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 637 | static void appendRunsForObject(int start, int end, RenderObject* obj, BidiState &bidi) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 638 | { |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 639 | if (start > end || obj->isFloating() || |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 640 | (obj->isPositioned() && !obj->hasStaticX() && !obj->hasStaticY() && !obj->container()->isInlineFlow())) |
hyatt | eb003b8 | 2002-11-15 22:35:10 +0000 | [diff] [blame] | 641 | return; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 642 | |
| 643 | bool haveNextMidpoint = (smidpoints && sCurrMidpoint < sNumMidpoints); |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 644 | BidiIterator nextMidpoint; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 645 | if (haveNextMidpoint) |
| 646 | nextMidpoint = smidpoints->at(sCurrMidpoint); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 647 | if (betweenMidpoints) { |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 648 | if (!(haveNextMidpoint && nextMidpoint.obj == obj)) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 649 | return; |
| 650 | // This is a new start point. Stop ignoring objects and |
| 651 | // adjust our start. |
| 652 | betweenMidpoints = false; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 653 | start = nextMidpoint.pos; |
| 654 | sCurrMidpoint++; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 655 | if (start < end) |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 656 | return appendRunsForObject(start, end, obj, bidi); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 657 | } |
| 658 | else { |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 659 | if (!smidpoints || !haveNextMidpoint || (obj != nextMidpoint.obj)) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 660 | addRun(new (obj->renderArena()) BidiRun(start, end, obj, bidi.context.get(), bidi.dir)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 661 | return; |
| 662 | } |
| 663 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 664 | // An end midpoint has been encountered within our object. We |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 665 | // need to go ahead and append a run with our endpoint. |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 666 | if (int(nextMidpoint.pos+1) <= end) { |
hyatt | 2617943 | 2002-11-17 01:57:27 +0000 | [diff] [blame] | 667 | betweenMidpoints = true; |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 668 | sCurrMidpoint++; |
hyatt | c64f9fc | 2003-03-14 01:25:59 +0000 | [diff] [blame] | 669 | 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] | 670 | if (int(nextMidpoint.pos+1) > start) |
| 671 | addRun(new (obj->renderArena()) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 672 | BidiRun(start, nextMidpoint.pos+1, obj, bidi.context.get(), bidi.dir)); |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 673 | return appendRunsForObject(nextMidpoint.pos+1, end, obj, bidi); |
hyatt | c64f9fc | 2003-03-14 01:25:59 +0000 | [diff] [blame] | 674 | } |
hyatt | 2617943 | 2002-11-17 01:57:27 +0000 | [diff] [blame] | 675 | } |
| 676 | else |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 677 | addRun(new (obj->renderArena()) BidiRun(start, end, obj, bidi.context.get(), bidi.dir)); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 681 | static void appendRun(BidiState &bidi) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 682 | { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 683 | if (emptyRun || !bidi.eor.obj) |
| 684 | return; |
weinig | f18aae3 | 2006-08-03 21:55:57 +0000 | [diff] [blame] | 685 | #if defined(BIDI_DEBUG) && BIDI_DEBUG > 1 |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 686 | kdDebug(6041) << "appendRun: dir="<<(int)dir<<endl; |
| 687 | #endif |
darin | f028f81 | 2002-06-10 20:08:04 +0000 | [diff] [blame] | 688 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 689 | bool b = bidi.adjustEmbedding; |
| 690 | bidi.adjustEmbedding = false; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 691 | |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 692 | int start = bidi.sor.pos; |
| 693 | RenderObject *obj = bidi.sor.obj; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 694 | while (obj && obj != bidi.eor.obj && obj != bidi.endOfLine.obj) { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 695 | appendRunsForObject(start, obj->length(), obj, bidi); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 696 | start = 0; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 697 | obj = bidiNext(bidi.sor.block, obj, bidi); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 698 | } |
justing | 5b0e042 | 2005-08-01 03:20:49 +0000 | [diff] [blame] | 699 | if (obj) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 700 | unsigned pos = obj == bidi.eor.obj ? bidi.eor.pos : UINT_MAX; |
| 701 | if (obj == bidi.endOfLine.obj && bidi.endOfLine.pos <= pos) { |
| 702 | bidi.reachedEndOfLine = true; |
| 703 | pos = bidi.endOfLine.pos; |
| 704 | } |
justing | 5b0e042 | 2005-08-01 03:20:49 +0000 | [diff] [blame] | 705 | // 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] | 706 | int end = obj->length() ? pos+1 : 0; |
justing | 5b0e042 | 2005-08-01 03:20:49 +0000 | [diff] [blame] | 707 | appendRunsForObject(start, end, obj, bidi); |
| 708 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 709 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 710 | bidi.eor.increment(bidi); |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 711 | bidi.sor = bidi.eor; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 712 | bidi.dir = OtherNeutral; |
| 713 | bidi.status.eor = OtherNeutral; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 714 | bidi.adjustEmbedding = b; |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 715 | } |
| 716 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 717 | static void embed(Direction d, BidiState& bidi) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 718 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 719 | bool b = bidi.adjustEmbedding; |
| 720 | bidi.adjustEmbedding = false; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 721 | if (d == PopDirectionalFormat) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 722 | BidiContext *c = bidi.context->parent; |
| 723 | if (c) { |
| 724 | if (!emptyRun && bidi.eor != bidi.last) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 725 | assert(bidi.status.eor != OtherNeutral); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 726 | // bidi.sor ... bidi.eor ... bidi.last eor; need to append the bidi.sor-bidi.eor run or extend it through bidi.last |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 727 | assert(bidi.status.last == EuropeanNumberSeparator |
| 728 | || bidi.status.last == EuropeanNumberTerminator |
| 729 | || bidi.status.last == CommonNumberSeparator |
| 730 | || bidi.status.last == BoundaryNeutral |
| 731 | || bidi.status.last == BlockSeparator |
| 732 | || bidi.status.last == SegmentSeparator |
| 733 | || bidi.status.last == WhiteSpaceNeutral |
| 734 | || bidi.status.last == OtherNeutral); |
| 735 | if (bidi.dir == OtherNeutral) |
mjs | 08191d5 | 2006-03-06 02:53:41 +0000 | [diff] [blame] | 736 | bidi.dir = bidi.context->dir(); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 737 | if (bidi.context->dir() == LeftToRight) { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 738 | // bidi.sor ... bidi.eor ... bidi.last L |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 739 | if (bidi.status.eor == EuropeanNumber) { |
| 740 | if (bidi.status.lastStrong != LeftToRight) { |
| 741 | bidi.dir = EuropeanNumber; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 742 | appendRun(bidi); |
| 743 | } |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 744 | } else if (bidi.status.eor == ArabicNumber) { |
| 745 | bidi.dir = ArabicNumber; |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 746 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 747 | } else if (bidi.status.eor != LeftToRight) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 748 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 749 | } else if (bidi.status.eor != RightToLeft && bidi.status.eor != RightToLeftArabic) |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 750 | appendRun(bidi); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 751 | bidi.eor = bidi.last; |
| 752 | } |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 753 | appendRun(bidi); |
| 754 | emptyRun = true; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 755 | // sor for the new run is determined by the higher level (rule X10) |
mjs | 08191d5 | 2006-03-06 02:53:41 +0000 | [diff] [blame] | 756 | bidi.status.last = bidi.context->dir(); |
| 757 | bidi.status.lastStrong = bidi.context->dir(); |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 758 | bidi.context = c; |
mjs | 08191d5 | 2006-03-06 02:53:41 +0000 | [diff] [blame] | 759 | bidi.status.eor = bidi.context->dir(); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 760 | bidi.eor.obj = 0; |
| 761 | } |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 762 | } else { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 763 | Direction runDir; |
| 764 | if (d == RightToLeftEmbedding || d == RightToLeftOverride) |
| 765 | runDir = RightToLeft; |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 766 | else |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 767 | runDir = LeftToRight; |
| 768 | bool override = d == LeftToRightOverride || d == RightToLeftOverride; |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 769 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 770 | unsigned char level = bidi.context->level; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 771 | if (runDir == RightToLeft) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 772 | if (level%2) // we have an odd level |
| 773 | level += 2; |
| 774 | else |
| 775 | level++; |
| 776 | } else { |
| 777 | if (level%2) // we have an odd level |
| 778 | level++; |
| 779 | else |
| 780 | level += 2; |
| 781 | } |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 782 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 783 | if (level < 61) { |
| 784 | if (!emptyRun && bidi.eor != bidi.last) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 785 | assert(bidi.status.eor != OtherNeutral); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 786 | // bidi.sor ... bidi.eor ... bidi.last eor; need to append the bidi.sor-bidi.eor run or extend it through bidi.last |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 787 | assert(bidi.status.last == EuropeanNumberSeparator |
| 788 | || bidi.status.last == EuropeanNumberTerminator |
| 789 | || bidi.status.last == CommonNumberSeparator |
| 790 | || bidi.status.last == BoundaryNeutral |
| 791 | || bidi.status.last == BlockSeparator |
| 792 | || bidi.status.last == SegmentSeparator |
| 793 | || bidi.status.last == WhiteSpaceNeutral |
| 794 | || bidi.status.last == OtherNeutral); |
| 795 | if (bidi.dir == OtherNeutral) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 796 | bidi.dir = runDir; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 797 | if (runDir == LeftToRight) { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 798 | // bidi.sor ... bidi.eor ... bidi.last L |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 799 | if (bidi.status.eor == EuropeanNumber) { |
| 800 | if (bidi.status.lastStrong != LeftToRight) { |
| 801 | bidi.dir = EuropeanNumber; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 802 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 803 | if (bidi.context->dir() != LeftToRight) |
| 804 | bidi.dir = RightToLeft; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 805 | } |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 806 | } else if (bidi.status.eor == ArabicNumber) { |
| 807 | bidi.dir = ArabicNumber; |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 808 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 809 | if (bidi.context->dir() != LeftToRight) { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 810 | bidi.eor = bidi.last; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 811 | bidi.dir = RightToLeft; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 812 | appendRun(bidi); |
| 813 | } |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 814 | } else if (bidi.status.eor != LeftToRight) { |
| 815 | if (bidi.context->dir() == LeftToRight || bidi.status.lastStrong == LeftToRight) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 816 | appendRun(bidi); |
| 817 | else |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 818 | bidi.dir = RightToLeft; |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 819 | } |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 820 | } else if (bidi.status.eor != RightToLeft && bidi.status.eor != RightToLeftArabic) { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 821 | // bidi.sor ... bidi.eor ... bidi.last R; bidi.eor=L/EN/AN; EN,AN behave like R (rule N1) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 822 | if (bidi.context->dir() == RightToLeft || bidi.status.lastStrong == RightToLeft || bidi.status.lastStrong == RightToLeftArabic) |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 823 | appendRun(bidi); |
| 824 | else |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 825 | bidi.dir = LeftToRight; |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 826 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 827 | bidi.eor = bidi.last; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 828 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 829 | appendRun(bidi); |
| 830 | emptyRun = true; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 831 | bidi.context = new BidiContext(level, runDir, bidi.context.get(), override); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 832 | bidi.status.last = runDir; |
| 833 | bidi.status.lastStrong = runDir; |
| 834 | bidi.status.eor = runDir; |
| 835 | bidi.eor.obj = 0; |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 836 | } |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 837 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 838 | bidi.adjustEmbedding = b; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 839 | } |
| 840 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 841 | InlineFlowBox* RenderBlock::createLineBoxes(RenderObject* obj) |
| 842 | { |
| 843 | // See if we have an unconstructed line box for this object that is also |
| 844 | // the last item on the line. |
darin | b53ebdc | 2006-07-09 15:10:21 +0000 | [diff] [blame] | 845 | ASSERT(obj->isInlineFlow() || obj == this); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 846 | RenderFlow* flow = static_cast<RenderFlow*>(obj); |
| 847 | |
| 848 | // Get the last box we made for this render object. |
| 849 | InlineFlowBox* box = flow->lastLineBox(); |
| 850 | |
| 851 | // If this box is constructed then it is from a previous line, and we need |
| 852 | // to make a new box for our line. If this box is unconstructed but it has |
| 853 | // something following it on the line, then we know we have to make a new box |
| 854 | // as well. In this situation our inline has actually been split in two on |
| 855 | // the same line (this can happen with very fancy language mixtures). |
| 856 | if (!box || box->isConstructed() || box->nextOnLine()) { |
| 857 | // We need to make a new box for this render object. Once |
| 858 | // made, we need to place it at the end of the current line. |
hyatt | 450813d | 2003-07-25 20:22:34 +0000 | [diff] [blame] | 859 | InlineBox* newBox = obj->createInlineBox(false, obj == this); |
darin | b53ebdc | 2006-07-09 15:10:21 +0000 | [diff] [blame] | 860 | ASSERT(newBox->isInlineFlowBox()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 861 | box = static_cast<InlineFlowBox*>(newBox); |
| 862 | box->setFirstLineStyleBit(m_firstLine); |
| 863 | |
| 864 | // We have a new box. Append it to the inline box we get by constructing our |
| 865 | // parent. If we have hit the block itself, then |box| represents the root |
| 866 | // inline box for the line, and it doesn't have to be appended to any parent |
| 867 | // inline. |
| 868 | if (obj != this) { |
| 869 | InlineFlowBox* parentBox = createLineBoxes(obj->parent()); |
| 870 | parentBox->addToLine(box); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | return box; |
| 875 | } |
| 876 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 877 | RootInlineBox* RenderBlock::constructLine(const BidiIterator& start, const BidiIterator& end) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 878 | { |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 879 | if (!sFirstBidiRun) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 880 | return 0; // We had no runs. Don't make a root inline box at all. The line is empty. |
| 881 | |
| 882 | InlineFlowBox* parentBox = 0; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 883 | for (BidiRun* r = sFirstBidiRun; r; r = r->nextRun) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 884 | // Create a box for our object. |
harrison | 8d773e7 | 2006-01-29 15:06:17 +0000 | [diff] [blame] | 885 | bool isOnlyRun = (sBidiRunCount == 1); |
| 886 | if (sBidiRunCount == 2 && !r->obj->isListMarker()) |
| 887 | isOnlyRun = ((style()->direction() == RTL) ? sLastBidiRun : sFirstBidiRun)->obj->isListMarker(); |
| 888 | r->box = r->obj->createInlineBox(r->obj->isPositioned(), false, isOnlyRun); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 889 | if (r->box) { |
| 890 | // If we have no parent box yet, or if the run is not simply a sibling, |
| 891 | // then we need to construct inline boxes as necessary to properly enclose the |
| 892 | // run's inline box. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 893 | if (!parentBox || parentBox->object() != r->obj->parent()) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 894 | // Create new inline boxes all the way back to the appropriate insertion point. |
| 895 | parentBox = createLineBoxes(r->obj->parent()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 896 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 897 | // Append the inline box to this line. |
| 898 | parentBox->addToLine(r->box); |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 899 | |
| 900 | if (r->box->isInlineTextBox()) { |
| 901 | InlineTextBox *text = static_cast<InlineTextBox*>(r->box); |
| 902 | text->setStart(r->start); |
adele | 8040761 | 2006-07-28 05:13:24 +0000 | [diff] [blame] | 903 | text->setLen(r->stop - r->start); |
| 904 | bool visuallyOrdered = r->obj->style()->visuallyOrdered(); |
adele | 68afa0b | 2007-02-05 23:25:44 +0000 | [diff] [blame] | 905 | text->m_reversed = r->reversed(visuallyOrdered); |
| 906 | text->m_dirOverride = r->dirOverride(visuallyOrdered); |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 907 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 908 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | // We should have a root inline box. It should be unconstructed and |
| 912 | // be the last continuation of our line list. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 913 | assert(lastLineBox() && !lastLineBox()->isConstructed()); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 914 | |
| 915 | // Set bits on our inline flow boxes that indicate which sides should |
| 916 | // paint borders/margins/padding. This knowledge will ultimately be used when |
| 917 | // we determine the horizontal positions and widths of all the inline boxes on |
| 918 | // the line. |
| 919 | RenderObject* endObject = 0; |
| 920 | bool lastLine = !end.obj; |
| 921 | if (end.obj && end.pos == 0) |
| 922 | endObject = end.obj; |
| 923 | lastLineBox()->determineSpacingForFlowBoxes(lastLine, endObject); |
| 924 | |
| 925 | // Now mark the line boxes as being constructed. |
| 926 | lastLineBox()->setConstructed(); |
| 927 | |
| 928 | // Return the last line. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 929 | return lastRootBox(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 930 | } |
| 931 | |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 932 | // usage: tw - (xpos % tw); |
| 933 | int RenderBlock::tabWidth(bool isWhitespacePre) |
| 934 | { |
| 935 | if (!isWhitespacePre) |
| 936 | return 0; |
| 937 | |
adele | 1a307da | 2006-06-01 06:30:08 +0000 | [diff] [blame] | 938 | if (m_tabWidth == -1) { |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 939 | const UChar spaceChar = ' '; |
hyatt | 3e99d1c | 2006-02-24 21:13:08 +0000 | [diff] [blame] | 940 | const Font& font = style()->font(); |
hyatt | 43d6c79 | 2006-05-11 10:19:34 +0000 | [diff] [blame] | 941 | int spaceWidth = font.width(TextRun(&spaceChar, 1)); |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 942 | m_tabWidth = spaceWidth * 8; |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | return m_tabWidth; |
| 946 | } |
| 947 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 948 | void RenderBlock::computeHorizontalPositionsForLine(RootInlineBox* lineBox, BidiState& bidi) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 949 | { |
| 950 | // First determine our total width. |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 951 | int availableWidth = lineWidth(m_height); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 952 | int totWidth = lineBox->getFlowSpacingWidth(); |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 953 | BidiRun* r = 0; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 954 | bool needsWordSpacing = false; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 955 | for (r = sFirstBidiRun; r; r = r->nextRun) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 956 | if (!r->box || r->obj->isPositioned() || r->box->isLineBreak()) |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 957 | continue; // Positioned objects are only participating to figure out their |
| 958 | // correct static x position. They have no effect on the width. |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 959 | // Similarly, line break boxes have no effect on the width. |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 960 | if (r->obj->isText()) { |
ddkilzer | fe11506 | 2006-07-14 04:42:01 +0000 | [diff] [blame] | 961 | RenderText* rt = static_cast<RenderText*>(r->obj); |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 962 | int textWidth = rt->width(r->start, r->stop-r->start, totWidth, m_firstLine); |
| 963 | int effectiveWidth = textWidth; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 964 | int rtLength = rt->textLength(); |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 965 | if (rtLength != 0) { |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 966 | if (r->start == 0 && needsWordSpacing && DeprecatedChar(rt->characters()[r->start]).isSpace()) |
| 967 | effectiveWidth += rt->style(m_firstLine)->font().wordSpacing(); |
| 968 | needsWordSpacing = !DeprecatedChar(rt->characters()[r->stop-1]).isSpace() && r->stop == rtLength; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 969 | } |
kocienda | ee70198 | 2004-10-05 23:06:58 +0000 | [diff] [blame] | 970 | r->box->setWidth(textWidth); |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 971 | } else if (!r->obj->isInlineFlow()) { |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 972 | r->obj->calcWidth(); |
| 973 | r->box->setWidth(r->obj->width()); |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 974 | if (!r->compact) |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 975 | totWidth += r->obj->marginLeft() + r->obj->marginRight(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 976 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 977 | |
| 978 | // Compacts don't contribute to the width of the line, since they are placed in the margin. |
| 979 | if (!r->compact) |
| 980 | totWidth += r->box->width(); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 981 | } |
| 982 | |
ddkilzer | fe11506 | 2006-07-14 04:42:01 +0000 | [diff] [blame] | 983 | if (totWidth > availableWidth && sLogicallyLastBidiRun->obj->style(m_firstLine)->autoWrap() && |
| 984 | sLogicallyLastBidiRun->obj->style(m_firstLine)->breakOnlyAfterWhiteSpace() && |
| 985 | !sLogicallyLastBidiRun->compact) { |
| 986 | sLogicallyLastBidiRun->box->setWidth(sLogicallyLastBidiRun->box->width() - totWidth + availableWidth); |
| 987 | totWidth = availableWidth; |
| 988 | } |
| 989 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 990 | // Armed with the total width of the line (without justification), |
| 991 | // we now examine our text-align property in order to determine where to position the |
| 992 | // objects horizontally. The total width of the line can be increased if we end up |
| 993 | // justifying text. |
| 994 | int x = leftOffset(m_height); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 995 | switch(style()->textAlign()) { |
| 996 | case LEFT: |
hyatt | 47c1d4d | 2003-07-24 22:07:45 +0000 | [diff] [blame] | 997 | case KHTML_LEFT: |
hyatt | 959a54e | 2004-09-27 17:52:18 +0000 | [diff] [blame] | 998 | // The direction of the block should determine what happens with wide lines. In |
| 999 | // particular with RTL blocks, wide lines should still spill out to the left. |
| 1000 | if (style()->direction() == RTL && totWidth > availableWidth) |
| 1001 | x -= (totWidth - availableWidth); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1002 | numSpaces = 0; |
| 1003 | break; |
| 1004 | case JUSTIFY: |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1005 | if (numSpaces != 0 && !bidi.current.atEnd() && !lineBox->endsWithBreak()) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1006 | break; |
| 1007 | // fall through |
| 1008 | case TAAUTO: |
| 1009 | numSpaces = 0; |
| 1010 | // for right to left fall through to right aligned |
weinig | da22cda | 2006-12-27 21:19:02 +0000 | [diff] [blame] | 1011 | if (style()->direction() == LTR) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1012 | break; |
| 1013 | case RIGHT: |
hyatt | 47c1d4d | 2003-07-24 22:07:45 +0000 | [diff] [blame] | 1014 | case KHTML_RIGHT: |
hyatt | 959a54e | 2004-09-27 17:52:18 +0000 | [diff] [blame] | 1015 | // Wide lines spill out of the block based off direction. |
| 1016 | // So even if text-align is right, if direction is LTR, wide lines should overflow out of the right |
| 1017 | // side of the block. |
| 1018 | if (style()->direction() == RTL || totWidth < availableWidth) |
| 1019 | x += availableWidth - totWidth; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1020 | numSpaces = 0; |
| 1021 | break; |
| 1022 | case CENTER: |
hyatt | 47c1d4d | 2003-07-24 22:07:45 +0000 | [diff] [blame] | 1023 | case KHTML_CENTER: |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1024 | int xd = (availableWidth - totWidth)/2; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1025 | x += xd > 0 ? xd : 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1026 | numSpaces = 0; |
| 1027 | break; |
| 1028 | } |
| 1029 | |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 1030 | if (numSpaces > 0) { |
| 1031 | for (r = sFirstBidiRun; r; r = r->nextRun) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1032 | if (!r->box) continue; |
| 1033 | |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 1034 | int spaceAdd = 0; |
| 1035 | if (numSpaces > 0 && r->obj->isText() && !r->compact) { |
| 1036 | // get the number of spaces in the run |
| 1037 | int spaces = 0; |
darin | a3c4828 | 2003-10-07 15:49:30 +0000 | [diff] [blame] | 1038 | for ( int i = r->start; i < r->stop; i++ ) { |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 1039 | UChar c = static_cast<RenderText*>(r->obj)->characters()[i]; |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 1040 | if (c == ' ' || c == '\n' || c == '\t') |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 1041 | spaces++; |
darin | a3c4828 | 2003-10-07 15:49:30 +0000 | [diff] [blame] | 1042 | } |
hyatt | 870bdda | 2003-05-21 23:37:33 +0000 | [diff] [blame] | 1043 | |
darin | b53ebdc | 2006-07-09 15:10:21 +0000 | [diff] [blame] | 1044 | ASSERT(spaces <= numSpaces); |
hyatt | 870bdda | 2003-05-21 23:37:33 +0000 | [diff] [blame] | 1045 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1046 | // Only justify text if whitespace is collapsed. |
| 1047 | if (r->obj->style()->collapseWhiteSpace()) { |
hyatt | 870bdda | 2003-05-21 23:37:33 +0000 | [diff] [blame] | 1048 | spaceAdd = (availableWidth - totWidth)*spaces/numSpaces; |
kocienda | 01bcc35 | 2003-09-25 16:51:11 +0000 | [diff] [blame] | 1049 | static_cast<InlineTextBox*>(r->box)->setSpaceAdd(spaceAdd); |
hyatt | 870bdda | 2003-05-21 23:37:33 +0000 | [diff] [blame] | 1050 | totWidth += spaceAdd; |
| 1051 | } |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 1052 | numSpaces -= spaces; |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 1053 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1054 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1055 | } |
hyatt | acbb0d4 | 2003-04-25 01:32:49 +0000 | [diff] [blame] | 1056 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1057 | // The widths of all runs are now known. We can now place every inline box (and |
| 1058 | // compute accurate widths for the inline flow boxes). |
hyatt | 1f14a61 | 2004-12-07 00:34:02 +0000 | [diff] [blame] | 1059 | int leftPosition = x; |
| 1060 | int rightPosition = x; |
darin | 06dcb9c | 2005-08-15 04:31:09 +0000 | [diff] [blame] | 1061 | needsWordSpacing = false; |
| 1062 | lineBox->placeBoxesHorizontally(x, leftPosition, rightPosition, needsWordSpacing); |
hyatt | 1f14a61 | 2004-12-07 00:34:02 +0000 | [diff] [blame] | 1063 | lineBox->setHorizontalOverflowPositions(leftPosition, rightPosition); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1066 | void RenderBlock::computeVerticalPositionsForLine(RootInlineBox* lineBox) |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1067 | { |
| 1068 | lineBox->verticallyAlignBoxes(m_height); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1069 | lineBox->setBlockHeight(m_height); |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1070 | |
hyatt | 35a85e5 | 2003-02-14 19:43:07 +0000 | [diff] [blame] | 1071 | // See if the line spilled out. If so set overflow height accordingly. |
| 1072 | int bottomOfLine = lineBox->bottomOverflow(); |
| 1073 | if (bottomOfLine > m_height && bottomOfLine > m_overflowHeight) |
| 1074 | m_overflowHeight = bottomOfLine; |
| 1075 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1076 | // Now make sure we place replaced render objects correctly. |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1077 | for (BidiRun* r = sFirstBidiRun; r; r = r->nextRun) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1078 | if (!r->box) |
| 1079 | continue; // Skip runs with no line boxes. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1080 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1081 | // Align positioned boxes with the top of the line box. This is |
| 1082 | // a reasonable approximation of an appropriate y position. |
| 1083 | if (r->obj->isPositioned()) |
| 1084 | r->box->setYPos(m_height); |
| 1085 | |
| 1086 | // Position is used to properly position both replaced elements and |
| 1087 | // to update the static normal flow x/y of positioned elements. |
adele | 8040761 | 2006-07-28 05:13:24 +0000 | [diff] [blame] | 1088 | r->obj->position(r->box); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 1089 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1090 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1091 | |
| 1092 | // collects one line of the paragraph and transforms it to visual order |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1093 | void RenderBlock::bidiReorderLine(const BidiIterator& start, const BidiIterator& end, BidiState& bidi) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1094 | { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1095 | if (start == end) { |
| 1096 | if (start.current() == '\n') |
| 1097 | m_height += lineHeight(m_firstLine, true); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1098 | return; |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1099 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1100 | |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 1101 | sFirstBidiRun = 0; |
| 1102 | sLastBidiRun = 0; |
| 1103 | sBidiRunCount = 0; |
rjw | 834c806 | 2005-02-25 23:41:39 +0000 | [diff] [blame] | 1104 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1105 | assert(bidi.dir == OtherNeutral); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1106 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1107 | emptyRun = true; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1108 | |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1109 | bidi.eor.obj = 0; |
darin | f028f81 | 2002-06-10 20:08:04 +0000 | [diff] [blame] | 1110 | |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1111 | numSpaces = 0; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1112 | |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1113 | bidi.current = start; |
| 1114 | bidi.last = bidi.current; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1115 | bool pastEnd = false; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1116 | BidiState stateAtEnd; |
rjw | 834c806 | 2005-02-25 23:41:39 +0000 | [diff] [blame] | 1117 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1118 | while (true) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1119 | Direction dirCurrent; |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1120 | if (pastEnd && (previousLineBrokeCleanly || bidi.current.atEnd())) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1121 | BidiContext *c = bidi.context.get(); |
| 1122 | while (c->parent) |
| 1123 | c = c->parent; |
mjs | 08191d5 | 2006-03-06 02:53:41 +0000 | [diff] [blame] | 1124 | dirCurrent = c->dir(); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 1125 | if (previousLineBrokeCleanly) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1126 | // A deviation from the Unicode Bidi Algorithm in order to match |
| 1127 | // Mac OS X text and WinIE: a hard line break resets bidi state. |
| 1128 | stateAtEnd.context = c; |
| 1129 | stateAtEnd.status.eor = dirCurrent; |
| 1130 | stateAtEnd.status.last = dirCurrent; |
| 1131 | stateAtEnd.status.lastStrong = dirCurrent; |
| 1132 | } |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1133 | } else { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1134 | dirCurrent = bidi.current.direction(); |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 1135 | if (bidi.context->override |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1136 | && dirCurrent != RightToLeftEmbedding |
| 1137 | && dirCurrent != LeftToRightEmbedding |
| 1138 | && dirCurrent != RightToLeftOverride |
| 1139 | && dirCurrent != LeftToRightOverride |
| 1140 | && dirCurrent != PopDirectionalFormat) |
mjs | 08191d5 | 2006-03-06 02:53:41 +0000 | [diff] [blame] | 1141 | dirCurrent = bidi.context->dir(); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1142 | else if (dirCurrent == NonSpacingMark) |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 1143 | dirCurrent = bidi.status.last; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1144 | } |
darin | f028f81 | 2002-06-10 20:08:04 +0000 | [diff] [blame] | 1145 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1146 | assert(bidi.status.eor != OtherNeutral); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1147 | switch (dirCurrent) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1148 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1149 | // embedding and overrides (X1-X9 in the Bidi specs) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1150 | case RightToLeftEmbedding: |
| 1151 | case LeftToRightEmbedding: |
| 1152 | case RightToLeftOverride: |
| 1153 | case LeftToRightOverride: |
| 1154 | case PopDirectionalFormat: |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1155 | embed(dirCurrent, bidi); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1156 | break; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1157 | |
| 1158 | // strong types |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1159 | case LeftToRight: |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1160 | switch(bidi.status.last) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1161 | case RightToLeft: |
| 1162 | case RightToLeftArabic: |
| 1163 | case EuropeanNumber: |
| 1164 | case ArabicNumber: |
| 1165 | if (bidi.status.last != EuropeanNumber || bidi.status.lastStrong != LeftToRight) |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1166 | appendRun(bidi); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1167 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1168 | case LeftToRight: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1169 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1170 | case EuropeanNumberSeparator: |
| 1171 | case EuropeanNumberTerminator: |
| 1172 | case CommonNumberSeparator: |
| 1173 | case BoundaryNeutral: |
| 1174 | case BlockSeparator: |
| 1175 | case SegmentSeparator: |
| 1176 | case WhiteSpaceNeutral: |
| 1177 | case OtherNeutral: |
| 1178 | if (bidi.status.eor == EuropeanNumber) { |
| 1179 | if (bidi.status.lastStrong != LeftToRight) { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1180 | // the numbers need to be on a higher embedding level, so let's close that run |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1181 | bidi.dir = EuropeanNumber; |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1182 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1183 | if (bidi.context->dir() != LeftToRight) { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1184 | // the neutrals take the embedding direction, which is R |
| 1185 | bidi.eor = bidi.last; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1186 | bidi.dir = RightToLeft; |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1187 | appendRun(bidi); |
| 1188 | } |
| 1189 | } |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1190 | } else if (bidi.status.eor == ArabicNumber) { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1191 | // Arabic numbers are always on a higher embedding level, so let's close that run |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1192 | bidi.dir = ArabicNumber; |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1193 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1194 | if (bidi.context->dir() != LeftToRight) { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1195 | // the neutrals take the embedding direction, which is R |
| 1196 | bidi.eor = bidi.last; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1197 | bidi.dir = RightToLeft; |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1198 | appendRun(bidi); |
| 1199 | } |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1200 | } else if(bidi.status.eor != LeftToRight) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1201 | //last stuff takes embedding dir |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1202 | if (bidi.context->dir() != LeftToRight && bidi.status.lastStrong != LeftToRight) { |
darin | 6f05b4c | 2005-05-27 01:17:32 +0000 | [diff] [blame] | 1203 | bidi.eor = bidi.last; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1204 | bidi.dir = RightToLeft; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1205 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1206 | appendRun(bidi); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1207 | } |
| 1208 | default: |
| 1209 | break; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1210 | } |
| 1211 | bidi.eor = bidi.current; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1212 | bidi.status.eor = LeftToRight; |
| 1213 | bidi.status.lastStrong = LeftToRight; |
| 1214 | bidi.dir = LeftToRight; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1215 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1216 | case RightToLeftArabic: |
| 1217 | case RightToLeft: |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1218 | switch (bidi.status.last) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1219 | case LeftToRight: |
| 1220 | case EuropeanNumber: |
| 1221 | case ArabicNumber: |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 1222 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1223 | case RightToLeft: |
| 1224 | case RightToLeftArabic: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1225 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1226 | case EuropeanNumberSeparator: |
| 1227 | case EuropeanNumberTerminator: |
| 1228 | case CommonNumberSeparator: |
| 1229 | case BoundaryNeutral: |
| 1230 | case BlockSeparator: |
| 1231 | case SegmentSeparator: |
| 1232 | case WhiteSpaceNeutral: |
| 1233 | case OtherNeutral: |
| 1234 | if (bidi.status.eor != RightToLeft && bidi.status.eor != RightToLeftArabic) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1235 | //last stuff takes embedding dir |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1236 | if (bidi.context->dir() != RightToLeft && bidi.status.lastStrong != RightToLeft |
| 1237 | && bidi.status.lastStrong != RightToLeftArabic) { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1238 | bidi.eor = bidi.last; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1239 | bidi.dir = LeftToRight; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1240 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1241 | appendRun(bidi); |
| 1242 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1243 | default: |
| 1244 | break; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1245 | } |
| 1246 | bidi.eor = bidi.current; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1247 | bidi.status.eor = RightToLeft; |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1248 | bidi.status.lastStrong = dirCurrent; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1249 | bidi.dir = RightToLeft; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1250 | break; |
| 1251 | |
| 1252 | // weak types: |
| 1253 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1254 | case EuropeanNumber: |
| 1255 | if (bidi.status.lastStrong != RightToLeftArabic) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1256 | // if last strong was AL change EN to AN |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1257 | switch (bidi.status.last) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1258 | case EuropeanNumber: |
| 1259 | case LeftToRight: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1260 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1261 | case RightToLeft: |
| 1262 | case RightToLeftArabic: |
| 1263 | case ArabicNumber: |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 1264 | bidi.eor = bidi.last; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1265 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1266 | bidi.dir = EuropeanNumber; |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 1267 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1268 | case EuropeanNumberSeparator: |
| 1269 | case CommonNumberSeparator: |
| 1270 | if (bidi.status.eor == EuropeanNumber) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1271 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1272 | case EuropeanNumberTerminator: |
| 1273 | case BoundaryNeutral: |
| 1274 | case BlockSeparator: |
| 1275 | case SegmentSeparator: |
| 1276 | case WhiteSpaceNeutral: |
| 1277 | case OtherNeutral: |
| 1278 | if (bidi.status.eor == RightToLeft) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1279 | // neutrals go to R |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1280 | bidi.eor = bidi.status.last == EuropeanNumberTerminator ? bidi.lastBeforeET : bidi.last; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1281 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1282 | bidi.dir = EuropeanNumber; |
| 1283 | } else if (bidi.status.eor != LeftToRight && |
| 1284 | (bidi.status.eor != EuropeanNumber || bidi.status.lastStrong != LeftToRight) && |
| 1285 | bidi.dir != LeftToRight) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1286 | // numbers on both sides, neutrals get right to left direction |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1287 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1288 | bidi.eor = bidi.status.last == EuropeanNumberTerminator ? bidi.lastBeforeET : bidi.last; |
| 1289 | bidi.dir = RightToLeft; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1290 | appendRun(bidi); |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1291 | bidi.dir = EuropeanNumber; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1292 | } |
| 1293 | default: |
| 1294 | break; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1295 | } |
| 1296 | bidi.eor = bidi.current; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1297 | bidi.status.eor = EuropeanNumber; |
| 1298 | if (bidi.dir == OtherNeutral) |
| 1299 | bidi.dir = LeftToRight; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1300 | break; |
| 1301 | } |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1302 | case ArabicNumber: |
| 1303 | dirCurrent = ArabicNumber; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1304 | switch (bidi.status.last) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1305 | case LeftToRight: |
| 1306 | if (bidi.context->dir() == LeftToRight) |
mjs | 89ab891 | 2005-11-28 04:37:33 +0000 | [diff] [blame] | 1307 | appendRun(bidi); |
| 1308 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1309 | case ArabicNumber: |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1310 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1311 | case RightToLeft: |
| 1312 | case RightToLeftArabic: |
| 1313 | case EuropeanNumber: |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 1314 | bidi.eor = bidi.last; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1315 | appendRun(bidi); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1316 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1317 | case CommonNumberSeparator: |
| 1318 | if (bidi.status.eor == ArabicNumber) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1319 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1320 | case EuropeanNumberSeparator: |
| 1321 | case EuropeanNumberTerminator: |
| 1322 | case BoundaryNeutral: |
| 1323 | case BlockSeparator: |
| 1324 | case SegmentSeparator: |
| 1325 | case WhiteSpaceNeutral: |
| 1326 | case OtherNeutral: |
| 1327 | if (bidi.status.eor != RightToLeft && bidi.status.eor != RightToLeftArabic) { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1328 | // run of L before neutrals, neutrals take embedding dir (N2) |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1329 | if (bidi.context->dir() == RightToLeft || bidi.status.lastStrong == RightToLeft |
| 1330 | || bidi.status.lastStrong == RightToLeftArabic) { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1331 | // the embedding direction is R |
| 1332 | // close the L run |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1333 | appendRun(bidi); |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1334 | // neutrals become an R run |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1335 | bidi.dir = RightToLeft; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1336 | } else { |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1337 | // the embedding direction is L |
| 1338 | // append neutrals to the L run and close it |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1339 | bidi.dir = LeftToRight; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1340 | } |
| 1341 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1342 | bidi.eor = bidi.last; |
| 1343 | appendRun(bidi); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1344 | default: |
| 1345 | break; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1346 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1347 | bidi.eor = bidi.current; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1348 | bidi.status.eor = ArabicNumber; |
| 1349 | if (bidi.dir == OtherNeutral) |
| 1350 | bidi.dir = ArabicNumber; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1351 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1352 | case EuropeanNumberSeparator: |
| 1353 | case CommonNumberSeparator: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1354 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1355 | case EuropeanNumberTerminator: |
| 1356 | if (bidi.status.last == EuropeanNumber) { |
| 1357 | dirCurrent = EuropeanNumber; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1358 | bidi.eor = bidi.current; |
| 1359 | bidi.status.eor = dirCurrent; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1360 | } else if (bidi.status.last != EuropeanNumberTerminator) |
darin | e4fa9e2 | 2005-12-16 18:18:50 +0000 | [diff] [blame] | 1361 | bidi.lastBeforeET = emptyRun ? bidi.eor : bidi.last; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1362 | break; |
| 1363 | |
| 1364 | // boundary neutrals should be ignored |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1365 | case BoundaryNeutral: |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 1366 | if (bidi.eor == bidi.last) |
| 1367 | bidi.eor = bidi.current; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1368 | break; |
| 1369 | // neutrals |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1370 | case BlockSeparator: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1371 | // ### what do we do with newline and paragraph seperators that come to here? |
| 1372 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1373 | case SegmentSeparator: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1374 | // ### implement rule L1 |
| 1375 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1376 | case WhiteSpaceNeutral: |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 1377 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1378 | case OtherNeutral: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | default: |
| 1381 | break; |
| 1382 | } |
| 1383 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1384 | if (pastEnd) { |
| 1385 | if (bidi.eor == bidi.current) { |
| 1386 | if (!bidi.reachedEndOfLine) { |
| 1387 | bidi.eor = bidi.endOfLine; |
| 1388 | switch (bidi.status.eor) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1389 | case LeftToRight: |
| 1390 | case RightToLeft: |
| 1391 | case ArabicNumber: |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1392 | bidi.dir = bidi.status.eor; |
| 1393 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1394 | case EuropeanNumber: |
| 1395 | bidi.dir = bidi.status.lastStrong == LeftToRight ? LeftToRight : EuropeanNumber; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1396 | break; |
| 1397 | default: |
| 1398 | assert(false); |
| 1399 | } |
| 1400 | appendRun(bidi); |
| 1401 | } |
| 1402 | bidi = stateAtEnd; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1403 | bidi.dir = OtherNeutral; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1404 | break; |
| 1405 | } |
| 1406 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1407 | |
| 1408 | // set status.last as needed. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1409 | switch (dirCurrent) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1410 | case EuropeanNumberTerminator: |
| 1411 | if (bidi.status.last != EuropeanNumber) |
| 1412 | bidi.status.last = EuropeanNumberTerminator; |
ggaren | ef026b2 | 2005-07-06 00:21:53 +0000 | [diff] [blame] | 1413 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1414 | case EuropeanNumberSeparator: |
| 1415 | case CommonNumberSeparator: |
| 1416 | case SegmentSeparator: |
| 1417 | case WhiteSpaceNeutral: |
| 1418 | case OtherNeutral: |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1419 | switch(bidi.status.last) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1420 | case LeftToRight: |
| 1421 | case RightToLeft: |
| 1422 | case RightToLeftArabic: |
| 1423 | case EuropeanNumber: |
| 1424 | case ArabicNumber: |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1425 | bidi.status.last = dirCurrent; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1426 | break; |
| 1427 | default: |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1428 | bidi.status.last = OtherNeutral; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1429 | } |
| 1430 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1431 | case NonSpacingMark: |
| 1432 | case BoundaryNeutral: |
| 1433 | case RightToLeftEmbedding: |
| 1434 | case LeftToRightEmbedding: |
| 1435 | case RightToLeftOverride: |
| 1436 | case LeftToRightOverride: |
| 1437 | case PopDirectionalFormat: |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1438 | // ignore these |
| 1439 | break; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1440 | case EuropeanNumber: |
rjw | 2028aa4 | 2003-01-14 21:14:16 +0000 | [diff] [blame] | 1441 | // fall through |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1442 | default: |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1443 | bidi.status.last = dirCurrent; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1444 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1445 | |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1446 | bidi.last = bidi.current; |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1447 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1448 | if (emptyRun && !(dirCurrent == RightToLeftEmbedding |
| 1449 | || dirCurrent == LeftToRightEmbedding |
| 1450 | || dirCurrent == RightToLeftOverride |
| 1451 | || dirCurrent == LeftToRightOverride |
| 1452 | || dirCurrent == PopDirectionalFormat)) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1453 | bidi.sor = bidi.current; |
| 1454 | emptyRun = false; |
| 1455 | } |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1456 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1457 | // this causes the operator ++ to open and close embedding levels as needed |
| 1458 | // for the CSS unicode-bidi property |
| 1459 | bidi.adjustEmbedding = true; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1460 | bidi.current.increment(bidi); |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 1461 | bidi.adjustEmbedding = false; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1462 | if (emptyRun && (dirCurrent == RightToLeftEmbedding |
| 1463 | || dirCurrent == LeftToRightEmbedding |
| 1464 | || dirCurrent == RightToLeftOverride |
| 1465 | || dirCurrent == LeftToRightOverride |
| 1466 | || dirCurrent == PopDirectionalFormat)) { |
darin | ef0c09f | 2005-10-09 01:46:17 +0000 | [diff] [blame] | 1467 | // exclude the embedding char itself from the new run so that ATSUI will never see it |
| 1468 | bidi.eor.obj = 0; |
| 1469 | bidi.last = bidi.current; |
| 1470 | bidi.sor = bidi.current; |
| 1471 | } |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1472 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1473 | if (!pastEnd && (bidi.current == end || bidi.current.atEnd())) { |
| 1474 | if (emptyRun) |
| 1475 | break; |
| 1476 | stateAtEnd = bidi; |
| 1477 | bidi.endOfLine = bidi.last; |
| 1478 | pastEnd = true; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1479 | } |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1480 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1481 | |
ddkilzer | fe11506 | 2006-07-14 04:42:01 +0000 | [diff] [blame] | 1482 | sLogicallyLastBidiRun = sLastBidiRun; |
| 1483 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1484 | // reorder line according to run structure... |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1485 | // do not reverse for visually ordered web sites |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1486 | if (!style()->visuallyOrdered()) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1487 | |
| 1488 | // first find highest and lowest levels |
darin | 479ef85 | 2006-01-30 06:06:32 +0000 | [diff] [blame] | 1489 | unsigned char levelLow = 128; |
| 1490 | unsigned char levelHigh = 0; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1491 | BidiRun* r = sFirstBidiRun; |
| 1492 | while (r) { |
| 1493 | if (r->level > levelHigh) |
| 1494 | levelHigh = r->level; |
| 1495 | if (r->level < levelLow) |
| 1496 | levelLow = r->level; |
| 1497 | r = r->nextRun; |
| 1498 | } |
| 1499 | |
| 1500 | // implements reordering of the line (L2 according to Bidi spec): |
| 1501 | // L2. From the highest level found in the text to the lowest odd level on each line, |
| 1502 | // reverse any contiguous sequence of characters that are at that level or higher. |
| 1503 | |
| 1504 | // reversing is only done up to the lowest odd level |
| 1505 | if (!(levelLow%2)) |
| 1506 | levelLow++; |
| 1507 | |
| 1508 | int count = sBidiRunCount - 1; |
| 1509 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1510 | while (levelHigh >= levelLow) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1511 | int i = 0; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 1512 | BidiRun* currRun = sFirstBidiRun; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1513 | while (i < count) { |
| 1514 | while (i < count && currRun && currRun->level < levelHigh) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1515 | i++; |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 1516 | currRun = currRun->nextRun; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1517 | } |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 1518 | int start = i; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1519 | while (i <= count && currRun && currRun->level >= levelHigh) { |
hyatt | 2f1e710 | 2003-02-20 01:27:03 +0000 | [diff] [blame] | 1520 | i++; |
| 1521 | currRun = currRun->nextRun; |
| 1522 | } |
| 1523 | int end = i-1; |
| 1524 | reverseRuns(start, end); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1525 | } |
| 1526 | levelHigh--; |
| 1527 | } |
| 1528 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1529 | bidi.endOfLine.obj = 0; |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1530 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1531 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1532 | static void buildCompactRuns(RenderObject* compactObj, BidiState& bidi) |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1533 | { |
| 1534 | sBuildingCompactRuns = true; |
| 1535 | if (!compactObj->isRenderBlock()) { |
| 1536 | // Just append a run for our object. |
| 1537 | isLineEmpty = false; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1538 | addRun(new (compactObj->renderArena()) BidiRun(0, compactObj->length(), compactObj, bidi.context.get(), bidi.dir)); |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1539 | } |
| 1540 | else { |
| 1541 | // Format the compact like it is its own single line. We build up all the runs for |
| 1542 | // the little compact and then reorder them for bidi. |
| 1543 | RenderBlock* compactBlock = static_cast<RenderBlock*>(compactObj); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1544 | bidi.adjustEmbedding = true; |
| 1545 | BidiIterator start(compactBlock, bidiFirst(compactBlock, bidi), 0); |
| 1546 | bidi.adjustEmbedding = false; |
darin | 8341f37 | 2003-04-29 18:30:31 +0000 | [diff] [blame] | 1547 | BidiIterator end = start; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1548 | |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1549 | betweenMidpoints = false; |
| 1550 | isLineEmpty = true; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1551 | previousLineBrokeCleanly = true; |
hyatt | 01eff98 | 2003-03-14 20:13:23 +0000 | [diff] [blame] | 1552 | |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1553 | end = compactBlock->findNextLineBreak(start, bidi); |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1554 | if (!isLineEmpty) |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1555 | compactBlock->bidiReorderLine(start, end, bidi); |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1556 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1557 | |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1558 | sCompactFirstBidiRun = sFirstBidiRun; |
| 1559 | sCompactLastBidiRun = sLastBidiRun; |
| 1560 | sCompactBidiRunCount = sBidiRunCount; |
| 1561 | |
| 1562 | sNumMidpoints = 0; |
| 1563 | sCurrMidpoint = 0; |
| 1564 | betweenMidpoints = false; |
| 1565 | sBuildingCompactRuns = false; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
hyatt | 673184e | 2006-01-14 22:07:08 +0000 | [diff] [blame] | 1568 | IntRect RenderBlock::layoutInlineChildren(bool relayoutChildren) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1569 | { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1570 | BidiState bidi; |
| 1571 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1572 | bool useRepaintRect = false; |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1573 | int repaintTop = 0; |
| 1574 | int repaintBottom = 0; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1575 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1576 | m_overflowHeight = 0; |
| 1577 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1578 | invalidateVerticalPositions(); |
hyatt | dd7dfe9 | 2003-11-16 20:48:12 +0000 | [diff] [blame] | 1579 | |
| 1580 | m_height = borderTop() + paddingTop(); |
hyatt | f9f247b | 2007-01-12 22:53:40 +0000 | [diff] [blame] | 1581 | int toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight(); |
hyatt | dd7dfe9 | 2003-11-16 20:48:12 +0000 | [diff] [blame] | 1582 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1583 | // Figure out if we should clear out our line boxes. |
| 1584 | // FIXME: Handle resize eventually! |
| 1585 | // FIXME: Do something better when floats are present. |
hyatt | 452d311 | 2006-07-11 01:22:07 +0000 | [diff] [blame] | 1586 | bool fullLayout = !firstLineBox() || !firstChild() || selfNeedsLayout() || relayoutChildren || containsFloats(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1587 | if (fullLayout) |
| 1588 | deleteLineBoxes(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1589 | |
| 1590 | // Text truncation only kicks in if your overflow isn't visible and your text-overflow-mode isn't |
| 1591 | // clip. |
| 1592 | // FIXME: CSS3 says that descendants that are clipped must also know how to truncate. This is insanely |
| 1593 | // difficult to figure out (especially in the middle of doing layout), and is really an esoteric pile of nonsense |
| 1594 | // anyway, so we won't worry about following the draft here. |
| 1595 | bool hasTextOverflow = style()->textOverflow() && hasOverflowClip(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1596 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1597 | // Walk all the lines and delete our ellipsis line boxes if they exist. |
| 1598 | if (hasTextOverflow) |
| 1599 | deleteEllipsisLineBoxes(); |
| 1600 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1601 | if (firstChild()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1602 | // layout replaced elements |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 1603 | bool endOfInline = false; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1604 | RenderObject *o = bidiFirst(this, bidi, false); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1605 | bool hasFloat = false; |
| 1606 | while (o) { |
| 1607 | if (o->isReplaced() || o->isFloating() || o->isPositioned()) { |
hyatt | 89377f1 | 2002-12-13 21:24:40 +0000 | [diff] [blame] | 1608 | if (relayoutChildren || o->style()->width().isPercent() || o->style()->height().isPercent()) |
hyatt | adbb2ef | 2003-11-18 09:21:44 +0000 | [diff] [blame] | 1609 | o->setChildNeedsLayout(true, false); |
hyatt | 3ac0135 | 2003-03-22 01:37:33 +0000 | [diff] [blame] | 1610 | if (o->isPositioned()) |
| 1611 | o->containingBlock()->insertPositionedObject(o); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1612 | else { |
| 1613 | if (o->isFloating()) |
| 1614 | hasFloat = true; |
| 1615 | else if (fullLayout || o->needsLayout()) // Replaced elements |
| 1616 | o->dirtyLineBoxes(fullLayout); |
hyatt | 390427a | 2003-05-03 18:33:42 +0000 | [diff] [blame] | 1617 | o->layoutIfNeeded(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1618 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1619 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1620 | else if (o->isText() || (o->isInlineFlow() && !endOfInline)) { |
| 1621 | if (fullLayout || o->selfNeedsLayout()) |
| 1622 | o->dirtyLineBoxes(fullLayout); |
hyatt | f4fe67f | 2003-10-07 04:43:23 +0000 | [diff] [blame] | 1623 | o->setNeedsLayout(false); |
hyatt | f4fe67f | 2003-10-07 04:43:23 +0000 | [diff] [blame] | 1624 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1625 | o = bidiNext(this, o, bidi, false, &endOfInline); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1628 | if (hasFloat) |
| 1629 | fullLayout = true; // FIXME: Will need to find a way to optimize floats some day. |
| 1630 | |
hyatt | 837eb36 | 2004-05-21 22:17:10 +0000 | [diff] [blame] | 1631 | if (fullLayout && !selfNeedsLayout()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1632 | setNeedsLayout(true, false); // Mark ourselves as needing a full layout. This way we'll repaint like |
| 1633 | // we're supposed to. |
hyatt | 837eb36 | 2004-05-21 22:17:10 +0000 | [diff] [blame] | 1634 | if (!document()->view()->needsFullRepaint() && m_layer) { |
| 1635 | // Because we waited until we were already inside layout to discover |
| 1636 | // that the block really needed a full layout, we missed our chance to repaint the layer |
| 1637 | // before layout started. Luckily the layer has cached the repaint rect for its original |
| 1638 | // 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] | 1639 | RenderView* c = view(); |
sfalken | 6f98c4d | 2007-01-11 01:39:58 +0000 | [diff] [blame] | 1640 | if (c && !c->printing()) |
hyatt | 837eb36 | 2004-05-21 22:17:10 +0000 | [diff] [blame] | 1641 | c->repaintViewRectangle(m_layer->repaintRect()); |
| 1642 | } |
| 1643 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1644 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1645 | BidiContext *startEmbed; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1646 | if (style()->direction() == LTR) { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1647 | startEmbed = new BidiContext(0, LeftToRight, NULL, style()->unicodeBidi() == Override); |
| 1648 | bidi.status.eor = LeftToRight; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1649 | } else { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1650 | startEmbed = new BidiContext(1, RightToLeft, NULL, style()->unicodeBidi() == Override); |
| 1651 | bidi.status.eor = RightToLeft; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1652 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1653 | |
mjs | 08191d5 | 2006-03-06 02:53:41 +0000 | [diff] [blame] | 1654 | bidi.status.lastStrong = startEmbed->dir(); |
| 1655 | bidi.status.last = startEmbed->dir(); |
| 1656 | bidi.status.eor = startEmbed->dir(); |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1657 | bidi.context = startEmbed; |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1658 | bidi.dir = OtherNeutral; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1659 | |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1660 | if (!smidpoints) |
darin | 91298e5 | 2006-06-12 01:10:17 +0000 | [diff] [blame] | 1661 | smidpoints = new Vector<BidiIterator>(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1662 | |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1663 | sNumMidpoints = 0; |
| 1664 | sCurrMidpoint = 0; |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1665 | sCompactFirstBidiRun = sCompactLastBidiRun = 0; |
| 1666 | sCompactBidiRunCount = 0; |
hyatt | 01eff98 | 2003-03-14 20:13:23 +0000 | [diff] [blame] | 1667 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1668 | // We want to skip ahead to the first dirty line |
| 1669 | BidiIterator start; |
| 1670 | RootInlineBox* startLine = determineStartPosition(fullLayout, start, bidi); |
| 1671 | |
| 1672 | // We also find the first clean line and extract these lines. We will add them back |
| 1673 | // if we determine that we're able to synchronize after handling all our dirty lines. |
| 1674 | BidiIterator cleanLineStart; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1675 | BidiStatus cleanLineBidiStatus; |
| 1676 | BidiContext* cleanLineBidiContext; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1677 | int endLineYPos; |
| 1678 | RootInlineBox* endLine = (fullLayout || !startLine) ? |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1679 | 0 : determineEndPosition(startLine, cleanLineStart, cleanLineBidiStatus, cleanLineBidiContext, endLineYPos); |
| 1680 | if (endLine && cleanLineBidiContext) |
| 1681 | cleanLineBidiContext->ref(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1682 | if (startLine) { |
| 1683 | useRepaintRect = true; |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1684 | repaintTop = m_height; |
| 1685 | repaintBottom = m_height; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1686 | RenderArena* arena = renderArena(); |
| 1687 | RootInlineBox* box = startLine; |
| 1688 | while (box) { |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1689 | repaintTop = min(repaintTop, box->topOverflow()); |
| 1690 | repaintBottom = max(repaintBottom, box->bottomOverflow()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1691 | RootInlineBox* next = box->nextRootBox(); |
| 1692 | box->deleteLine(arena); |
| 1693 | box = next; |
| 1694 | } |
| 1695 | startLine = 0; |
| 1696 | } |
| 1697 | |
| 1698 | BidiIterator end = start; |
| 1699 | |
| 1700 | bool endLineMatched = false; |
| 1701 | while (!end.atEnd()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1702 | start = end; |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1703 | if (endLine && (endLineMatched = matchedEndLine(start, bidi.status, bidi.context.get(), cleanLineStart, cleanLineBidiStatus, cleanLineBidiContext, endLine, endLineYPos, repaintBottom, repaintTop))) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1704 | break; |
| 1705 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1706 | betweenMidpoints = false; |
| 1707 | isLineEmpty = true; |
hyatt | 75c30b6 | 2004-07-16 20:15:34 +0000 | [diff] [blame] | 1708 | if (m_firstLine && firstChild() && firstChild()->isCompact() && firstChild()->isRenderBlock()) { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1709 | buildCompactRuns(firstChild(), bidi); |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1710 | start.obj = firstChild()->nextSibling(); |
| 1711 | end = start; |
| 1712 | } |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1713 | end = findNextLineBreak(start, bidi); |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 1714 | if (start.atEnd()) { |
| 1715 | deleteBidiRuns(renderArena()); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1716 | break; |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 1717 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1718 | if (!isLineEmpty) { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1719 | bidiReorderLine(start, end, bidi); |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1720 | |
| 1721 | // Now that the runs have been ordered, we create the line boxes. |
| 1722 | // At the same time we figure out where border/padding/margin should be applied for |
| 1723 | // inline flow boxes. |
| 1724 | if (sCompactFirstBidiRun) { |
| 1725 | // We have a compact line sharing this line. Link the compact runs |
| 1726 | // to our runs to create a single line of runs. |
| 1727 | sCompactLastBidiRun->nextRun = sFirstBidiRun; |
| 1728 | sFirstBidiRun = sCompactFirstBidiRun; |
| 1729 | sBidiRunCount += sCompactBidiRunCount; |
| 1730 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1731 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1732 | RootInlineBox* lineBox = 0; |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1733 | if (sBidiRunCount) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1734 | lineBox = constructLine(start, end); |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1735 | if (lineBox) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1736 | lineBox->setEndsWithBreak(previousLineBrokeCleanly); |
| 1737 | |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1738 | // Now we position all of our text runs horizontally. |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1739 | computeHorizontalPositionsForLine(lineBox, bidi); |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1740 | |
| 1741 | // Now position our text runs vertically. |
| 1742 | computeVerticalPositionsForLine(lineBox); |
hyatt | bddcc61 | 2006-07-24 23:16:15 +0000 | [diff] [blame] | 1743 | |
| 1744 | #if PLATFORM(MAC) |
| 1745 | // Highlight acts as an overflow inflation. |
| 1746 | if (style()->highlight() != nullAtom) |
| 1747 | lineBox->addHighlightOverflow(); |
| 1748 | #endif |
hyatt | dfb0905 | 2003-03-11 02:58:59 +0000 | [diff] [blame] | 1749 | } |
| 1750 | } |
ggaren | ec11e5b | 2007-02-25 02:14:54 +0000 | [diff] [blame] | 1751 | |
| 1752 | deleteBidiRuns(renderArena()); |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1753 | |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 1754 | if (end == start) { |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1755 | bidi.adjustEmbedding = true; |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 1756 | end.increment(bidi); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1757 | bidi.adjustEmbedding = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1758 | } |
hyatt | 35a85e5 | 2003-02-14 19:43:07 +0000 | [diff] [blame] | 1759 | |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1760 | if (lineBox) { |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1761 | lineBox->setLineBreakInfo(end.obj, end.pos, &bidi.status, bidi.context.get()); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1762 | if (useRepaintRect) { |
| 1763 | repaintTop = min(repaintTop, lineBox->topOverflow()); |
| 1764 | repaintBottom = max(repaintBottom, lineBox->bottomOverflow()); |
| 1765 | } |
| 1766 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1767 | |
hyatt | 35a85e5 | 2003-02-14 19:43:07 +0000 | [diff] [blame] | 1768 | m_firstLine = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 1769 | newLine(); |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1770 | } |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 1771 | |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1772 | sNumMidpoints = 0; |
| 1773 | sCurrMidpoint = 0; |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 1774 | sCompactFirstBidiRun = sCompactLastBidiRun = 0; |
| 1775 | sCompactBidiRunCount = 0; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1776 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1777 | |
| 1778 | if (endLine) { |
| 1779 | if (endLineMatched) { |
| 1780 | // Attach all the remaining lines, and then adjust their y-positions as needed. |
| 1781 | for (RootInlineBox* line = endLine; line; line = line->nextRootBox()) |
| 1782 | line->attachLine(); |
| 1783 | |
| 1784 | // Now apply the offset to each line if needed. |
| 1785 | int delta = m_height - endLineYPos; |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 1786 | if (delta) { |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1787 | for (RootInlineBox* line = endLine; line; line = line->nextRootBox()) { |
| 1788 | repaintTop = min(repaintTop, line->topOverflow() + (delta < 0 ? delta : 0)); |
| 1789 | repaintBottom = max(repaintBottom, line->bottomOverflow() + (delta > 0 ? delta : 0)); |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 1790 | line->adjustPosition(0, delta); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1791 | } |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 1792 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1793 | m_height = lastRootBox()->blockHeight(); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1794 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1795 | // Delete all the remaining lines. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1796 | InlineRunBox* line = endLine; |
| 1797 | RenderArena* arena = renderArena(); |
| 1798 | while (line) { |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1799 | repaintTop = min(repaintTop, line->topOverflow()); |
| 1800 | repaintBottom = max(repaintBottom, line->bottomOverflow()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1801 | InlineRunBox* next = line->nextLineBox(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1802 | line->deleteLine(arena); |
| 1803 | line = next; |
| 1804 | } |
| 1805 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1806 | if (cleanLineBidiContext) |
| 1807 | cleanLineBidiContext->deref(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1808 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1809 | } |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 1810 | |
| 1811 | sNumMidpoints = 0; |
| 1812 | sCurrMidpoint = 0; |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1813 | |
hyatt | efa0088 | 2003-03-22 23:27:03 +0000 | [diff] [blame] | 1814 | // in case we have a float on the last line, it might not be positioned up to now. |
| 1815 | // This has to be done before adding in the bottom border/padding, or the float will |
| 1816 | // include the padding incorrectly. -dwh |
| 1817 | positionNewFloats(); |
| 1818 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1819 | // Now add in the bottom border/padding. |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1820 | m_height += toAdd; |
| 1821 | |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1822 | // Always make sure this is at least our height. |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 1823 | m_overflowHeight = max(m_height, m_overflowHeight); |
hyatt | a70560a | 2002-11-20 01:53:20 +0000 | [diff] [blame] | 1824 | |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 1825 | // See if any lines spill out of the block. If so, we need to update our overflow width. |
| 1826 | checkLinesForOverflow(); |
| 1827 | |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1828 | IntRect repaintRect(0, 0, 0, 0); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1829 | if (useRepaintRect) { |
eseidel | cf075d0 | 2006-03-26 22:58:26 +0000 | [diff] [blame] | 1830 | repaintRect.setX(m_overflowLeft); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1831 | repaintRect.setWidth(m_overflowWidth - m_overflowLeft); |
| 1832 | repaintRect.setY(repaintTop); |
| 1833 | repaintRect.setHeight(repaintBottom - repaintTop); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1834 | } |
hyatt | a6960b1 | 2004-12-07 02:09:10 +0000 | [diff] [blame] | 1835 | |
adele | 7a470a7 | 2006-04-20 22:22:14 +0000 | [diff] [blame] | 1836 | if (!firstLineBox() && hasLineIfEmpty()) |
adele | 05abee3 | 2006-08-25 23:44:05 +0000 | [diff] [blame] | 1837 | m_height += lineHeight(true, true); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 1838 | |
| 1839 | // See if we have any lines that spill out of our block. If we do, then we will possibly need to |
| 1840 | // truncate text. |
| 1841 | if (hasTextOverflow) |
| 1842 | checkLinesForTextOverflow(); |
| 1843 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1844 | return repaintRect; |
| 1845 | |
weinig | f18aae3 | 2006-08-03 21:55:57 +0000 | [diff] [blame] | 1846 | #if defined(BIDI_DEBUG) && BIDI_DEBUG > 1 |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 1847 | kdDebug(6041) << " ------- bidi end " << this << " -------" << endl; |
darin | f028f81 | 2002-06-10 20:08:04 +0000 | [diff] [blame] | 1848 | #endif |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1851 | RootInlineBox* RenderBlock::determineStartPosition(bool fullLayout, BidiIterator& start, BidiState& bidi) |
| 1852 | { |
| 1853 | RootInlineBox* curr = 0; |
| 1854 | RootInlineBox* last = 0; |
| 1855 | RenderObject* startObj = 0; |
| 1856 | int pos = 0; |
| 1857 | |
| 1858 | if (fullLayout) { |
| 1859 | // Nuke all our lines. |
| 1860 | if (firstRootBox()) { |
| 1861 | RenderArena* arena = renderArena(); |
| 1862 | curr = firstRootBox(); |
| 1863 | while (curr) { |
| 1864 | RootInlineBox* next = curr->nextRootBox(); |
| 1865 | curr->deleteLine(arena); |
| 1866 | curr = next; |
| 1867 | } |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 1868 | ASSERT(!firstLineBox() && !lastLineBox()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1869 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1870 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1871 | for (curr = firstRootBox(); curr && !curr->isDirty(); curr = curr->nextRootBox()); |
| 1872 | if (curr) { |
| 1873 | // We have a dirty line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1874 | if (RootInlineBox* prevRootBox = curr->prevRootBox()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1875 | // We have a previous line. |
mjs | 9f78dd9 | 2007-02-12 04:06:07 +0000 | [diff] [blame] | 1876 | if (!prevRootBox->endsWithBreak() || prevRootBox->lineBreakObj()->isText() && prevRootBox->lineBreakPos() >= static_cast<RenderText*>(prevRootBox->lineBreakObj())->textLength()) |
| 1877 | // The previous line didn't break cleanly or broke at a newline |
| 1878 | // that has been deleted, so treat it as dirty too. |
| 1879 | curr = prevRootBox; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1880 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1881 | } else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1882 | // No dirty lines were found. |
| 1883 | // If the last line didn't break cleanly, treat it as dirty. |
| 1884 | if (lastRootBox() && !lastRootBox()->endsWithBreak()) |
| 1885 | curr = lastRootBox(); |
| 1886 | } |
| 1887 | |
| 1888 | // If we have no dirty lines, then last is just the last root box. |
| 1889 | last = curr ? curr->prevRootBox() : lastRootBox(); |
| 1890 | } |
| 1891 | |
| 1892 | m_firstLine = !last; |
| 1893 | previousLineBrokeCleanly = !last || last->endsWithBreak(); |
| 1894 | if (last) { |
| 1895 | m_height = last->blockHeight(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1896 | startObj = last->lineBreakObj(); |
| 1897 | pos = last->lineBreakPos(); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1898 | bidi.status = last->lineBreakBidiStatus(); |
| 1899 | bidi.context = last->lineBreakBidiContext(); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1900 | } else { |
| 1901 | bidi.adjustEmbedding = true; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 1902 | startObj = bidiFirst(this, bidi, 0); |
darin | dde0150 | 2005-12-18 22:55:35 +0000 | [diff] [blame] | 1903 | bidi.adjustEmbedding = false; |
| 1904 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1905 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1906 | start = BidiIterator(this, startObj, pos); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1907 | |
| 1908 | return curr; |
| 1909 | } |
| 1910 | |
| 1911 | RootInlineBox* RenderBlock::determineEndPosition(RootInlineBox* startLine, BidiIterator& cleanLineStart, |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1912 | BidiStatus& cleanLineBidiStatus, BidiContext*& cleanLineBidiContext, |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1913 | int& yPos) |
| 1914 | { |
| 1915 | RootInlineBox* last = 0; |
hyatt | a6960b1 | 2004-12-07 02:09:10 +0000 | [diff] [blame] | 1916 | if (!startLine) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1917 | last = 0; |
| 1918 | else { |
hyatt | 04420ca | 2004-07-16 00:05:42 +0000 | [diff] [blame] | 1919 | for (RootInlineBox* curr = startLine->nextRootBox(); curr; curr = curr->nextRootBox()) { |
| 1920 | if (curr->isDirty()) |
| 1921 | last = 0; |
| 1922 | else if (!last) |
| 1923 | last = curr; |
| 1924 | } |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | if (!last) |
| 1928 | return 0; |
| 1929 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1930 | RootInlineBox* prev = last->prevRootBox(); |
| 1931 | cleanLineStart = BidiIterator(this, prev->lineBreakObj(), prev->lineBreakPos()); |
| 1932 | cleanLineBidiStatus = prev->lineBreakBidiStatus(); |
| 1933 | cleanLineBidiContext = prev->lineBreakBidiContext(); |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1934 | yPos = prev->blockHeight(); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1935 | |
| 1936 | for (RootInlineBox* line = last; line; line = line->nextRootBox()) |
| 1937 | line->extractLine(); // Disconnect all line boxes from their render objects while preserving |
| 1938 | // their connections to one another. |
| 1939 | |
| 1940 | return last; |
| 1941 | } |
| 1942 | |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1943 | bool RenderBlock::matchedEndLine(const BidiIterator& start, const BidiStatus& status, BidiContext* context, |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1944 | const BidiIterator& endLineStart, const BidiStatus& endLineStatus, BidiContext* endLineContext, |
| 1945 | RootInlineBox*& endLine, int& endYPos, int& repaintBottom, int& repaintTop) |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1946 | { |
hyatt | 4073160 | 2005-04-18 18:12:42 +0000 | [diff] [blame] | 1947 | if (start == endLineStart) |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1948 | return status == endLineStatus && *context == *endLineContext; |
hyatt | 4073160 | 2005-04-18 18:12:42 +0000 | [diff] [blame] | 1949 | else { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1950 | // The first clean line doesn't match, but we can check a handful of following lines to try |
| 1951 | // to match back up. |
| 1952 | static int numLines = 8; // The # of lines we're willing to match against. |
| 1953 | RootInlineBox* line = endLine; |
| 1954 | for (int i = 0; i < numLines && line; i++, line = line->nextRootBox()) { |
| 1955 | if (line->lineBreakObj() == start.obj && line->lineBreakPos() == start.pos) { |
| 1956 | // We have a match. |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 1957 | if (line->lineBreakBidiStatus() != status || *line->lineBreakBidiContext() != *context) |
| 1958 | return false; // ...but the bidi state doesn't match. |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1959 | RootInlineBox* result = line->nextRootBox(); |
| 1960 | |
| 1961 | // Set our yPos to be the block height of endLine. |
| 1962 | if (result) |
| 1963 | endYPos = line->blockHeight(); |
| 1964 | |
| 1965 | // Now delete the lines that we failed to sync. |
| 1966 | RootInlineBox* boxToDelete = endLine; |
| 1967 | RenderArena* arena = renderArena(); |
| 1968 | while (boxToDelete && boxToDelete != result) { |
ap | 9059f6f | 2006-07-24 16:55:02 +0000 | [diff] [blame] | 1969 | repaintTop = min(repaintTop, boxToDelete->topOverflow()); |
| 1970 | repaintBottom = max(repaintBottom, boxToDelete->bottomOverflow()); |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 1971 | RootInlineBox* next = boxToDelete->nextRootBox(); |
| 1972 | boxToDelete->deleteLine(arena); |
| 1973 | boxToDelete = next; |
| 1974 | } |
| 1975 | |
| 1976 | endLine = result; |
| 1977 | return result; |
| 1978 | } |
| 1979 | } |
| 1980 | } |
| 1981 | return false; |
| 1982 | } |
| 1983 | |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 1984 | static inline bool skipNonBreakingSpace(BidiIterator &it) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1985 | { |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 1986 | if (it.obj->style()->nbspMode() != SPACE || it.current() != noBreakSpace) |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1987 | return false; |
| 1988 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1989 | // FIXME: This is bad. It makes nbsp inconsistent with space and won't work correctly |
| 1990 | // with m_minWidth/m_maxWidth. |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1991 | // Do not skip a non-breaking space if it is the first character |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 1992 | // on a line after a clean line break (or on the first line, since previousLineBrokeCleanly starts off |
| 1993 | // |true|). |
| 1994 | if (isLineEmpty && previousLineBrokeCleanly) |
kocienda | 498d198 | 2004-10-15 21:07:24 +0000 | [diff] [blame] | 1995 | return false; |
| 1996 | |
| 1997 | return true; |
kocienda | 9844008 | 2004-10-14 23:51:47 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
hyatt | d995321 | 2005-11-03 21:05:59 +0000 | [diff] [blame] | 2000 | static inline bool shouldCollapseWhiteSpace(const RenderStyle* style) |
| 2001 | { |
| 2002 | return style->collapseWhiteSpace() || (style->whiteSpace() == PRE_WRAP && (!isLineEmpty || !previousLineBrokeCleanly)); |
| 2003 | } |
| 2004 | |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2005 | static inline bool shouldPreserveNewline(RenderObject* object) |
| 2006 | { |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 2007 | #if ENABLE(SVG) |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2008 | if (object->isSVGText()) |
| 2009 | return false; |
| 2010 | #endif |
| 2011 | |
| 2012 | return object->style()->preserveNewline(); |
| 2013 | } |
| 2014 | |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2015 | int RenderBlock::skipWhitespace(BidiIterator &it, BidiState &bidi) |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2016 | { |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 2017 | // FIXME: The entire concept of the skipWhitespace function is flawed, since we really need to be building |
| 2018 | // line boxes even for containers that may ultimately collapse away. Otherwise we'll never get positioned |
| 2019 | // elements quite right. In other words, we need to build this function's work into the normal line |
| 2020 | // object iteration process. |
| 2021 | int w = lineWidth(m_height); |
hyatt | 81b2976 | 2007-02-20 01:41:26 +0000 | [diff] [blame] | 2022 | while (!it.atEnd() && (it.obj->isFloatingOrPositioned() || it.obj->isInlineFlow() || |
| 2023 | (shouldCollapseWhiteSpace(it.obj->style()) && !it.obj->isBR() && |
| 2024 | (it.current() == ' ' || it.current() == '\t' || (!shouldPreserveNewline(it.obj) && it.current() == '\n') || |
| 2025 | it.current() == softHyphen || skipNonBreakingSpace(it))))) { |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2026 | if (it.obj->isFloatingOrPositioned()) { |
| 2027 | RenderObject *o = it.obj; |
hyatt | 3b5905b | 2003-02-01 01:13:30 +0000 | [diff] [blame] | 2028 | // add to special objects... |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2029 | if (o->isFloating()) { |
hyatt | 3ac0135 | 2003-03-22 01:37:33 +0000 | [diff] [blame] | 2030 | insertFloatingObject(o); |
hyatt | 38e3263 | 2003-07-31 00:46:03 +0000 | [diff] [blame] | 2031 | positionNewFloats(); |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 2032 | w = lineWidth(m_height); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2033 | } |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2034 | else if (o->isPositioned()) { |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 2035 | // FIXME: The math here is actually not really right. It's a best-guess approximation that |
| 2036 | // will work for the common cases |
| 2037 | RenderObject* c = o->container(); |
| 2038 | if (c->isInlineFlow()) { |
| 2039 | // A relative positioned inline encloses us. In this case, we also have to determine our |
| 2040 | // position as though we were an inline. Set |staticX| and |staticY| on the relative positioned |
| 2041 | // inline so that we can obtain the value later. |
| 2042 | c->setStaticX(style()->direction() == LTR ? |
| 2043 | leftOffset(m_height) : rightOffset(m_height)); |
| 2044 | c->setStaticY(m_height); |
| 2045 | } |
| 2046 | |
| 2047 | if (o->hasStaticX()) { |
| 2048 | bool wasInline = o->style()->isOriginalDisplayInlineType(); |
| 2049 | if (wasInline) |
| 2050 | o->setStaticX(style()->direction() == LTR ? |
| 2051 | leftOffset(m_height) : |
| 2052 | width() - rightOffset(m_height)); |
| 2053 | else |
| 2054 | o->setStaticX(style()->direction() == LTR ? |
| 2055 | borderLeft() + paddingLeft() : |
| 2056 | borderRight() + paddingRight()); |
| 2057 | } |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2058 | if (o->hasStaticY()) |
| 2059 | o->setStaticY(m_height); |
| 2060 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2061 | } |
hyatt | 4b38169 | 2003-03-10 21:11:59 +0000 | [diff] [blame] | 2062 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2063 | bidi.adjustEmbedding = true; |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2064 | it.increment(bidi); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2065 | bidi.adjustEmbedding = false; |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2066 | } |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 2067 | return w; |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | BidiIterator RenderBlock::findNextLineBreak(BidiIterator &start, BidiState &bidi) |
| 2071 | { |
thatcher | 459b94a | 2005-10-13 22:07:51 +0000 | [diff] [blame] | 2072 | // eliminate spaces at beginning of line |
| 2073 | int width = skipWhitespace(start, bidi); |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2074 | int w = 0; |
| 2075 | int tmpW = 0; |
kocienda | e40cb94 | 2004-10-05 20:05:38 +0000 | [diff] [blame] | 2076 | |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 2077 | if (start.atEnd()) |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 2078 | return start; |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2079 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2080 | // This variable is used only if whitespace isn't set to PRE, and it tells us whether |
| 2081 | // or not we are currently ignoring whitespace. |
| 2082 | bool ignoringSpaces = false; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2083 | BidiIterator ignoreStart; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2084 | |
| 2085 | // This variable tracks whether the very last character we saw was a space. We use |
| 2086 | // this to detect when we encounter a second space so we know we have to terminate |
| 2087 | // a run. |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2088 | bool currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2089 | bool currentCharacterIsWS = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2090 | RenderObject* trailingSpaceObject = 0; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2091 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2092 | BidiIterator lBreak = start; |
| 2093 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2094 | RenderObject *o = start.obj; |
| 2095 | RenderObject *last = o; |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 2096 | RenderObject *previous = o; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2097 | int pos = start.pos; |
| 2098 | |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2099 | bool prevLineBrokeCleanly = previousLineBrokeCleanly; |
| 2100 | previousLineBrokeCleanly = false; |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 2101 | |
| 2102 | bool autoWrapWasEverTrueOnLine = false; |
hyatt | 01eff98 | 2003-03-14 20:13:23 +0000 | [diff] [blame] | 2103 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2104 | EWhiteSpace currWS = style()->whiteSpace(); |
| 2105 | EWhiteSpace lastWS = currWS; |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2106 | while (o) { |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2107 | currWS = o->isReplaced() ? o->parent()->style()->whiteSpace() : o->style()->whiteSpace(); |
| 2108 | lastWS = last->isReplaced() ? last->parent()->style()->whiteSpace() : last->style()->whiteSpace(); |
| 2109 | |
| 2110 | bool autoWrap = RenderStyle::autoWrap(currWS); |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 2111 | autoWrapWasEverTrueOnLine = autoWrapWasEverTrueOnLine || autoWrap; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2112 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 2113 | #if ENABLE(SVG) |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2114 | bool preserveNewline = o->isSVGText() ? false : RenderStyle::preserveNewline(currWS); |
| 2115 | #else |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2116 | bool preserveNewline = RenderStyle::preserveNewline(currWS); |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2117 | #endif |
| 2118 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2119 | bool collapseWhiteSpace = RenderStyle::collapseWhiteSpace(currWS); |
| 2120 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2121 | if (o->isBR()) { |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2122 | if (w + tmpW <= width) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2123 | lBreak.obj = o; |
| 2124 | lBreak.pos = 0; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2125 | lBreak.increment(bidi); |
| 2126 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2127 | // A <br> always breaks a line, so don't let the line be collapsed |
| 2128 | // 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] | 2129 | // get collapsed away. It only does this if the previous line broke |
| 2130 | // cleanly. Otherwise the <br> has no effect on whether the line is |
| 2131 | // empty or not. |
| 2132 | if (prevLineBrokeCleanly) |
| 2133 | isLineEmpty = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2134 | trailingSpaceObject = 0; |
hyatt | 0c3a986 | 2004-02-23 21:26:26 +0000 | [diff] [blame] | 2135 | previousLineBrokeCleanly = true; |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 2136 | |
| 2137 | if (!isLineEmpty) { |
| 2138 | // only check the clear status for non-empty lines. |
| 2139 | EClear clear = o->style()->clear(); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2140 | if (clear != CNONE) |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 2141 | m_clearStatus = (EClear) (m_clearStatus | clear); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2142 | } |
| 2143 | } |
| 2144 | goto end; |
| 2145 | } |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2146 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2147 | if (o->isFloatingOrPositioned()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2148 | // add to special objects... |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2149 | if (o->isFloating()) { |
hyatt | 3ac0135 | 2003-03-22 01:37:33 +0000 | [diff] [blame] | 2150 | insertFloatingObject(o); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2151 | // check if it fits in the current line. |
| 2152 | // If it does, position it now, otherwise, position |
| 2153 | // it after moving to next line (in newLine() func) |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2154 | if (o->width() + o->marginLeft() + o->marginRight() + w + tmpW <= width) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2155 | positionNewFloats(); |
| 2156 | width = lineWidth(m_height); |
| 2157 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2158 | } else if (o->isPositioned()) { |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 2159 | // If our original display wasn't an inline type, then we can |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2160 | // go ahead and determine our static x position now. |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 2161 | bool isInlineType = o->style()->isOriginalDisplayInlineType(); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2162 | bool needToSetStaticX = o->hasStaticX(); |
| 2163 | if (o->hasStaticX() && !isInlineType) { |
| 2164 | o->setStaticX(o->parent()->style()->direction() == LTR ? |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2165 | borderLeft() + paddingLeft() : |
| 2166 | borderRight() + paddingRight()); |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2167 | needToSetStaticX = false; |
| 2168 | } |
| 2169 | |
| 2170 | // If our original display was an INLINE type, then we can go ahead |
| 2171 | // and determine our static y position now. |
| 2172 | bool needToSetStaticY = o->hasStaticY(); |
| 2173 | if (o->hasStaticY() && isInlineType) { |
| 2174 | o->setStaticY(m_height); |
| 2175 | needToSetStaticY = false; |
| 2176 | } |
| 2177 | |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 2178 | bool needToCreateLineBox = needToSetStaticX || needToSetStaticY; |
| 2179 | RenderObject* c = o->container(); |
| 2180 | if (c->isInlineFlow() && (!needToSetStaticX || !needToSetStaticY)) |
| 2181 | needToCreateLineBox = true; |
| 2182 | |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2183 | // If we're ignoring spaces, we have to stop and include this object and |
| 2184 | // then start ignoring spaces again. |
hyatt | 853cd7d | 2004-11-05 02:59:48 +0000 | [diff] [blame] | 2185 | if (needToCreateLineBox) { |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 2186 | trailingSpaceObject = 0; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2187 | ignoreStart.obj = o; |
| 2188 | ignoreStart.pos = 0; |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 2189 | if (ignoringSpaces) { |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2190 | addMidpoint(ignoreStart); // Stop ignoring spaces. |
| 2191 | addMidpoint(ignoreStart); // Start ignoring again. |
hyatt | bc7f07f | 2003-05-27 20:04:26 +0000 | [diff] [blame] | 2192 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2193 | |
hyatt | 851816b | 2003-07-08 07:54:17 +0000 | [diff] [blame] | 2194 | } |
hyatt | 98ee7e4 | 2003-05-14 01:39:15 +0000 | [diff] [blame] | 2195 | } |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2196 | } else if (o->isInlineFlow()) { |
| 2197 | // Only empty inlines matter. We treat those similarly to replaced elements. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2198 | assert(!o->firstChild()); |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2199 | tmpW += o->marginLeft() + o->borderLeft() + o->paddingLeft() + |
| 2200 | o->marginRight() + o->borderRight() + o->paddingRight(); |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2201 | } else if (o->isReplaced()) { |
hyatt | de39634 | 2003-10-29 08:57:20 +0000 | [diff] [blame] | 2202 | // Break on replaced elements if either has normal white-space. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2203 | if (autoWrap || RenderStyle::autoWrap(lastWS)) { |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 2204 | w += tmpW; |
| 2205 | tmpW = 0; |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 2206 | lBreak.obj = o; |
| 2207 | lBreak.pos = 0; |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2210 | if (ignoringSpaces) { |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 2211 | BidiIterator startMid( 0, o, 0 ); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 2212 | addMidpoint(startMid); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2213 | } |
| 2214 | isLineEmpty = false; |
| 2215 | ignoringSpaces = false; |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2216 | currentCharacterIsSpace = false; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2217 | currentCharacterIsWS = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2218 | trailingSpaceObject = 0; |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 2219 | |
mjs | d26b297 | 2007-02-13 13:09:04 +0000 | [diff] [blame] | 2220 | if (o->isListMarker() && !static_cast<RenderListMarker*>(o)->isInside()) { |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 2221 | // The marker must not have an effect on whitespace at the start |
| 2222 | // of the line. We start ignoring spaces to make sure that any additional |
| 2223 | // spaces we see will be discarded. |
| 2224 | // |
| 2225 | // Optimize for a common case. If we can't find whitespace after the list |
| 2226 | // item, then this is all moot. -dwh |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2227 | RenderObject* next = bidiNext(start.block, o, bidi); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2228 | if (style()->collapseWhiteSpace() && next && !next->isBR() && next->isText() && static_cast<RenderText*>(next)->textLength() > 0) { |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 2229 | RenderText *nextText = static_cast<RenderText*>(next); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2230 | UChar nextChar = nextText->characters()[0]; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2231 | if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) { |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2232 | currentCharacterIsSpace = true; |
| 2233 | currentCharacterIsWS = true; |
| 2234 | ignoringSpaces = true; |
| 2235 | BidiIterator endMid( 0, o, 0 ); |
| 2236 | addMidpoint(endMid); |
| 2237 | } |
hyatt | e85e4a7 | 2002-12-08 02:06:16 +0000 | [diff] [blame] | 2238 | } |
justing | 244d3a3 | 2006-04-13 01:31:24 +0000 | [diff] [blame] | 2239 | } else |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2240 | tmpW += o->width() + o->marginLeft() + o->marginRight() + inlineWidth(o); |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2241 | } else if (o->isText()) { |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2242 | RenderText* t = static_cast<RenderText*>(o); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2243 | int strlen = t->textLength(); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2244 | int len = strlen - pos; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2245 | const UChar* str = t->characters(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2246 | |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2247 | const Font& f = t->style(m_firstLine)->font(); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2248 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2249 | int lastSpace = pos; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 2250 | int wordSpacing = o->style()->wordSpacing(); |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2251 | int lastSpaceWordSpacing = 0; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2252 | |
| 2253 | bool appliedStartWidth = pos > 0; // If the span originated on a previous line, |
| 2254 | // then assume the start width has been applied. |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2255 | int wrapW = tmpW + inlineWidth(o, !appliedStartWidth, true); |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 2256 | int nextBreakable = -1; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2257 | bool breakNBSP = autoWrap && o->style()->nbspMode() == SPACE; |
| 2258 | // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word, |
| 2259 | // which is only possible if the word is the first thing on the line, that is, if |w| is zero. |
| 2260 | bool breakWords = o->style()->wordWrap() == BREAK_WORD && ((autoWrap && !w) || currWS == PRE); |
| 2261 | bool midWordBreak = false; |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2262 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2263 | while (len) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2264 | bool previousCharacterIsSpace = currentCharacterIsSpace; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2265 | bool previousCharacterIsWS = currentCharacterIsWS; |
darin | 7ab3109 | 2006-05-10 04:59:57 +0000 | [diff] [blame] | 2266 | UChar c = str[pos]; |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2267 | currentCharacterIsSpace = c == ' ' || c == '\t' || (!preserveNewline && (c == '\n')); |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 2268 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2269 | if (!collapseWhiteSpace || !currentCharacterIsSpace) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2270 | isLineEmpty = false; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 2271 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2272 | // Check for soft hyphens. Go ahead and ignore them. |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2273 | if (c == softHyphen) { |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2274 | if (!ignoringSpaces) { |
| 2275 | // Ignore soft hyphens |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 2276 | BidiIterator endMid; |
| 2277 | if (pos > 0) |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2278 | endMid = BidiIterator(0, o, pos - 1); |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 2279 | else |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2280 | endMid = BidiIterator(0, previous, previous->isText() ? static_cast<RenderText*>(previous)->textLength() - 1 : 0); |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 2281 | // Two consecutive soft hyphens. Avoid overlapping midpoints. |
| 2282 | if (sNumMidpoints && smidpoints->at(sNumMidpoints - 1).obj == endMid.obj && smidpoints->at(sNumMidpoints - 1).pos > endMid.pos) |
| 2283 | sNumMidpoints--; |
| 2284 | else |
| 2285 | addMidpoint(endMid); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2286 | |
| 2287 | // Add the width up to but not including the hyphen. |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2288 | tmpW += t->width(lastSpace, pos - lastSpace, f, w + tmpW) + lastSpaceWordSpacing; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2289 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2290 | // 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] | 2291 | // on the line if it shows when we break. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2292 | if (autoWrap) |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2293 | tmpW += t->width(pos, 1, f, w + tmpW); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2294 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2295 | BidiIterator startMid(0, o, pos + 1); |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2296 | addMidpoint(startMid); |
| 2297 | } |
| 2298 | |
| 2299 | pos++; |
| 2300 | len--; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2301 | lastSpaceWordSpacing = 0; |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2302 | lastSpace = pos; // Cheesy hack to prevent adding in widths of the run twice. |
| 2303 | continue; |
| 2304 | } |
| 2305 | |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 2306 | bool applyWordSpacing = false; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2307 | |
darin | f9e5d6c | 2007-01-09 14:54:26 +0000 | [diff] [blame] | 2308 | currentCharacterIsWS = currentCharacterIsSpace || (breakNBSP && c == noBreakSpace); |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2309 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2310 | if (breakWords && !midWordBreak) { |
harrison | 208ea79 | 2005-07-29 23:42:59 +0000 | [diff] [blame] | 2311 | wrapW += t->width(pos, 1, f, w+wrapW); |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2312 | midWordBreak = w + wrapW > width; |
| 2313 | } |
darin | 47ece0d | 2005-09-04 07:42:31 +0000 | [diff] [blame] | 2314 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2315 | bool betweenWords = c == '\n' || (currWS != PRE && isBreakable(str, pos, strlen, nextBreakable, breakNBSP)); |
| 2316 | |
| 2317 | if (betweenWords || midWordBreak) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2318 | bool stoppedIgnoringSpaces = false; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2319 | if (ignoringSpaces) { |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2320 | if (!currentCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2321 | // Stop ignoring spaces and begin at this |
| 2322 | // new point. |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 2323 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2324 | lastSpaceWordSpacing = 0; |
hyatt | 48710d6 | 2003-08-21 09:17:13 +0000 | [diff] [blame] | 2325 | lastSpace = pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2326 | BidiIterator startMid(0, o, pos); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 2327 | addMidpoint(startMid); |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2328 | stoppedIgnoringSpaces = true; |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2329 | } else { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2330 | // Just keep ignoring these spaces. |
| 2331 | pos++; |
| 2332 | len--; |
| 2333 | continue; |
| 2334 | } |
| 2335 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2336 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2337 | int additionalTmpW = t->width(lastSpace, pos - lastSpace, f, w+tmpW) + lastSpaceWordSpacing; |
| 2338 | tmpW += additionalTmpW; |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2339 | if (!appliedStartWidth) { |
| 2340 | tmpW += inlineWidth(o, true, false); |
| 2341 | appliedStartWidth = true; |
| 2342 | } |
| 2343 | |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2344 | applyWordSpacing = wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace; |
hyatt | 3aff233 | 2003-01-23 01:15:28 +0000 | [diff] [blame] | 2345 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2346 | if (autoWrap && w + tmpW > width && !w) { |
hyatt | e2b1409 | 2003-01-23 23:33:39 +0000 | [diff] [blame] | 2347 | int fb = nearestFloatBottom(m_height); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2348 | int newLineWidth = lineWidth(fb); |
hyatt | 2df5219 | 2003-03-28 22:05:02 +0000 | [diff] [blame] | 2349 | // See if |tmpW| will fit on the new line. As long as it does not, |
| 2350 | // keep adjusting our float bottom until we find some room. |
| 2351 | int lastFloatBottom = m_height; |
| 2352 | while (lastFloatBottom < fb && tmpW > newLineWidth) { |
| 2353 | lastFloatBottom = fb; |
| 2354 | fb = nearestFloatBottom(fb); |
| 2355 | newLineWidth = lineWidth(fb); |
| 2356 | } |
| 2357 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2358 | if (!w && m_height < fb && width < newLineWidth) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2359 | m_height = fb; |
| 2360 | width = newLineWidth; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2361 | } |
| 2362 | } |
| 2363 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2364 | if (autoWrap || breakWords) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2365 | // If we break only after white-space, consider the current character |
kocienda | e413424 | 2004-10-25 18:48:44 +0000 | [diff] [blame] | 2366 | // as candidate width for this line. |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2367 | bool lineWasTooWide = false; |
| 2368 | if (w + tmpW <= width && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) { |
| 2369 | int charWidth = t->width(pos, 1, f, w + tmpW) + (applyWordSpacing ? wordSpacing : 0); |
| 2370 | // Check if line is too big even without the extra space |
| 2371 | // at the end of the line. If it is not, do nothing. |
| 2372 | // If the line needs the extra whitespace to be too long, |
| 2373 | // then move the line break to the space and skip all |
| 2374 | // additional whitespace. |
| 2375 | if (w + tmpW + charWidth > width) { |
| 2376 | lineWasTooWide = true; |
| 2377 | lBreak.obj = o; |
| 2378 | lBreak.pos = pos; |
| 2379 | if (pos > 0) { |
| 2380 | // Separate the trailing space into its own box, which we will |
| 2381 | // resize to fit on the line in computeHorizontalPositionsForLine(). |
| 2382 | BidiIterator midpoint(0, o, pos); |
| 2383 | addMidpoint(BidiIterator(0, o, pos-1)); // Stop |
| 2384 | addMidpoint(BidiIterator(0, o, pos)); // Start |
kocienda | e413424 | 2004-10-25 18:48:44 +0000 | [diff] [blame] | 2385 | } |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2386 | skipWhitespace(lBreak, bidi); |
kocienda | 9dbe9b1 | 2004-10-22 20:07:05 +0000 | [diff] [blame] | 2387 | } |
ap | 932806a | 2006-10-01 09:06:09 +0000 | [diff] [blame] | 2388 | } |
| 2389 | if (lineWasTooWide || w + tmpW > width) { |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2390 | if (lBreak.obj && shouldPreserveNewline(lBreak.obj) && lBreak.obj->isText() && static_cast<RenderText*>(lBreak.obj)->characters()[lBreak.pos] == '\n') { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2391 | if (!stoppedIgnoringSpaces && pos > 0) { |
| 2392 | // We need to stop right before the newline and then start up again. |
| 2393 | BidiIterator midpoint(0, o, pos); |
| 2394 | addMidpoint(BidiIterator(0, o, pos-1)); // Stop |
| 2395 | addMidpoint(BidiIterator(0, o, pos)); // Start |
| 2396 | } |
| 2397 | lBreak.increment(bidi); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 2398 | previousLineBrokeCleanly = true; |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 2399 | } |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2400 | goto end; // Didn't fit. Jump to the end. |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2401 | } else { |
| 2402 | if (midWordBreak) |
| 2403 | tmpW -= additionalTmpW; |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2404 | if (pos > 0 && str[pos-1] == softHyphen) |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2405 | // Subtract the width of the soft hyphen out since we fit on a line. |
| 2406 | tmpW -= t->width(pos-1, 1, f, w+tmpW); |
| 2407 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2408 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2409 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2410 | if (c == '\n' && preserveNewline) { |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2411 | if (!stoppedIgnoringSpaces && pos > 0) { |
| 2412 | // We need to stop right before the newline and then start up again. |
| 2413 | BidiIterator midpoint(0, o, pos); |
| 2414 | addMidpoint(BidiIterator(0, o, pos-1)); // Stop |
| 2415 | addMidpoint(BidiIterator(0, o, pos)); // Start |
| 2416 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2417 | lBreak.obj = o; |
| 2418 | lBreak.pos = pos; |
hyatt | 0c05e10 | 2006-04-14 08:15:00 +0000 | [diff] [blame] | 2419 | lBreak.increment(bidi); |
adele | 7fc3e83 | 2006-02-17 09:31:35 +0000 | [diff] [blame] | 2420 | previousLineBrokeCleanly = true; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2421 | return lBreak; |
| 2422 | } |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2423 | |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2424 | if (autoWrap && betweenWords) { |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2425 | w += tmpW; |
| 2426 | tmpW = 0; |
| 2427 | lBreak.obj = o; |
| 2428 | lBreak.pos = pos; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2429 | // Auto-wrapping text should not wrap in the middle of a word once it has had an |
| 2430 | // opportunity to break after a word. |
| 2431 | breakWords = false; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2432 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2433 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2434 | if (midWordBreak) { |
| 2435 | // Remember this as a breakable position in case |
| 2436 | // adding the end width forces a break. |
| 2437 | lBreak.obj = o; |
| 2438 | lBreak.pos = pos; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2439 | midWordBreak &= breakWords; |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2440 | } else { |
| 2441 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
| 2442 | lastSpace = pos; |
| 2443 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2444 | |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2445 | if (!ignoringSpaces && o->style()->collapseWhiteSpace()) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2446 | // If we encounter a newline, or if we encounter a |
| 2447 | // second space, we need to go ahead and break up this |
| 2448 | // run and enter a mode where we start collapsing spaces. |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2449 | if (currentCharacterIsSpace && previousCharacterIsSpace) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2450 | ignoringSpaces = true; |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2451 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2452 | // We just entered a mode where we are ignoring |
| 2453 | // spaces. Create a midpoint to terminate the run |
| 2454 | // before the second space. |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2455 | addMidpoint(ignoreStart); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2456 | } |
| 2457 | } |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2458 | } else if (ignoringSpaces) { |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2459 | // Stop ignoring spaces and begin at this |
| 2460 | // new point. |
| 2461 | ignoringSpaces = false; |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2462 | lastSpaceWordSpacing = applyWordSpacing ? wordSpacing : 0; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2463 | lastSpace = pos; // e.g., "Foo goo", don't add in any of the ignored spaces. |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2464 | BidiIterator startMid(0, o, pos); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 2465 | addMidpoint(startMid); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2466 | } |
hyatt | 98b1628 | 2004-03-31 18:43:12 +0000 | [diff] [blame] | 2467 | |
| 2468 | if (currentCharacterIsSpace && !previousCharacterIsSpace) { |
| 2469 | ignoreStart.obj = o; |
| 2470 | ignoreStart.pos = pos; |
| 2471 | } |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2472 | |
| 2473 | if (!currentCharacterIsWS && previousCharacterIsWS) { |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2474 | if (autoWrap && o->style()->breakOnlyAfterWhiteSpace()) { |
harrison | e343c41 | 2005-01-18 01:07:26 +0000 | [diff] [blame] | 2475 | lBreak.obj = o; |
| 2476 | lBreak.pos = pos; |
| 2477 | } |
| 2478 | } |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2479 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2480 | if (collapseWhiteSpace && currentCharacterIsSpace && !ignoringSpaces) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2481 | trailingSpaceObject = o; |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2482 | else if (!o->style()->collapseWhiteSpace() || !currentCharacterIsSpace) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2483 | trailingSpaceObject = 0; |
| 2484 | |
| 2485 | pos++; |
| 2486 | len--; |
| 2487 | } |
| 2488 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2489 | // IMPORTANT: pos is > length here! |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2490 | if (!ignoringSpaces) |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2491 | tmpW += t->width(lastSpace, pos - lastSpace, f, w+tmpW) + lastSpaceWordSpacing; |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2492 | tmpW += inlineWidth(o, !appliedStartWidth, true); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2493 | } else |
weinig | f28a1c3 | 2007-02-14 14:10:31 +0000 | [diff] [blame] | 2494 | ASSERT_NOT_REACHED(); |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2495 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2496 | RenderObject* next = bidiNext(start.block, o, bidi); |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2497 | bool checkForBreak = autoWrap; |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2498 | if (w && w + tmpW > width && lBreak.obj && currWS == NOWRAP) |
hyatt | 74eec4d | 2003-03-23 08:02:47 +0000 | [diff] [blame] | 2499 | checkForBreak = true; |
| 2500 | else if (next && o->isText() && next->isText() && !next->isBR()) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2501 | if (autoWrap || (next->style()->autoWrap())) { |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2502 | if (currentCharacterIsSpace) |
| 2503 | checkForBreak = true; |
| 2504 | else { |
harrison | 07b5e58 | 2005-08-15 23:31:16 +0000 | [diff] [blame] | 2505 | checkForBreak = false; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2506 | RenderText* nextText = static_cast<RenderText*>(next); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2507 | if (nextText->textLength() != 0) { |
| 2508 | UChar c = nextText->characters()[0]; |
zimmermann | ac3781f | 2007-02-04 01:25:03 +0000 | [diff] [blame] | 2509 | if (c == ' ' || c == '\t' || (c == '\n' && !shouldPreserveNewline(next))) |
eseidel | d13fe53 | 2005-11-30 02:40:29 +0000 | [diff] [blame] | 2510 | // If the next item on the line is text, and if we did not end with |
| 2511 | // a space, then the next text run continues our word (and so it needs to |
| 2512 | // keep adding to |tmpW|. Just update and continue. |
| 2513 | checkForBreak = true; |
harrison | 07b5e58 | 2005-08-15 23:31:16 +0000 | [diff] [blame] | 2514 | } |
ddkilzer | 5d01fa2 | 2007-01-29 03:10:37 +0000 | [diff] [blame] | 2515 | bool willFitOnLine = (w + tmpW <= width); |
ddkilzer | e760502 | 2007-01-31 12:51:30 +0000 | [diff] [blame] | 2516 | bool canPlaceOnLine = willFitOnLine || !willFitOnLine && !autoWrapWasEverTrueOnLine; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2517 | if (canPlaceOnLine && checkForBreak) { |
| 2518 | w += tmpW; |
| 2519 | tmpW = 0; |
| 2520 | lBreak.obj = next; |
| 2521 | lBreak.pos = 0; |
| 2522 | } |
| 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2527 | if (checkForBreak && (w + tmpW > width)) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2528 | // if we have floats, try to get below them. |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2529 | if (currentCharacterIsSpace && !ignoringSpaces && o->style()->collapseWhiteSpace()) |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2530 | trailingSpaceObject = 0; |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 2531 | |
hyatt | e2b1409 | 2003-01-23 23:33:39 +0000 | [diff] [blame] | 2532 | int fb = nearestFloatBottom(m_height); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2533 | int newLineWidth = lineWidth(fb); |
hyatt | 2df5219 | 2003-03-28 22:05:02 +0000 | [diff] [blame] | 2534 | // See if |tmpW| will fit on the new line. As long as it does not, |
| 2535 | // keep adjusting our float bottom until we find some room. |
| 2536 | int lastFloatBottom = m_height; |
| 2537 | while (lastFloatBottom < fb && tmpW > newLineWidth) { |
| 2538 | lastFloatBottom = fb; |
| 2539 | fb = nearestFloatBottom(fb); |
| 2540 | newLineWidth = lineWidth(fb); |
| 2541 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2542 | if (!w && m_height < fb && width < newLineWidth) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2543 | m_height = fb; |
darin | b70665a | 2002-04-15 23:43:21 +0000 | [diff] [blame] | 2544 | width = newLineWidth; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2545 | } |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 2546 | |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 2547 | // |width| may have been adjusted because we got shoved down past a float (thus |
| 2548 | // giving us more room), so we need to retest, and only jump to |
| 2549 | // the end label if we still don't fit on the line. -dwh |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2550 | if (w + tmpW > width) |
hyatt | a14d174 | 2003-01-02 20:25:46 +0000 | [diff] [blame] | 2551 | goto end; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2552 | } |
hyatt | 1d9e29b | 2003-04-10 01:48:53 +0000 | [diff] [blame] | 2553 | |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 2554 | last = o; |
bdakin | 9151ba5 | 2005-10-24 22:51:06 +0000 | [diff] [blame] | 2555 | if (!o->isFloating() && (!o->isPositioned() || o->hasStaticX() || o->hasStaticY() || !o->container()->isInlineFlow())) |
| 2556 | previous = o; |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2557 | o = next; |
hyatt | f14a4a3 | 2002-11-21 22:06:32 +0000 | [diff] [blame] | 2558 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2559 | if (!last->isFloatingOrPositioned() && last->isReplaced() && autoWrap && |
mjs | d26b297 | 2007-02-13 13:09:04 +0000 | [diff] [blame] | 2560 | (!last->isListMarker() || static_cast<RenderListMarker*>(last)->isInside())) { |
hyatt | 711fe23 | 2002-11-20 21:25:14 +0000 | [diff] [blame] | 2561 | w += tmpW; |
| 2562 | tmpW = 0; |
| 2563 | lBreak.obj = o; |
| 2564 | lBreak.pos = 0; |
| 2565 | } |
| 2566 | |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2567 | // Clear out our character space bool, since inline <pre>s don't collapse whitespace |
| 2568 | // with adjacent inline normal/nowrap spans. |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2569 | if (!collapseWhiteSpace) |
hyatt | a9f48e3 | 2003-02-03 22:48:01 +0000 | [diff] [blame] | 2570 | currentCharacterIsSpace = false; |
| 2571 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2572 | pos = 0; |
| 2573 | } |
| 2574 | |
hyatt | b0d9f60 | 2007-01-15 01:28:23 +0000 | [diff] [blame] | 2575 | |
| 2576 | if (w + tmpW <= width || lastWS == NOWRAP) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2577 | lBreak.obj = 0; |
| 2578 | lBreak.pos = 0; |
| 2579 | } |
| 2580 | |
| 2581 | end: |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2582 | |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2583 | if (lBreak == start && !lBreak.obj->isBR()) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2584 | // we just add as much as possible |
weinig | 98726da | 2007-03-15 01:22:19 +0000 | [diff] [blame^] | 2585 | if (style()->whiteSpace() == PRE) { |
hyatt | dca76e9 | 2005-11-02 08:52:50 +0000 | [diff] [blame] | 2586 | // FIXME: Don't really understand this case. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2587 | if (pos != 0) { |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2588 | lBreak.obj = o; |
| 2589 | lBreak.pos = pos - 1; |
| 2590 | } else { |
| 2591 | lBreak.obj = last; |
hyatt | c3731d4 | 2002-12-12 06:20:22 +0000 | [diff] [blame] | 2592 | lBreak.pos = last->isText() ? last->length() : 0; |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2593 | } |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2594 | } else if (lBreak.obj) { |
| 2595 | if (last != o && !last->isListMarker()) { |
bdakin | a964eb3 | 2005-10-24 17:47:26 +0000 | [diff] [blame] | 2596 | // 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] | 2597 | lBreak.obj = o; |
| 2598 | lBreak.pos = 0; |
| 2599 | } else { |
hyatt | dda1d1b | 2002-12-13 09:44:17 +0000 | [diff] [blame] | 2600 | // Don't ever break in the middle of a word if we can help it. |
| 2601 | // There's no room at all. We just have to be on this line, |
| 2602 | // even though we'll spill out. |
| 2603 | lBreak.obj = o; |
| 2604 | lBreak.pos = pos; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2605 | } |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | // make sure we consume at least one char/object. |
hyatt | 275d070 | 2005-11-03 23:53:57 +0000 | [diff] [blame] | 2610 | if (lBreak == start) |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 2611 | lBreak.increment(bidi); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2612 | |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 2613 | // Sanity check our midpoints. |
mjs | fe301d7 | 2003-10-02 18:46:18 +0000 | [diff] [blame] | 2614 | checkMidpoints(lBreak, bidi); |
hyatt | fe99c87 | 2003-07-31 22:25:29 +0000 | [diff] [blame] | 2615 | |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2616 | if (trailingSpaceObject) { |
| 2617 | // This object is either going to be part of the last midpoint, or it is going |
| 2618 | // to be the actual endpoint. In both cases we just decrease our pos by 1 level to |
| 2619 | // exclude the space, allowing it to - in effect - collapse into the newline. |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 2620 | if (sNumMidpoints%2==1) { |
| 2621 | BidiIterator* midpoints = smidpoints->data(); |
| 2622 | midpoints[sNumMidpoints-1].pos--; |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2623 | } |
| 2624 | //else if (lBreak.pos > 0) |
| 2625 | // lBreak.pos--; |
| 2626 | else if (lBreak.obj == 0 && trailingSpaceObject->isText()) { |
hyatt | d20075d | 2002-11-16 02:23:32 +0000 | [diff] [blame] | 2627 | // Add a new end midpoint that stops right at the very end. |
hyatt | d20075d | 2002-11-16 02:23:32 +0000 | [diff] [blame] | 2628 | RenderText* text = static_cast<RenderText *>(trailingSpaceObject); |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 2629 | unsigned length = text->textLength(); |
| 2630 | unsigned pos = length >= 2 ? length - 2 : UINT_MAX; |
eseidel | 789896f | 2005-11-27 22:52:09 +0000 | [diff] [blame] | 2631 | BidiIterator endMid(0, trailingSpaceObject, pos); |
hyatt | 85586af | 2003-02-19 23:22:42 +0000 | [diff] [blame] | 2632 | addMidpoint(endMid); |
hyatt | 33f8d49 | 2002-11-12 21:44:52 +0000 | [diff] [blame] | 2633 | } |
| 2634 | } |
rjw | c9c257d | 2003-01-24 03:46:17 +0000 | [diff] [blame] | 2635 | |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2636 | // We might have made lBreak an iterator that points past the end |
| 2637 | // of the object. Do this adjustment to make it point to the start |
| 2638 | // of the next object instead to avoid confusing the rest of the |
| 2639 | // code. |
| 2640 | if (lBreak.pos > 0) { |
darin | 5400892 | 2006-01-13 16:39:05 +0000 | [diff] [blame] | 2641 | lBreak.pos--; |
| 2642 | lBreak.increment(bidi); |
mjs | 54b6400 | 2003-04-02 02:59:02 +0000 | [diff] [blame] | 2643 | } |
| 2644 | |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2645 | if (lBreak.obj && lBreak.pos >= 2 && lBreak.obj->isText()) { |
| 2646 | // For soft hyphens on line breaks, we have to chop out the midpoints that made us |
| 2647 | // 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] | 2648 | UChar c = static_cast<RenderText*>(lBreak.obj)->characters()[lBreak.pos-1]; |
| 2649 | if (c == softHyphen) |
hyatt | 78b8513 | 2004-03-29 20:07:45 +0000 | [diff] [blame] | 2650 | chopMidpointsAt(lBreak.obj, lBreak.pos-2); |
| 2651 | } |
| 2652 | |
kocienda | bb0c24b | 2001-08-24 14:24:40 +0000 | [diff] [blame] | 2653 | return lBreak; |
| 2654 | } |
| 2655 | |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2656 | void RenderBlock::checkLinesForOverflow() |
| 2657 | { |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2658 | m_overflowWidth = m_width; |
| 2659 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
darin | 7bd7095 | 2006-04-13 07:07:34 +0000 | [diff] [blame] | 2660 | m_overflowLeft = min(curr->leftOverflow(), m_overflowLeft); |
| 2661 | m_overflowTop = min(curr->topOverflow(), m_overflowTop); |
| 2662 | m_overflowWidth = max(curr->rightOverflow(), m_overflowWidth); |
| 2663 | m_overflowHeight = max(curr->bottomOverflow(), m_overflowHeight); |
hyatt | b4b2087 | 2004-10-20 21:34:01 +0000 | [diff] [blame] | 2664 | } |
| 2665 | } |
| 2666 | |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2667 | void RenderBlock::deleteEllipsisLineBoxes() |
| 2668 | { |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2669 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 2670 | curr->clearTruncation(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | void RenderBlock::checkLinesForTextOverflow() |
| 2674 | { |
| 2675 | // Determine the width of the ellipsis using the current font. |
darin | dbba2bb | 2007-01-11 12:23:49 +0000 | [diff] [blame] | 2676 | // FIXME: CSS3 says this is configurable, also need to use 0x002E (FULL STOP) if horizontal ellipsis is "not renderable" |
| 2677 | TextRun ellipsisRun(&horizontalEllipsis, 1); |
| 2678 | static AtomicString ellipsisStr(&horizontalEllipsis, 1); |
hyatt | 3e99d1c | 2006-02-24 21:13:08 +0000 | [diff] [blame] | 2679 | const Font& firstLineFont = firstLineStyle()->font(); |
| 2680 | const Font& font = style()->font(); |
hyatt | 43d6c79 | 2006-05-11 10:19:34 +0000 | [diff] [blame] | 2681 | int firstLineEllipsisWidth = firstLineFont.width(ellipsisRun); |
| 2682 | int ellipsisWidth = (font == firstLineFont) ? firstLineEllipsisWidth : font.width(ellipsisRun); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2683 | |
| 2684 | // For LTR text truncation, we want to get the right edge of our padding box, and then we want to see |
| 2685 | // if the right edge of a line box exceeds that. For RTL, we use the left edge of the padding box and |
| 2686 | // check the left edge of the line box to see if it is less |
| 2687 | // Include the scrollbar for overflow blocks, which means we want to use "contentWidth()" |
| 2688 | bool ltr = style()->direction() == LTR; |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2689 | for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) { |
hyatt | da77c4b | 2004-06-17 18:09:49 +0000 | [diff] [blame] | 2690 | int blockEdge = ltr ? rightOffset(curr->yPos()) : leftOffset(curr->yPos()); |
hyatt | 1a8d251 | 2004-06-17 01:38:30 +0000 | [diff] [blame] | 2691 | int lineBoxEdge = ltr ? curr->xPos() + curr->width() : curr->xPos(); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2692 | if ((ltr && lineBoxEdge > blockEdge) || (!ltr && lineBoxEdge < blockEdge)) { |
hyatt | f918d2d | 2004-06-15 07:24:11 +0000 | [diff] [blame] | 2693 | // 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] | 2694 | // can be truncated. In order for truncation to be possible, the line must have sufficient space to |
| 2695 | // accommodate our truncation string, and no replaced elements (images, tables) can overlap the ellipsis |
| 2696 | // space. |
| 2697 | int width = curr == firstRootBox() ? firstLineEllipsisWidth : ellipsisWidth; |
hyatt | 1a8d251 | 2004-06-17 01:38:30 +0000 | [diff] [blame] | 2698 | if (curr->canAccommodateEllipsis(ltr, blockEdge, lineBoxEdge, width)) |
| 2699 | curr->placeEllipsis(ellipsisStr, ltr, blockEdge, width); |
hyatt | ed77ad8 | 2004-06-15 07:21:23 +0000 | [diff] [blame] | 2700 | } |
| 2701 | } |
| 2702 | } |
| 2703 | |
hyatt | ffe7871 | 2003-02-11 01:59:29 +0000 | [diff] [blame] | 2704 | } |