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