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

Side by Side Diff: Source/core/editing/iterators/TextIterator.cpp

Issue 1041463003: Remove methods of TextIterator that take Range objects (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
3 * Copyright (C) 2005 Alexey Proskuryakov. 3 * Copyright (C) 2005 Alexey Proskuryakov.
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 for (Node* node = rangeEndContainer; node; node = node->parentOrShadowHostNo de()) { 71 for (Node* node = rangeEndContainer; node; node = node->parentOrShadowHostNo de()) {
72 if (Node* next = node->nextSibling()) 72 if (Node* next = node->nextSibling())
73 return next; 73 return next;
74 } 74 }
75 return 0; 75 return 0;
76 } 76 }
77 77
78 // -------- 78 // --------
79 79
80 TextIterator::TextIterator(const Range* range, TextIteratorBehaviorFlags behavio r)
81 : m_startContainer(nullptr)
82 , m_startOffset(0)
83 , m_endContainer(nullptr)
84 , m_endOffset(0)
85 , m_positionNode(nullptr)
86 , m_textLength(0)
87 , m_needsAnotherNewline(false)
88 , m_textBox(0)
89 , m_remainingTextBox(0)
90 , m_firstLetterText(nullptr)
91 , m_lastTextNode(nullptr)
92 , m_lastTextNodeEndedWithCollapsedSpace(false)
93 , m_lastCharacter(0)
94 , m_sortedTextBoxesPosition(0)
95 , m_hasEmitted(false)
96 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions)
97 , m_entersTextControls(behavior & TextIteratorEntersTextControls)
98 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText)
99 , m_handledFirstLetter(false)
100 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility)
101 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
102 , m_shouldStop(false)
103 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
104 , m_entersOpenShadowRoots(behavior & TextIteratorEntersOpenShadowRoots)
105 , m_emitsObjectReplacementCharacter(behavior & TextIteratorEmitsObjectReplac ementCharacter)
106 , m_breaksAtReplacedElement(!(behavior & TextIteratorDoesNotBreakAtReplacedE lement))
107 {
108 if (range)
109 initialize(range->startPosition(), range->endPosition());
110 }
111
112 TextIterator::TextIterator(const Position& start, const Position& end, TextItera torBehaviorFlags behavior) 80 TextIterator::TextIterator(const Position& start, const Position& end, TextItera torBehaviorFlags behavior)
113 : m_startContainer(nullptr) 81 : m_startContainer(nullptr)
114 , m_startOffset(0) 82 , m_startOffset(0)
115 , m_endContainer(nullptr) 83 , m_endContainer(nullptr)
116 , m_endOffset(0) 84 , m_endOffset(0)
117 , m_positionNode(nullptr) 85 , m_positionNode(nullptr)
118 , m_textLength(0) 86 , m_textLength(0)
119 , m_needsAnotherNewline(false) 87 , m_needsAnotherNewline(false)
120 , m_textBox(0) 88 , m_textBox(0)
121 , m_remainingTextBox(0) 89 , m_remainingTextBox(0)
122 , m_firstLetterText(nullptr) 90 , m_firstLetterText(nullptr)
123 , m_lastTextNode(nullptr) 91 , m_lastTextNode(nullptr)
124 , m_lastTextNodeEndedWithCollapsedSpace(false) 92 , m_lastTextNodeEndedWithCollapsedSpace(false)
125 , m_lastCharacter(0) 93 , m_lastCharacter(0)
126 , m_sortedTextBoxesPosition(0) 94 , m_sortedTextBoxesPosition(0)
127 , m_hasEmitted(false) 95 , m_hasEmitted(false)
128 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions) 96 , m_emitsCharactersBetweenAllVisiblePositions(behavior & TextIteratorEmitsCh aractersBetweenAllVisiblePositions)
129 , m_entersTextControls(behavior & TextIteratorEntersTextControls) 97 , m_entersTextControls(behavior & TextIteratorEntersTextControls)
130 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText) 98 , m_emitsOriginalText(behavior & TextIteratorEmitsOriginalText)
131 , m_handledFirstLetter(false) 99 , m_handledFirstLetter(false)
132 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility) 100 , m_ignoresStyleVisibility(behavior & TextIteratorIgnoresStyleVisibility)
133 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls) 101 , m_stopsOnFormControls(behavior & TextIteratorStopsOnFormControls)
134 , m_shouldStop(false) 102 , m_shouldStop(false)
135 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText) 103 , m_emitsImageAltText(behavior & TextIteratorEmitsImageAltText)
136 , m_entersOpenShadowRoots(behavior & TextIteratorEntersOpenShadowRoots) 104 , m_entersOpenShadowRoots(behavior & TextIteratorEntersOpenShadowRoots)
137 , m_emitsObjectReplacementCharacter(behavior & TextIteratorEmitsObjectReplac ementCharacter) 105 , m_emitsObjectReplacementCharacter(behavior & TextIteratorEmitsObjectReplac ementCharacter)
138 , m_breaksAtReplacedElement(!(behavior & TextIteratorDoesNotBreakAtReplacedE lement)) 106 , m_breaksAtReplacedElement(!(behavior & TextIteratorDoesNotBreakAtReplacedE lement))
139 { 107 {
108 if (start.isNull() || end.isNull())
haraken 2015/03/30 07:34:28 Why do we need this check? It seems the old code
hajimehoshi 2015/03/30 07:40:56 It is because there are some cases in which |range
hajimehoshi 2015/03/30 07:51:15 That was my misunderstanding: All editing tests pa
109 return;
110
140 initialize(start, end); 111 initialize(start, end);
141 } 112 }
142 113
143 void TextIterator::initialize(const Position& start, const Position& end) 114 void TextIterator::initialize(const Position& start, const Position& end)
144 { 115 {
145 ASSERT(comparePositions(start, end) <= 0); 116 ASSERT(comparePositions(start, end) <= 0);
146 117
147 // Get and validate |start| and |end|. 118 // Get and validate |start| and |end|.
148 Node* startContainer = start.containerNode(); 119 Node* startContainer = start.containerNode();
149 if (!startContainer) 120 if (!startContainer)
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 Position TextIterator::startPosition() const 1074 Position TextIterator::startPosition() const
1104 { 1075 {
1105 return createLegacyEditingPosition(startContainer(), startOffset()); 1076 return createLegacyEditingPosition(startContainer(), startOffset());
1106 } 1077 }
1107 1078
1108 Position TextIterator::endPosition() const 1079 Position TextIterator::endPosition() const
1109 { 1080 {
1110 return createLegacyEditingPosition(endContainer(), endOffset()); 1081 return createLegacyEditingPosition(endContainer(), endOffset());
1111 } 1082 }
1112 1083
1113 int TextIterator::rangeLength(const Range* r, bool forSelectionPreservation)
1114 {
1115 int length = 0;
1116 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character;
1117 if (forSelectionPreservation)
1118 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions;
1119 for (TextIterator it(r, behaviorFlags); !it.atEnd(); it.advance())
1120 length += it.length();
1121
1122 return length;
1123 }
1124
1125 int TextIterator::rangeLength(const Position& start, const Position& end, bool f orSelectionPreservation) 1084 int TextIterator::rangeLength(const Position& start, const Position& end, bool f orSelectionPreservation)
1126 { 1085 {
1127 int length = 0; 1086 int length = 0;
1128 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character; 1087 TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacement Character;
1129 if (forSelectionPreservation) 1088 if (forSelectionPreservation)
1130 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions; 1089 behaviorFlags |= TextIteratorEmitsCharactersBetweenAllVisiblePositions;
1131 for (TextIterator it(start, end, behaviorFlags); !it.atEnd(); it.advance()) 1090 for (TextIterator it(start, end, behaviorFlags); !it.atEnd(); it.advance())
1132 length += it.length(); 1091 length += it.length();
1133 1092
1134 return length; 1093 return length;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 } 1125 }
1167 1126
1168 if (!bufferLength) 1127 if (!bufferLength)
1169 return emptyString(); 1128 return emptyString();
1170 1129
1171 return builder.toString(); 1130 return builder.toString();
1172 } 1131 }
1173 1132
1174 String plainText(const Range* r, TextIteratorBehaviorFlags behavior) 1133 String plainText(const Range* r, TextIteratorBehaviorFlags behavior)
1175 { 1134 {
1176 TextIterator it(r, behavior); 1135 TextIterator it(r->startPosition(), r->endPosition(), behavior);
1177 return createPlainText(it); 1136 return createPlainText(it);
1178 } 1137 }
1179 1138
1180 String plainText(const Position& start, const Position& end, TextIteratorBehavio rFlags behavior) 1139 String plainText(const Position& start, const Position& end, TextIteratorBehavio rFlags behavior)
1181 { 1140 {
1182 TextIterator it(start, end, behavior); 1141 TextIterator it(start, end, behavior);
1183 return createPlainText(it); 1142 return createPlainText(it);
1184 } 1143 }
1185 1144
1186 } 1145 }
OLDNEW
« no previous file with comments | « Source/core/editing/iterators/TextIterator.h ('k') | Source/core/editing/iterators/TextIteratorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698