| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 | 900 |
| 901 // Use the character iterator to translate the next value into a DOM | 901 // Use the character iterator to translate the next value into a DOM |
| 902 // position. | 902 // position. |
| 903 BackwardsCharacterIteratorAlgorithm<Strategy> charIt(start, end); | 903 BackwardsCharacterIteratorAlgorithm<Strategy> charIt(start, end); |
| 904 charIt.advance(string.size() - suffixLength - next); | 904 charIt.advance(string.size() - suffixLength - next); |
| 905 // TODO(yosin) charIt can get out of shadow host. | 905 // TODO(yosin) charIt can get out of shadow host. |
| 906 return createVisiblePosition(charIt.endPosition()); | 906 return createVisiblePosition(charIt.endPosition()); |
| 907 } | 907 } |
| 908 | 908 |
| 909 template <typename Strategy> | 909 template <typename Strategy> |
| 910 static VisiblePositionTemplate<Strategy> nextBoundary( | 910 static PositionTemplate<Strategy> nextBoundary( |
| 911 const VisiblePositionTemplate<Strategy>& c, | 911 const VisiblePositionTemplate<Strategy>& c, |
| 912 BoundarySearchFunction searchFunction) { | 912 BoundarySearchFunction searchFunction) { |
| 913 DCHECK(c.isValid()) << c; | 913 DCHECK(c.isValid()) << c; |
| 914 PositionTemplate<Strategy> pos = c.deepEquivalent(); | 914 PositionTemplate<Strategy> pos = c.deepEquivalent(); |
| 915 Node* boundary = parentEditingBoundary(pos); | 915 Node* boundary = parentEditingBoundary(pos); |
| 916 if (!boundary) | 916 if (!boundary) |
| 917 return VisiblePositionTemplate<Strategy>(); | 917 return PositionTemplate<Strategy>(); |
| 918 | 918 |
| 919 Document& d = boundary->document(); | 919 Document& d = boundary->document(); |
| 920 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent()); | 920 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent()); |
| 921 | 921 |
| 922 BackwardsTextBuffer prefixString; | 922 BackwardsTextBuffer prefixString; |
| 923 if (requiresContextForWordBoundary(characterAfter(c))) { | 923 if (requiresContextForWordBoundary(characterAfter(c))) { |
| 924 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> backwardsIterator( | 924 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> backwardsIterator( |
| 925 PositionTemplate<Strategy>::firstPositionInNode(&d), start); | 925 PositionTemplate<Strategy>::firstPositionInNode(&d), start); |
| 926 while (!backwardsIterator.atEnd()) { | 926 while (!backwardsIterator.atEnd()) { |
| 927 backwardsIterator.copyTextTo(&prefixString); | 927 backwardsIterator.copyTextTo(&prefixString); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 const VisiblePositionTemplate<Strategy> visPos = | 1011 const VisiblePositionTemplate<Strategy> visPos = |
| 1012 createVisiblePosition(pos); | 1012 createVisiblePosition(pos); |
| 1013 if (visPos.deepEquivalent() == | 1013 if (visPos.deepEquivalent() == |
| 1014 createVisiblePosition(charIt.startPosition()).deepEquivalent()) { | 1014 createVisiblePosition(charIt.startPosition()).deepEquivalent()) { |
| 1015 charIt.advance(1); | 1015 charIt.advance(1); |
| 1016 pos = charIt.startPosition(); | 1016 pos = charIt.startPosition(); |
| 1017 } | 1017 } |
| 1018 } | 1018 } |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 // generate VisiblePosition, use TextAffinity::Upstream affinity if possible | 1021 return pos; |
| 1022 return createVisiblePosition(pos, VP_UPSTREAM_IF_POSSIBLE); | |
| 1023 } | 1022 } |
| 1024 | 1023 |
| 1025 // --------- | 1024 // --------- |
| 1026 | 1025 |
| 1027 static unsigned startWordBoundary( | 1026 static unsigned startWordBoundary( |
| 1028 const UChar* characters, | 1027 const UChar* characters, |
| 1029 unsigned length, | 1028 unsigned length, |
| 1030 unsigned offset, | 1029 unsigned offset, |
| 1031 BoundarySearchContextAvailability mayHaveMoreContext, | 1030 BoundarySearchContextAvailability mayHaveMoreContext, |
| 1032 bool& needMoreContext) { | 1031 bool& needMoreContext) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 if (isStartOfParagraph(c)) | 1099 if (isStartOfParagraph(c)) |
| 1101 return c; | 1100 return c; |
| 1102 | 1101 |
| 1103 p = previousPositionOf(c); | 1102 p = previousPositionOf(c); |
| 1104 if (p.isNull()) | 1103 if (p.isNull()) |
| 1105 return c; | 1104 return c; |
| 1106 } else if (isEndOfParagraph(c)) { | 1105 } else if (isEndOfParagraph(c)) { |
| 1107 return c; | 1106 return c; |
| 1108 } | 1107 } |
| 1109 | 1108 |
| 1110 return nextBoundary(p, endWordBoundary); | 1109 return createVisiblePosition(nextBoundary(p, endWordBoundary), |
| 1110 VP_UPSTREAM_IF_POSSIBLE); |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 VisiblePosition endOfWord(const VisiblePosition& c, EWordSide side) { | 1113 VisiblePosition endOfWord(const VisiblePosition& c, EWordSide side) { |
| 1114 return endOfWordAlgorithm<EditingStrategy>(c, side); | 1114 return endOfWordAlgorithm<EditingStrategy>(c, side); |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 VisiblePositionInFlatTree endOfWord(const VisiblePositionInFlatTree& c, | 1117 VisiblePositionInFlatTree endOfWord(const VisiblePositionInFlatTree& c, |
| 1118 EWordSide side) { | 1118 EWordSide side) { |
| 1119 return endOfWordAlgorithm<EditingInFlatTreeStrategy>(c, side); | 1119 return endOfWordAlgorithm<EditingInFlatTreeStrategy>(c, side); |
| 1120 } | 1120 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1151 static_cast<int>(length - offset)) { | 1151 static_cast<int>(length - offset)) { |
| 1152 needMoreContext = true; | 1152 needMoreContext = true; |
| 1153 return length; | 1153 return length; |
| 1154 } | 1154 } |
| 1155 needMoreContext = false; | 1155 needMoreContext = false; |
| 1156 return findNextWordFromIndex(characters, length, offset, true); | 1156 return findNextWordFromIndex(characters, length, offset, true); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 VisiblePosition nextWordPosition(const VisiblePosition& c) { | 1159 VisiblePosition nextWordPosition(const VisiblePosition& c) { |
| 1160 DCHECK(c.isValid()) << c; | 1160 DCHECK(c.isValid()) << c; |
| 1161 VisiblePosition next = nextBoundary(c, nextWordPositionBoundary); | 1161 VisiblePosition next = createVisiblePosition( |
| 1162 nextBoundary(c, nextWordPositionBoundary), VP_UPSTREAM_IF_POSSIBLE); |
| 1162 return honorEditingBoundaryAtOrAfter(next, c.deepEquivalent()); | 1163 return honorEditingBoundaryAtOrAfter(next, c.deepEquivalent()); |
| 1163 } | 1164 } |
| 1164 | 1165 |
| 1165 // --------- | 1166 // --------- |
| 1166 | 1167 |
| 1167 enum LineEndpointComputationMode { UseLogicalOrdering, UseInlineBoxOrdering }; | 1168 enum LineEndpointComputationMode { UseLogicalOrdering, UseInlineBoxOrdering }; |
| 1168 template <typename Strategy> | 1169 template <typename Strategy> |
| 1169 static PositionWithAffinityTemplate<Strategy> startPositionForLine( | 1170 static PositionWithAffinityTemplate<Strategy> startPositionForLine( |
| 1170 const PositionWithAffinityTemplate<Strategy>& c, | 1171 const PositionWithAffinityTemplate<Strategy>& c, |
| 1171 LineEndpointComputationMode mode) { | 1172 LineEndpointComputationMode mode) { |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1694 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
| 1694 return iterator->next(); | 1695 return iterator->next(); |
| 1695 } | 1696 } |
| 1696 | 1697 |
| 1697 // TODO(yosin) This includes the space after the punctuation that marks the end | 1698 // TODO(yosin) This includes the space after the punctuation that marks the end |
| 1698 // of the sentence. | 1699 // of the sentence. |
| 1699 template <typename Strategy> | 1700 template <typename Strategy> |
| 1700 static VisiblePositionTemplate<Strategy> endOfSentenceAlgorithm( | 1701 static VisiblePositionTemplate<Strategy> endOfSentenceAlgorithm( |
| 1701 const VisiblePositionTemplate<Strategy>& c) { | 1702 const VisiblePositionTemplate<Strategy>& c) { |
| 1702 DCHECK(c.isValid()) << c; | 1703 DCHECK(c.isValid()) << c; |
| 1703 return nextBoundary(c, endSentenceBoundary); | 1704 return createVisiblePosition(nextBoundary(c, endSentenceBoundary), |
| 1705 VP_UPSTREAM_IF_POSSIBLE); |
| 1704 } | 1706 } |
| 1705 | 1707 |
| 1706 VisiblePosition endOfSentence(const VisiblePosition& c) { | 1708 VisiblePosition endOfSentence(const VisiblePosition& c) { |
| 1707 return endOfSentenceAlgorithm<EditingStrategy>(c); | 1709 return endOfSentenceAlgorithm<EditingStrategy>(c); |
| 1708 } | 1710 } |
| 1709 | 1711 |
| 1710 VisiblePositionInFlatTree endOfSentence(const VisiblePositionInFlatTree& c) { | 1712 VisiblePositionInFlatTree endOfSentence(const VisiblePositionInFlatTree& c) { |
| 1711 return endOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c); | 1713 return endOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c); |
| 1712 } | 1714 } |
| 1713 | 1715 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1736 BoundarySearchContextAvailability, | 1738 BoundarySearchContextAvailability, |
| 1737 bool&) { | 1739 bool&) { |
| 1738 // FIXME: This is identical to endSentenceBoundary. This isn't right, it needs | 1740 // FIXME: This is identical to endSentenceBoundary. This isn't right, it needs |
| 1739 // to move to the equivlant position in the following sentence. | 1741 // to move to the equivlant position in the following sentence. |
| 1740 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); | 1742 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); |
| 1741 return iterator->following(0); | 1743 return iterator->following(0); |
| 1742 } | 1744 } |
| 1743 | 1745 |
| 1744 VisiblePosition nextSentencePosition(const VisiblePosition& c) { | 1746 VisiblePosition nextSentencePosition(const VisiblePosition& c) { |
| 1745 DCHECK(c.isValid()) << c; | 1747 DCHECK(c.isValid()) << c; |
| 1746 VisiblePosition next = nextBoundary(c, nextSentencePositionBoundary); | 1748 VisiblePosition next = createVisiblePosition( |
| 1749 nextBoundary(c, nextSentencePositionBoundary), VP_UPSTREAM_IF_POSSIBLE); |
| 1747 return honorEditingBoundaryAtOrAfter(next, c.deepEquivalent()); | 1750 return honorEditingBoundaryAtOrAfter(next, c.deepEquivalent()); |
| 1748 } | 1751 } |
| 1749 | 1752 |
| 1750 EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) { | 1753 EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) { |
| 1751 DCHECK(range.isNotNull()); | 1754 DCHECK(range.isNotNull()); |
| 1752 const VisiblePosition& visibleEnd = | 1755 const VisiblePosition& visibleEnd = |
| 1753 createVisiblePosition(range.endPosition()); | 1756 createVisiblePosition(range.endPosition()); |
| 1754 DCHECK(visibleEnd.isNotNull()); | 1757 DCHECK(visibleEnd.isNotNull()); |
| 1755 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); | 1758 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); |
| 1756 // TODO(xiaochengh): |sentenceEnd < range.endPosition()| is possible, | 1759 // TODO(xiaochengh): |sentenceEnd < range.endPosition()| is possible, |
| (...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3965 | 3968 |
| 3966 VisiblePositionInFlatTree previousPositionOf( | 3969 VisiblePositionInFlatTree previousPositionOf( |
| 3967 const VisiblePositionInFlatTree& visiblePosition, | 3970 const VisiblePositionInFlatTree& visiblePosition, |
| 3968 EditingBoundaryCrossingRule rule) { | 3971 EditingBoundaryCrossingRule rule) { |
| 3969 DCHECK(visiblePosition.isValid()) << visiblePosition; | 3972 DCHECK(visiblePosition.isValid()) << visiblePosition; |
| 3970 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( | 3973 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( |
| 3971 visiblePosition.deepEquivalent(), rule); | 3974 visiblePosition.deepEquivalent(), rule); |
| 3972 } | 3975 } |
| 3973 | 3976 |
| 3974 } // namespace blink | 3977 } // namespace blink |
| OLD | NEW |