|
Lines 166-178
static int boxIndexInVector(const Inline
Source/WebCore/editing/visible_units.cpp_sec1
|
| 166 |
return 0; |
166 |
return 0; |
| 167 |
} |
167 |
} |
| 168 |
|
168 |
|
| 169 |
static const InlineTextBox* previousBoxInLine(const RootInlineBox* root, const InlineTextBox* box, Vector<InlineBox*>& leafBoxesInLogicalOrder) |
169 |
class CachedRootAndLeafBoxesInLogicalOrder { |
|
|
170 |
public: |
| 171 |
CachedRootAndLeafBoxesInLogicalOrder(); |
| 172 |
const Vector<InlineBox*>& collectLeafBoxesInLogicalOrder(const RootInlineBox*); |
| 173 |
const Vector<InlineBox*>& leafBoxesInLogicalOrder() const { return m_leafBoxes; } |
| 174 |
|
| 175 |
private: |
| 176 |
const RootInlineBox* m_rootInlineBox; |
| 177 |
Vector<InlineBox*> m_leafBoxes; |
| 178 |
}; |
| 179 |
|
| 180 |
CachedRootAndLeafBoxesInLogicalOrder::CachedRootAndLeafBoxesInLogicalOrder() : m_rootInlineBox(0) { }; |
| 181 |
|
| 182 |
const Vector<InlineBox*>& CachedRootAndLeafBoxesInLogicalOrder::collectLeafBoxesInLogicalOrder(const RootInlineBox* root) |
| 183 |
{ |
| 184 |
if (m_rootInlineBox != root) { |
| 185 |
m_rootInlineBox = root; |
| 186 |
m_leafBoxes.clear(); |
| 187 |
root->collectLeafBoxesInLogicalOrder(m_leafBoxes); |
| 188 |
} |
| 189 |
return m_leafBoxes; |
| 190 |
} |
| 191 |
|
| 192 |
static const InlineTextBox* previousBoxInLine(const RootInlineBox* root, const InlineTextBox* box, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes) |
| 170 |
{ |
193 |
{ |
| 171 |
if (!root) |
194 |
if (!root) |
| 172 |
return 0; |
195 |
return 0; |
| 173 |
|
196 |
|
| 174 |
leafBoxesInLogicalOrder.clear(); |
197 |
const Vector<InlineBox*>& leafBoxesInLogicalOrder = rootAndLeafBoxes.collectLeafBoxesInLogicalOrder(root); |
| 175 |
root->collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder); |
|
|
| 176 |
|
198 |
|
| 177 |
// If box is null, root is box's previous RootInlineBox, and previousBox is the last logical box in root. |
199 |
// If box is null, root is box's previous RootInlineBox, and previousBox is the last logical box in root. |
| 178 |
int boxIndex = leafBoxesInLogicalOrder.size() - 1; |
200 |
int boxIndex = leafBoxesInLogicalOrder.size() - 1; |
|
Lines 187-202
static const InlineTextBox* previousBoxI
Source/WebCore/editing/visible_units.cpp_sec2
|
| 187 |
return 0; |
209 |
return 0; |
| 188 |
} |
210 |
} |
| 189 |
|
211 |
|
| 190 |
static const InlineTextBox* logicallyPreviousBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& previousBoxInDifferentBlock) |
212 |
static const InlineTextBox* logicallyPreviousBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& previousBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes) |
| 191 |
{ |
213 |
{ |
| 192 |
const InlineBox* startBox = textBox; |
214 |
const InlineBox* startBox = textBox; |
| 193 |
Vector<InlineBox*> leafBoxesInLogicalOrder; |
|
|
| 194 |
|
215 |
|
| 195 |
const InlineTextBox* previousBox = previousBoxInLine(startBox->root(), textBox, leafBoxesInLogicalOrder); |
216 |
const InlineTextBox* previousBox = previousBoxInLine(startBox->root(), textBox, rootAndLeafBoxes); |
| 196 |
if (previousBox) |
217 |
if (previousBox) |
| 197 |
return previousBox; |
218 |
return previousBox; |
| 198 |
|
219 |
|
| 199 |
previousBox = previousBoxInLine(startBox->root()->prevRootBox(), 0, leafBoxesInLogicalOrder); |
220 |
previousBox = previousBoxInLine(startBox->root()->prevRootBox(), 0, rootAndLeafBoxes); |
| 200 |
if (previousBox) |
221 |
if (previousBox) |
| 201 |
return previousBox; |
222 |
return previousBox; |
| 202 |
|
223 |
|
|
Lines 205-230
static const InlineTextBox* logicallyPre
Source/WebCore/editing/visible_units.cpp_sec3
|
| 205 |
if (!previousRoot) |
226 |
if (!previousRoot) |
| 206 |
break; |
227 |
break; |
| 207 |
|
228 |
|
| 208 |
previousBox = previousBoxInLine(previousRoot, 0, leafBoxesInLogicalOrder); |
229 |
previousBox = previousBoxInLine(previousRoot, 0, rootAndLeafBoxes); |
| 209 |
if (previousBox) { |
230 |
if (previousBox) { |
| 210 |
previousBoxInDifferentBlock = true; |
231 |
previousBoxInDifferentBlock = true; |
| 211 |
return previousBox; |
232 |
return previousBox; |
| 212 |
} |
233 |
} |
| 213 |
|
234 |
|
| 214 |
if (!leafBoxesInLogicalOrder.size()) |
235 |
if (!rootAndLeafBoxes.leafBoxesInLogicalOrder().size()) |
| 215 |
break; |
236 |
break; |
| 216 |
startBox = leafBoxesInLogicalOrder[0]; |
237 |
startBox = rootAndLeafBoxes.leafBoxesInLogicalOrder()[0]; |
| 217 |
} |
238 |
} |
| 218 |
return 0; |
239 |
return 0; |
| 219 |
} |
240 |
} |
| 220 |
|
241 |
|
| 221 |
static const InlineTextBox* nextBoxInLine(const RootInlineBox* root, const InlineTextBox* box, Vector<InlineBox*>& leafBoxesInLogicalOrder) |
242 |
static const InlineTextBox* nextBoxInLine(const RootInlineBox* root, const InlineTextBox* box, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes) |
| 222 |
{ |
243 |
{ |
| 223 |
if (!root) |
244 |
if (!root) |
| 224 |
return 0; |
245 |
return 0; |
| 225 |
|
246 |
|
| 226 |
leafBoxesInLogicalOrder.clear(); |
247 |
const Vector<InlineBox*>& leafBoxesInLogicalOrder = rootAndLeafBoxes.collectLeafBoxesInLogicalOrder(root); |
| 227 |
root->collectLeafBoxesInLogicalOrder(leafBoxesInLogicalOrder); |
|
|
| 228 |
|
248 |
|
| 229 |
// If box is null, root is box's next RootInlineBox, and nextBox is the first logical box in root. |
249 |
// If box is null, root is box's next RootInlineBox, and nextBox is the first logical box in root. |
| 230 |
// Otherwise, root is box's RootInlineBox, and nextBox is the next logical box in the same line. |
250 |
// Otherwise, root is box's RootInlineBox, and nextBox is the next logical box in the same line. |
|
Lines 240-255
static const InlineTextBox* nextBoxInLin
Source/WebCore/editing/visible_units.cpp_sec4
|
| 240 |
return 0; |
260 |
return 0; |
| 241 |
} |
261 |
} |
| 242 |
|
262 |
|
| 243 |
static const InlineTextBox* logicallyNextBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock) |
263 |
static const InlineTextBox* logicallyNextBox(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes) |
| 244 |
{ |
264 |
{ |
| 245 |
const InlineBox* startBox = textBox; |
265 |
const InlineBox* startBox = textBox; |
| 246 |
Vector<InlineBox*> leafBoxesInLogicalOrder; |
|
|
| 247 |
|
266 |
|
| 248 |
const InlineTextBox* nextBox = nextBoxInLine(startBox->root(), textBox, leafBoxesInLogicalOrder); |
267 |
const InlineTextBox* nextBox = nextBoxInLine(startBox->root(), textBox, rootAndLeafBoxes); |
| 249 |
if (nextBox) |
268 |
if (nextBox) |
| 250 |
return nextBox; |
269 |
return nextBox; |
| 251 |
|
270 |
|
| 252 |
nextBox = nextBoxInLine(startBox->root()->nextRootBox(), 0, leafBoxesInLogicalOrder); |
271 |
nextBox = nextBoxInLine(startBox->root()->nextRootBox(), 0, rootAndLeafBoxes); |
| 253 |
if (nextBox) |
272 |
if (nextBox) |
| 254 |
return nextBox; |
273 |
return nextBox; |
| 255 |
|
274 |
|
|
Lines 258-283
static const InlineTextBox* logicallyNex
Source/WebCore/editing/visible_units.cpp_sec5
|
| 258 |
if (!nextRoot) |
277 |
if (!nextRoot) |
| 259 |
break; |
278 |
break; |
| 260 |
|
279 |
|
| 261 |
nextBox = nextBoxInLine(nextRoot, 0, leafBoxesInLogicalOrder); |
280 |
nextBox = nextBoxInLine(nextRoot, 0, rootAndLeafBoxes); |
| 262 |
if (nextBox) { |
281 |
if (nextBox) { |
| 263 |
nextBoxInDifferentBlock = true; |
282 |
nextBoxInDifferentBlock = true; |
| 264 |
return nextBox; |
283 |
return nextBox; |
| 265 |
} |
284 |
} |
| 266 |
|
285 |
|
| 267 |
if (!leafBoxesInLogicalOrder.size()) |
286 |
if (!rootAndLeafBoxes.leafBoxesInLogicalOrder().size()) |
| 268 |
break; |
287 |
break; |
| 269 |
startBox = leafBoxesInLogicalOrder[0]; |
288 |
startBox = rootAndLeafBoxes.leafBoxesInLogicalOrder()[0]; |
| 270 |
} |
289 |
} |
| 271 |
return 0; |
290 |
return 0; |
| 272 |
} |
291 |
} |
| 273 |
|
292 |
|
| 274 |
static TextBreakIterator* wordBreakIteratorForMinOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, |
293 |
static TextBreakIterator* wordBreakIteratorForMinOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, |
| 275 |
int& previousBoxLength, bool& previousBoxInDifferentBlock) |
294 |
int& previousBoxLength, bool& previousBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes) |
| 276 |
{ |
295 |
{ |
| 277 |
previousBoxInDifferentBlock = false; |
296 |
previousBoxInDifferentBlock = false; |
| 278 |
|
297 |
|
| 279 |
// FIXME: Handle the case when we don't have an inline text box. |
298 |
// FIXME: Handle the case when we don't have an inline text box. |
| 280 |
const InlineTextBox* previousBox = logicallyPreviousBox(visiblePosition, textBox, previousBoxInDifferentBlock); |
299 |
const InlineTextBox* previousBox = logicallyPreviousBox(visiblePosition, textBox, previousBoxInDifferentBlock, rootAndLeafBoxes); |
| 281 |
|
300 |
|
| 282 |
int len = 0; |
301 |
int len = 0; |
| 283 |
Vector<UChar, 1024> string; |
302 |
Vector<UChar, 1024> string; |
|
Lines 292-303
static TextBreakIterator* wordBreakItera
Source/WebCore/editing/visible_units.cpp_sec6
|
| 292 |
return wordBreakIterator(string.data(), len); |
311 |
return wordBreakIterator(string.data(), len); |
| 293 |
} |
312 |
} |
| 294 |
|
313 |
|
| 295 |
static TextBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock) |
314 |
static TextBreakIterator* wordBreakIteratorForMaxOffsetBoundary(const VisiblePosition& visiblePosition, const InlineTextBox* textBox, bool& nextBoxInDifferentBlock, CachedRootAndLeafBoxesInLogicalOrder& rootAndLeafBoxes) |
| 296 |
{ |
315 |
{ |
| 297 |
nextBoxInDifferentBlock = false; |
316 |
nextBoxInDifferentBlock = false; |
| 298 |
|
317 |
|
| 299 |
// FIXME: Handle the case when we don't have an inline text box. |
318 |
// FIXME: Handle the case when we don't have an inline text box. |
| 300 |
const InlineTextBox* nextBox = logicallyNextBox(visiblePosition, textBox, nextBoxInDifferentBlock); |
319 |
const InlineTextBox* nextBox = logicallyNextBox(visiblePosition, textBox, nextBoxInDifferentBlock, rootAndLeafBoxes); |
| 301 |
|
320 |
|
| 302 |
int len = 0; |
321 |
int len = 0; |
| 303 |
Vector<UChar, 1024> string; |
322 |
Vector<UChar, 1024> string; |
|
Lines 340-345
static VisiblePosition visualWordPositio
Source/WebCore/editing/visible_units.cpp_sec7
|
| 340 |
VisiblePosition current = visiblePosition; |
359 |
VisiblePosition current = visiblePosition; |
| 341 |
TextBreakIterator* iter = 0; |
360 |
TextBreakIterator* iter = 0; |
| 342 |
|
361 |
|
|
|
362 |
CachedRootAndLeafBoxesInLogicalOrder rootAndLeafBoxes; |
| 363 |
|
| 343 |
while (1) { |
364 |
while (1) { |
| 344 |
VisiblePosition adjacentCharacterPosition = direction == MoveRight ? current.right(true) : current.left(true); |
365 |
VisiblePosition adjacentCharacterPosition = direction == MoveRight ? current.right(true) : current.left(true); |
| 345 |
if (adjacentCharacterPosition == current || adjacentCharacterPosition.isNull()) |
366 |
if (adjacentCharacterPosition == current || adjacentCharacterPosition.isNull()) |
|
Lines 363-371
static VisiblePosition visualWordPositio
Source/WebCore/editing/visible_units.cpp_sec8
|
| 363 |
bool movingIntoNewBox = previouslyVisitedBox != box; |
384 |
bool movingIntoNewBox = previouslyVisitedBox != box; |
| 364 |
|
385 |
|
| 365 |
if (offsetInBox == box->caretMinOffset()) |
386 |
if (offsetInBox == box->caretMinOffset()) |
| 366 |
iter = wordBreakIteratorForMinOffsetBoundary(visiblePosition, textBox, previousBoxLength, previousBoxInDifferentBlock); |
387 |
iter = wordBreakIteratorForMinOffsetBoundary(visiblePosition, textBox, previousBoxLength, previousBoxInDifferentBlock, rootAndLeafBoxes); |
| 367 |
else if (offsetInBox == box->caretMaxOffset()) |
388 |
else if (offsetInBox == box->caretMaxOffset()) |
| 368 |
iter = wordBreakIteratorForMaxOffsetBoundary(visiblePosition, textBox, nextBoxInDifferentBlock); |
389 |
iter = wordBreakIteratorForMaxOffsetBoundary(visiblePosition, textBox, nextBoxInDifferentBlock, rootAndLeafBoxes); |
| 369 |
else if (movingIntoNewBox) { |
390 |
else if (movingIntoNewBox) { |
| 370 |
iter = wordBreakIterator(textBox->textRenderer()->text()->characters() + textBox->start(), textBox->len()); |
391 |
iter = wordBreakIterator(textBox->textRenderer()->text()->characters() + textBox->start(), textBox->len()); |
| 371 |
previouslyVisitedBox = box; |
392 |
previouslyVisitedBox = box; |