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

Side by Side Diff: Source/core/css/SiblingTraversalStrategies.h

Issue 167013002: Port SiblingTraversalStrategies to ElementTraversal API (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/css/SelectorChecker.cpp ('k') | Source/core/dom/ElementTraversal.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) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 12 matching lines...) Expand all
23 * You should have received a copy of the GNU Library General Public License 23 * You should have received a copy of the GNU Library General Public License
24 * along with this library; see the file COPYING.LIB. If not, write to 24 * along with this library; see the file COPYING.LIB. If not, write to
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA. 26 * Boston, MA 02110-1301, USA.
27 */ 27 */
28 28
29 #ifndef SiblingTraversalStrategies_h 29 #ifndef SiblingTraversalStrategies_h
30 #define SiblingTraversalStrategies_h 30 #define SiblingTraversalStrategies_h
31 31
32 #include "core/dom/Element.h" 32 #include "core/dom/Element.h"
33 #include "core/dom/ElementTraversal.h"
33 #include "core/rendering/style/RenderStyle.h" 34 #include "core/rendering/style/RenderStyle.h"
34 35
35 namespace WebCore { 36 namespace WebCore {
36 37
37 struct DOMSiblingTraversalStrategy { 38 struct DOMSiblingTraversalStrategy {
38 bool isFirstChild(Element*) const; 39 bool isFirstChild(Element&) const;
39 bool isLastChild(Element*) const; 40 bool isLastChild(Element&) const;
40 bool isFirstOfType(Element*, const QualifiedName&) const; 41 bool isFirstOfType(Element&, const QualifiedName&) const;
41 bool isLastOfType(Element*, const QualifiedName&) const; 42 bool isLastOfType(Element&, const QualifiedName&) const;
42 43
43 int countElementsBefore(Element*) const; 44 int countElementsBefore(Element&) const;
44 int countElementsAfter(Element*) const; 45 int countElementsAfter(Element&) const;
45 int countElementsOfTypeBefore(Element*, const QualifiedName&) const; 46 int countElementsOfTypeBefore(Element&, const QualifiedName&) const;
46 int countElementsOfTypeAfter(Element*, const QualifiedName&) const; 47 int countElementsOfTypeAfter(Element&, const QualifiedName&) const;
47 }; 48 };
48 49
49 inline bool DOMSiblingTraversalStrategy::isFirstChild(Element* element) const 50 inline bool DOMSiblingTraversalStrategy::isFirstChild(Element& element) const
50 { 51 {
51 return !element->previousElementSibling(); 52 return !ElementTraversal::previousSibling(element);
52 } 53 }
53 54
54 inline bool DOMSiblingTraversalStrategy::isLastChild(Element* element) const 55 inline bool DOMSiblingTraversalStrategy::isLastChild(Element& element) const
55 { 56 {
56 return !element->nextElementSibling(); 57 return !ElementTraversal::nextSibling(element);
57 } 58 }
58 59
59 inline bool DOMSiblingTraversalStrategy::isFirstOfType(Element* element, const Q ualifiedName& type) const 60 inline bool DOMSiblingTraversalStrategy::isFirstOfType(Element& element, const Q ualifiedName& type) const
60 { 61 {
61 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) { 62 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling)) {
62 if (sibling->hasTagName(type)) 63 if (sibling->hasTagName(type))
63 return false; 64 return false;
64 } 65 }
65 return true; 66 return true;
66 } 67 }
67 68
68 inline bool DOMSiblingTraversalStrategy::isLastOfType(Element* element, const Qu alifiedName& type) const 69 inline bool DOMSiblingTraversalStrategy::isLastOfType(Element& element, const Qu alifiedName& type) const
69 { 70 {
70 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) { 71 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling)) {
71 if (sibling->hasTagName(type)) 72 if (sibling->hasTagName(type))
72 return false; 73 return false;
73 } 74 }
74 return true; 75 return true;
75 } 76 }
76 77
77 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element* element) co nst 78 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element) co nst
78 { 79 {
79 int count = 0; 80 int count = 0;
80 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) 81 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling))
81 count++; 82 count++;
82 83
83 return count; 84 return count;
84 } 85 }
85 86
86 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element* eleme nt, const QualifiedName& type) const 87 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme nt, const QualifiedName& type) const
87 { 88 {
88 int count = 0; 89 int count = 0;
89 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) { 90 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling)) {
90 if (sibling->hasTagName(type)) 91 if (sibling->hasTagName(type))
91 ++count; 92 ++count;
92 } 93 }
93 94
94 return count; 95 return count;
95 } 96 }
96 97
97 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element* element) con st 98 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) con st
98 { 99 {
99 int count = 0; 100 int count = 0;
100 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) 101 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling))
101 ++count; 102 ++count;
102 103
103 return count; 104 return count;
104 } 105 }
105 106
106 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element* elemen t, const QualifiedName& type) const 107 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& elemen t, const QualifiedName& type) const
107 { 108 {
108 int count = 0; 109 int count = 0;
109 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) { 110 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling)) {
110 if (sibling->hasTagName(type)) 111 if (sibling->hasTagName(type))
111 ++count; 112 ++count;
112 } 113 }
113 114
114 return count; 115 return count;
115 } 116 }
116 117
117 struct ShadowDOMSiblingTraversalStrategy { 118 struct ShadowDOMSiblingTraversalStrategy {
118 ShadowDOMSiblingTraversalStrategy(const Vector<Node*, 32>& siblings, int nth ) 119 ShadowDOMSiblingTraversalStrategy(const Vector<Node*, 32>& siblings, int nth )
119 : m_siblings(siblings) 120 : m_siblings(siblings)
120 , m_nth(nth) 121 , m_nth(nth)
121 { 122 {
122 } 123 }
123 124
124 bool isFirstChild(Element*) const; 125 bool isFirstChild(Element&) const;
125 bool isLastChild(Element*) const; 126 bool isLastChild(Element&) const;
126 bool isFirstOfType(Element*, const QualifiedName&) const; 127 bool isFirstOfType(Element&, const QualifiedName&) const;
127 bool isLastOfType(Element*, const QualifiedName&) const; 128 bool isLastOfType(Element&, const QualifiedName&) const;
128 129
129 int countElementsBefore(Element*) const; 130 int countElementsBefore(Element&) const;
130 int countElementsAfter(Element*) const; 131 int countElementsAfter(Element&) const;
131 int countElementsOfTypeBefore(Element*, const QualifiedName&) const; 132 int countElementsOfTypeBefore(Element&, const QualifiedName&) const;
132 int countElementsOfTypeAfter(Element*, const QualifiedName&) const; 133 int countElementsOfTypeAfter(Element&, const QualifiedName&) const;
133 134
134 private: 135 private:
135 const Vector<Node*, 32>& m_siblings; 136 const Vector<Node*, 32>& m_siblings;
136 int m_nth; 137 int m_nth;
137 }; 138 };
138 139
139 inline bool ShadowDOMSiblingTraversalStrategy::isFirstChild(Element* element) co nst 140 inline bool ShadowDOMSiblingTraversalStrategy::isFirstChild(Element& element) co nst
140 { 141 {
141 ASSERT(element == toElement(m_siblings[m_nth])); 142 ASSERT(element == toElement(m_siblings[m_nth]));
142 143
143 for (int i = m_nth - 1; i >= 0; --i) { 144 for (int i = m_nth - 1; i >= 0; --i) {
144 if (m_siblings[i]->isElementNode()) 145 if (m_siblings[i]->isElementNode())
145 return false; 146 return false;
146 } 147 }
147 148
148 return true; 149 return true;
149 } 150 }
150 151
151 inline bool ShadowDOMSiblingTraversalStrategy::isLastChild(Element* element) con st 152 inline bool ShadowDOMSiblingTraversalStrategy::isLastChild(Element& element) con st
152 { 153 {
153 ASSERT(element == toElement(m_siblings[m_nth])); 154 ASSERT(element == toElement(m_siblings[m_nth]));
154 155
155 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) { 156 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) {
156 if (m_siblings[i]->isElementNode()) 157 if (m_siblings[i]->isElementNode())
157 return false; 158 return false;
158 } 159 }
159 160
160 return true; 161 return true;
161 } 162 }
162 163
163 inline bool ShadowDOMSiblingTraversalStrategy::isFirstOfType(Element* element, c onst QualifiedName& type) const 164 inline bool ShadowDOMSiblingTraversalStrategy::isFirstOfType(Element& element, c onst QualifiedName& type) const
164 { 165 {
165 ASSERT(element == toElement(m_siblings[m_nth])); 166 ASSERT(element == toElement(m_siblings[m_nth]));
166 167
167 for (int i = m_nth - 1; i >= 0; --i) { 168 for (int i = m_nth - 1; i >= 0; --i) {
168 if (m_siblings[i]->hasTagName(type)) 169 if (m_siblings[i]->hasTagName(type))
169 return false; 170 return false;
170 } 171 }
171 172
172 return true; 173 return true;
173 } 174 }
174 175
175 inline bool ShadowDOMSiblingTraversalStrategy::isLastOfType(Element* element, co nst QualifiedName& type) const 176 inline bool ShadowDOMSiblingTraversalStrategy::isLastOfType(Element& element, co nst QualifiedName& type) const
176 { 177 {
177 ASSERT(element == toElement(m_siblings[m_nth])); 178 ASSERT(element == toElement(m_siblings[m_nth]));
178 179
179 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) { 180 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) {
180 if (m_siblings[i]->hasTagName(type)) 181 if (m_siblings[i]->hasTagName(type))
181 return false; 182 return false;
182 } 183 }
183 184
184 return true; 185 return true;
185 } 186 }
186 187
187 inline int ShadowDOMSiblingTraversalStrategy::countElementsBefore(Element* eleme nt) const 188 inline int ShadowDOMSiblingTraversalStrategy::countElementsBefore(Element& eleme nt) const
188 { 189 {
189 ASSERT(element == toElement(m_siblings[m_nth])); 190 ASSERT(element == toElement(m_siblings[m_nth]));
190 191
191 int count = 0; 192 int count = 0;
192 for (int i = m_nth - 1; i >= 0; --i) { 193 for (int i = m_nth - 1; i >= 0; --i) {
193 if (m_siblings[i]->isElementNode()) 194 if (m_siblings[i]->isElementNode())
194 ++count; 195 ++count;
195 } 196 }
196 197
197 return count; 198 return count;
198 } 199 }
199 200
200 inline int ShadowDOMSiblingTraversalStrategy::countElementsAfter(Element* elemen t) const 201 inline int ShadowDOMSiblingTraversalStrategy::countElementsAfter(Element& elemen t) const
201 { 202 {
202 ASSERT(element == toElement(m_siblings[m_nth])); 203 ASSERT(element == toElement(m_siblings[m_nth]));
203 204
204 int count = 0; 205 int count = 0;
205 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) { 206 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) {
206 if (m_siblings[i]->isElementNode()) 207 if (m_siblings[i]->isElementNode())
207 return ++count; 208 return ++count;
208 } 209 }
209 210
210 return count; 211 return count;
211 } 212 }
212 213
213 inline int ShadowDOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element* element, const QualifiedName& type) const 214 inline int ShadowDOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& element, const QualifiedName& type) const
214 { 215 {
215 ASSERT(element == toElement(m_siblings[m_nth])); 216 ASSERT(element == toElement(m_siblings[m_nth]));
216 217
217 int count = 0; 218 int count = 0;
218 for (int i = m_nth - 1; i >= 0; --i) { 219 for (int i = m_nth - 1; i >= 0; --i) {
219 if (m_siblings[i]->hasTagName(type)) 220 if (m_siblings[i]->hasTagName(type))
220 ++count; 221 ++count;
221 } 222 }
222 223
223 return count; 224 return count;
224 } 225 }
225 226
226 inline int ShadowDOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element* element, const QualifiedName& type) const 227 inline int ShadowDOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& element, const QualifiedName& type) const
227 { 228 {
228 ASSERT(element == toElement(m_siblings[m_nth])); 229 ASSERT(element == toElement(m_siblings[m_nth]));
229 230
230 int count = 0; 231 int count = 0;
231 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) { 232 for (size_t i = m_nth + 1; i < m_siblings.size(); ++i) {
232 if (m_siblings[i]->hasTagName(type)) 233 if (m_siblings[i]->hasTagName(type))
233 return ++count; 234 return ++count;
234 } 235 }
235 236
236 return count; 237 return count;
237 } 238 }
238 239
239 } 240 }
240 241
241 #endif 242 #endif
OLDNEW
« no previous file with comments | « Source/core/css/SelectorChecker.cpp ('k') | Source/core/dom/ElementTraversal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698