Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 2725053006: Change VisibleUnits::previousBoundary to return Position rather than VisiblePosition (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 MayHaveMoreContext 803 MayHaveMoreContext
804 }; 804 };
805 805
806 typedef unsigned (*BoundarySearchFunction)(const UChar*, 806 typedef unsigned (*BoundarySearchFunction)(const UChar*,
807 unsigned length, 807 unsigned length,
808 unsigned offset, 808 unsigned offset,
809 BoundarySearchContextAvailability, 809 BoundarySearchContextAvailability,
810 bool& needMoreContext); 810 bool& needMoreContext);
811 811
812 template <typename Strategy> 812 template <typename Strategy>
813 static VisiblePositionTemplate<Strategy> previousBoundary( 813 static PositionTemplate<Strategy> previousBoundary(
814 const VisiblePositionTemplate<Strategy>& c, 814 const VisiblePositionTemplate<Strategy>& c,
815 BoundarySearchFunction searchFunction) { 815 BoundarySearchFunction searchFunction) {
816 DCHECK(c.isValid()) << c; 816 DCHECK(c.isValid()) << c;
817 const PositionTemplate<Strategy> pos = c.deepEquivalent(); 817 const PositionTemplate<Strategy> pos = c.deepEquivalent();
818 Node* boundary = parentEditingBoundary(pos); 818 Node* boundary = parentEditingBoundary(pos);
819 if (!boundary) 819 if (!boundary)
820 return VisiblePositionTemplate<Strategy>(); 820 return PositionTemplate<Strategy>();
821 821
822 const PositionTemplate<Strategy> start = 822 const PositionTemplate<Strategy> start =
823 PositionTemplate<Strategy>::editingPositionOf(boundary, 0) 823 PositionTemplate<Strategy>::editingPositionOf(boundary, 0)
824 .parentAnchoredEquivalent(); 824 .parentAnchoredEquivalent();
825 const PositionTemplate<Strategy> end = pos.parentAnchoredEquivalent(); 825 const PositionTemplate<Strategy> end = pos.parentAnchoredEquivalent();
826 826
827 ForwardsTextBuffer suffixString; 827 ForwardsTextBuffer suffixString;
828 if (requiresContextForWordBoundary(characterBefore(c))) { 828 if (requiresContextForWordBoundary(characterBefore(c))) {
829 TextIteratorAlgorithm<Strategy> forwardsIterator( 829 TextIteratorAlgorithm<Strategy> forwardsIterator(
830 end, PositionTemplate<Strategy>::afterNode(boundary)); 830 end, PositionTemplate<Strategy>::afterNode(boundary));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 // more context, but there is no earlier text. Force a search with 881 // more context, but there is no earlier text. Force a search with
882 // what's available. 882 // what's available.
883 // TODO(xiaochengh): Do we have to search the whole string? 883 // TODO(xiaochengh): Do we have to search the whole string?
884 next = searchFunction(string.data(), string.size(), 884 next = searchFunction(string.data(), string.size(),
885 string.size() - suffixLength, DontHaveMoreContext, 885 string.size() - suffixLength, DontHaveMoreContext,
886 needMoreContext); 886 needMoreContext);
887 DCHECK(!needMoreContext); 887 DCHECK(!needMoreContext);
888 } 888 }
889 889
890 if (!next) 890 if (!next)
891 return createVisiblePosition(it.atEnd() ? it.startPosition() : pos); 891 return it.atEnd() ? it.startPosition() : pos;
892 892
893 Node* node = it.startContainer(); 893 Node* node = it.startContainer();
894 int boundaryOffset = remainingLength + next; 894 int boundaryOffset = remainingLength + next;
895 if (node->isTextNode() && boundaryOffset <= node->maxCharacterOffset()) { 895 if (node->isTextNode() && boundaryOffset <= node->maxCharacterOffset()) {
896 // The next variable contains a usable index into a text node 896 // The next variable contains a usable index into a text node
897 return createVisiblePosition( 897 return PositionTemplate<Strategy>(node, boundaryOffset);
898 PositionTemplate<Strategy>(node, boundaryOffset));
899 } 898 }
900 899
901 // Use the character iterator to translate the next value into a DOM 900 // Use the character iterator to translate the next value into a DOM
902 // position. 901 // position.
903 BackwardsCharacterIteratorAlgorithm<Strategy> charIt(start, end); 902 BackwardsCharacterIteratorAlgorithm<Strategy> charIt(start, end);
904 charIt.advance(string.size() - suffixLength - next); 903 charIt.advance(string.size() - suffixLength - next);
905 // TODO(yosin) charIt can get out of shadow host. 904 // TODO(yosin) charIt can get out of shadow host.
906 return createVisiblePosition(charIt.endPosition()); 905 return charIt.endPosition();
907 } 906 }
908 907
909 template <typename Strategy> 908 template <typename Strategy>
910 static VisiblePositionTemplate<Strategy> nextBoundary( 909 static VisiblePositionTemplate<Strategy> nextBoundary(
911 const VisiblePositionTemplate<Strategy>& c, 910 const VisiblePositionTemplate<Strategy>& c,
912 BoundarySearchFunction searchFunction) { 911 BoundarySearchFunction searchFunction) {
913 DCHECK(c.isValid()) << c; 912 DCHECK(c.isValid()) << c;
914 PositionTemplate<Strategy> pos = c.deepEquivalent(); 913 PositionTemplate<Strategy> pos = c.deepEquivalent();
915 Node* boundary = parentEditingBoundary(pos); 914 Node* boundary = parentEditingBoundary(pos);
916 if (!boundary) 915 if (!boundary)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 VisiblePositionTemplate<Strategy> p = c; 1053 VisiblePositionTemplate<Strategy> p = c;
1055 if (side == RightWordIfOnBoundary) { 1054 if (side == RightWordIfOnBoundary) {
1056 // at paragraph end, the startofWord is the current position 1055 // at paragraph end, the startofWord is the current position
1057 if (isEndOfParagraph(c)) 1056 if (isEndOfParagraph(c))
1058 return c; 1057 return c;
1059 1058
1060 p = nextPositionOf(c); 1059 p = nextPositionOf(c);
1061 if (p.isNull()) 1060 if (p.isNull())
1062 return c; 1061 return c;
1063 } 1062 }
1064 return previousBoundary(p, startWordBoundary); 1063 return createVisiblePosition(previousBoundary(p, startWordBoundary));
1065 } 1064 }
1066 1065
1067 VisiblePosition startOfWord(const VisiblePosition& c, EWordSide side) { 1066 VisiblePosition startOfWord(const VisiblePosition& c, EWordSide side) {
1068 return startOfWordAlgorithm<EditingStrategy>(c, side); 1067 return startOfWordAlgorithm<EditingStrategy>(c, side);
1069 } 1068 }
1070 1069
1071 VisiblePositionInFlatTree startOfWord(const VisiblePositionInFlatTree& c, 1070 VisiblePositionInFlatTree startOfWord(const VisiblePositionInFlatTree& c,
1072 EWordSide side) { 1071 EWordSide side) {
1073 return startOfWordAlgorithm<EditingInFlatTreeStrategy>(c, side); 1072 return startOfWordAlgorithm<EditingInFlatTreeStrategy>(c, side);
1074 } 1073 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 !startOfLastWordBoundaryContext(characters, offset)) { 1128 !startOfLastWordBoundaryContext(characters, offset)) {
1130 needMoreContext = true; 1129 needMoreContext = true;
1131 return 0; 1130 return 0;
1132 } 1131 }
1133 needMoreContext = false; 1132 needMoreContext = false;
1134 return findNextWordFromIndex(characters, length, offset, false); 1133 return findNextWordFromIndex(characters, length, offset, false);
1135 } 1134 }
1136 1135
1137 VisiblePosition previousWordPosition(const VisiblePosition& c) { 1136 VisiblePosition previousWordPosition(const VisiblePosition& c) {
1138 DCHECK(c.isValid()) << c; 1137 DCHECK(c.isValid()) << c;
1139 VisiblePosition prev = previousBoundary(c, previousWordPositionBoundary); 1138 VisiblePosition prev =
1139 createVisiblePosition(previousBoundary(c, previousWordPositionBoundary));
1140 return honorEditingBoundaryAtOrBefore(prev, c.deepEquivalent()); 1140 return honorEditingBoundaryAtOrBefore(prev, c.deepEquivalent());
1141 } 1141 }
1142 1142
1143 static unsigned nextWordPositionBoundary( 1143 static unsigned nextWordPositionBoundary(
1144 const UChar* characters, 1144 const UChar* characters,
1145 unsigned length, 1145 unsigned length,
1146 unsigned offset, 1146 unsigned offset,
1147 BoundarySearchContextAvailability mayHaveMoreContext, 1147 BoundarySearchContextAvailability mayHaveMoreContext,
1148 bool& needMoreContext) { 1148 bool& needMoreContext) {
1149 if (mayHaveMoreContext && 1149 if (mayHaveMoreContext &&
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 bool&) { 1667 bool&) {
1668 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); 1668 TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
1669 // FIXME: The following function can return -1; we don't handle that. 1669 // FIXME: The following function can return -1; we don't handle that.
1670 return iterator->preceding(length); 1670 return iterator->preceding(length);
1671 } 1671 }
1672 1672
1673 template <typename Strategy> 1673 template <typename Strategy>
1674 static VisiblePositionTemplate<Strategy> startOfSentenceAlgorithm( 1674 static VisiblePositionTemplate<Strategy> startOfSentenceAlgorithm(
1675 const VisiblePositionTemplate<Strategy>& c) { 1675 const VisiblePositionTemplate<Strategy>& c) {
1676 DCHECK(c.isValid()) << c; 1676 DCHECK(c.isValid()) << c;
1677 return previousBoundary(c, startSentenceBoundary); 1677 return createVisiblePosition(previousBoundary(c, startSentenceBoundary));
1678 } 1678 }
1679 1679
1680 VisiblePosition startOfSentence(const VisiblePosition& c) { 1680 VisiblePosition startOfSentence(const VisiblePosition& c) {
1681 return startOfSentenceAlgorithm<EditingStrategy>(c); 1681 return startOfSentenceAlgorithm<EditingStrategy>(c);
1682 } 1682 }
1683 1683
1684 VisiblePositionInFlatTree startOfSentence(const VisiblePositionInFlatTree& c) { 1684 VisiblePositionInFlatTree startOfSentence(const VisiblePositionInFlatTree& c) {
1685 return startOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c); 1685 return startOfSentenceAlgorithm<EditingInFlatTreeStrategy>(c);
1686 } 1686 }
1687 1687
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 bool&) { 1719 bool&) {
1720 // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's 1720 // FIXME: This is identical to startSentenceBoundary. I'm pretty sure that's
1721 // not right. 1721 // not right.
1722 TextBreakIterator* iterator = sentenceBreakIterator(characters, length); 1722 TextBreakIterator* iterator = sentenceBreakIterator(characters, length);
1723 // FIXME: The following function can return -1; we don't handle that. 1723 // FIXME: The following function can return -1; we don't handle that.
1724 return iterator->preceding(length); 1724 return iterator->preceding(length);
1725 } 1725 }
1726 1726
1727 VisiblePosition previousSentencePosition(const VisiblePosition& c) { 1727 VisiblePosition previousSentencePosition(const VisiblePosition& c) {
1728 DCHECK(c.isValid()) << c; 1728 DCHECK(c.isValid()) << c;
1729 VisiblePosition prev = previousBoundary(c, previousSentencePositionBoundary); 1729 VisiblePosition prev = createVisiblePosition(
1730 previousBoundary(c, previousSentencePositionBoundary));
1730 return honorEditingBoundaryAtOrBefore(prev, c.deepEquivalent()); 1731 return honorEditingBoundaryAtOrBefore(prev, c.deepEquivalent());
1731 } 1732 }
1732 1733
1733 static unsigned nextSentencePositionBoundary(const UChar* characters, 1734 static unsigned nextSentencePositionBoundary(const UChar* characters,
1734 unsigned length, 1735 unsigned length,
1735 unsigned, 1736 unsigned,
1736 BoundarySearchContextAvailability, 1737 BoundarySearchContextAvailability,
1737 bool&) { 1738 bool&) {
1738 // FIXME: This is identical to endSentenceBoundary. This isn't right, it needs 1739 // FIXME: This is identical to endSentenceBoundary. This isn't right, it needs
1739 // to move to the equivlant position in the following sentence. 1740 // to move to the equivlant position in the following sentence.
(...skipping 2225 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 3966
3966 VisiblePositionInFlatTree previousPositionOf( 3967 VisiblePositionInFlatTree previousPositionOf(
3967 const VisiblePositionInFlatTree& visiblePosition, 3968 const VisiblePositionInFlatTree& visiblePosition,
3968 EditingBoundaryCrossingRule rule) { 3969 EditingBoundaryCrossingRule rule) {
3969 DCHECK(visiblePosition.isValid()) << visiblePosition; 3970 DCHECK(visiblePosition.isValid()) << visiblePosition;
3970 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( 3971 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(
3971 visiblePosition.deepEquivalent(), rule); 3972 visiblePosition.deepEquivalent(), rule);
3972 } 3973 }
3973 3974
3974 } // namespace blink 3975 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698