| 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 22 matching lines...) Expand all Loading... |
| 33 #include "core/dom/Text.h" | 33 #include "core/dom/Text.h" |
| 34 #include "core/editing/EditingUtilities.h" | 34 #include "core/editing/EditingUtilities.h" |
| 35 #include "core/editing/FrameSelection.h" | 35 #include "core/editing/FrameSelection.h" |
| 36 #include "core/editing/Position.h" | 36 #include "core/editing/Position.h" |
| 37 #include "core/editing/PositionIterator.h" | 37 #include "core/editing/PositionIterator.h" |
| 38 #include "core/editing/RenderedPosition.h" | 38 #include "core/editing/RenderedPosition.h" |
| 39 #include "core/editing/TextAffinity.h" | 39 #include "core/editing/TextAffinity.h" |
| 40 #include "core/editing/VisiblePosition.h" | 40 #include "core/editing/VisiblePosition.h" |
| 41 #include "core/editing/iterators/BackwardsCharacterIterator.h" | 41 #include "core/editing/iterators/BackwardsCharacterIterator.h" |
| 42 #include "core/editing/iterators/CharacterIterator.h" | 42 #include "core/editing/iterators/CharacterIterator.h" |
| 43 #include "core/editing/iterators/ForwardsTextBuffer.h" |
| 43 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" | 44 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" |
| 44 #include "core/editing/iterators/TextIterator.h" | 45 #include "core/editing/iterators/TextIterator.h" |
| 45 #include "core/frame/LocalFrame.h" | 46 #include "core/frame/LocalFrame.h" |
| 46 #include "core/frame/Settings.h" | 47 #include "core/frame/Settings.h" |
| 47 #include "core/html/HTMLBRElement.h" | 48 #include "core/html/HTMLBRElement.h" |
| 48 #include "core/html/HTMLTextFormControlElement.h" | 49 #include "core/html/HTMLTextFormControlElement.h" |
| 49 #include "core/layout/HitTestRequest.h" | 50 #include "core/layout/HitTestRequest.h" |
| 50 #include "core/layout/HitTestResult.h" | 51 #include "core/layout/HitTestResult.h" |
| 51 #include "core/layout/LayoutBlockFlow.h" | 52 #include "core/layout/LayoutBlockFlow.h" |
| 52 #include "core/layout/LayoutInline.h" | 53 #include "core/layout/LayoutInline.h" |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 static VisiblePositionTemplate<Strategy> previousBoundary(const VisiblePositionT
emplate<Strategy>& c, BoundarySearchFunction searchFunction) | 660 static VisiblePositionTemplate<Strategy> previousBoundary(const VisiblePositionT
emplate<Strategy>& c, BoundarySearchFunction searchFunction) |
| 660 { | 661 { |
| 661 const PositionTemplate<Strategy> pos = c.deepEquivalent(); | 662 const PositionTemplate<Strategy> pos = c.deepEquivalent(); |
| 662 Node* boundary = parentEditingBoundary(pos); | 663 Node* boundary = parentEditingBoundary(pos); |
| 663 if (!boundary) | 664 if (!boundary) |
| 664 return VisiblePositionTemplate<Strategy>(); | 665 return VisiblePositionTemplate<Strategy>(); |
| 665 | 666 |
| 666 const PositionTemplate<Strategy> start = PositionTemplate<Strategy>::editing
PositionOf(boundary, 0).parentAnchoredEquivalent(); | 667 const PositionTemplate<Strategy> start = PositionTemplate<Strategy>::editing
PositionOf(boundary, 0).parentAnchoredEquivalent(); |
| 667 const PositionTemplate<Strategy> end = pos.parentAnchoredEquivalent(); | 668 const PositionTemplate<Strategy> end = pos.parentAnchoredEquivalent(); |
| 668 | 669 |
| 669 Vector<UChar, 1024> string; | 670 ForwardsTextBuffer suffixString; |
| 670 unsigned suffixLength = 0; | 671 unsigned suffixLength = 0; |
| 671 | 672 |
| 672 if (requiresContextForWordBoundary(characterBefore(c))) { | 673 if (requiresContextForWordBoundary(characterBefore(c))) { |
| 673 TextIteratorAlgorithm<Strategy> forwardsIterator(end, PositionTemplate<S
trategy>::afterNode(boundary)); | 674 TextIteratorAlgorithm<Strategy> forwardsIterator(end, PositionTemplate<S
trategy>::afterNode(boundary)); |
| 674 while (!forwardsIterator.atEnd()) { | 675 while (!forwardsIterator.atEnd()) { |
| 675 Vector<UChar, 1024> characters; | 676 // TODO(xiaochengh): Eliminate this intermediate buffer. |
| 676 forwardsIterator.copyTextTo(characters); | 677 ForwardsTextBuffer characters; |
| 678 forwardsIterator.copyTextTo(&characters); |
| 677 int i = endOfFirstWordBoundaryContext(characters.data(), characters.
size()); | 679 int i = endOfFirstWordBoundaryContext(characters.data(), characters.
size()); |
| 678 string.append(characters.data(), i); | 680 suffixString.pushRange(characters.data(), i); |
| 679 suffixLength += i; | 681 suffixLength += i; |
| 680 if (static_cast<unsigned>(i) < characters.size()) | 682 if (static_cast<unsigned>(i) < characters.size()) |
| 681 break; | 683 break; |
| 682 forwardsIterator.advance(); | 684 forwardsIterator.advance(); |
| 683 } | 685 } |
| 684 } | 686 } |
| 685 | 687 |
| 688 Vector<UChar, 1024> string; |
| 689 string.append(suffixString.data(), suffixString.size()); |
| 690 |
| 686 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> it(start, end); | 691 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> it(start, end); |
| 687 unsigned next = 0; | 692 unsigned next = 0; |
| 688 bool needMoreContext = false; | 693 bool needMoreContext = false; |
| 689 while (!it.atEnd()) { | 694 while (!it.atEnd()) { |
| 690 bool inTextSecurityMode = it.isInTextSecurityMode(); | 695 bool inTextSecurityMode = it.isInTextSecurityMode(); |
| 691 // iterate to get chunks until the searchFunction returns a non-zero | 696 // iterate to get chunks until the searchFunction returns a non-zero |
| 692 // value. | 697 // value. |
| 693 // TODO(xiaochengh): Iterative prepending has quadratic running time | 698 // TODO(xiaochengh): Iterative prepending has quadratic running time |
| 694 // in the worst case. Should improve it to linear. | 699 // in the worst case. Should improve it to linear. |
| 695 if (!inTextSecurityMode) { | 700 if (!inTextSecurityMode) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 static VisiblePositionTemplate<Strategy> nextBoundary(const VisiblePositionTempl
ate<Strategy>& c, BoundarySearchFunction searchFunction) | 744 static VisiblePositionTemplate<Strategy> nextBoundary(const VisiblePositionTempl
ate<Strategy>& c, BoundarySearchFunction searchFunction) |
| 740 { | 745 { |
| 741 PositionTemplate<Strategy> pos = c.deepEquivalent(); | 746 PositionTemplate<Strategy> pos = c.deepEquivalent(); |
| 742 Node* boundary = parentEditingBoundary(pos); | 747 Node* boundary = parentEditingBoundary(pos); |
| 743 if (!boundary) | 748 if (!boundary) |
| 744 return VisiblePositionTemplate<Strategy>(); | 749 return VisiblePositionTemplate<Strategy>(); |
| 745 | 750 |
| 746 Document& d = boundary->document(); | 751 Document& d = boundary->document(); |
| 747 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent()); | 752 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent()); |
| 748 | 753 |
| 749 Vector<UChar, 1024> string; | 754 Vector<UChar, 1024> prefixString; |
| 750 unsigned prefixLength = 0; | 755 unsigned prefixLength = 0; |
| 751 | 756 |
| 752 if (requiresContextForWordBoundary(characterAfter(c))) { | 757 if (requiresContextForWordBoundary(characterAfter(c))) { |
| 753 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> backwardsIterator(Pos
itionTemplate<Strategy>::firstPositionInNode(&d), start); | 758 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> backwardsIterator(Pos
itionTemplate<Strategy>::firstPositionInNode(&d), start); |
| 754 while (!backwardsIterator.atEnd()) { | 759 while (!backwardsIterator.atEnd()) { |
| 760 // TODO(xiaochengh): Eliminate this intermediate buffer. |
| 755 Vector<UChar, 1024> characters; | 761 Vector<UChar, 1024> characters; |
| 756 backwardsIterator.copyTextTo(characters); | 762 backwardsIterator.copyTextTo(characters); |
| 757 int length = characters.size(); | 763 int length = characters.size(); |
| 758 int i = startOfLastWordBoundaryContext(characters.data(), length); | 764 int i = startOfLastWordBoundaryContext(characters.data(), length); |
| 759 // TODO(xiaochengh): Iterative prepending has quadratic running | 765 // TODO(xiaochengh): Iterative prepending has quadratic running |
| 760 // time in the worst case. Should improve it to linear. | 766 // time in the worst case. Should improve it to linear. |
| 761 string.prepend(characters.data() + i, length - i); | 767 prefixString.prepend(characters.data() + i, length - i); |
| 762 prefixLength += length - i; | 768 prefixLength += length - i; |
| 763 if (i > 0) | 769 if (i > 0) |
| 764 break; | 770 break; |
| 765 backwardsIterator.advance(); | 771 backwardsIterator.advance(); |
| 766 } | 772 } |
| 767 } | 773 } |
| 768 | 774 |
| 775 ForwardsTextBuffer string; |
| 776 string.pushRange(prefixString.data(), prefixString.size()); |
| 777 |
| 769 const PositionTemplate<Strategy> searchStart = PositionTemplate<Strategy>::e
ditingPositionOf(start.anchorNode(), start.offsetInContainerNode()); | 778 const PositionTemplate<Strategy> searchStart = PositionTemplate<Strategy>::e
ditingPositionOf(start.anchorNode(), start.offsetInContainerNode()); |
| 770 const PositionTemplate<Strategy> searchEnd = PositionTemplate<Strategy>::las
tPositionInNode(boundary); | 779 const PositionTemplate<Strategy> searchEnd = PositionTemplate<Strategy>::las
tPositionInNode(boundary); |
| 771 TextIteratorAlgorithm<Strategy> it(searchStart, searchEnd, TextIteratorEmits
CharactersBetweenAllVisiblePositions); | 780 TextIteratorAlgorithm<Strategy> it(searchStart, searchEnd, TextIteratorEmits
CharactersBetweenAllVisiblePositions); |
| 772 const unsigned invalidOffset = static_cast<unsigned>(-1); | 781 const unsigned invalidOffset = static_cast<unsigned>(-1); |
| 773 unsigned next = invalidOffset; | 782 unsigned next = invalidOffset; |
| 774 unsigned offset = prefixLength; | 783 unsigned offset = prefixLength; |
| 775 bool needMoreContext = false; | 784 bool needMoreContext = false; |
| 776 while (!it.atEnd()) { | 785 while (!it.atEnd()) { |
| 777 // Keep asking the iterator for chunks until the search function | 786 // Keep asking the iterator for chunks until the search function |
| 778 // returns an end value not equal to the length of the string passed to | 787 // returns an end value not equal to the length of the string passed to |
| 779 // it. | 788 // it. |
| 780 bool inTextSecurityMode = it.isInTextSecurityMode(); | 789 bool inTextSecurityMode = it.isInTextSecurityMode(); |
| 781 if (!inTextSecurityMode) { | 790 if (!inTextSecurityMode) { |
| 782 it.copyTextTo(string); | 791 it.copyTextTo(&string); |
| 783 } else { | 792 } else { |
| 784 // Treat bullets used in the text security mode as regular | 793 // Treat bullets used in the text security mode as regular |
| 785 // characters when looking for boundaries | 794 // characters when looking for boundaries |
| 786 Vector<UChar, 1024> iteratorString; | 795 string.pushCharacters('x', it.length()); |
| 787 iteratorString.fill('x', it.length()); | |
| 788 string.append(iteratorString.data(), iteratorString.size()); | |
| 789 } | 796 } |
| 790 next = searchFunction(string.data(), string.size(), offset, MayHaveMoreC
ontext, needMoreContext); | 797 next = searchFunction(string.data(), string.size(), offset, MayHaveMoreC
ontext, needMoreContext); |
| 791 if (next != string.size()) | 798 if (next != string.size()) |
| 792 break; | 799 break; |
| 793 it.advance(); | 800 it.advance(); |
| 794 if (!needMoreContext) { | 801 if (!needMoreContext) { |
| 795 // When the search does not need more context, skip all examined | 802 // When the search does not need more context, skip all examined |
| 796 // characters except the last one, in case it is a boundary. | 803 // characters except the last one, in case it is a boundary. |
| 797 offset = string.size(); | 804 offset = string.size(); |
| 798 U16_BACK_1(string.data(), 0, offset); | 805 U16_BACK_1(string.data(), 0, offset); |
| (...skipping 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3350 { | 3357 { |
| 3351 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); | 3358 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); |
| 3352 } | 3359 } |
| 3353 | 3360 |
| 3354 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed
Tree& visiblePosition, EditingBoundaryCrossingRule rule) | 3361 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed
Tree& visiblePosition, EditingBoundaryCrossingRule rule) |
| 3355 { | 3362 { |
| 3356 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos
ition, rule); | 3363 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos
ition, rule); |
| 3357 } | 3364 } |
| 3358 | 3365 |
| 3359 } // namespace blink | 3366 } // namespace blink |
| OLD | NEW |