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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 return VisiblePosition(); | 1035 return VisiblePosition(); |
1036 return VisiblePosition(lastPositionInNode(rootElement), DOWNSTREAM); | 1036 return VisiblePosition(lastPositionInNode(rootElement), DOWNSTREAM); |
1037 } | 1037 } |
1038 | 1038 |
1039 // --------- | 1039 // --------- |
1040 | 1040 |
1041 static unsigned startSentenceBoundary(const UChar* characters, unsigned length,
unsigned, BoundarySearchContextAvailability, bool&) | 1041 static unsigned startSentenceBoundary(const UChar* characters, unsigned length,
unsigned, BoundarySearchContextAvailability, bool&) |
1042 { | 1042 { |
1043 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1043 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1044 // FIXME: The following function can return -1; we don't handle that. | 1044 // FIXME: The following function can return -1; we don't handle that. |
1045 return textBreakPreceding(iterator, length); | 1045 return iterator->preceding(length); |
1046 } | 1046 } |
1047 | 1047 |
1048 VisiblePosition startOfSentence(const VisiblePosition &c) | 1048 VisiblePosition startOfSentence(const VisiblePosition &c) |
1049 { | 1049 { |
1050 return previousBoundary(c, startSentenceBoundary); | 1050 return previousBoundary(c, startSentenceBoundary); |
1051 } | 1051 } |
1052 | 1052 |
1053 static unsigned endSentenceBoundary(const UChar* characters, unsigned length, un
signed, BoundarySearchContextAvailability, bool&) | 1053 static unsigned endSentenceBoundary(const UChar* characters, unsigned length, un
signed, BoundarySearchContextAvailability, bool&) |
1054 { | 1054 { |
1055 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1055 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1056 return textBreakNext(iterator); | 1056 return iterator->next(); |
1057 } | 1057 } |
1058 | 1058 |
1059 // FIXME: This includes the space after the punctuation that marks the end of th
e sentence. | 1059 // FIXME: This includes the space after the punctuation that marks the end of th
e sentence. |
1060 VisiblePosition endOfSentence(const VisiblePosition &c) | 1060 VisiblePosition endOfSentence(const VisiblePosition &c) |
1061 { | 1061 { |
1062 return nextBoundary(c, endSentenceBoundary); | 1062 return nextBoundary(c, endSentenceBoundary); |
1063 } | 1063 } |
1064 | 1064 |
1065 static unsigned previousSentencePositionBoundary(const UChar* characters, unsign
ed length, unsigned, BoundarySearchContextAvailability, bool&) | 1065 static unsigned previousSentencePositionBoundary(const UChar* characters, unsign
ed length, unsigned, BoundarySearchContextAvailability, bool&) |
1066 { | 1066 { |
1067 // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's
not right. | 1067 // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's
not right. |
1068 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1068 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1069 // FIXME: The following function can return -1; we don't handle that. | 1069 // FIXME: The following function can return -1; we don't handle that. |
1070 return textBreakPreceding(iterator, length); | 1070 return iterator->preceding(length); |
1071 } | 1071 } |
1072 | 1072 |
1073 VisiblePosition previousSentencePosition(const VisiblePosition &c) | 1073 VisiblePosition previousSentencePosition(const VisiblePosition &c) |
1074 { | 1074 { |
1075 VisiblePosition prev = previousBoundary(c, previousSentencePositionBoundary)
; | 1075 VisiblePosition prev = previousBoundary(c, previousSentencePositionBoundary)
; |
1076 return c.honorEditingBoundaryAtOrBefore(prev); | 1076 return c.honorEditingBoundaryAtOrBefore(prev); |
1077 } | 1077 } |
1078 | 1078 |
1079 static unsigned nextSentencePositionBoundary(const UChar* characters, unsigned l
ength, unsigned, BoundarySearchContextAvailability, bool&) | 1079 static unsigned nextSentencePositionBoundary(const UChar* characters, unsigned l
ength, unsigned, BoundarySearchContextAvailability, bool&) |
1080 { | 1080 { |
1081 // FIXME: This is identical to endSentenceBoundary. This isn't right, it nee
ds to | 1081 // FIXME: This is identical to endSentenceBoundary. This isn't right, it nee
ds to |
1082 // move to the equivlant position in the following sentence. | 1082 // move to the equivlant position in the following sentence. |
1083 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1083 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
1084 return textBreakFollowing(iterator, 0); | 1084 return iterator->following(0); |
1085 } | 1085 } |
1086 | 1086 |
1087 VisiblePosition nextSentencePosition(const VisiblePosition &c) | 1087 VisiblePosition nextSentencePosition(const VisiblePosition &c) |
1088 { | 1088 { |
1089 VisiblePosition next = nextBoundary(c, nextSentencePositionBoundary); | 1089 VisiblePosition next = nextBoundary(c, nextSentencePositionBoundary); |
1090 return c.honorEditingBoundaryAtOrAfter(next); | 1090 return c.honorEditingBoundaryAtOrAfter(next); |
1091 } | 1091 } |
1092 | 1092 |
1093 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
ngRule boundaryCrossingRule) | 1093 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi
ngRule boundaryCrossingRule) |
1094 { | 1094 { |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 { | 1407 { |
1408 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); | 1408 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); |
1409 } | 1409 } |
1410 | 1410 |
1411 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) | 1411 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) |
1412 { | 1412 { |
1413 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); | 1413 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); |
1414 } | 1414 } |
1415 | 1415 |
1416 } | 1416 } |
OLD | NEW |