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 * 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 |
11 * License as published by the Free Software Foundation; either | 11 * License as published by the Free Software Foundation; either |
12 * version 2 of the License, or (at your option) any later version. | 12 * version 2 of the License, or (at your option) any later version. |
13 * | 13 * |
14 * This library is distributed in the hope that it will be useful, | 14 * This library is distributed in the hope that it will be useful, |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 * Library General Public License for more details. | 17 * Library General Public License for more details. |
18 * | 18 * |
19 * You should have received a copy of the GNU Library General Public License | 19 * You should have received a copy of the GNU Library General Public License |
20 * along with this library; see the file COPYING.LIB. If not, write to | 20 * along with this library; see the file COPYING.LIB. If not, write to |
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 * Boston, MA 02110-1301, USA. | 22 * Boston, MA 02110-1301, USA. |
23 * | 23 * |
24 */ | 24 */ |
25 | 25 |
26 #ifndef NodeTraversal_h | 26 #ifndef NodeTraversal_h |
27 #define NodeTraversal_h | 27 #define NodeTraversal_h |
28 | 28 |
| 29 #include "core/dom/ContainerNode.h" |
29 #include "core/dom/Node.h" | 30 #include "core/dom/Node.h" |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 | 33 |
33 class NodeTraversal { | 34 class NodeTraversal { |
34 public: | 35 public: |
35 // Does a pre-order traversal of the tree to find the next node after this o
ne. | 36 // Does a pre-order traversal of the tree to find the next node after this o
ne. |
36 // This uses the same order that tags appear in the source file. If the stay
Within | 37 // This uses the same order that tags appear in the source file. If the stay
Within |
37 // argument is non-null, the traversal will stop once the specified node is
reached. | 38 // argument is non-null, the traversal will stop once the specified node is
reached. |
38 // This can be used to restrict traversal to a particular sub-tree. | 39 // This can be used to restrict traversal to a particular sub-tree. |
(...skipping 21 matching lines...) Expand all Loading... |
60 // Like previous, but visits parents before their children. | 61 // Like previous, but visits parents before their children. |
61 static Node* previousPostOrder(const Node&, const Node* stayWithin = 0); | 62 static Node* previousPostOrder(const Node&, const Node* stayWithin = 0); |
62 | 63 |
63 // Pre-order traversal including the pseudo-elements. | 64 // Pre-order traversal including the pseudo-elements. |
64 static Node* previousIncludingPseudo(const Node&, const Node* stayWithin = 0
); | 65 static Node* previousIncludingPseudo(const Node&, const Node* stayWithin = 0
); |
65 static Node* nextIncludingPseudo(const Node&, const Node* stayWithin = 0); | 66 static Node* nextIncludingPseudo(const Node&, const Node* stayWithin = 0); |
66 static Node* nextIncludingPseudoSkippingChildren(const Node&, const Node* st
ayWithin = 0); | 67 static Node* nextIncludingPseudoSkippingChildren(const Node&, const Node* st
ayWithin = 0); |
67 | 68 |
68 static Node* nextAncestorSibling(const Node&); | 69 static Node* nextAncestorSibling(const Node&); |
69 static Node* nextAncestorSibling(const Node&, const Node* stayWithin); | 70 static Node* nextAncestorSibling(const Node&, const Node* stayWithin); |
| 71 static Node& highestAncestorOrSelf(Node&); |
70 | 72 |
71 private: | 73 private: |
72 template <class NodeType> | 74 template <class NodeType> |
73 static Node* traverseNextTemplate(NodeType&); | 75 static Node* traverseNextTemplate(NodeType&); |
74 template <class NodeType> | 76 template <class NodeType> |
75 static Node* traverseNextTemplate(NodeType&, const Node* stayWithin); | 77 static Node* traverseNextTemplate(NodeType&, const Node* stayWithin); |
76 }; | 78 }; |
77 | 79 |
78 template <class NodeType> | 80 template <class NodeType> |
79 inline Node* NodeTraversal::traverseNextTemplate(NodeType& current) | 81 inline Node* NodeTraversal::traverseNextTemplate(NodeType& current) |
(...skipping 26 matching lines...) Expand all Loading... |
106 | 108 |
107 inline Node* NodeTraversal::nextSkippingChildren(const Node& current, const Node
* stayWithin) | 109 inline Node* NodeTraversal::nextSkippingChildren(const Node& current, const Node
* stayWithin) |
108 { | 110 { |
109 if (current == stayWithin) | 111 if (current == stayWithin) |
110 return 0; | 112 return 0; |
111 if (current.nextSibling()) | 113 if (current.nextSibling()) |
112 return current.nextSibling(); | 114 return current.nextSibling(); |
113 return nextAncestorSibling(current, stayWithin); | 115 return nextAncestorSibling(current, stayWithin); |
114 } | 116 } |
115 | 117 |
| 118 inline Node& NodeTraversal::highestAncestorOrSelf(Node& current) |
| 119 { |
| 120 Node* highest = ¤t; |
| 121 while (highest->parentNode()) |
| 122 highest = highest->parentNode(); |
| 123 return *highest; |
| 124 } |
| 125 |
116 } // namespace blink | 126 } // namespace blink |
117 | 127 |
118 #endif | 128 #endif |
OLD | NEW |