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

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

Issue 166573003: Port ParentNode API to ElementTraversal (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/ParentNode.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) 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 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 14 matching lines...) Expand all
25 #ifndef ElementTraversal_h 25 #ifndef ElementTraversal_h
26 #define ElementTraversal_h 26 #define ElementTraversal_h
27 27
28 #include "core/dom/Element.h" 28 #include "core/dom/Element.h"
29 #include "core/dom/NodeTraversal.h" 29 #include "core/dom/NodeTraversal.h"
30 30
31 namespace WebCore { 31 namespace WebCore {
32 32
33 namespace ElementTraversal { 33 namespace ElementTraversal {
34 34
35 // First element child of the node. 35 // First / Last element child of the node.
36 Element* firstWithin(const Node&); 36 Element* firstWithin(const Node&);
37 Element* firstWithin(const ContainerNode&); 37 Element* firstWithin(const ContainerNode&);
38 Element* lastWithin(const Node&);
39 Element* lastWithin(const ContainerNode&);
38 40
39 // Pre-order traversal skipping non-element nodes. 41 // Pre-order traversal skipping non-element nodes.
40 Element* next(const Node&); 42 Element* next(const Node&);
41 Element* next(const Node&, const Node* stayWithin); 43 Element* next(const Node&, const Node* stayWithin);
42 Element* next(const ContainerNode&); 44 Element* next(const ContainerNode&);
43 Element* next(const ContainerNode&, const Node* stayWithin); 45 Element* next(const ContainerNode&, const Node* stayWithin);
44 46
45 // Like next, but skips children. 47 // Like next, but skips children.
46 Element* nextSkippingChildren(const Node&); 48 Element* nextSkippingChildren(const Node&);
47 Element* nextSkippingChildren(const Node&, const Node* stayWithin); 49 Element* nextSkippingChildren(const Node&, const Node* stayWithin);
(...skipping 17 matching lines...) Expand all
65 // Except for the root containers, only elements can have element children. 67 // Except for the root containers, only elements can have element children.
66 Node* node = current.firstChild(); 68 Node* node = current.firstChild();
67 while (node && !node->isElementNode()) 69 while (node && !node->isElementNode())
68 node = node->nextSibling(); 70 node = node->nextSibling();
69 return toElement(node); 71 return toElement(node);
70 } 72 }
71 inline Element* firstWithin(const ContainerNode& current) { return firstElementW ithinTemplate(current); } 73 inline Element* firstWithin(const ContainerNode& current) { return firstElementW ithinTemplate(current); }
72 inline Element* firstWithin(const Node& current) { return firstElementWithinTemp late(current); } 74 inline Element* firstWithin(const Node& current) { return firstElementWithinTemp late(current); }
73 75
74 template <class NodeType> 76 template <class NodeType>
77 inline Element* lastWithinTemplate(NodeType& current)
78 {
79 Node* node = current.lastChild();
80 while (node && !node->isElementNode())
81 node = node->previousSibling();
82 return toElement(node);
83 }
84 inline Element* lastWithin(const ContainerNode& current) { return lastWithinTemp late(current); }
85 inline Element* lastWithin(const Node& current) { return lastWithinTemplate(curr ent); }
86
87 template <class NodeType>
75 inline Element* traverseNextElementTemplate(NodeType& current) 88 inline Element* traverseNextElementTemplate(NodeType& current)
76 { 89 {
77 Node* node = NodeTraversal::next(current); 90 Node* node = NodeTraversal::next(current);
78 while (node && !node->isElementNode()) 91 while (node && !node->isElementNode())
79 node = NodeTraversal::nextSkippingChildren(*node); 92 node = NodeTraversal::nextSkippingChildren(*node);
80 return toElement(node); 93 return toElement(node);
81 } 94 }
82 inline Element* next(const ContainerNode& current) { return traverseNextElementT emplate(current); } 95 inline Element* next(const ContainerNode& current) { return traverseNextElementT emplate(current); }
83 inline Element* next(const Node& current) { return traverseNextElementTemplate(c urrent); } 96 inline Element* next(const Node& current) { return traverseNextElementTemplate(c urrent); }
84 97
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 while (node && !node->isElementNode()) 166 while (node && !node->isElementNode())
154 node = node->nextSibling(); 167 node = node->nextSibling();
155 return toElement(node); 168 return toElement(node);
156 } 169 }
157 170
158 } 171 }
159 172
160 } 173 }
161 174
162 #endif 175 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/ParentNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698