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

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

Issue 171773008: Rename childNodeCount() / childNode() methods for clarity (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Further renaming for consistency Created 6 years, 10 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
« no previous file with comments | « Source/core/editing/ReplaceSelectionCommand.cpp ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | 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, 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 169
170 #endif 170 #endif
171 171
172 // This function is like Range::pastLastNode, except for the fact that it can cl imb up out of shadow trees. 172 // This function is like Range::pastLastNode, except for the fact that it can cl imb up out of shadow trees.
173 static Node* nextInPreOrderCrossingShadowBoundaries(Node* rangeEndContainer, int rangeEndOffset) 173 static Node* nextInPreOrderCrossingShadowBoundaries(Node* rangeEndContainer, int rangeEndOffset)
174 { 174 {
175 if (!rangeEndContainer) 175 if (!rangeEndContainer)
176 return 0; 176 return 0;
177 if (rangeEndOffset >= 0 && !rangeEndContainer->offsetInCharacters()) { 177 if (rangeEndOffset >= 0 && !rangeEndContainer->offsetInCharacters()) {
178 if (Node* next = rangeEndContainer->childNode(rangeEndOffset)) 178 if (Node* next = rangeEndContainer->traverseToChildAt(rangeEndOffset))
179 return next; 179 return next;
180 } 180 }
181 for (Node* node = rangeEndContainer; node; node = node->parentOrShadowHostNo de()) { 181 for (Node* node = rangeEndContainer; node; node = node->parentOrShadowHostNo de()) {
182 if (Node* next = node->nextSibling()) 182 if (Node* next = node->nextSibling())
183 return next; 183 return next;
184 } 184 }
185 return 0; 185 return 0;
186 } 186 }
187 187
188 // -------- 188 // --------
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 RefPtr<Range> textRange = range(); 1136 RefPtr<Range> textRange = range();
1137 if (!textRange) 1137 if (!textRange)
1138 return 0; 1138 return 0;
1139 1139
1140 Node* node = textRange->startContainer(); 1140 Node* node = textRange->startContainer();
1141 if (!node) 1141 if (!node)
1142 return 0; 1142 return 0;
1143 if (node->offsetInCharacters()) 1143 if (node->offsetInCharacters())
1144 return node; 1144 return node;
1145 1145
1146 return node->childNode(textRange->startOffset()); 1146 return node->traverseToChildAt(textRange->startOffset());
1147 } 1147 }
1148 1148
1149 // -------- 1149 // --------
1150 1150
1151 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r, TextIteratorBehaviorFlags behavior) 1151 SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range* r, TextIteratorBehaviorFlags behavior)
1152 : m_node(0) 1152 : m_node(0)
1153 , m_offset(0) 1153 , m_offset(0)
1154 , m_handledNode(false) 1154 , m_handledNode(false)
1155 , m_handledChildren(false) 1155 , m_handledChildren(false)
1156 , m_startNode(0) 1156 , m_startNode(0)
(...skipping 20 matching lines...) Expand all
1177 return; 1177 return;
1178 1178
1179 Node* startNode = r->startContainer(); 1179 Node* startNode = r->startContainer();
1180 if (!startNode) 1180 if (!startNode)
1181 return; 1181 return;
1182 Node* endNode = r->endContainer(); 1182 Node* endNode = r->endContainer();
1183 int startOffset = r->startOffset(); 1183 int startOffset = r->startOffset();
1184 int endOffset = r->endOffset(); 1184 int endOffset = r->endOffset();
1185 1185
1186 if (!startNode->offsetInCharacters() && startOffset >= 0) { 1186 if (!startNode->offsetInCharacters() && startOffset >= 0) {
1187 // childNode() will return 0 if the offset is out of range. We rely on t his behavior 1187 // traverseToChildAt() will return 0 if the offset is out of range. We r ely on this behavior
1188 // instead of calling childNodeCount() to avoid traversing the children twice. 1188 // instead of calling countChildren() to avoid traversing the children t wice.
1189 if (Node* childAtOffset = startNode->childNode(startOffset)) { 1189 if (Node* childAtOffset = startNode->traverseToChildAt(startOffset)) {
1190 startNode = childAtOffset; 1190 startNode = childAtOffset;
1191 startOffset = 0; 1191 startOffset = 0;
1192 } 1192 }
1193 } 1193 }
1194 if (!endNode->offsetInCharacters() && endOffset > 0) { 1194 if (!endNode->offsetInCharacters() && endOffset > 0) {
1195 // childNode() will return 0 if the offset is out of range. We rely on t his behavior 1195 // traverseToChildAt() will return 0 if the offset is out of range. We r ely on this behavior
1196 // instead of calling childNodeCount() to avoid traversing the children twice. 1196 // instead of calling countChildren() to avoid traversing the children t wice.
1197 if (Node* childAtOffset = endNode->childNode(endOffset - 1)) { 1197 if (Node* childAtOffset = endNode->traverseToChildAt(endOffset - 1)) {
1198 endNode = childAtOffset; 1198 endNode = childAtOffset;
1199 endOffset = lastOffsetInNode(endNode); 1199 endOffset = lastOffsetInNode(endNode);
1200 } 1200 }
1201 } 1201 }
1202 1202
1203 m_node = endNode; 1203 m_node = endNode;
1204 setUpFullyClippedStack(m_fullyClippedStack, m_node); 1204 setUpFullyClippedStack(m_fullyClippedStack, m_node);
1205 m_offset = endOffset; 1205 m_offset = endOffset;
1206 m_handledNode = false; 1206 m_handledNode = false;
1207 m_handledChildren = !endOffset; 1207 m_handledChildren = !endOffset;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 } else if (renderer && (renderer->isImage() || renderer->isWidget()) ) { 1250 } else if (renderer && (renderer->isImage() || renderer->isWidget()) ) {
1251 if (renderer->style()->visibility() == VISIBLE && m_offset > 0) 1251 if (renderer->style()->visibility() == VISIBLE && m_offset > 0)
1252 m_handledNode = handleReplacedElement(); 1252 m_handledNode = handleReplacedElement();
1253 } else { 1253 } else {
1254 m_handledNode = handleNonTextNode(); 1254 m_handledNode = handleNonTextNode();
1255 } 1255 }
1256 if (m_positionNode) 1256 if (m_positionNode)
1257 return; 1257 return;
1258 } 1258 }
1259 1259
1260 if (!m_handledChildren && m_node->hasChildNodes()) { 1260 if (!m_handledChildren && m_node->hasChildren()) {
1261 m_node = m_node->lastChild(); 1261 m_node = m_node->lastChild();
1262 pushFullyClippedState(m_fullyClippedStack, m_node); 1262 pushFullyClippedState(m_fullyClippedStack, m_node);
1263 } else { 1263 } else {
1264 // Exit empty containers as we pass over them or containers 1264 // Exit empty containers as we pass over them or containers
1265 // where [container, 0] is where we started iterating. 1265 // where [container, 0] is where we started iterating.
1266 if (!m_handledNode 1266 if (!m_handledNode
1267 && canHaveChildrenForEditing(m_node) 1267 && canHaveChildrenForEditing(m_node)
1268 && m_node->parentNode() 1268 && m_node->parentNode()
1269 && (!m_node->lastChild() || (m_node == m_endNode && !m_endOffset ))) { 1269 && (!m_node->lastChild() || (m_node == m_endNode && !m_endOffset ))) {
1270 exitNode(); 1270 exitNode();
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 if (!matchLength) 2081 if (!matchLength)
2082 return collapsedToBoundary(range, !(options & Backwards)); 2082 return collapsedToBoundary(range, !(options & Backwards));
2083 } 2083 }
2084 2084
2085 // Then, find the document position of the start and the end of the text. 2085 // Then, find the document position of the start and the end of the text.
2086 CharacterIterator computeRangeIterator(range, TextIteratorEntersTextControls | TextIteratorEntersAuthorShadowRoots); 2086 CharacterIterator computeRangeIterator(range, TextIteratorEntersTextControls | TextIteratorEntersAuthorShadowRoots);
2087 return characterSubrange(computeRangeIterator, matchStart, matchLength); 2087 return characterSubrange(computeRangeIterator, matchStart, matchLength);
2088 } 2088 }
2089 2089
2090 } 2090 }
OLDNEW
« no previous file with comments | « Source/core/editing/ReplaceSelectionCommand.cpp ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698