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

Side by Side Diff: Source/core/dom/Range.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/PositionIterator.h ('k') | Source/core/dom/RangeBoundaryPoint.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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
5 * (C) 2001 Peter Kelly (pmk@post.com) 5 * (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if (lastChild && lastChild == m_start.childBefore()) { 901 if (lastChild && lastChild == m_start.childBefore()) {
902 // The insertion will do nothing, but we need to extend the range to include 902 // The insertion will do nothing, but we need to extend the range to include
903 // the inserted nodes. 903 // the inserted nodes.
904 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t oDocumentFragment(newNode)->firstChild() : newNode.get(); 904 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t oDocumentFragment(newNode)->firstChild() : newNode.get();
905 ASSERT(firstChild); 905 ASSERT(firstChild);
906 m_start.setToBeforeChild(*firstChild); 906 m_start.setToBeforeChild(*firstChild);
907 return; 907 return;
908 } 908 }
909 909
910 container = m_start.container(); 910 container = m_start.container();
911 container->insertBefore(newNode.release(), container->traverseToChildAt( m_start.offset()), exceptionState); 911 container->insertBefore(newNode.release(), NodeTraversal::childAt(*conta iner, m_start.offset()), exceptionState);
912 if (exceptionState.hadException()) 912 if (exceptionState.hadException())
913 return; 913 return;
914 914
915 // Note that m_start.offset() may have changed as a result of container- >insertBefore, 915 // Note that m_start.offset() may have changed as a result of container- >insertBefore,
916 // when the node we are inserting comes before the range in the same con tainer. 916 // when the node we are inserting comes before the range in the same con tainer.
917 if (collapsed && numNewChildren) 917 if (collapsed && numNewChildren)
918 m_end.set(m_start.container(), m_start.offset() + numNewChildren, la stChild.get()); 918 m_end.set(m_start.container(), m_start.offset() + numNewChildren, la stChild.get());
919 } 919 }
920 } 920 }
921 921
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 case Node::PROCESSING_INSTRUCTION_NODE: 1013 case Node::PROCESSING_INSTRUCTION_NODE:
1014 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length()) 1014 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length())
1015 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to than the node's length (" + String::number(toProcessingInstruction(n)->data().length()) + ")."); 1015 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to than the node's length (" + String::number(toProcessingInstruction(n)->data().length()) + ").");
1016 return 0; 1016 return 0;
1017 case Node::ATTRIBUTE_NODE: 1017 case Node::ATTRIBUTE_NODE:
1018 case Node::DOCUMENT_FRAGMENT_NODE: 1018 case Node::DOCUMENT_FRAGMENT_NODE:
1019 case Node::DOCUMENT_NODE: 1019 case Node::DOCUMENT_NODE:
1020 case Node::ELEMENT_NODE: { 1020 case Node::ELEMENT_NODE: {
1021 if (!offset) 1021 if (!offset)
1022 return 0; 1022 return 0;
1023 Node* childBefore = n->traverseToChildAt(offset - 1); 1023 Node* childBefore = NodeTraversal::childAt(*n, offset - 1);
1024 if (!childBefore) 1024 if (!childBefore)
1025 exceptionState.throwDOMException(IndexSizeError, "There is no ch ild at offset " + String::number(offset) + "."); 1025 exceptionState.throwDOMException(IndexSizeError, "There is no ch ild at offset " + String::number(offset) + ".");
1026 return childBefore; 1026 return childBefore;
1027 } 1027 }
1028 } 1028 }
1029 ASSERT_NOT_REACHED(); 1029 ASSERT_NOT_REACHED();
1030 return 0; 1030 return 0;
1031 } 1031 }
1032 1032
1033 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const 1033 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 exceptionState.throwDOMException(HierarchyRequestError, "The Range c ontains a doctype node."); 1303 exceptionState.throwDOMException(HierarchyRequestError, "The Range c ontains a doctype node.");
1304 return; 1304 return;
1305 } 1305 }
1306 } 1306 }
1307 } 1307 }
1308 1308
1309 Node* Range::firstNode() const 1309 Node* Range::firstNode() const
1310 { 1310 {
1311 if (m_start.container()->offsetInCharacters()) 1311 if (m_start.container()->offsetInCharacters())
1312 return m_start.container(); 1312 return m_start.container();
1313 if (Node* child = m_start.container()->traverseToChildAt(m_start.offset())) 1313 if (Node* child = NodeTraversal::childAt(*m_start.container(), m_start.offse t()))
1314 return child; 1314 return child;
1315 if (!m_start.offset()) 1315 if (!m_start.offset())
1316 return m_start.container(); 1316 return m_start.container();
1317 return NodeTraversal::nextSkippingChildren(*m_start.container()); 1317 return NodeTraversal::nextSkippingChildren(*m_start.container());
1318 } 1318 }
1319 1319
1320 ShadowRoot* Range::shadowRoot() const 1320 ShadowRoot* Range::shadowRoot() const
1321 { 1321 {
1322 return startContainer() ? startContainer()->containingShadowRoot() : 0; 1322 return startContainer() ? startContainer()->containingShadowRoot() : 0;
1323 } 1323 }
1324 1324
1325 Node* Range::pastLastNode() const 1325 Node* Range::pastLastNode() const
1326 { 1326 {
1327 if (m_end.container()->offsetInCharacters()) 1327 if (m_end.container()->offsetInCharacters())
1328 return NodeTraversal::nextSkippingChildren(*m_end.container()); 1328 return NodeTraversal::nextSkippingChildren(*m_end.container());
1329 if (Node* child = m_end.container()->traverseToChildAt(m_end.offset())) 1329 if (Node* child = NodeTraversal::childAt(*m_end.container(), m_end.offset()) )
1330 return child; 1330 return child;
1331 return NodeTraversal::nextSkippingChildren(*m_end.container()); 1331 return NodeTraversal::nextSkippingChildren(*m_end.container());
1332 } 1332 }
1333 1333
1334 IntRect Range::boundingBox() const 1334 IntRect Range::boundingBox() const
1335 { 1335 {
1336 IntRect result; 1336 IntRect result;
1337 Vector<IntRect> rects; 1337 Vector<IntRect> rects;
1338 textRects(rects); 1338 textRects(rects);
1339 const size_t n = rects.size(); 1339 const size_t n = rects.size();
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 1702
1703 void showTree(const blink::Range* range) 1703 void showTree(const blink::Range* range)
1704 { 1704 {
1705 if (range && range->boundaryPointsValid()) { 1705 if (range && range->boundaryPointsValid()) {
1706 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1706 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1707 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1707 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1708 } 1708 }
1709 } 1709 }
1710 1710
1711 #endif 1711 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/PositionIterator.h ('k') | Source/core/dom/RangeBoundaryPoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698