| 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 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 17 matching lines...) Expand all Loading... |
| 28 #include "core/dom/Node.h" | 28 #include "core/dom/Node.h" |
| 29 | 29 |
| 30 namespace WebCore { | 30 namespace WebCore { |
| 31 | 31 |
| 32 namespace NodeTraversal { | 32 namespace NodeTraversal { |
| 33 | 33 |
| 34 // Does a pre-order traversal of the tree to find the next node after this one. | 34 // Does a pre-order traversal of the tree to find the next node after this one. |
| 35 // This uses the same order that tags appear in the source file. If the stayWith
in | 35 // This uses the same order that tags appear in the source file. If the stayWith
in |
| 36 // argument is non-null, the traversal will stop once the specified node is reac
hed. | 36 // argument is non-null, the traversal will stop once the specified node is reac
hed. |
| 37 // This can be used to restrict traversal to a particular sub-tree. | 37 // This can be used to restrict traversal to a particular sub-tree. |
| 38 Node* next(const Node*); | 38 Node* next(const Node&); |
| 39 Node* next(const Node*, const Node* stayWithin); | 39 Node* next(const Node&, const Node* stayWithin); |
| 40 Node* next(const ContainerNode*); | 40 Node* next(const ContainerNode&); |
| 41 Node* next(const ContainerNode*, const Node* stayWithin); | 41 Node* next(const ContainerNode&, const Node* stayWithin); |
| 42 | 42 |
| 43 // Like next, but skips children and starts with the next sibling. | 43 // Like next, but skips children and starts with the next sibling. |
| 44 Node* nextSkippingChildren(const Node*); | 44 Node* nextSkippingChildren(const Node*); |
| 45 Node* nextSkippingChildren(const Node*, const Node* stayWithin); | 45 Node* nextSkippingChildren(const Node*, const Node* stayWithin); |
| 46 Node* nextSkippingChildren(const ContainerNode*); | 46 Node* nextSkippingChildren(const ContainerNode*); |
| 47 Node* nextSkippingChildren(const ContainerNode*, const Node* stayWithin); | 47 Node* nextSkippingChildren(const ContainerNode*, const Node* stayWithin); |
| 48 | 48 |
| 49 // Does a reverse pre-order traversal to find the node that comes before the cur
rent one in document order | 49 // Does a reverse pre-order traversal to find the node that comes before the cur
rent one in document order |
| 50 Node* previous(const Node*, const Node* stayWithin = 0); | 50 Node* previous(const Node*, const Node* stayWithin = 0); |
| 51 | 51 |
| 52 // Like previous, but skips children and starts with the next sibling. | 52 // Like previous, but skips children and starts with the next sibling. |
| 53 Node* previousSkippingChildren(const Node*, const Node* stayWithin = 0); | 53 Node* previousSkippingChildren(const Node*, const Node* stayWithin = 0); |
| 54 | 54 |
| 55 // Like next, but visits parents after their children. | 55 // Like next, but visits parents after their children. |
| 56 Node* nextPostOrder(const Node*, const Node* stayWithin = 0); | 56 Node* nextPostOrder(const Node*, const Node* stayWithin = 0); |
| 57 | 57 |
| 58 // Like previous/previousSkippingChildren, but visits parents before their child
ren. | 58 // Like previous/previousSkippingChildren, but visits parents before their child
ren. |
| 59 Node* previousPostOrder(const Node*, const Node* stayWithin = 0); | 59 Node* previousPostOrder(const Node*, const Node* stayWithin = 0); |
| 60 Node* previousSkippingChildrenPostOrder(const Node*, const Node* stayWithin = 0)
; | 60 Node* previousSkippingChildrenPostOrder(const Node*, const Node* stayWithin = 0)
; |
| 61 | 61 |
| 62 // Pre-order traversal including the pseudo-elements. | 62 // Pre-order traversal including the pseudo-elements. |
| 63 Node* previousIncludingPseudo(const Node*, const Node* stayWithin = 0); | 63 Node* previousIncludingPseudo(const Node*, const Node* stayWithin = 0); |
| 64 Node* nextIncludingPseudo(const Node*, const Node* stayWithin = 0); | 64 Node* nextIncludingPseudo(const Node*, const Node* stayWithin = 0); |
| 65 Node* nextIncludingPseudoSkippingChildren(const Node*, const Node* stayWithin =
0); | 65 Node* nextIncludingPseudoSkippingChildren(const Node*, const Node* stayWithin =
0); |
| 66 | 66 |
| 67 Node* nextAncestorSibling(const Node*); | 67 Node* nextAncestorSibling(const Node*); |
| 68 Node* nextAncestorSibling(const Node*, const Node* stayWithin); | 68 Node* nextAncestorSibling(const Node*, const Node* stayWithin); |
| 69 | 69 |
| 70 template <class NodeType> | 70 template <class NodeType> |
| 71 inline Node* traverseNextTemplate(NodeType* current) | 71 inline Node* traverseNextTemplate(NodeType& current) |
| 72 { | 72 { |
| 73 if (current->firstChild()) | 73 if (current.firstChild()) |
| 74 return current->firstChild(); | 74 return current.firstChild(); |
| 75 if (current->nextSibling()) | 75 if (current.nextSibling()) |
| 76 return current->nextSibling(); | 76 return current.nextSibling(); |
| 77 return nextAncestorSibling(current); | 77 return nextAncestorSibling(¤t); |
| 78 } | 78 } |
| 79 inline Node* next(const Node* current) { return traverseNextTemplate(current); } | 79 inline Node* next(const Node& current) { return traverseNextTemplate(current); } |
| 80 inline Node* next(const ContainerNode* current) { return traverseNextTemplate(cu
rrent); } | 80 inline Node* next(const ContainerNode& current) { return traverseNextTemplate(cu
rrent); } |
| 81 | 81 |
| 82 template <class NodeType> | 82 template <class NodeType> |
| 83 inline Node* traverseNextTemplate(NodeType* current, const Node* stayWithin) | 83 inline Node* traverseNextTemplate(NodeType& current, const Node* stayWithin) |
| 84 { | 84 { |
| 85 if (current->firstChild()) | 85 if (current.firstChild()) |
| 86 return current->firstChild(); | 86 return current.firstChild(); |
| 87 if (current == stayWithin) | 87 if (current == stayWithin) |
| 88 return 0; | 88 return 0; |
| 89 if (current->nextSibling()) | 89 if (current.nextSibling()) |
| 90 return current->nextSibling(); | 90 return current.nextSibling(); |
| 91 return nextAncestorSibling(current, stayWithin); | 91 return nextAncestorSibling(¤t, stayWithin); |
| 92 } | 92 } |
| 93 inline Node* next(const Node* current, const Node* stayWithin) { return traverse
NextTemplate(current, stayWithin); } | 93 inline Node* next(const Node& current, const Node* stayWithin) { return traverse
NextTemplate(current, stayWithin); } |
| 94 inline Node* next(const ContainerNode* current, const Node* stayWithin) { return
traverseNextTemplate(current, stayWithin); } | 94 inline Node* next(const ContainerNode& current, const Node* stayWithin) { return
traverseNextTemplate(current, stayWithin); } |
| 95 | 95 |
| 96 template <class NodeType> | 96 template <class NodeType> |
| 97 inline Node* traverseNextSkippingChildrenTemplate(NodeType* current) | 97 inline Node* traverseNextSkippingChildrenTemplate(NodeType* current) |
| 98 { | 98 { |
| 99 if (current->nextSibling()) | 99 if (current->nextSibling()) |
| 100 return current->nextSibling(); | 100 return current->nextSibling(); |
| 101 return nextAncestorSibling(current); | 101 return nextAncestorSibling(current); |
| 102 } | 102 } |
| 103 inline Node* nextSkippingChildren(const Node* current) { return traverseNextSkip
pingChildrenTemplate(current); } | 103 inline Node* nextSkippingChildren(const Node* current) { return traverseNextSkip
pingChildrenTemplate(current); } |
| 104 inline Node* nextSkippingChildren(const ContainerNode* current) { return travers
eNextSkippingChildrenTemplate(current); } | 104 inline Node* nextSkippingChildren(const ContainerNode* current) { return travers
eNextSkippingChildrenTemplate(current); } |
| 105 | 105 |
| 106 template <class NodeType> | 106 template <class NodeType> |
| 107 inline Node* traverseNextSkippingChildrenTemplate(NodeType* current, const Node*
stayWithin) | 107 inline Node* traverseNextSkippingChildrenTemplate(NodeType* current, const Node*
stayWithin) |
| 108 { | 108 { |
| 109 if (current == stayWithin) | 109 if (current == stayWithin) |
| 110 return 0; | 110 return 0; |
| 111 if (current->nextSibling()) | 111 if (current->nextSibling()) |
| 112 return current->nextSibling(); | 112 return current->nextSibling(); |
| 113 return nextAncestorSibling(current, stayWithin); | 113 return nextAncestorSibling(current, stayWithin); |
| 114 } | 114 } |
| 115 inline Node* nextSkippingChildren(const Node* current, const Node* stayWithin) {
return traverseNextSkippingChildrenTemplate(current, stayWithin); } | 115 inline Node* nextSkippingChildren(const Node* current, const Node* stayWithin) {
return traverseNextSkippingChildrenTemplate(current, stayWithin); } |
| 116 inline Node* nextSkippingChildren(const ContainerNode* current, const Node* stay
Within) { return traverseNextSkippingChildrenTemplate(current, stayWithin); } | 116 inline Node* nextSkippingChildren(const ContainerNode* current, const Node* stay
Within) { return traverseNextSkippingChildrenTemplate(current, stayWithin); } |
| 117 | 117 |
| 118 } | 118 } |
| 119 | 119 |
| 120 } | 120 } |
| 121 | 121 |
| 122 #endif | 122 #endif |
| OLD | NEW |