Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 template <class ElementType> | 34 template <class ElementType> |
| 35 class Traversal { | 35 class Traversal { |
| 36 public: | 36 public: |
| 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. | |
|
esprehn
2014/03/21 07:58:33
The comment doesn't add anything.
Inactive
2014/03/21 14:37:24
Each set of ElementTraversal functions is grouped
| |
| 44 static ElementType* firstAncestor(const Node& current); | |
| 45 | |
| 43 // First or last ElementType descendant of the node. | 46 // First or last ElementType descendant of the node. |
| 44 // For Elements firstWithin() is always the same as firstChild(). | 47 // For Elements firstWithin() is always the same as firstChild(). |
| 45 static ElementType* firstWithin(const ContainerNode& current) { return first WithinTemplate(current); } | 48 static ElementType* firstWithin(const ContainerNode& current) { return first WithinTemplate(current); } |
| 46 static ElementType* firstWithin(const Node& current) { return firstWithinTem plate(current); } | 49 static ElementType* firstWithin(const Node& current) { return firstWithinTem plate(current); } |
| 47 static ElementType* lastWithin(const ContainerNode& current) { return lastWi thinTemplate(current); } | 50 static ElementType* lastWithin(const ContainerNode& current) { return lastWi thinTemplate(current); } |
| 48 static ElementType* lastWithin(const Node& current) { return lastWithinTempl ate(current); } | 51 static ElementType* lastWithin(const Node& current) { return lastWithinTempl ate(current); } |
| 49 | 52 |
| 50 // Pre-order traversal skipping non-element nodes. | 53 // Pre-order traversal skipping non-element nodes. |
| 51 static ElementType* next(const ContainerNode& current) { return nextTemplate (current); } | 54 static ElementType* next(const ContainerNode& current) { return nextTemplate (current); } |
| 52 static ElementType* next(const Node& current) { return nextTemplate(current) ; } | 55 static ElementType* next(const Node& current) { return nextTemplate(current) ; } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 template <class NodeType> | 163 template <class NodeType> |
| 161 inline ElementType* Traversal<ElementType>::firstChildTemplate(NodeType& current ) | 164 inline ElementType* Traversal<ElementType>::firstChildTemplate(NodeType& current ) |
| 162 { | 165 { |
| 163 Node* node = current.firstChild(); | 166 Node* node = current.firstChild(); |
| 164 while (node && !isElementOfType<const ElementType>(*node)) | 167 while (node && !isElementOfType<const ElementType>(*node)) |
| 165 node = node->nextSibling(); | 168 node = node->nextSibling(); |
| 166 return toElement<ElementType>(node); | 169 return toElement<ElementType>(node); |
| 167 } | 170 } |
| 168 | 171 |
| 169 template <class ElementType> | 172 template <class ElementType> |
| 173 inline ElementType* Traversal<ElementType>::firstAncestor(const Node& current) | |
| 174 { | |
| 175 ContainerNode* ancestor = current.parentNode(); | |
|
Inactive
2014/03/15 23:50:18
One idea that came to mind, we could potentially o
| |
| 176 while (ancestor && !isElementOfType<const ElementType>(*ancestor)) | |
| 177 ancestor = ancestor->parentNode(); | |
| 178 return toElement<ElementType>(ancestor); | |
| 179 } | |
| 180 | |
| 181 template <class ElementType> | |
| 170 template <class NodeType> | 182 template <class NodeType> |
| 171 inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current) | 183 inline ElementType* Traversal<ElementType>::lastChildTemplate(NodeType& current) |
| 172 { | 184 { |
| 173 Node* node = current.lastChild(); | 185 Node* node = current.lastChild(); |
| 174 while (node && !isElementOfType<const ElementType>(*node)) | 186 while (node && !isElementOfType<const ElementType>(*node)) |
| 175 node = node->previousSibling(); | 187 node = node->previousSibling(); |
| 176 return toElement<ElementType>(node); | 188 return toElement<ElementType>(node); |
| 177 } | 189 } |
| 178 | 190 |
| 179 template <class ElementType> | 191 template <class ElementType> |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 { | 318 { |
| 307 Node* node = current.nextSibling(); | 319 Node* node = current.nextSibling(); |
| 308 while (node && !isElementOfType<const ElementType>(*node)) | 320 while (node && !isElementOfType<const ElementType>(*node)) |
| 309 node = node->nextSibling(); | 321 node = node->nextSibling(); |
| 310 return toElement<ElementType>(node); | 322 return toElement<ElementType>(node); |
| 311 } | 323 } |
| 312 | 324 |
| 313 } // namespace WebCore | 325 } // namespace WebCore |
| 314 | 326 |
| 315 #endif | 327 #endif |
| OLD | NEW |