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