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