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

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

Issue 229213002: Make HTMLCollection / NodeList backward traversal consistent with forward one (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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) 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, 2013 Appl e Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Appl e 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 27 matching lines...) Expand all
38 static ElementType* firstChild(const ContainerNode& current) { return firstC hildTemplate(current); } 38 static ElementType* firstChild(const ContainerNode& current) { return firstC hildTemplate(current); }
39 static ElementType* firstChild(const Node& current) { return firstChildTempl ate(current); } 39 static ElementType* firstChild(const Node& current) { return firstChildTempl ate(current); }
40 static ElementType* lastChild(const ContainerNode& current) { return lastChi ldTemplate(current); } 40 static ElementType* lastChild(const ContainerNode& current) { return lastChi ldTemplate(current); }
41 static ElementType* lastChild(const Node& current) { return lastChildTemplat e(current); } 41 static ElementType* lastChild(const Node& current) { return lastChildTemplat e(current); }
42 42
43 // First ElementType ancestor of the node. 43 // First ElementType ancestor of the node.
44 static ElementType* firstAncestor(const Node& current); 44 static ElementType* firstAncestor(const Node& current);
45 static ElementType* firstAncestorOrSelf(Node& current) { return firstAncesto rOrSelfTemplate(current); } 45 static ElementType* firstAncestorOrSelf(Node& current) { return firstAncesto rOrSelfTemplate(current); }
46 static ElementType* firstAncestorOrSelf(Element& current) { return firstAnce storOrSelfTemplate(current); } 46 static ElementType* firstAncestorOrSelf(Element& current) { return firstAnce storOrSelfTemplate(current); }
47 47
48 // First or last ElementType descendant of the node. 48 // First or last ElementType descendant of the node.
Inactive 2014/04/09 23:14:29 BTW, the comment here clearly says we are supposed
49 // For Elements firstWithin() is always the same as firstChild(). 49 // For Elements firstWithin() is always the same as firstChild().
50 static ElementType* firstWithin(const ContainerNode& current) { return first WithinTemplate(current); } 50 static ElementType* firstWithin(const ContainerNode& current) { return first WithinTemplate(current); }
51 static ElementType* firstWithin(const Node& current) { return firstWithinTem plate(current); } 51 static ElementType* firstWithin(const Node& current) { return firstWithinTem plate(current); }
52 static ElementType* lastWithin(const ContainerNode& current) { return lastWi thinTemplate(current); } 52 static ElementType* lastWithin(const ContainerNode& current) { return lastWi thinTemplate(current); }
53 static ElementType* lastWithin(const Node& current) { return lastWithinTempl ate(current); } 53 static ElementType* lastWithin(const Node& current) { return lastWithinTempl ate(current); }
54 54
55 // Pre-order traversal skipping non-element nodes. 55 // Pre-order traversal skipping non-element nodes.
56 static ElementType* next(const ContainerNode& current) { return nextTemplate (current); } 56 static ElementType* next(const ContainerNode& current) { return nextTemplate (current); }
57 static ElementType* next(const Node& current) { return nextTemplate(current) ; } 57 static ElementType* next(const Node& current) { return nextTemplate(current) ; }
58 static ElementType* next(const ContainerNode& current, const Node* stayWithi n) { return nextTemplate(current, stayWithin); } 58 static ElementType* next(const ContainerNode& current, const Node* stayWithi n) { return nextTemplate(current, stayWithin); }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 template <class NodeType> 112 template <class NodeType>
113 inline Element* Traversal<Element>::firstWithinTemplate(NodeType& current) 113 inline Element* Traversal<Element>::firstWithinTemplate(NodeType& current)
114 { 114 {
115 return firstChildTemplate(current); 115 return firstChildTemplate(current);
116 } 116 }
117 117
118 template <> 118 template <>
119 template <class NodeType> 119 template <class NodeType>
120 inline Element* Traversal<Element>::lastWithinTemplate(NodeType& current) 120 inline Element* Traversal<Element>::lastWithinTemplate(NodeType& current)
121 { 121 {
122 return lastChildTemplate(current); 122 Node* node = NodeTraversal::lastWithin(current);
Inactive 2014/04/09 23:19:07 Also see that WebKit is doing the same thing that
123 while (node && !node->isElementNode())
124 node = NodeTraversal::previous(*node, &current);
125 return toElement(node);
123 } 126 }
124 127
125 template <> 128 template <>
126 template <class NodeType> 129 template <class NodeType>
127 inline Element* Traversal<Element>::nextTemplate(NodeType& current) 130 inline Element* Traversal<Element>::nextTemplate(NodeType& current)
128 { 131 {
129 Node* node = NodeTraversal::next(current); 132 Node* node = NodeTraversal::next(current);
130 while (node && !node->isElementNode()) 133 while (node && !node->isElementNode())
131 node = NodeTraversal::nextSkippingChildren(*node); 134 node = NodeTraversal::nextSkippingChildren(*node);
132 return toElement(node); 135 return toElement(node);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 { 334 {
332 Node* node = current.nextSibling(); 335 Node* node = current.nextSibling();
333 while (node && !isElementOfType<const ElementType>(*node)) 336 while (node && !isElementOfType<const ElementType>(*node))
334 node = node->nextSibling(); 337 node = node->nextSibling();
335 return toElement<ElementType>(node); 338 return toElement<ElementType>(node);
336 } 339 }
337 340
338 } // namespace WebCore 341 } // namespace WebCore
339 342
340 #endif 343 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698