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

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

Issue 2359723002: Prune CreateVisiblePositionDeprecated from most of VisibleUnits (Closed)
Patch Set: Created 4 years, 2 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 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 return PositionWithAffinityTemplate<Strategy>(); 194 return PositionWithAffinityTemplate<Strategy>();
195 195
196 // Return the last position before |pos| that is in the same editable region 196 // Return the last position before |pos| that is in the same editable region
197 // as this position 197 // as this position
198 return lastEditablePositionBeforePositionInRoot(pos.position(), *highestRoot ); 198 return lastEditablePositionBeforePositionInRoot(pos.position(), *highestRoot );
199 } 199 }
200 200
201 template <typename Strategy> 201 template <typename Strategy>
202 static VisiblePositionTemplate<Strategy> honorEditingBoundaryAtOrBefore(const Vi siblePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor) 202 static VisiblePositionTemplate<Strategy> honorEditingBoundaryAtOrBefore(const Vi siblePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor)
203 { 203 {
204 return createVisiblePositionDeprecated(honorEditingBoundaryAtOrBefore(pos.to PositionWithAffinity(), anchor)); 204 DCHECK(pos.isValid());
205 return createVisiblePosition(honorEditingBoundaryAtOrBefore(pos.toPositionWi thAffinity(), anchor));
205 } 206 }
206 207
207 template <typename Strategy> 208 template <typename Strategy>
208 static VisiblePositionTemplate<Strategy> honorEditingBoundaryAtOrAfter(const Vis iblePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor) 209 static VisiblePositionTemplate<Strategy> honorEditingBoundaryAtOrAfter(const Vis iblePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor)
209 { 210 {
210 if (pos.isNull()) 211 if (pos.isNull())
211 return pos; 212 return pos;
212 213
213 ContainerNode* highestRoot = highestEditableRoot(anchor); 214 ContainerNode* highestRoot = highestEditableRoot(anchor);
214 215
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if (editable == hasEditableStyle(*node, editableType)) 307 if (editable == hasEditableStyle(*node, editableType))
307 return node; 308 return node;
308 node = nextAtomicLeafNode(*node); 309 node = nextAtomicLeafNode(*node);
309 } 310 }
310 return 0; 311 return 0;
311 } 312 }
312 313
313 // FIXME: consolidate with code in previousLinePosition. 314 // FIXME: consolidate with code in previousLinePosition.
314 static Position previousRootInlineBoxCandidatePosition(Node* node, const Visible Position& visiblePosition, EditableType editableType) 315 static Position previousRootInlineBoxCandidatePosition(Node* node, const Visible Position& visiblePosition, EditableType editableType)
315 { 316 {
317 DCHECK(visiblePosition.isValid());
316 ContainerNode* highestRoot = highestEditableRoot(visiblePosition.deepEquival ent(), editableType); 318 ContainerNode* highestRoot = highestEditableRoot(visiblePosition.deepEquival ent(), editableType);
317 Node* previousNode = previousLeafWithSameEditability(node, editableType); 319 Node* previousNode = previousLeafWithSameEditability(node, editableType);
318 320
319 while (previousNode && (!previousNode->layoutObject() || inSameLine(createVi siblePositionDeprecated(firstPositionInOrBeforeNode(previousNode)), visiblePosit ion))) 321 while (previousNode && (!previousNode->layoutObject() || inSameLine(createVi siblePosition(firstPositionInOrBeforeNode(previousNode)), visiblePosition)))
320 previousNode = previousLeafWithSameEditability(previousNode, editableTyp e); 322 previousNode = previousLeafWithSameEditability(previousNode, editableTyp e);
321 323
322 while (previousNode && !previousNode->isShadowRoot()) { 324 while (previousNode && !previousNode->isShadowRoot()) {
323 if (highestEditableRoot(firstPositionInOrBeforeNode(previousNode), edita bleType) != highestRoot) 325 if (highestEditableRoot(firstPositionInOrBeforeNode(previousNode), edita bleType) != highestRoot)
324 break; 326 break;
325 327
326 Position pos = isHTMLBRElement(*previousNode) ? Position::beforeNode(pre viousNode) : 328 Position pos = isHTMLBRElement(*previousNode) ? Position::beforeNode(pre viousNode) :
327 Position::editingPositionOf(previousNode, caretMaxOffset(previousNod e)); 329 Position::editingPositionOf(previousNode, caretMaxOffset(previousNod e));
328 330
329 if (isVisuallyEquivalentCandidate(pos)) 331 if (isVisuallyEquivalentCandidate(pos))
330 return pos; 332 return pos;
331 333
332 previousNode = previousLeafWithSameEditability(previousNode, editableTyp e); 334 previousNode = previousLeafWithSameEditability(previousNode, editableTyp e);
333 } 335 }
334 return Position(); 336 return Position();
335 } 337 }
336 338
337 static Position nextRootInlineBoxCandidatePosition(Node* node, const VisiblePosi tion& visiblePosition, EditableType editableType) 339 static Position nextRootInlineBoxCandidatePosition(Node* node, const VisiblePosi tion& visiblePosition, EditableType editableType)
338 { 340 {
341 DCHECK(visiblePosition.isValid());
339 ContainerNode* highestRoot = highestEditableRoot(visiblePosition.deepEquival ent(), editableType); 342 ContainerNode* highestRoot = highestEditableRoot(visiblePosition.deepEquival ent(), editableType);
340 Node* nextNode = nextLeafWithSameEditability(node, editableType); 343 Node* nextNode = nextLeafWithSameEditability(node, editableType);
341 while (nextNode && (!nextNode->layoutObject() || inSameLine(createVisiblePos itionDeprecated(firstPositionInOrBeforeNode(nextNode)), visiblePosition))) 344 while (nextNode && (!nextNode->layoutObject() || inSameLine(createVisiblePos ition(firstPositionInOrBeforeNode(nextNode)), visiblePosition)))
342 nextNode = nextLeafWithSameEditability(nextNode, ContentIsEditable); 345 nextNode = nextLeafWithSameEditability(nextNode, ContentIsEditable);
343 346
344 while (nextNode && !nextNode->isShadowRoot()) { 347 while (nextNode && !nextNode->isShadowRoot()) {
345 if (highestEditableRoot(firstPositionInOrBeforeNode(nextNode), editableT ype) != highestRoot) 348 if (highestEditableRoot(firstPositionInOrBeforeNode(nextNode), editableT ype) != highestRoot)
346 break; 349 break;
347 350
348 Position pos; 351 Position pos;
349 pos = Position::editingPositionOf(nextNode, caretMinOffset(nextNode)); 352 pos = Position::editingPositionOf(nextNode, caretMinOffset(nextNode));
350 353
351 if (isVisuallyEquivalentCandidate(pos)) 354 if (isVisuallyEquivalentCandidate(pos))
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 return boundary; 702 return boundary;
700 } 703 }
701 704
702 enum BoundarySearchContextAvailability { DontHaveMoreContext, MayHaveMoreContext }; 705 enum BoundarySearchContextAvailability { DontHaveMoreContext, MayHaveMoreContext };
703 706
704 typedef unsigned (*BoundarySearchFunction)(const UChar*, unsigned length, unsign ed offset, BoundarySearchContextAvailability, bool& needMoreContext); 707 typedef unsigned (*BoundarySearchFunction)(const UChar*, unsigned length, unsign ed offset, BoundarySearchContextAvailability, bool& needMoreContext);
705 708
706 template <typename Strategy> 709 template <typename Strategy>
707 static VisiblePositionTemplate<Strategy> previousBoundary(const VisiblePositionT emplate<Strategy>& c, BoundarySearchFunction searchFunction) 710 static VisiblePositionTemplate<Strategy> previousBoundary(const VisiblePositionT emplate<Strategy>& c, BoundarySearchFunction searchFunction)
708 { 711 {
712 DCHECK(c.isValid());
709 const PositionTemplate<Strategy> pos = c.deepEquivalent(); 713 const PositionTemplate<Strategy> pos = c.deepEquivalent();
710 Node* boundary = parentEditingBoundary(pos); 714 Node* boundary = parentEditingBoundary(pos);
711 if (!boundary) 715 if (!boundary)
712 return VisiblePositionTemplate<Strategy>(); 716 return VisiblePositionTemplate<Strategy>();
713 717
714 const PositionTemplate<Strategy> start = PositionTemplate<Strategy>::editing PositionOf(boundary, 0).parentAnchoredEquivalent(); 718 const PositionTemplate<Strategy> start = PositionTemplate<Strategy>::editing PositionOf(boundary, 0).parentAnchoredEquivalent();
715 const PositionTemplate<Strategy> end = pos.parentAnchoredEquivalent(); 719 const PositionTemplate<Strategy> end = pos.parentAnchoredEquivalent();
716 720
717 ForwardsTextBuffer suffixString; 721 ForwardsTextBuffer suffixString;
718 if (requiresContextForWordBoundary(characterBefore(c))) { 722 if (requiresContextForWordBoundary(characterBefore(c))) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 if (needMoreContext) { 768 if (needMoreContext) {
765 // The last search returned the beginning of the buffer and asked for 769 // The last search returned the beginning of the buffer and asked for
766 // more context, but there is no earlier text. Force a search with 770 // more context, but there is no earlier text. Force a search with
767 // what's available. 771 // what's available.
768 // TODO(xiaochengh): Do we have to search the whole string? 772 // TODO(xiaochengh): Do we have to search the whole string?
769 next = searchFunction(string.data(), string.size(), string.size() - suff ixLength, DontHaveMoreContext, needMoreContext); 773 next = searchFunction(string.data(), string.size(), string.size() - suff ixLength, DontHaveMoreContext, needMoreContext);
770 DCHECK(!needMoreContext); 774 DCHECK(!needMoreContext);
771 } 775 }
772 776
773 if (!next) 777 if (!next)
774 return createVisiblePositionDeprecated(it.atEnd() ? it.startPosition() : pos); 778 return createVisiblePosition(it.atEnd() ? it.startPosition() : pos);
775 779
776 Node* node = it.startContainer(); 780 Node* node = it.startContainer();
777 int boundaryOffset = remainingLength + next; 781 int boundaryOffset = remainingLength + next;
778 if (node->isTextNode() && boundaryOffset <= node->maxCharacterOffset()) { 782 if (node->isTextNode() && boundaryOffset <= node->maxCharacterOffset()) {
779 // The next variable contains a usable index into a text node 783 // The next variable contains a usable index into a text node
780 return createVisiblePositionDeprecated(PositionTemplate<Strategy>(node, boundaryOffset)); 784 return createVisiblePosition(PositionTemplate<Strategy>(node, boundaryOf fset));
781 } 785 }
782 786
783 // Use the character iterator to translate the next value into a DOM 787 // Use the character iterator to translate the next value into a DOM
784 // position. 788 // position.
785 BackwardsCharacterIteratorAlgorithm<Strategy> charIt(start, end); 789 BackwardsCharacterIteratorAlgorithm<Strategy> charIt(start, end);
786 charIt.advance(string.size() - suffixLength - next); 790 charIt.advance(string.size() - suffixLength - next);
787 // TODO(yosin) charIt can get out of shadow host. 791 // TODO(yosin) charIt can get out of shadow host.
788 return createVisiblePositionDeprecated(charIt.endPosition()); 792 return createVisiblePosition(charIt.endPosition());
789 } 793 }
790 794
791 template <typename Strategy> 795 template <typename Strategy>
792 static VisiblePositionTemplate<Strategy> nextBoundary(const VisiblePositionTempl ate<Strategy>& c, BoundarySearchFunction searchFunction) 796 static VisiblePositionTemplate<Strategy> nextBoundary(const VisiblePositionTempl ate<Strategy>& c, BoundarySearchFunction searchFunction)
793 { 797 {
798 DCHECK(c.isValid());
794 PositionTemplate<Strategy> pos = c.deepEquivalent(); 799 PositionTemplate<Strategy> pos = c.deepEquivalent();
795 Node* boundary = parentEditingBoundary(pos); 800 Node* boundary = parentEditingBoundary(pos);
796 if (!boundary) 801 if (!boundary)
797 return VisiblePositionTemplate<Strategy>(); 802 return VisiblePositionTemplate<Strategy>();
798 803
799 Document& d = boundary->document(); 804 Document& d = boundary->document();
800 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent()); 805 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent());
801 806
802 BackwardsTextBuffer prefixString; 807 BackwardsTextBuffer prefixString;
803 if (requiresContextForWordBoundary(characterAfter(c))) { 808 if (requiresContextForWordBoundary(characterAfter(c))) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 // Use the character iterator to translate the next value into a DOM 871 // Use the character iterator to translate the next value into a DOM
867 // position. 872 // position.
868 CharacterIteratorAlgorithm<Strategy> charIt(searchStart, searchEnd, Text IteratorEmitsCharactersBetweenAllVisiblePositions); 873 CharacterIteratorAlgorithm<Strategy> charIt(searchStart, searchEnd, Text IteratorEmitsCharactersBetweenAllVisiblePositions);
869 charIt.advance(next - prefixLength - 1); 874 charIt.advance(next - prefixLength - 1);
870 pos = charIt.endPosition(); 875 pos = charIt.endPosition();
871 876
872 if (charIt.characterAt(0) == '\n') { 877 if (charIt.characterAt(0) == '\n') {
873 // TODO(yosin) workaround for collapsed range (where only start 878 // TODO(yosin) workaround for collapsed range (where only start
874 // position is correct) emitted for some emitted newlines 879 // position is correct) emitted for some emitted newlines
875 // (see rdar://5192593) 880 // (see rdar://5192593)
876 const VisiblePositionTemplate<Strategy> visPos = createVisiblePositi onDeprecated(pos); 881 const VisiblePositionTemplate<Strategy> visPos = createVisiblePositi on(pos);
877 if (visPos.deepEquivalent() == createVisiblePositionDeprecated(charI t.startPosition()).deepEquivalent()) { 882 if (visPos.deepEquivalent() == createVisiblePosition(charIt.startPos ition()).deepEquivalent()) {
878 charIt.advance(1); 883 charIt.advance(1);
879 pos = charIt.startPosition(); 884 pos = charIt.startPosition();
880 } 885 }
881 } 886 }
882 } 887 }
883 888
884 // generate VisiblePosition, use TextAffinity::Upstream affinity if possible 889 // generate VisiblePosition, use TextAffinity::Upstream affinity if possible
885 return createVisiblePositionDeprecated(pos, VP_UPSTREAM_IF_POSSIBLE); 890 return createVisiblePosition(pos, VP_UPSTREAM_IF_POSSIBLE);
886 } 891 }
887 892
888 // --------- 893 // ---------
889 894
890 static unsigned startWordBoundary(const UChar* characters, unsigned length, unsi gned offset, BoundarySearchContextAvailability mayHaveMoreContext, bool& needMor eContext) 895 static unsigned startWordBoundary(const UChar* characters, unsigned length, unsi gned offset, BoundarySearchContextAvailability mayHaveMoreContext, bool& needMor eContext)
891 { 896 {
892 TRACE_EVENT0("blink", "startWordBoundary"); 897 TRACE_EVENT0("blink", "startWordBoundary");
893 DCHECK(offset); 898 DCHECK(offset);
894 if (mayHaveMoreContext && !startOfLastWordBoundaryContext(characters, offset )) { 899 if (mayHaveMoreContext && !startOfLastWordBoundaryContext(characters, offset )) {
895 needMoreContext = true; 900 needMoreContext = true;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1066 }
1062 1067
1063 static PositionInFlatTreeWithAffinity startOfLine(const PositionInFlatTreeWithAf finity& currentPosition) 1068 static PositionInFlatTreeWithAffinity startOfLine(const PositionInFlatTreeWithAf finity& currentPosition)
1064 { 1069 {
1065 return startOfLineAlgorithm<EditingInFlatTreeStrategy>(currentPosition); 1070 return startOfLineAlgorithm<EditingInFlatTreeStrategy>(currentPosition);
1066 } 1071 }
1067 1072
1068 // FIXME: Rename this function to reflect the fact it ignores bidi levels. 1073 // FIXME: Rename this function to reflect the fact it ignores bidi levels.
1069 VisiblePosition startOfLine(const VisiblePosition& currentPosition) 1074 VisiblePosition startOfLine(const VisiblePosition& currentPosition)
1070 { 1075 {
1071 return createVisiblePositionDeprecated(startOfLine(currentPosition.toPositio nWithAffinity())); 1076 DCHECK(currentPosition.isValid());
1077 return createVisiblePosition(startOfLine(currentPosition.toPositionWithAffin ity()));
1072 } 1078 }
1073 1079
1074 VisiblePositionInFlatTree startOfLine(const VisiblePositionInFlatTree& currentPo sition) 1080 VisiblePositionInFlatTree startOfLine(const VisiblePositionInFlatTree& currentPo sition)
1075 { 1081 {
1076 return createVisiblePositionDeprecated(startOfLine(currentPosition.toPositio nWithAffinity())); 1082 DCHECK(currentPosition.isValid());
1083 return createVisiblePosition(startOfLine(currentPosition.toPositionWithAffin ity()));
1077 } 1084 }
1078 1085
1079 template <typename Strategy> 1086 template <typename Strategy>
1080 static PositionWithAffinityTemplate<Strategy> logicalStartOfLineAlgorithm(const PositionWithAffinityTemplate<Strategy>& c) 1087 static PositionWithAffinityTemplate<Strategy> logicalStartOfLineAlgorithm(const PositionWithAffinityTemplate<Strategy>& c)
1081 { 1088 {
1082 // TODO: this is the current behavior that might need to be fixed. 1089 // TODO: this is the current behavior that might need to be fixed.
1083 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail. 1090 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail.
1084 PositionWithAffinityTemplate<Strategy> visPos = startPositionForLine(c, UseL ogicalOrdering); 1091 PositionWithAffinityTemplate<Strategy> visPos = startPositionForLine(c, UseL ogicalOrdering);
1085 1092
1086 if (ContainerNode* editableRoot = highestEditableRoot(c.position())) { 1093 if (ContainerNode* editableRoot = highestEditableRoot(c.position())) {
1087 if (!editableRoot->contains(visPos.position().computeContainerNode())) 1094 if (!editableRoot->contains(visPos.position().computeContainerNode()))
1088 return PositionWithAffinityTemplate<Strategy>(PositionTemplate<Strat egy>::firstPositionInNode(editableRoot)); 1095 return PositionWithAffinityTemplate<Strategy>(PositionTemplate<Strat egy>::firstPositionInNode(editableRoot));
1089 } 1096 }
1090 1097
1091 return honorEditingBoundaryAtOrBefore(visPos, c.position()); 1098 return honorEditingBoundaryAtOrBefore(visPos, c.position());
1092 } 1099 }
1093 1100
1094 VisiblePosition logicalStartOfLine(const VisiblePosition& currentPosition) 1101 VisiblePosition logicalStartOfLine(const VisiblePosition& currentPosition)
1095 { 1102 {
1096 return createVisiblePositionDeprecated(logicalStartOfLineAlgorithm<EditingSt rategy>(currentPosition.toPositionWithAffinity())); 1103 DCHECK(currentPosition.isValid());
1104 return createVisiblePosition(logicalStartOfLineAlgorithm<EditingStrategy>(cu rrentPosition.toPositionWithAffinity()));
1097 } 1105 }
1098 1106
1099 VisiblePositionInFlatTree logicalStartOfLine(const VisiblePositionInFlatTree& cu rrentPosition) 1107 VisiblePositionInFlatTree logicalStartOfLine(const VisiblePositionInFlatTree& cu rrentPosition)
1100 { 1108 {
1101 return createVisiblePositionDeprecated(logicalStartOfLineAlgorithm<EditingIn FlatTreeStrategy>(currentPosition.toPositionWithAffinity())); 1109 DCHECK(currentPosition.isValid());
1110 return createVisiblePosition(logicalStartOfLineAlgorithm<EditingInFlatTreeSt rategy>(currentPosition.toPositionWithAffinity()));
1102 } 1111 }
1103 1112
1104 template <typename Strategy> 1113 template <typename Strategy>
1105 static VisiblePositionTemplate<Strategy> endPositionForLine(const VisiblePositio nTemplate<Strategy>& c, LineEndpointComputationMode mode) 1114 static VisiblePositionTemplate<Strategy> endPositionForLine(const VisiblePositio nTemplate<Strategy>& c, LineEndpointComputationMode mode)
1106 { 1115 {
1116 DCHECK(c.isValid());
1107 if (c.isNull()) 1117 if (c.isNull())
1108 return VisiblePositionTemplate<Strategy>(); 1118 return VisiblePositionTemplate<Strategy>();
1109 1119
1110 RootInlineBox* rootBox = RenderedPosition(c).rootBox(); 1120 RootInlineBox* rootBox = RenderedPosition(c).rootBox();
1111 if (!rootBox) { 1121 if (!rootBox) {
1112 // There are VisiblePositions at offset 0 in blocks without 1122 // There are VisiblePositions at offset 0 in blocks without
1113 // RootInlineBoxes, like empty editable blocks and bordered blocks. 1123 // RootInlineBoxes, like empty editable blocks and bordered blocks.
1114 const PositionTemplate<Strategy> p = c.deepEquivalent(); 1124 const PositionTemplate<Strategy> p = c.deepEquivalent();
1115 if (p.anchorNode()->layoutObject() && p.anchorNode()->layoutObject()->is LayoutBlock() && !p.computeEditingOffset()) 1125 if (p.anchorNode()->layoutObject() && p.anchorNode()->layoutObject()->is LayoutBlock() && !p.computeEditingOffset())
1116 return c; 1126 return c;
(...skipping 29 matching lines...) Expand all
1146 } else if (endBox->isInlineTextBox() && endNode->isTextNode()) { 1156 } else if (endBox->isInlineTextBox() && endNode->isTextNode()) {
1147 InlineTextBox* endTextBox = toInlineTextBox(endBox); 1157 InlineTextBox* endTextBox = toInlineTextBox(endBox);
1148 int endOffset = endTextBox->start(); 1158 int endOffset = endTextBox->start();
1149 if (!endTextBox->isLineBreak()) 1159 if (!endTextBox->isLineBreak())
1150 endOffset += endTextBox->len(); 1160 endOffset += endTextBox->len();
1151 pos = PositionTemplate<Strategy>(toText(endNode), endOffset); 1161 pos = PositionTemplate<Strategy>(toText(endNode), endOffset);
1152 } else { 1162 } else {
1153 pos = PositionTemplate<Strategy>::afterNode(endNode); 1163 pos = PositionTemplate<Strategy>::afterNode(endNode);
1154 } 1164 }
1155 1165
1156 return createVisiblePositionDeprecated(pos, VP_UPSTREAM_IF_POSSIBLE); 1166 return createVisiblePosition(pos, VP_UPSTREAM_IF_POSSIBLE);
1157 } 1167 }
1158 1168
1159 // TODO(yosin) Rename this function to reflect the fact it ignores bidi levels. 1169 // TODO(yosin) Rename this function to reflect the fact it ignores bidi levels.
1160 template <typename Strategy> 1170 template <typename Strategy>
1161 static VisiblePositionTemplate<Strategy> endOfLineAlgorithm(const VisiblePositio nTemplate<Strategy>& currentPosition) 1171 static VisiblePositionTemplate<Strategy> endOfLineAlgorithm(const VisiblePositio nTemplate<Strategy>& currentPosition)
1162 { 1172 {
1163 // TODO(yosin) this is the current behavior that might need to be fixed. 1173 // TODO(yosin) this is the current behavior that might need to be fixed.
1164 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail. 1174 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail.
1165 VisiblePositionTemplate<Strategy> visPos = endPositionForLine(currentPositio n, UseInlineBoxOrdering); 1175 VisiblePositionTemplate<Strategy> visPos = endPositionForLine(currentPositio n, UseInlineBoxOrdering);
1166 1176
(...skipping 28 matching lines...) Expand all
1195 1205
1196 template <typename Strategy> 1206 template <typename Strategy>
1197 static bool inSameLogicalLine(const VisiblePositionTemplate<Strategy>& a, const VisiblePositionTemplate<Strategy>& b) 1207 static bool inSameLogicalLine(const VisiblePositionTemplate<Strategy>& a, const VisiblePositionTemplate<Strategy>& b)
1198 { 1208 {
1199 return a.isNotNull() && logicalStartOfLine(a).deepEquivalent() == logicalSta rtOfLine(b).deepEquivalent(); 1209 return a.isNotNull() && logicalStartOfLine(a).deepEquivalent() == logicalSta rtOfLine(b).deepEquivalent();
1200 } 1210 }
1201 1211
1202 template <typename Strategy> 1212 template <typename Strategy>
1203 VisiblePositionTemplate<Strategy> logicalEndOfLineAlgorithm(const VisiblePositio nTemplate<Strategy>& currentPosition) 1213 VisiblePositionTemplate<Strategy> logicalEndOfLineAlgorithm(const VisiblePositio nTemplate<Strategy>& currentPosition)
1204 { 1214 {
1215 DCHECK(currentPosition.isValid());
1205 // TODO(yosin) this is the current behavior that might need to be fixed. 1216 // TODO(yosin) this is the current behavior that might need to be fixed.
1206 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail. 1217 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail.
1207 VisiblePositionTemplate<Strategy> visPos = endPositionForLine(currentPositio n, UseLogicalOrdering); 1218 VisiblePositionTemplate<Strategy> visPos = endPositionForLine(currentPositio n, UseLogicalOrdering);
1208 1219
1209 // Make sure the end of line is at the same line as the given input 1220 // Make sure the end of line is at the same line as the given input
1210 // position. For a wrapping line, the logical end position for the 1221 // position. For a wrapping line, the logical end position for the
1211 // not-last-2-lines might incorrectly hand back the logical beginning of the 1222 // not-last-2-lines might incorrectly hand back the logical beginning of the
1212 // next line. For example, 1223 // next line. For example,
1213 // <div contenteditable dir="rtl" style="line-break:before-white-space">xyz 1224 // <div contenteditable dir="rtl" style="line-break:before-white-space">xyz
1214 // a xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz </div> 1225 // a xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz </div>
1215 // In this case, use the previous position of the computed logical end 1226 // In this case, use the previous position of the computed logical end
1216 // position. 1227 // position.
1217 if (!inSameLogicalLine(currentPosition, visPos)) 1228 if (!inSameLogicalLine(currentPosition, visPos))
1218 visPos = previousPositionOf(visPos); 1229 visPos = previousPositionOf(visPos);
1219 1230
1220 if (ContainerNode* editableRoot = highestEditableRoot(currentPosition.deepEq uivalent())) { 1231 if (ContainerNode* editableRoot = highestEditableRoot(currentPosition.deepEq uivalent())) {
1221 if (!editableRoot->contains(visPos.deepEquivalent().computeContainerNode ())) 1232 if (!editableRoot->contains(visPos.deepEquivalent().computeContainerNode ()))
1222 return createVisiblePositionDeprecated(PositionTemplate<Strategy>::l astPositionInNode(editableRoot)); 1233 return createVisiblePosition(PositionTemplate<Strategy>::lastPositio nInNode(editableRoot));
1223 } 1234 }
1224 1235
1225 return honorEditingBoundaryAtOrAfter(visPos, currentPosition.deepEquivalent( )); 1236 return honorEditingBoundaryAtOrAfter(visPos, currentPosition.deepEquivalent( ));
1226 } 1237 }
1227 1238
1228 VisiblePosition logicalEndOfLine(const VisiblePosition& currentPosition) 1239 VisiblePosition logicalEndOfLine(const VisiblePosition& currentPosition)
1229 { 1240 {
1230 return logicalEndOfLineAlgorithm<EditingStrategy>(currentPosition); 1241 return logicalEndOfLineAlgorithm<EditingStrategy>(currentPosition);
1231 } 1242 }
1232 1243
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 root = box->root().prevRootBox(); 1366 root = box->root().prevRootBox();
1356 // We want to skip zero height boxes. 1367 // We want to skip zero height boxes.
1357 // This could happen in case it is a TrailingFloatsRootInlineBox. 1368 // This could happen in case it is a TrailingFloatsRootInlineBox.
1358 if (!root || !root->logicalHeight() || !root->firstLeafChild()) 1369 if (!root || !root->logicalHeight() || !root->firstLeafChild())
1359 root = 0; 1370 root = 0;
1360 } 1371 }
1361 1372
1362 if (!root) { 1373 if (!root) {
1363 Position position = previousRootInlineBoxCandidatePosition(node, visible Position, editableType); 1374 Position position = previousRootInlineBoxCandidatePosition(node, visible Position, editableType);
1364 if (position.isNotNull()) { 1375 if (position.isNotNull()) {
1365 RenderedPosition renderedPosition((createVisiblePositionDeprecated(p osition))); 1376 RenderedPosition renderedPosition((createVisiblePosition(position))) ;
1366 root = renderedPosition.rootBox(); 1377 root = renderedPosition.rootBox();
1367 if (!root) 1378 if (!root)
1368 return createVisiblePositionDeprecated(position); 1379 return createVisiblePosition(position);
1369 } 1380 }
1370 } 1381 }
1371 1382
1372 if (root) { 1383 if (root) {
1373 // FIXME: Can be wrong for multi-column layout and with transforms. 1384 // FIXME: Can be wrong for multi-column layout and with transforms.
1374 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock( root, lineDirectionPoint); 1385 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock( root, lineDirectionPoint);
1375 LineLayoutItem lineLayoutItem = root->closestLeafChildForPoint(pointInLi ne, isEditablePosition(p))->getLineLayoutItem(); 1386 LineLayoutItem lineLayoutItem = root->closestLeafChildForPoint(pointInLi ne, isEditablePosition(p))->getLineLayoutItem();
1376 Node* node = lineLayoutItem.node(); 1387 Node* node = lineLayoutItem.node();
1377 if (node && editingIgnoresContent(node)) 1388 if (node && editingIgnoresContent(node))
1378 return VisiblePosition::inParentBeforeNode(*node); 1389 return VisiblePosition::inParentBeforeNode(*node);
1379 return createVisiblePositionDeprecated(lineLayoutItem.positionForPoint(p ointInLine)); 1390 return createVisiblePosition(lineLayoutItem.positionForPoint(pointInLine ));
1380 } 1391 }
1381 1392
1382 // Could not find a previous line. This means we must already be on the firs t line. 1393 // Could not find a previous line. This means we must already be on the firs t line.
1383 // Move to the start of the content in this block, which effectively moves u s 1394 // Move to the start of the content in this block, which effectively moves u s
1384 // to the start of the line we're on. 1395 // to the start of the line we're on.
1385 Element* rootElement = hasEditableStyle(*node, editableType) ? rootEditableE lement(*node, editableType) : node->document().documentElement(); 1396 Element* rootElement = hasEditableStyle(*node, editableType) ? rootEditableE lement(*node, editableType) : node->document().documentElement();
1386 if (!rootElement) 1397 if (!rootElement)
1387 return VisiblePosition(); 1398 return VisiblePosition();
1388 return VisiblePosition::firstPositionInNode(rootElement); 1399 return VisiblePosition::firstPositionInNode(rootElement);
1389 } 1400 }
(...skipping 21 matching lines...) Expand all
1411 if (!root || !root->logicalHeight() || !root->firstLeafChild()) 1422 if (!root || !root->logicalHeight() || !root->firstLeafChild())
1412 root = 0; 1423 root = 0;
1413 } 1424 }
1414 1425
1415 if (!root) { 1426 if (!root) {
1416 // FIXME: We need do the same in previousLinePosition. 1427 // FIXME: We need do the same in previousLinePosition.
1417 Node* child = NodeTraversal::childAt(*node, p.computeEditingOffset()); 1428 Node* child = NodeTraversal::childAt(*node, p.computeEditingOffset());
1418 node = child ? child : &NodeTraversal::lastWithinOrSelf(*node); 1429 node = child ? child : &NodeTraversal::lastWithinOrSelf(*node);
1419 Position position = nextRootInlineBoxCandidatePosition(node, visiblePosi tion, editableType); 1430 Position position = nextRootInlineBoxCandidatePosition(node, visiblePosi tion, editableType);
1420 if (position.isNotNull()) { 1431 if (position.isNotNull()) {
1421 RenderedPosition renderedPosition((createVisiblePositionDeprecated(p osition))); 1432 RenderedPosition renderedPosition((createVisiblePosition(position))) ;
1422 root = renderedPosition.rootBox(); 1433 root = renderedPosition.rootBox();
1423 if (!root) 1434 if (!root)
1424 return createVisiblePositionDeprecated(position); 1435 return createVisiblePosition(position);
1425 } 1436 }
1426 } 1437 }
1427 1438
1428 if (root) { 1439 if (root) {
1429 // FIXME: Can be wrong for multi-column layout and with transforms. 1440 // FIXME: Can be wrong for multi-column layout and with transforms.
1430 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock( root, lineDirectionPoint); 1441 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock( root, lineDirectionPoint);
1431 LineLayoutItem lineLayoutItem = root->closestLeafChildForPoint(pointInLi ne, isEditablePosition(p))->getLineLayoutItem(); 1442 LineLayoutItem lineLayoutItem = root->closestLeafChildForPoint(pointInLi ne, isEditablePosition(p))->getLineLayoutItem();
1432 Node* node = lineLayoutItem.node(); 1443 Node* node = lineLayoutItem.node();
1433 if (node && editingIgnoresContent(node)) 1444 if (node && editingIgnoresContent(node))
1434 return VisiblePosition::inParentBeforeNode(*node); 1445 return VisiblePosition::inParentBeforeNode(*node);
1435 return createVisiblePositionDeprecated(lineLayoutItem.positionForPoint(p ointInLine)); 1446 return createVisiblePosition(lineLayoutItem.positionForPoint(pointInLine ));
1436 } 1447 }
1437 1448
1438 // Could not find a next line. This means we must already be on the last lin e. 1449 // Could not find a next line. This means we must already be on the last lin e.
1439 // Move to the end of the content in this block, which effectively moves us 1450 // Move to the end of the content in this block, which effectively moves us
1440 // to the end of the line we're on. 1451 // to the end of the line we're on.
1441 Element* rootElement = hasEditableStyle(*node, editableType) ? rootEditableE lement(*node, editableType) : node->document().documentElement(); 1452 Element* rootElement = hasEditableStyle(*node, editableType) ? rootEditableE lement(*node, editableType) : node->document().documentElement();
1442 if (!rootElement) 1453 if (!rootElement)
1443 return VisiblePosition(); 1454 return VisiblePosition();
1444 return VisiblePosition::lastPositionInNode(rootElement); 1455 return VisiblePosition::lastPositionInNode(rootElement);
1445 } 1456 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 1603
1593 if (candidateType == PositionAnchorType::OffsetInAnchor) 1604 if (candidateType == PositionAnchorType::OffsetInAnchor)
1594 return PositionTemplate<Strategy>(candidateNode, candidateOffset); 1605 return PositionTemplate<Strategy>(candidateNode, candidateOffset);
1595 1606
1596 return PositionTemplate<Strategy>(candidateNode, candidateType); 1607 return PositionTemplate<Strategy>(candidateNode, candidateType);
1597 } 1608 }
1598 1609
1599 template <typename Strategy> 1610 template <typename Strategy>
1600 VisiblePositionTemplate<Strategy> startOfParagraphAlgorithm(const VisiblePositio nTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule boundaryCrossi ngRule) 1611 VisiblePositionTemplate<Strategy> startOfParagraphAlgorithm(const VisiblePositio nTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule boundaryCrossi ngRule)
1601 { 1612 {
1613 // TODO(xiaochengh): Ensure that this function is called with a valid
1614 // |visiblePosition|, and add |DCHECK(visiblePosition.isValid())|;
1602 return createVisiblePositionDeprecated(startOfParagraphAlgorithm(visiblePosi tion.deepEquivalent(), boundaryCrossingRule)); 1615 return createVisiblePositionDeprecated(startOfParagraphAlgorithm(visiblePosi tion.deepEquivalent(), boundaryCrossingRule));
1603 } 1616 }
1604 1617
1605 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi ngRule boundaryCrossingRule) 1618 VisiblePosition startOfParagraph(const VisiblePosition& c, EditingBoundaryCrossi ngRule boundaryCrossingRule)
1606 { 1619 {
1607 return startOfParagraphAlgorithm<EditingStrategy>(c, boundaryCrossingRule); 1620 return startOfParagraphAlgorithm<EditingStrategy>(c, boundaryCrossingRule);
1608 } 1621 }
1609 1622
1610 VisiblePositionInFlatTree startOfParagraph(const VisiblePositionInFlatTree& c, E ditingBoundaryCrossingRule boundaryCrossingRule) 1623 VisiblePositionInFlatTree startOfParagraph(const VisiblePositionInFlatTree& c, E ditingBoundaryCrossingRule boundaryCrossingRule)
1611 { 1624 {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 1696
1684 if (candidateType == PositionAnchorType::OffsetInAnchor) 1697 if (candidateType == PositionAnchorType::OffsetInAnchor)
1685 return PositionTemplate<Strategy>(candidateNode, candidateOffset); 1698 return PositionTemplate<Strategy>(candidateNode, candidateOffset);
1686 1699
1687 return PositionTemplate<Strategy>(candidateNode, candidateType); 1700 return PositionTemplate<Strategy>(candidateNode, candidateType);
1688 } 1701 }
1689 1702
1690 template <typename Strategy> 1703 template <typename Strategy>
1691 static VisiblePositionTemplate<Strategy> endOfParagraphAlgorithm(const VisiblePo sitionTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule boundaryC rossingRule) 1704 static VisiblePositionTemplate<Strategy> endOfParagraphAlgorithm(const VisiblePo sitionTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule boundaryC rossingRule)
1692 { 1705 {
1706 // TODO(xiaochengh): Ensure that this function is called with a valid
1707 // |visiblePosition|, and add |DCHECK(visiblePosition.isValid())|;
1693 return createVisiblePositionDeprecated(endOfParagraphAlgorithm(visiblePositi on.deepEquivalent(), boundaryCrossingRule)); 1708 return createVisiblePositionDeprecated(endOfParagraphAlgorithm(visiblePositi on.deepEquivalent(), boundaryCrossingRule));
1694 } 1709 }
1695 1710
1696 VisiblePosition endOfParagraph(const VisiblePosition& c, EditingBoundaryCrossing Rule boundaryCrossingRule) 1711 VisiblePosition endOfParagraph(const VisiblePosition& c, EditingBoundaryCrossing Rule boundaryCrossingRule)
1697 { 1712 {
1698 return endOfParagraphAlgorithm<EditingStrategy>(c, boundaryCrossingRule); 1713 return endOfParagraphAlgorithm<EditingStrategy>(c, boundaryCrossingRule);
1699 } 1714 }
1700 1715
1701 VisiblePositionInFlatTree endOfParagraph(const VisiblePositionInFlatTree& c, Edi tingBoundaryCrossingRule boundaryCrossingRule) 1716 VisiblePositionInFlatTree endOfParagraph(const VisiblePositionInFlatTree& c, Edi tingBoundaryCrossingRule boundaryCrossingRule)
1702 { 1717 {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 bool isEndOfBlock(const VisiblePosition& pos) 1820 bool isEndOfBlock(const VisiblePosition& pos)
1806 { 1821 {
1807 return pos.isNotNull() && pos.deepEquivalent() == endOfBlock(pos, CanCrossEd itingBoundary).deepEquivalent(); 1822 return pos.isNotNull() && pos.deepEquivalent() == endOfBlock(pos, CanCrossEd itingBoundary).deepEquivalent();
1808 } 1823 }
1809 1824
1810 // --------- 1825 // ---------
1811 1826
1812 template <typename Strategy> 1827 template <typename Strategy>
1813 static VisiblePositionTemplate<Strategy> startOfDocumentAlgorithm(const VisibleP ositionTemplate<Strategy>& visiblePosition) 1828 static VisiblePositionTemplate<Strategy> startOfDocumentAlgorithm(const VisibleP ositionTemplate<Strategy>& visiblePosition)
1814 { 1829 {
1830 DCHECK(visiblePosition.isValid());
1815 Node* node = visiblePosition.deepEquivalent().anchorNode(); 1831 Node* node = visiblePosition.deepEquivalent().anchorNode();
1816 if (!node || !node->document().documentElement()) 1832 if (!node || !node->document().documentElement())
1817 return VisiblePositionTemplate<Strategy>(); 1833 return VisiblePositionTemplate<Strategy>();
1818 1834
1819 return createVisiblePositionDeprecated(PositionTemplate<Strategy>::firstPosi tionInNode(node->document().documentElement())); 1835 return createVisiblePosition(PositionTemplate<Strategy>::firstPositionInNode (node->document().documentElement()));
1820 } 1836 }
1821 1837
1822 VisiblePosition startOfDocument(const VisiblePosition& c) 1838 VisiblePosition startOfDocument(const VisiblePosition& c)
1823 { 1839 {
1824 return startOfDocumentAlgorithm<EditingStrategy>(c); 1840 return startOfDocumentAlgorithm<EditingStrategy>(c);
1825 } 1841 }
1826 1842
1827 VisiblePositionInFlatTree startOfDocument(const VisiblePositionInFlatTree& c) 1843 VisiblePositionInFlatTree startOfDocument(const VisiblePositionInFlatTree& c)
1828 { 1844 {
1829 return startOfDocumentAlgorithm<EditingInFlatTreeStrategy>(c); 1845 return startOfDocumentAlgorithm<EditingInFlatTreeStrategy>(c);
1830 } 1846 }
1831 1847
1832 template <typename Strategy> 1848 template <typename Strategy>
1833 static VisiblePositionTemplate<Strategy> endOfDocumentAlgorithm(const VisiblePos itionTemplate<Strategy>& visiblePosition) 1849 static VisiblePositionTemplate<Strategy> endOfDocumentAlgorithm(const VisiblePos itionTemplate<Strategy>& visiblePosition)
1834 { 1850 {
1851 DCHECK(visiblePosition.isValid());
1835 Node* node = visiblePosition.deepEquivalent().anchorNode(); 1852 Node* node = visiblePosition.deepEquivalent().anchorNode();
1836 if (!node || !node->document().documentElement()) 1853 if (!node || !node->document().documentElement())
1837 return VisiblePositionTemplate<Strategy>(); 1854 return VisiblePositionTemplate<Strategy>();
1838 1855
1839 Element* doc = node->document().documentElement(); 1856 Element* doc = node->document().documentElement();
1840 return createVisiblePositionDeprecated(PositionTemplate<Strategy>::lastPosit ionInNode(doc)); 1857 return createVisiblePosition(PositionTemplate<Strategy>::lastPositionInNode( doc));
1841 } 1858 }
1842 1859
1843 VisiblePosition endOfDocument(const VisiblePosition& c) 1860 VisiblePosition endOfDocument(const VisiblePosition& c)
1844 { 1861 {
1845 return endOfDocumentAlgorithm<EditingStrategy>(c); 1862 return endOfDocumentAlgorithm<EditingStrategy>(c);
1846 } 1863 }
1847 1864
1848 VisiblePositionInFlatTree endOfDocument(const VisiblePositionInFlatTree& c) 1865 VisiblePositionInFlatTree endOfDocument(const VisiblePositionInFlatTree& c)
1849 { 1866 {
1850 return endOfDocumentAlgorithm<EditingInFlatTreeStrategy>(c); 1867 return endOfDocumentAlgorithm<EditingInFlatTreeStrategy>(c);
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
2238 return false; 2255 return false;
2239 } 2256 }
2240 2257
2241 VisiblePosition visiblePositionForContentsPoint(const IntPoint& contentsPoint, L ocalFrame* frame) 2258 VisiblePosition visiblePositionForContentsPoint(const IntPoint& contentsPoint, L ocalFrame* frame)
2242 { 2259 {
2243 HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | H itTestRequest::Active | HitTestRequest::IgnoreClipping; 2260 HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | H itTestRequest::Active | HitTestRequest::IgnoreClipping;
2244 HitTestResult result(request, contentsPoint); 2261 HitTestResult result(request, contentsPoint);
2245 frame->document()->layoutViewItem().hitTest(result); 2262 frame->document()->layoutViewItem().hitTest(result);
2246 2263
2247 if (Node* node = result.innerNode()) 2264 if (Node* node = result.innerNode())
2248 return createVisiblePositionDeprecated(positionRespectingEditingBoundary (frame->selection().selection().start(), result.localPoint(), node)); 2265 return createVisiblePosition(positionRespectingEditingBoundary(frame->se lection().selection().start(), result.localPoint(), node));
2249 return VisiblePosition(); 2266 return VisiblePosition();
2250 } 2267 }
2251 2268
2252 // TODO(yosin): We should use |associatedLayoutObjectOf()| in "VisibleUnits.cpp" 2269 // TODO(yosin): We should use |associatedLayoutObjectOf()| in "VisibleUnits.cpp"
2253 // where it takes |LayoutObject| from |Position|. 2270 // where it takes |LayoutObject| from |Position|.
2254 // Note about ::first-letter pseudo-element: 2271 // Note about ::first-letter pseudo-element:
2255 // When an element has ::first-letter pseudo-element, first letter characters 2272 // When an element has ::first-letter pseudo-element, first letter characters
2256 // are taken from |Text| node and first letter characters are considered 2273 // are taken from |Text| node and first letter characters are considered
2257 // as content of <pseudo:first-letter>. 2274 // as content of <pseudo:first-letter>.
2258 // For following HTML, 2275 // For following HTML,
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2805 } 2822 }
2806 2823
2807 IntRect absoluteCaretBoundsOf(const VisiblePositionInFlatTree& visiblePosition) 2824 IntRect absoluteCaretBoundsOf(const VisiblePositionInFlatTree& visiblePosition)
2808 { 2825 {
2809 return absoluteCaretBoundsOfAlgorithm<EditingInFlatTreeStrategy>(visiblePosi tion); 2826 return absoluteCaretBoundsOfAlgorithm<EditingInFlatTreeStrategy>(visiblePosi tion);
2810 } 2827 }
2811 2828
2812 template <typename Strategy> 2829 template <typename Strategy>
2813 static VisiblePositionTemplate<Strategy> skipToEndOfEditingBoundary(const Visibl ePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor) 2830 static VisiblePositionTemplate<Strategy> skipToEndOfEditingBoundary(const Visibl ePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor)
2814 { 2831 {
2832 DCHECK(pos.isValid());
2815 if (pos.isNull()) 2833 if (pos.isNull())
2816 return pos; 2834 return pos;
2817 2835
2818 ContainerNode* highestRoot = highestEditableRoot(anchor); 2836 ContainerNode* highestRoot = highestEditableRoot(anchor);
2819 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); 2837 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent());
2820 2838
2821 // Return |pos| itself if the two are from the very same editable region, 2839 // Return |pos| itself if the two are from the very same editable region,
2822 // or both are non-editable. 2840 // or both are non-editable.
2823 if (highestRootOfPos == highestRoot) 2841 if (highestRootOfPos == highestRoot)
2824 return pos; 2842 return pos;
2825 2843
2826 // If this is not editable but |pos| has an editable root, skip to the end 2844 // If this is not editable but |pos| has an editable root, skip to the end
2827 if (!highestRoot && highestRootOfPos) 2845 if (!highestRoot && highestRootOfPos)
2828 return createVisiblePositionDeprecated(PositionTemplate<Strategy>(highes tRootOfPos, PositionAnchorType::AfterAnchor).parentAnchoredEquivalent()); 2846 return createVisiblePosition(PositionTemplate<Strategy>(highestRootOfPos , PositionAnchorType::AfterAnchor).parentAnchoredEquivalent());
2829 2847
2830 // That must mean that |pos| is not editable. Return the next position after 2848 // That must mean that |pos| is not editable. Return the next position after
2831 // |pos| that is in the same editable region as this position 2849 // |pos| that is in the same editable region as this position
2832 DCHECK(highestRoot); 2850 DCHECK(highestRoot);
2833 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), *highestRoot); 2851 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), *highestRoot);
2834 } 2852 }
2835 2853
2836 template <typename Strategy> 2854 template <typename Strategy>
2837 static UChar32 characterAfterAlgorithm(const VisiblePositionTemplate<Strategy>& visiblePosition) 2855 static UChar32 characterAfterAlgorithm(const VisiblePositionTemplate<Strategy>& visiblePosition)
2838 { 2856 {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
3028 if ((isVisuallyEquivalentCandidate(p) && mostForwardCaretPosition(p) != downstreamStart) || p.atStartOfTree() || p.atEndOfTree()) 3046 if ((isVisuallyEquivalentCandidate(p) && mostForwardCaretPosition(p) != downstreamStart) || p.atStartOfTree() || p.atEndOfTree())
3029 return p; 3047 return p;
3030 3048
3031 DCHECK_NE(p, deepPosition); 3049 DCHECK_NE(p, deepPosition);
3032 } 3050 }
3033 } 3051 }
3034 3052
3035 template <typename Strategy> 3053 template <typename Strategy>
3036 VisiblePositionTemplate<Strategy> leftPositionOfAlgorithm(const VisiblePositionT emplate<Strategy>& visiblePosition) 3054 VisiblePositionTemplate<Strategy> leftPositionOfAlgorithm(const VisiblePositionT emplate<Strategy>& visiblePosition)
3037 { 3055 {
3056 DCHECK(visiblePosition.isValid());
3038 const PositionTemplate<Strategy> pos = leftVisuallyDistinctCandidate(visible Position); 3057 const PositionTemplate<Strategy> pos = leftVisuallyDistinctCandidate(visible Position);
3039 // TODO(yosin) Why can't we move left from the last position in a tree? 3058 // TODO(yosin) Why can't we move left from the last position in a tree?
3040 if (pos.atStartOfTree() || pos.atEndOfTree()) 3059 if (pos.atStartOfTree() || pos.atEndOfTree())
3041 return VisiblePositionTemplate<Strategy>(); 3060 return VisiblePositionTemplate<Strategy>();
3042 3061
3043 const VisiblePositionTemplate<Strategy> left = createVisiblePositionDeprecat ed(pos); 3062 const VisiblePositionTemplate<Strategy> left = createVisiblePosition(pos);
3044 DCHECK_NE(left.deepEquivalent(), visiblePosition.deepEquivalent()); 3063 DCHECK_NE(left.deepEquivalent(), visiblePosition.deepEquivalent());
3045 3064
3046 return directionOfEnclosingBlock(left.deepEquivalent()) == LTR ? honorEditin gBoundaryAtOrBefore(left, visiblePosition.deepEquivalent()) : honorEditingBounda ryAtOrAfter(left, visiblePosition.deepEquivalent()); 3065 return directionOfEnclosingBlock(left.deepEquivalent()) == LTR ? honorEditin gBoundaryAtOrBefore(left, visiblePosition.deepEquivalent()) : honorEditingBounda ryAtOrAfter(left, visiblePosition.deepEquivalent());
3047 } 3066 }
3048 3067
3049 VisiblePosition leftPositionOf(const VisiblePosition& visiblePosition) 3068 VisiblePosition leftPositionOf(const VisiblePosition& visiblePosition)
3050 { 3069 {
3051 return leftPositionOfAlgorithm<EditingStrategy>(visiblePosition); 3070 return leftPositionOfAlgorithm<EditingStrategy>(visiblePosition);
3052 } 3071 }
3053 3072
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3206 if ((isVisuallyEquivalentCandidate(p) && mostForwardCaretPosition(p) != downstreamStart) || p.atStartOfTree() || p.atEndOfTree()) 3225 if ((isVisuallyEquivalentCandidate(p) && mostForwardCaretPosition(p) != downstreamStart) || p.atStartOfTree() || p.atEndOfTree())
3207 return p; 3226 return p;
3208 3227
3209 DCHECK_NE(p, deepPosition); 3228 DCHECK_NE(p, deepPosition);
3210 } 3229 }
3211 } 3230 }
3212 3231
3213 template <typename Strategy> 3232 template <typename Strategy>
3214 static VisiblePositionTemplate<Strategy> rightPositionOfAlgorithm(const VisibleP ositionTemplate<Strategy>& visiblePosition) 3233 static VisiblePositionTemplate<Strategy> rightPositionOfAlgorithm(const VisibleP ositionTemplate<Strategy>& visiblePosition)
3215 { 3234 {
3235 DCHECK(visiblePosition.isValid());
3216 const PositionTemplate<Strategy> pos = rightVisuallyDistinctCandidate(visibl ePosition); 3236 const PositionTemplate<Strategy> pos = rightVisuallyDistinctCandidate(visibl ePosition);
3217 // FIXME: Why can't we move left from the last position in a tree? 3237 // FIXME: Why can't we move left from the last position in a tree?
3218 if (pos.atStartOfTree() || pos.atEndOfTree()) 3238 if (pos.atStartOfTree() || pos.atEndOfTree())
3219 return VisiblePositionTemplate<Strategy>(); 3239 return VisiblePositionTemplate<Strategy>();
3220 3240
3221 const VisiblePositionTemplate<Strategy> right = createVisiblePositionDepreca ted(pos); 3241 const VisiblePositionTemplate<Strategy> right = createVisiblePosition(pos);
3222 DCHECK_NE(right.deepEquivalent(), visiblePosition.deepEquivalent()); 3242 DCHECK_NE(right.deepEquivalent(), visiblePosition.deepEquivalent());
3223 3243
3224 return directionOfEnclosingBlock(right.deepEquivalent()) == LTR ? honorEditi ngBoundaryAtOrAfter(right, visiblePosition.deepEquivalent()) : honorEditingBound aryAtOrBefore(right, visiblePosition.deepEquivalent()); 3244 return directionOfEnclosingBlock(right.deepEquivalent()) == LTR ? honorEditi ngBoundaryAtOrAfter(right, visiblePosition.deepEquivalent()) : honorEditingBound aryAtOrBefore(right, visiblePosition.deepEquivalent());
3225 } 3245 }
3226 3246
3227 VisiblePosition rightPositionOf(const VisiblePosition& visiblePosition) 3247 VisiblePosition rightPositionOf(const VisiblePosition& visiblePosition)
3228 { 3248 {
3229 return rightPositionOfAlgorithm<EditingStrategy>(visiblePosition); 3249 return rightPositionOfAlgorithm<EditingStrategy>(visiblePosition);
3230 } 3250 }
3231 3251
3232 VisiblePositionInFlatTree rightPositionOf(const VisiblePositionInFlatTree& visib lePosition) 3252 VisiblePositionInFlatTree rightPositionOf(const VisiblePositionInFlatTree& visib lePosition)
3233 { 3253 {
3234 return rightPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePosition); 3254 return rightPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePosition);
3235 } 3255 }
3236 3256
3237 template <typename Strategy> 3257 template <typename Strategy>
3238 static VisiblePositionTemplate<Strategy> nextPositionOfAlgorithm(const VisiblePo sitionTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule rule) 3258 static VisiblePositionTemplate<Strategy> nextPositionOfAlgorithm(const VisiblePo sitionTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule rule)
3239 { 3259 {
3260 // TODO(xiaochengh): Ensure that this function is called with a valid
3261 // |visiblePosition|, and add |DCHECK(visiblePosition.isValid())|;
3240 const VisiblePositionTemplate<Strategy> next = createVisiblePositionDeprecat ed(nextVisuallyDistinctCandidate(visiblePosition.deepEquivalent()), visiblePosit ion.affinity()); 3262 const VisiblePositionTemplate<Strategy> next = createVisiblePositionDeprecat ed(nextVisuallyDistinctCandidate(visiblePosition.deepEquivalent()), visiblePosit ion.affinity());
3241 3263
3242 switch (rule) { 3264 switch (rule) {
3243 case CanCrossEditingBoundary: 3265 case CanCrossEditingBoundary:
3244 return next; 3266 return next;
3245 case CannotCrossEditingBoundary: 3267 case CannotCrossEditingBoundary:
3246 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalen t()); 3268 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalen t());
3247 case CanSkipOverEditingBoundary: 3269 case CanSkipOverEditingBoundary:
3248 return skipToEndOfEditingBoundary(next, visiblePosition.deepEquivalent() ); 3270 return skipToEndOfEditingBoundary(next, visiblePosition.deepEquivalent() );
3249 } 3271 }
3250 NOTREACHED(); 3272 NOTREACHED();
3251 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalent()) ; 3273 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalent()) ;
3252 } 3274 }
3253 3275
3254 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo undaryCrossingRule rule) 3276 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo undaryCrossingRule rule)
3255 { 3277 {
3256 return nextPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); 3278 return nextPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule);
3257 } 3279 }
3258 3280
3259 VisiblePositionInFlatTree nextPositionOf(const VisiblePositionInFlatTree& visibl ePosition, EditingBoundaryCrossingRule rule) 3281 VisiblePositionInFlatTree nextPositionOf(const VisiblePositionInFlatTree& visibl ePosition, EditingBoundaryCrossingRule rule)
3260 { 3282 {
3261 return nextPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePosition, r ule); 3283 return nextPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePosition, r ule);
3262 } 3284 }
3263 3285
3264 template <typename Strategy> 3286 template <typename Strategy>
3265 static VisiblePositionTemplate<Strategy> skipToStartOfEditingBoundary(const Visi blePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor) 3287 static VisiblePositionTemplate<Strategy> skipToStartOfEditingBoundary(const Visi blePositionTemplate<Strategy>& pos, const PositionTemplate<Strategy>& anchor)
3266 { 3288 {
3289 DCHECK(pos.isValid());
3267 if (pos.isNull()) 3290 if (pos.isNull())
3268 return pos; 3291 return pos;
3269 3292
3270 ContainerNode* highestRoot = highestEditableRoot(anchor); 3293 ContainerNode* highestRoot = highestEditableRoot(anchor);
3271 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); 3294 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent());
3272 3295
3273 // Return |pos| itself if the two are from the very same editable region, or 3296 // Return |pos| itself if the two are from the very same editable region, or
3274 // both are non-editable. 3297 // both are non-editable.
3275 if (highestRootOfPos == highestRoot) 3298 if (highestRootOfPos == highestRoot)
3276 return pos; 3299 return pos;
3277 3300
3278 // If this is not editable but |pos| has an editable root, skip to the start 3301 // If this is not editable but |pos| has an editable root, skip to the start
3279 if (!highestRoot && highestRootOfPos) 3302 if (!highestRoot && highestRootOfPos)
3280 return createVisiblePositionDeprecated(previousVisuallyDistinctCandidate (PositionTemplate<Strategy>(highestRootOfPos, PositionAnchorType::BeforeAnchor). parentAnchoredEquivalent())); 3303 return createVisiblePosition(previousVisuallyDistinctCandidate(PositionT emplate<Strategy>(highestRootOfPos, PositionAnchorType::BeforeAnchor).parentAnch oredEquivalent()));
3281 3304
3282 // That must mean that |pos| is not editable. Return the last position 3305 // That must mean that |pos| is not editable. Return the last position
3283 // before |pos| that is in the same editable region as this position 3306 // before |pos| that is in the same editable region as this position
3284 DCHECK(highestRoot); 3307 DCHECK(highestRoot);
3285 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(), *highestRoot); 3308 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(), *highestRoot);
3286 } 3309 }
3287 3310
3288 template <typename Strategy> 3311 template <typename Strategy>
3289 static VisiblePositionTemplate<Strategy> previousPositionOfAlgorithm(const Visib lePositionTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule rule) 3312 static VisiblePositionTemplate<Strategy> previousPositionOfAlgorithm(const Visib lePositionTemplate<Strategy>& visiblePosition, EditingBoundaryCrossingRule rule)
3290 { 3313 {
3314 // TODO(xiaochengh): Ensure that this function is called with a valid
3315 // |visiblePosition|, and add |DCHECK(visiblePosition.isValid())|;
3291 const PositionTemplate<Strategy> pos = previousVisuallyDistinctCandidate(vis iblePosition.deepEquivalent()); 3316 const PositionTemplate<Strategy> pos = previousVisuallyDistinctCandidate(vis iblePosition.deepEquivalent());
3292 3317
3293 // return null visible position if there is no previous visible position 3318 // return null visible position if there is no previous visible position
3294 if (pos.atStartOfTree()) 3319 if (pos.atStartOfTree())
3295 return VisiblePositionTemplate<Strategy>(); 3320 return VisiblePositionTemplate<Strategy>();
3296 3321
3297 // we should always be able to make the affinity |TextAffinity::Downstream|, 3322 // we should always be able to make the affinity |TextAffinity::Downstream|,
3298 // because going previous from an |TextAffinity::Upstream| position can 3323 // because going previous from an |TextAffinity::Upstream| position can
3299 // never yield another |TextAffinity::Upstream position| (unless line wrap 3324 // never yield another |TextAffinity::Upstream position| (unless line wrap
3300 // length is 0!). 3325 // length is 0!).
(...skipping 18 matching lines...) Expand all
3319 { 3344 {
3320 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); 3345 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule);
3321 } 3346 }
3322 3347
3323 VisiblePositionInFlatTree previousPositionOf(const VisiblePositionInFlatTree& vi siblePosition, EditingBoundaryCrossingRule rule) 3348 VisiblePositionInFlatTree previousPositionOf(const VisiblePositionInFlatTree& vi siblePosition, EditingBoundaryCrossingRule rule)
3324 { 3349 {
3325 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePositio n, rule); 3350 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(visiblePositio n, rule);
3326 } 3351 }
3327 3352
3328 } // namespace blink 3353 } // 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