| 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 10 matching lines...) Expand all Loading... |
| 21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
| 22 * | 22 * |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #include "core/dom/NodeTraversal.h" | 26 #include "core/dom/NodeTraversal.h" |
| 27 | 27 |
| 28 #include "core/dom/ContainerNode.h" | 28 #include "core/dom/ContainerNode.h" |
| 29 | 29 |
| 30 namespace WebCore { | 30 namespace WebCore { |
| 31 namespace NodeTraversal { | |
| 32 | 31 |
| 33 Node* previousIncludingPseudo(const Node& current, const Node* stayWithin) | 32 Node* NodeTraversal::previousIncludingPseudo(const Node& current, const Node* st
ayWithin) |
| 34 { | 33 { |
| 35 if (current == stayWithin) | 34 if (current == stayWithin) |
| 36 return 0; | 35 return 0; |
| 37 if (Node* previous = current.pseudoAwarePreviousSibling()) { | 36 if (Node* previous = current.pseudoAwarePreviousSibling()) { |
| 38 while (previous->pseudoAwareLastChild()) | 37 while (previous->pseudoAwareLastChild()) |
| 39 previous = previous->pseudoAwareLastChild(); | 38 previous = previous->pseudoAwareLastChild(); |
| 40 return previous; | 39 return previous; |
| 41 } | 40 } |
| 42 return current.parentNode(); | 41 return current.parentNode(); |
| 43 } | 42 } |
| 44 | 43 |
| 45 Node* nextIncludingPseudo(const Node& current, const Node* stayWithin) | 44 Node* NodeTraversal::nextIncludingPseudo(const Node& current, const Node* stayWi
thin) |
| 46 { | 45 { |
| 47 if (Node* next = current.pseudoAwareFirstChild()) | 46 if (Node* next = current.pseudoAwareFirstChild()) |
| 48 return next; | 47 return next; |
| 49 if (current == stayWithin) | 48 if (current == stayWithin) |
| 50 return 0; | 49 return 0; |
| 51 if (Node* next = current.pseudoAwareNextSibling()) | 50 if (Node* next = current.pseudoAwareNextSibling()) |
| 52 return next; | 51 return next; |
| 53 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { | 52 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { |
| 54 if (parent == stayWithin) | 53 if (parent == stayWithin) |
| 55 return 0; | 54 return 0; |
| 56 if (Node* next = parent->pseudoAwareNextSibling()) | 55 if (Node* next = parent->pseudoAwareNextSibling()) |
| 57 return next; | 56 return next; |
| 58 } | 57 } |
| 59 return 0; | 58 return 0; |
| 60 } | 59 } |
| 61 | 60 |
| 62 Node* nextIncludingPseudoSkippingChildren(const Node& current, const Node* stayW
ithin) | 61 Node* NodeTraversal::nextIncludingPseudoSkippingChildren(const Node& current, co
nst Node* stayWithin) |
| 63 { | 62 { |
| 64 if (current == stayWithin) | 63 if (current == stayWithin) |
| 65 return 0; | 64 return 0; |
| 66 if (Node* next = current.pseudoAwareNextSibling()) | 65 if (Node* next = current.pseudoAwareNextSibling()) |
| 67 return next; | 66 return next; |
| 68 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { | 67 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { |
| 69 if (parent == stayWithin) | 68 if (parent == stayWithin) |
| 70 return 0; | 69 return 0; |
| 71 if (Node* next = parent->pseudoAwareNextSibling()) | 70 if (Node* next = parent->pseudoAwareNextSibling()) |
| 72 return next; | 71 return next; |
| 73 } | 72 } |
| 74 return 0; | 73 return 0; |
| 75 } | 74 } |
| 76 | 75 |
| 77 Node* nextAncestorSibling(const Node& current) | 76 Node* NodeTraversal::nextAncestorSibling(const Node& current) |
| 78 { | 77 { |
| 79 ASSERT(!current.nextSibling()); | 78 ASSERT(!current.nextSibling()); |
| 80 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { | 79 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { |
| 81 if (parent->nextSibling()) | 80 if (parent->nextSibling()) |
| 82 return parent->nextSibling(); | 81 return parent->nextSibling(); |
| 83 } | 82 } |
| 84 return 0; | 83 return 0; |
| 85 } | 84 } |
| 86 | 85 |
| 87 Node* nextAncestorSibling(const Node& current, const Node* stayWithin) | 86 Node* NodeTraversal::nextAncestorSibling(const Node& current, const Node* stayWi
thin) |
| 88 { | 87 { |
| 89 ASSERT(!current.nextSibling()); | 88 ASSERT(!current.nextSibling()); |
| 90 ASSERT(current != stayWithin); | 89 ASSERT(current != stayWithin); |
| 91 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { | 90 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { |
| 92 if (parent == stayWithin) | 91 if (parent == stayWithin) |
| 93 return 0; | 92 return 0; |
| 94 if (parent->nextSibling()) | 93 if (parent->nextSibling()) |
| 95 return parent->nextSibling(); | 94 return parent->nextSibling(); |
| 96 } | 95 } |
| 97 return 0; | 96 return 0; |
| 98 } | 97 } |
| 99 | 98 |
| 100 Node* previous(const Node& current, const Node* stayWithin) | 99 Node* NodeTraversal::previous(const Node& current, const Node* stayWithin) |
| 101 { | 100 { |
| 102 if (current == stayWithin) | 101 if (current == stayWithin) |
| 103 return 0; | 102 return 0; |
| 104 if (current.previousSibling()) { | 103 if (current.previousSibling()) { |
| 105 Node* previous = current.previousSibling(); | 104 Node* previous = current.previousSibling(); |
| 106 while (previous->lastChild()) | 105 while (previous->lastChild()) |
| 107 previous = previous->lastChild(); | 106 previous = previous->lastChild(); |
| 108 return previous; | 107 return previous; |
| 109 } | 108 } |
| 110 return current.parentNode(); | 109 return current.parentNode(); |
| 111 } | 110 } |
| 112 | 111 |
| 113 Node* previousSkippingChildren(const Node& current, const Node* stayWithin) | 112 Node* NodeTraversal::previousSkippingChildren(const Node& current, const Node* s
tayWithin) |
| 114 { | 113 { |
| 115 if (current == stayWithin) | 114 if (current == stayWithin) |
| 116 return 0; | 115 return 0; |
| 117 if (current.previousSibling()) | 116 if (current.previousSibling()) |
| 118 return current.previousSibling(); | 117 return current.previousSibling(); |
| 119 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { | 118 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { |
| 120 if (parent == stayWithin) | 119 if (parent == stayWithin) |
| 121 return 0; | 120 return 0; |
| 122 if (parent->previousSibling()) | 121 if (parent->previousSibling()) |
| 123 return parent->previousSibling(); | 122 return parent->previousSibling(); |
| 124 } | 123 } |
| 125 return 0; | 124 return 0; |
| 126 } | 125 } |
| 127 | 126 |
| 128 Node* nextPostOrder(const Node& current, const Node* stayWithin) | 127 Node* NodeTraversal::nextPostOrder(const Node& current, const Node* stayWithin) |
| 129 { | 128 { |
| 130 if (current == stayWithin) | 129 if (current == stayWithin) |
| 131 return 0; | 130 return 0; |
| 132 if (!current.nextSibling()) | 131 if (!current.nextSibling()) |
| 133 return current.parentNode(); | 132 return current.parentNode(); |
| 134 Node* next = current.nextSibling(); | 133 Node* next = current.nextSibling(); |
| 135 while (next->firstChild()) | 134 while (next->firstChild()) |
| 136 next = next->firstChild(); | 135 next = next->firstChild(); |
| 137 return next; | 136 return next; |
| 138 } | 137 } |
| 139 | 138 |
| 140 static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* s
tayWithin) | 139 static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* s
tayWithin) |
| 141 { | 140 { |
| 142 ASSERT(!current.previousSibling()); | 141 ASSERT(!current.previousSibling()); |
| 143 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { | 142 for (Node* parent = current.parentNode(); parent; parent = parent->parentNod
e()) { |
| 144 if (parent == stayWithin) | 143 if (parent == stayWithin) |
| 145 return 0; | 144 return 0; |
| 146 if (parent->previousSibling()) | 145 if (parent->previousSibling()) |
| 147 return parent->previousSibling(); | 146 return parent->previousSibling(); |
| 148 } | 147 } |
| 149 return 0; | 148 return 0; |
| 150 } | 149 } |
| 151 | 150 |
| 152 Node* previousPostOrder(const Node& current, const Node* stayWithin) | 151 Node* NodeTraversal::previousPostOrder(const Node& current, const Node* stayWith
in) |
| 153 { | 152 { |
| 154 if (current.lastChild()) | 153 if (current.lastChild()) |
| 155 return current.lastChild(); | 154 return current.lastChild(); |
| 156 if (current == stayWithin) | 155 if (current == stayWithin) |
| 157 return 0; | 156 return 0; |
| 158 if (current.previousSibling()) | 157 if (current.previousSibling()) |
| 159 return current.previousSibling(); | 158 return current.previousSibling(); |
| 160 return previousAncestorSiblingPostOrder(current, stayWithin); | 159 return previousAncestorSiblingPostOrder(current, stayWithin); |
| 161 } | 160 } |
| 162 | 161 |
| 163 } | 162 } // namespace WebCore |
| 164 } | |
| OLD | NEW |