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

Side by Side Diff: Source/core/dom/Position.cpp

Issue 425223005: Move Node/ContainerNode's traverseToChildAt() to NodeTraversal (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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/dom/NodeTraversal.h ('k') | Source/core/dom/PositionIterator.h » ('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, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 Node* Position::computeNodeBeforePosition() const 227 Node* Position::computeNodeBeforePosition() const
228 { 228 {
229 if (!m_anchorNode) 229 if (!m_anchorNode)
230 return 0; 230 return 0;
231 switch (anchorType()) { 231 switch (anchorType()) {
232 case PositionIsBeforeChildren: 232 case PositionIsBeforeChildren:
233 return 0; 233 return 0;
234 case PositionIsAfterChildren: 234 case PositionIsAfterChildren:
235 return m_anchorNode->lastChild(); 235 return m_anchorNode->lastChild();
236 case PositionIsOffsetInAnchor: 236 case PositionIsOffsetInAnchor:
237 return m_anchorNode->traverseToChildAt(m_offset - 1); // -1 converts to traverseToChildAt((unsigned)-1) and returns null. 237 return m_offset ? NodeTraversal::childAt(*m_anchorNode, m_offset - 1) : 0;
238 case PositionIsBeforeAnchor: 238 case PositionIsBeforeAnchor:
239 return m_anchorNode->previousSibling(); 239 return m_anchorNode->previousSibling();
240 case PositionIsAfterAnchor: 240 case PositionIsAfterAnchor:
241 return m_anchorNode.get(); 241 return m_anchorNode.get();
242 } 242 }
243 ASSERT_NOT_REACHED(); 243 ASSERT_NOT_REACHED();
244 return 0; 244 return 0;
245 } 245 }
246 246
247 Node* Position::computeNodeAfterPosition() const 247 Node* Position::computeNodeAfterPosition() const
248 { 248 {
249 if (!m_anchorNode) 249 if (!m_anchorNode)
250 return 0; 250 return 0;
251 251
252 switch (anchorType()) { 252 switch (anchorType()) {
253 case PositionIsBeforeChildren: 253 case PositionIsBeforeChildren:
254 return m_anchorNode->firstChild(); 254 return m_anchorNode->firstChild();
255 case PositionIsAfterChildren: 255 case PositionIsAfterChildren:
256 return 0; 256 return 0;
257 case PositionIsOffsetInAnchor: 257 case PositionIsOffsetInAnchor:
258 return m_anchorNode->traverseToChildAt(m_offset); 258 return NodeTraversal::childAt(*m_anchorNode, m_offset);
259 case PositionIsBeforeAnchor: 259 case PositionIsBeforeAnchor:
260 return m_anchorNode.get(); 260 return m_anchorNode.get();
261 case PositionIsAfterAnchor: 261 case PositionIsAfterAnchor:
262 return m_anchorNode->nextSibling(); 262 return m_anchorNode->nextSibling();
263 } 263 }
264 ASSERT_NOT_REACHED(); 264 ASSERT_NOT_REACHED();
265 return 0; 265 return 0;
266 } 266 }
267 267
268 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo de, int offset) 268 Position::AnchorType Position::anchorTypeForLegacyEditingPosition(Node* anchorNo de, int offset)
(...skipping 27 matching lines...) Expand all
296 { 296 {
297 Node* node = deprecatedNode(); 297 Node* node = deprecatedNode();
298 if (!node) 298 if (!node)
299 return *this; 299 return *this;
300 300
301 int offset = deprecatedEditingOffset(); 301 int offset = deprecatedEditingOffset();
302 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie r. 302 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie r.
303 ASSERT(offset >= 0); 303 ASSERT(offset >= 0);
304 304
305 if (offset > 0) { 305 if (offset > 0) {
306 if (Node* child = node->traverseToChildAt(offset - 1)) 306 if (Node* child = NodeTraversal::childAt(*node, offset - 1))
307 return lastPositionInOrAfterNode(child); 307 return lastPositionInOrAfterNode(child);
308 308
309 // There are two reasons child might be 0: 309 // There are two reasons child might be 0:
310 // 1) The node is node like a text node that is not an element, and th erefore has no children. 310 // 1) The node is node like a text node that is not an element, and th erefore has no children.
311 // Going backward one character at a time is correct. 311 // Going backward one character at a time is correct.
312 // 2) The old offset was a bogus offset like (<br>, 1), and there is n o child. 312 // 2) The old offset was a bogus offset like (<br>, 1), and there is n o child.
313 // Going from 1 to 0 is correct. 313 // Going from 1 to 0 is correct.
314 switch (moveType) { 314 switch (moveType) {
315 case CodePoint: 315 case CodePoint:
316 return createLegacyEditingPosition(node, offset - 1); 316 return createLegacyEditingPosition(node, offset - 1);
(...skipping 14 matching lines...) Expand all
331 ASSERT(moveType != BackwardDeletion); 331 ASSERT(moveType != BackwardDeletion);
332 332
333 Node* node = deprecatedNode(); 333 Node* node = deprecatedNode();
334 if (!node) 334 if (!node)
335 return *this; 335 return *this;
336 336
337 int offset = deprecatedEditingOffset(); 337 int offset = deprecatedEditingOffset();
338 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie r. 338 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie r.
339 ASSERT(offset >= 0); 339 ASSERT(offset >= 0);
340 340
341 if (Node* child = node->traverseToChildAt(offset)) 341 if (Node* child = NodeTraversal::childAt(*node, offset))
342 return firstPositionInOrBeforeNode(child); 342 return firstPositionInOrBeforeNode(child);
343 343
344 if (!node->hasChildren() && offset < lastOffsetForEditing(node)) { 344 if (!node->hasChildren() && offset < lastOffsetForEditing(node)) {
345 // There are two reasons child might be 0: 345 // There are two reasons child might be 0:
346 // 1) The node is node like a text node that is not an element, and th erefore has no children. 346 // 1) The node is node like a text node that is not an element, and th erefore has no children.
347 // Going forward one character at a time is correct. 347 // Going forward one character at a time is correct.
348 // 2) The new offset is a bogus offset like (<br>, 1), and there is no child. 348 // 2) The new offset is a bogus offset like (<br>, 1), and there is no child.
349 // Going from 0 to 1 is correct. 349 // Going from 0 to 1 is correct.
350 return createLegacyEditingPosition(node, (moveType == Character) ? unche ckedNextOffset(node, offset) : offset + 1); 350 return createLegacyEditingPosition(node, (moveType == Character) ? unche ckedNextOffset(node, offset) : offset + 1);
351 } 351 }
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 pos.showTreeForThis(); 1304 pos.showTreeForThis();
1305 } 1305 }
1306 1306
1307 void showTree(const blink::Position* pos) 1307 void showTree(const blink::Position* pos)
1308 { 1308 {
1309 if (pos) 1309 if (pos)
1310 pos->showTreeForThis(); 1310 pos->showTreeForThis();
1311 } 1311 }
1312 1312
1313 #endif 1313 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/NodeTraversal.h ('k') | Source/core/dom/PositionIterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698