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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 it.advance(); | 507 it.advance(); |
508 } | 508 } |
509 if (needMoreContext) { | 509 if (needMoreContext) { |
510 // The last search returned the beginning of the buffer and asked for mo
re context, | 510 // The last search returned the beginning of the buffer and asked for mo
re context, |
511 // but there is no earlier text. Force a search with what's available. | 511 // but there is no earlier text. Force a search with what's available. |
512 next = searchFunction(string.data(), string.size(), string.size() - suff
ixLength, DontHaveMoreContext, needMoreContext); | 512 next = searchFunction(string.data(), string.size(), string.size() - suff
ixLength, DontHaveMoreContext, needMoreContext); |
513 ASSERT(!needMoreContext); | 513 ASSERT(!needMoreContext); |
514 } | 514 } |
515 | 515 |
516 if (!next) | 516 if (!next) |
517 return VisiblePosition(it.atEnd() ? it.range()->startPosition() : pos, D
OWNSTREAM); | 517 return VisiblePosition(it.atEnd() ? it.startPosition() : pos, DOWNSTREAM
); |
518 | 518 |
519 Node* node = it.range()->startContainer(); | 519 Node* node = it.startContainer(); |
520 if ((node->isTextNode() && static_cast<int>(next) <= node->maxCharacterOffse
t()) || (node->renderer() && node->renderer()->isBR() && !next)) | 520 if ((node->isTextNode() && static_cast<int>(next) <= node->maxCharacterOffse
t()) || (node->renderer() && node->renderer()->isBR() && !next)) |
521 // The next variable contains a usable index into a text node | 521 // The next variable contains a usable index into a text node |
522 return VisiblePosition(createLegacyEditingPosition(node, next), DOWNSTRE
AM); | 522 return VisiblePosition(createLegacyEditingPosition(node, next), DOWNSTRE
AM); |
523 | 523 |
524 // Use the character iterator to translate the next value into a DOM positio
n. | 524 // Use the character iterator to translate the next value into a DOM positio
n. |
525 BackwardsCharacterIterator charIt(searchRange.get()); | 525 BackwardsCharacterIterator charIt(searchRange.get()); |
526 charIt.advance(string.size() - suffixLength - next); | 526 charIt.advance(string.size() - suffixLength - next); |
527 // FIXME: charIt can get out of shadow host. | 527 // FIXME: charIt can get out of shadow host. |
528 return VisiblePosition(charIt.range()->endPosition(), DOWNSTREAM); | 528 return VisiblePosition(charIt.endPosition(), DOWNSTREAM); |
529 } | 529 } |
530 | 530 |
531 static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
tion searchFunction) | 531 static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
tion searchFunction) |
532 { | 532 { |
533 Position pos = c.deepEquivalent(); | 533 Position pos = c.deepEquivalent(); |
534 Node* boundary = pos.parentEditingBoundary(); | 534 Node* boundary = pos.parentEditingBoundary(); |
535 if (!boundary) | 535 if (!boundary) |
536 return VisiblePosition(); | 536 return VisiblePosition(); |
537 | 537 |
538 Document& d = boundary->document(); | 538 Document& d = boundary->document(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 it.advance(); | 583 it.advance(); |
584 } | 584 } |
585 if (needMoreContext) { | 585 if (needMoreContext) { |
586 // The last search returned the end of the buffer and asked for more con
text, | 586 // The last search returned the end of the buffer and asked for more con
text, |
587 // but there is no further text. Force a search with what's available. | 587 // but there is no further text. Force a search with what's available. |
588 next = searchFunction(string.data(), string.size(), prefixLength, DontHa
veMoreContext, needMoreContext); | 588 next = searchFunction(string.data(), string.size(), prefixLength, DontHa
veMoreContext, needMoreContext); |
589 ASSERT(!needMoreContext); | 589 ASSERT(!needMoreContext); |
590 } | 590 } |
591 | 591 |
592 if (it.atEnd() && next == string.size()) { | 592 if (it.atEnd() && next == string.size()) { |
593 pos = it.range()->startPosition(); | 593 pos = it.startPosition(); |
594 } else if (next != invalidOffset && next != prefixLength) { | 594 } else if (next != invalidOffset && next != prefixLength) { |
595 // Use the character iterator to translate the next value into a DOM pos
ition. | 595 // Use the character iterator to translate the next value into a DOM pos
ition. |
596 CharacterIterator charIt(searchRange.get(), TextIteratorEmitsCharactersB
etweenAllVisiblePositions); | 596 CharacterIterator charIt(searchRange.get(), TextIteratorEmitsCharactersB
etweenAllVisiblePositions); |
597 charIt.advance(next - prefixLength - 1); | 597 charIt.advance(next - prefixLength - 1); |
598 RefPtrWillBeRawPtr<Range> characterRange = charIt.range(); | 598 pos = charIt.endPosition(); |
599 pos = characterRange->endPosition(); | |
600 | 599 |
601 if (charIt.characterAt(0) == '\n') { | 600 if (charIt.characterAt(0) == '\n') { |
602 // FIXME: workaround for collapsed range (where only start position
is correct) emitted for some emitted newlines (see rdar://5192593) | 601 // FIXME: workaround for collapsed range (where only start position
is correct) emitted for some emitted newlines (see rdar://5192593) |
603 VisiblePosition visPos = VisiblePosition(pos); | 602 VisiblePosition visPos = VisiblePosition(pos); |
604 if (visPos == VisiblePosition(characterRange->startPosition())) { | 603 if (visPos == VisiblePosition(charIt.startPosition())) { |
605 charIt.advance(1); | 604 charIt.advance(1); |
606 pos = charIt.range()->startPosition(); | 605 pos = charIt.startPosition(); |
607 } | 606 } |
608 } | 607 } |
609 } | 608 } |
610 | 609 |
611 // generate VisiblePosition, use UPSTREAM affinity if possible | 610 // generate VisiblePosition, use UPSTREAM affinity if possible |
612 return VisiblePosition(pos, VP_UPSTREAM_IF_POSSIBLE); | 611 return VisiblePosition(pos, VP_UPSTREAM_IF_POSSIBLE); |
613 } | 612 } |
614 | 613 |
615 // --------- | 614 // --------- |
616 | 615 |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 int caretOffset; | 1406 int caretOffset; |
1408 position.position().getInlineBoxAndOffset(position.affinity(), inlineBox, ca
retOffset); | 1407 position.position().getInlineBoxAndOffset(position.affinity(), inlineBox, ca
retOffset); |
1409 | 1408 |
1410 if (inlineBox) | 1409 if (inlineBox) |
1411 renderer = &inlineBox->renderer(); | 1410 renderer = &inlineBox->renderer(); |
1412 | 1411 |
1413 return renderer->localCaretRect(inlineBox, caretOffset); | 1412 return renderer->localCaretRect(inlineBox, caretOffset); |
1414 } | 1413 } |
1415 | 1414 |
1416 } | 1415 } |
OLD | NEW |