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