OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 if (nextBox) { | 319 if (nextBox) { |
320 nextBox->textRenderer()->text().appendTo(string, nextBox->start(), nextB
ox->len()); | 320 nextBox->textRenderer()->text().appendTo(string, nextBox->start(), nextB
ox->len()); |
321 len += nextBox->len(); | 321 len += nextBox->len(); |
322 } | 322 } |
323 | 323 |
324 return wordBreakIterator(string.data(), len); | 324 return wordBreakIterator(string.data(), len); |
325 } | 325 } |
326 | 326 |
327 static bool isLogicalStartOfWord(TextBreakIterator* iter, int position, bool har
dLineBreak) | 327 static bool isLogicalStartOfWord(TextBreakIterator* iter, int position, bool har
dLineBreak) |
328 { | 328 { |
329 bool boundary = hardLineBreak ? true : isTextBreak(iter, position); | 329 bool boundary = hardLineBreak ? true : iter->isBoundary(position); |
330 if (!boundary) | 330 if (!boundary) |
331 return false; | 331 return false; |
332 | 332 |
333 textBreakFollowing(iter, position); | 333 iter->following(position); |
334 // isWordTextBreak returns true after moving across a word and false after m
oving across a punctuation/space. | 334 // isWordTextBreak returns true after moving across a word and false after m
oving across a punctuation/space. |
335 return isWordTextBreak(iter); | 335 return isWordTextBreak(iter); |
336 } | 336 } |
337 | 337 |
338 static bool islogicalEndOfWord(TextBreakIterator* iter, int position, bool hardL
ineBreak) | 338 static bool islogicalEndOfWord(TextBreakIterator* iter, int position, bool hardL
ineBreak) |
339 { | 339 { |
340 bool boundary = isTextBreak(iter, position); | 340 bool boundary = iter->isBoundary(position); |
341 return (hardLineBreak || boundary) && isWordTextBreak(iter); | 341 return (hardLineBreak || boundary) && isWordTextBreak(iter); |
342 } | 342 } |
343 | 343 |
344 enum CursorMovementDirection { MoveLeft, MoveRight }; | 344 enum CursorMovementDirection { MoveLeft, MoveRight }; |
345 | 345 |
346 static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition
, CursorMovementDirection direction, | 346 static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition
, CursorMovementDirection direction, |
347 bool skipsSpaceWhenMovingRight) | 347 bool skipsSpaceWhenMovingRight) |
348 { | 348 { |
349 if (visiblePosition.isNull()) | 349 if (visiblePosition.isNull()) |
350 return VisiblePosition(); | 350 return VisiblePosition(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 else if (offsetInBox == box->caretMaxOffset()) | 384 else if (offsetInBox == box->caretMaxOffset()) |
385 iter = wordBreakIteratorForMaxOffsetBoundary(visiblePosition, textBo
x, nextBoxInDifferentBlock, string, leafBoxes); | 385 iter = wordBreakIteratorForMaxOffsetBoundary(visiblePosition, textBo
x, nextBoxInDifferentBlock, string, leafBoxes); |
386 else if (movingIntoNewBox) { | 386 else if (movingIntoNewBox) { |
387 iter = wordBreakIterator(textBox->textRenderer()->text(), textBox->s
tart(), textBox->len()); | 387 iter = wordBreakIterator(textBox->textRenderer()->text(), textBox->s
tart(), textBox->len()); |
388 previouslyVisitedBox = box; | 388 previouslyVisitedBox = box; |
389 } | 389 } |
390 | 390 |
391 if (!iter) | 391 if (!iter) |
392 break; | 392 break; |
393 | 393 |
394 textBreakFirst(iter); | 394 iter->first(); |
395 int offsetInIterator = offsetInBox - textBox->start() + previousBoxLengt
h; | 395 int offsetInIterator = offsetInBox - textBox->start() + previousBoxLengt
h; |
396 | 396 |
397 bool isWordBreak; | 397 bool isWordBreak; |
398 bool boxHasSameDirectionalityAsBlock = box->direction() == blockDirectio
n; | 398 bool boxHasSameDirectionalityAsBlock = box->direction() == blockDirectio
n; |
399 bool movingBackward = (direction == MoveLeft && box->direction() == LTR)
|| (direction == MoveRight && box->direction() == RTL); | 399 bool movingBackward = (direction == MoveLeft && box->direction() == LTR)
|| (direction == MoveRight && box->direction() == RTL); |
400 if ((skipsSpaceWhenMovingRight && boxHasSameDirectionalityAsBlock) | 400 if ((skipsSpaceWhenMovingRight && boxHasSameDirectionalityAsBlock) |
401 || (!skipsSpaceWhenMovingRight && movingBackward)) { | 401 || (!skipsSpaceWhenMovingRight && movingBackward)) { |
402 bool logicalStartInRenderer = offsetInBox == static_cast<int>(textBo
x->start()) && previousBoxInDifferentBlock; | 402 bool logicalStartInRenderer = offsetInBox == static_cast<int>(textBo
x->start()) && previousBoxInDifferentBlock; |
403 isWordBreak = isLogicalStartOfWord(iter, offsetInIterator, logicalSt
artInRenderer); | 403 isWordBreak = isLogicalStartOfWord(iter, offsetInIterator, logicalSt
artInRenderer); |
404 } else { | 404 } else { |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 return VisiblePosition(); | 1036 return VisiblePosition(); |
1037 return VisiblePosition(lastPositionInNode(rootElement), DOWNSTREAM); | 1037 return VisiblePosition(lastPositionInNode(rootElement), DOWNSTREAM); |
1038 } | 1038 } |
1039 | 1039 |
1040 // --------- | 1040 // --------- |
1041 | 1041 |
1042 static unsigned startSentenceBoundary(const UChar* characters, unsigned length,
unsigned, BoundarySearchContextAvailability, bool&) | 1042 static unsigned startSentenceBoundary(const UChar* characters, unsigned length,
unsigned, BoundarySearchContextAvailability, bool&) |
1043 { | 1043 { |
1044 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1044 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1045 // FIXME: The following function can return -1; we don't handle that. | 1045 // FIXME: The following function can return -1; we don't handle that. |
1046 return textBreakPreceding(iterator, length); | 1046 return iterator->preceding(length); |
1047 } | 1047 } |
1048 | 1048 |
1049 VisiblePosition startOfSentence(const VisiblePosition &c) | 1049 VisiblePosition startOfSentence(const VisiblePosition &c) |
1050 { | 1050 { |
1051 return previousBoundary(c, startSentenceBoundary); | 1051 return previousBoundary(c, startSentenceBoundary); |
1052 } | 1052 } |
1053 | 1053 |
1054 static unsigned endSentenceBoundary(const UChar* characters, unsigned length, un
signed, BoundarySearchContextAvailability, bool&) | 1054 static unsigned endSentenceBoundary(const UChar* characters, unsigned length, un
signed, BoundarySearchContextAvailability, bool&) |
1055 { | 1055 { |
1056 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1056 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1057 return textBreakNext(iterator); | 1057 return iterator->next(); |
1058 } | 1058 } |
1059 | 1059 |
1060 // FIXME: This includes the space after the punctuation that marks the end of th
e sentence. | 1060 // FIXME: This includes the space after the punctuation that marks the end of th
e sentence. |
1061 VisiblePosition endOfSentence(const VisiblePosition &c) | 1061 VisiblePosition endOfSentence(const VisiblePosition &c) |
1062 { | 1062 { |
1063 return nextBoundary(c, endSentenceBoundary); | 1063 return nextBoundary(c, endSentenceBoundary); |
1064 } | 1064 } |
1065 | 1065 |
1066 static unsigned previousSentencePositionBoundary(const UChar* characters, unsign
ed length, unsigned, BoundarySearchContextAvailability, bool&) | 1066 static unsigned previousSentencePositionBoundary(const UChar* characters, unsign
ed length, unsigned, BoundarySearchContextAvailability, bool&) |
1067 { | 1067 { |
1068 // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's
not right. | 1068 // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's
not right. |
1069 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1069 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1070 // FIXME: The following function can return -1; we don't handle that. | 1070 // FIXME: The following function can return -1; we don't handle that. |
1071 return textBreakPreceding(iterator, length); | 1071 return iterator->preceding(length); |
1072 } | 1072 } |
1073 | 1073 |
1074 VisiblePosition previousSentencePosition(const VisiblePosition &c) | 1074 VisiblePosition previousSentencePosition(const VisiblePosition &c) |
1075 { | 1075 { |
1076 VisiblePosition prev = previousBoundary(c, previousSentencePositionBoundary)
; | 1076 VisiblePosition prev = previousBoundary(c, previousSentencePositionBoundary)
; |
1077 return c.honorEditingBoundaryAtOrBefore(prev); | 1077 return c.honorEditingBoundaryAtOrBefore(prev); |
1078 } | 1078 } |
1079 | 1079 |
1080 static unsigned nextSentencePositionBoundary(const UChar* characters, unsigned l
ength, unsigned, BoundarySearchContextAvailability, bool&) | 1080 static unsigned nextSentencePositionBoundary(const UChar* characters, unsigned l
ength, unsigned, BoundarySearchContextAvailability, bool&) |
1081 { | 1081 { |
1082 // FIXME: This is identical to endSentenceBoundary. This isn't right, it nee
ds to | 1082 // FIXME: This is identical to endSentenceBoundary. This isn't right, it nee
ds to |
1083 // move to the equivlant position in the following sentence. | 1083 // move to the equivlant position in the following sentence. |
1084 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1084 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1085 return textBreakFollowing(iterator, 0); | 1085 return iterator->following(0); |
1086 } | 1086 } |
1087 | 1087 |
1088 VisiblePosition nextSentencePosition(const VisiblePosition &c) | 1088 VisiblePosition nextSentencePosition(const VisiblePosition &c) |
1089 { | 1089 { |
1090 VisiblePosition next = nextBoundary(c, nextSentencePositionBoundary); | 1090 VisiblePosition next = nextBoundary(c, nextSentencePositionBoundary); |
1091 return c.honorEditingBoundaryAtOrAfter(next); | 1091 return c.honorEditingBoundaryAtOrAfter(next); |
1092 } | 1092 } |
1093 | 1093 |
1094 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
ngRule boundaryCrossingRule) | 1094 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
ngRule boundaryCrossingRule) |
1095 { | 1095 { |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 { | 1408 { |
1409 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); | 1409 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); |
1410 } | 1410 } |
1411 | 1411 |
1412 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) | 1412 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) |
1413 { | 1413 { |
1414 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); | 1414 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); |
1415 } | 1415 } |
1416 | 1416 |
1417 } | 1417 } |
OLD | NEW |