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

Side by Side Diff: Source/core/dom/NodeTraversal.h

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/Node.h ('k') | Source/core/dom/Position.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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
7 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 7 * Copyright (C) 2014 Samsung Electronics. 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 // Pre-order traversal including the pseudo-elements. 64 // Pre-order traversal including the pseudo-elements.
65 static Node* previousIncludingPseudo(const Node&, const Node* stayWithin = 0 ); 65 static Node* previousIncludingPseudo(const Node&, const Node* stayWithin = 0 );
66 static Node* nextIncludingPseudo(const Node&, const Node* stayWithin = 0); 66 static Node* nextIncludingPseudo(const Node&, const Node* stayWithin = 0);
67 static Node* nextIncludingPseudoSkippingChildren(const Node&, const Node* st ayWithin = 0); 67 static Node* nextIncludingPseudoSkippingChildren(const Node&, const Node* st ayWithin = 0);
68 68
69 static Node* nextAncestorSibling(const Node&); 69 static Node* nextAncestorSibling(const Node&);
70 static Node* nextAncestorSibling(const Node&, const Node* stayWithin); 70 static Node* nextAncestorSibling(const Node&, const Node* stayWithin);
71 static Node& highestAncestorOrSelf(Node&); 71 static Node& highestAncestorOrSelf(Node&);
72 72
73 // Children traversal.
74 static Node* childAt(const Node& parent, unsigned index) { return childAtTem plate(parent, index); }
75 static Node* childAt(const ContainerNode& parent, unsigned index) { return c hildAtTemplate(parent, index); }
76
73 private: 77 private:
74 template <class NodeType> 78 template <class NodeType>
75 static Node* traverseNextTemplate(NodeType&); 79 static Node* traverseNextTemplate(NodeType&);
76 template <class NodeType> 80 template <class NodeType>
77 static Node* traverseNextTemplate(NodeType&, const Node* stayWithin); 81 static Node* traverseNextTemplate(NodeType&, const Node* stayWithin);
82 template <class NodeType>
83 static Node* childAtTemplate(NodeType&, unsigned);
78 }; 84 };
79 85
80 template <class NodeType> 86 template <class NodeType>
81 inline Node* NodeTraversal::traverseNextTemplate(NodeType& current) 87 inline Node* NodeTraversal::traverseNextTemplate(NodeType& current)
82 { 88 {
83 if (current.hasChildren()) 89 if (current.hasChildren())
84 return current.firstChild(); 90 return current.firstChild();
85 if (current.nextSibling()) 91 if (current.nextSibling())
86 return current.nextSibling(); 92 return current.nextSibling();
87 return nextAncestorSibling(current); 93 return nextAncestorSibling(current);
(...skipping 28 matching lines...) Expand all
116 } 122 }
117 123
118 inline Node& NodeTraversal::highestAncestorOrSelf(Node& current) 124 inline Node& NodeTraversal::highestAncestorOrSelf(Node& current)
119 { 125 {
120 Node* highest = &current; 126 Node* highest = &current;
121 while (highest->parentNode()) 127 while (highest->parentNode())
122 highest = highest->parentNode(); 128 highest = highest->parentNode();
123 return *highest; 129 return *highest;
124 } 130 }
125 131
132 template <class NodeType>
133 inline Node* NodeTraversal::childAtTemplate(NodeType& parent, unsigned index)
134 {
135 Node* child = parent.firstChild();
136 while (child && index--)
137 child = child->nextSibling();
138 return child;
139 }
140
126 } // namespace blink 141 } // namespace blink
127 142
128 #endif 143 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/Position.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698