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

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

Issue 397303005: Add Traversal<>::firstAncestorOrSelf() overload taking a const reference in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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/Element.cpp ('k') | no next file » | 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, 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 26 matching lines...) Expand all
37 // First or last ElementType child of the node. 37 // First or last ElementType child of the node.
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 static const ElementType* firstAncestorOrSelf(const Node& current) { return firstAncestorOrSelfTemplate(const_cast<Node&>(current)); }
48 static const ElementType* firstAncestorOrSelf(const Element& current) { retu rn firstAncestorOrSelfTemplate(const_cast<Element&>(current)); }
47 49
48 // First or last ElementType descendant of the node. 50 // First or last ElementType descendant of the node.
49 // For Elements firstWithin() is always the same as firstChild(). 51 // For Elements firstWithin() is always the same as firstChild().
50 static ElementType* firstWithin(const ContainerNode& current) { return first WithinTemplate(current); } 52 static ElementType* firstWithin(const ContainerNode& current) { return first WithinTemplate(current); }
51 static ElementType* firstWithin(const Node& current) { return firstWithinTem plate(current); } 53 static ElementType* firstWithin(const Node& current) { return firstWithinTem plate(current); }
52 static ElementType* lastWithin(const ContainerNode& current) { return lastWi thinTemplate(current); } 54 static ElementType* lastWithin(const ContainerNode& current) { return lastWi thinTemplate(current); }
53 static ElementType* lastWithin(const Node& current) { return lastWithinTempl ate(current); } 55 static ElementType* lastWithin(const Node& current) { return lastWithinTempl ate(current); }
54 56
55 // Pre-order traversal skipping non-element nodes. 57 // Pre-order traversal skipping non-element nodes.
56 static ElementType* next(const ContainerNode& current) { return nextTemplate (current); } 58 static ElementType* next(const ContainerNode& current) { return nextTemplate (current); }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ContainerNode* ancestor = current.parentNode(); 184 ContainerNode* ancestor = current.parentNode();
183 while (ancestor && !isElementOfType<const ElementType>(*ancestor)) 185 while (ancestor && !isElementOfType<const ElementType>(*ancestor))
184 ancestor = ancestor->parentNode(); 186 ancestor = ancestor->parentNode();
185 return toElement<ElementType>(ancestor); 187 return toElement<ElementType>(ancestor);
186 } 188 }
187 189
188 template <class ElementType> 190 template <class ElementType>
189 template <class NodeType> 191 template <class NodeType>
190 inline ElementType* Traversal<ElementType>::firstAncestorOrSelfTemplate(NodeType & current) 192 inline ElementType* Traversal<ElementType>::firstAncestorOrSelfTemplate(NodeType & current)
191 { 193 {
192 if (isElementOfType<const ElementType>(current)) 194 if (isElementOfType<const ElementType>(current))
Inactive 2014/07/19 00:02:53 The reason there is an Element overload is to avoi
193 return &toElement<ElementType>(current); 195 return &toElement<ElementType>(current);
194 return firstAncestor(current); 196 return firstAncestor(current);
195 } 197 }
196 198
197 template <class ElementType> 199 template <class ElementType>
198 template <class NodeType> 200 template <class NodeType>
199 inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current) 201 inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current)
200 { 202 {
201 Node* node = current.lastChild(); 203 Node* node = current.lastChild();
202 while (node && !isElementOfType<const ElementType>(*node)) 204 while (node && !isElementOfType<const ElementType>(*node))
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 { 336 {
335 Node* node = current.nextSibling(); 337 Node* node = current.nextSibling();
336 while (node && !isElementOfType<const ElementType>(*node)) 338 while (node && !isElementOfType<const ElementType>(*node))
337 node = node->nextSibling(); 339 node = node->nextSibling();
338 return toElement<ElementType>(node); 340 return toElement<ElementType>(node);
339 } 341 }
340 342
341 } // namespace WebCore 343 } // namespace WebCore
342 344
343 #endif 345 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698