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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. |
5 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 5 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 * | 21 * |
22 */ | 22 */ |
23 | 23 |
24 #include "config.h" | 24 #include "config.h" |
25 #include "core/html/HTMLCollection.h" | 25 #include "core/html/HTMLCollection.h" |
26 | 26 |
27 #include "HTMLNames.h" | 27 #include "HTMLNames.h" |
28 #include "core/dom/ClassCollection.h" | 28 #include "core/dom/ClassCollection.h" |
29 #include "core/dom/ElementTraversal.h" | 29 #include "core/dom/ElementTraversal.h" |
30 #include "core/dom/NodeList.h" | |
31 #include "core/dom/NodeRareData.h" | 30 #include "core/dom/NodeRareData.h" |
32 #include "core/dom/NodeTraversal.h" | |
33 #include "core/html/HTMLElement.h" | 31 #include "core/html/HTMLElement.h" |
34 #include "core/html/HTMLObjectElement.h" | 32 #include "core/html/HTMLObjectElement.h" |
35 #include "core/html/HTMLOptionElement.h" | 33 #include "core/html/HTMLOptionElement.h" |
36 #include "wtf/HashSet.h" | 34 #include "wtf/HashSet.h" |
37 | 35 |
38 namespace WebCore { | 36 namespace WebCore { |
39 | 37 |
40 using namespace HTMLNames; | 38 using namespace HTMLNames; |
41 | 39 |
42 static bool shouldTypeOnlyIncludeDirectChildren(CollectionType type) | 40 static bool shouldTypeOnlyIncludeDirectChildren(CollectionType type) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 template <> inline bool isMatchingElement(const ClassCollection& collection, con
st Element& element) | 270 template <> inline bool isMatchingElement(const ClassCollection& collection, con
st Element& element) |
273 { | 271 { |
274 return collection.elementMatches(element); | 272 return collection.elementMatches(element); |
275 } | 273 } |
276 | 274 |
277 template <> inline bool isMatchingElement(const HTMLTagCollection& collection, c
onst Element& element) | 275 template <> inline bool isMatchingElement(const HTMLTagCollection& collection, c
onst Element& element) |
278 { | 276 { |
279 return collection.elementMatches(element); | 277 return collection.elementMatches(element); |
280 } | 278 } |
281 | 279 |
282 template <> inline bool isMatchingElement(const LiveNodeList& nodeList, const El
ement& element) | |
283 { | |
284 return nodeList.nodeMatches(element); | |
285 } | |
286 | |
287 Element* LiveNodeList::itemBefore(const Element* previous) const | |
288 { | |
289 return LiveNodeListBase::itemBefore(*this, previous); | |
290 } | |
291 | |
292 Element* HTMLCollection::itemBefore(const Element* previous) const | 280 Element* HTMLCollection::itemBefore(const Element* previous) const |
293 { | 281 { |
294 return LiveNodeListBase::itemBefore(*this, previous); | 282 return LiveNodeListBase::itemBefore(*this, previous); |
295 } | 283 } |
296 | 284 |
297 template <class NodeListType> | |
298 inline Element* firstMatchingElement(const NodeListType& nodeList, const Contain
erNode& root) | |
299 { | |
300 Element* element = ElementTraversal::firstWithin(root); | |
301 while (element && !isMatchingElement(nodeList, *element)) | |
302 element = ElementTraversal::next(*element, &root); | |
303 return element; | |
304 } | |
305 | |
306 template <class NodeListType> | |
307 inline Element* nextMatchingElement(const NodeListType& nodeList, Element& curre
nt, const ContainerNode& root) | |
308 { | |
309 Element* next = ¤t; | |
310 do { | |
311 next = ElementTraversal::next(*next, &root); | |
312 } while (next && !isMatchingElement(nodeList, *next)); | |
313 return next; | |
314 } | |
315 | |
316 template <class NodeListType> | |
317 inline Element* traverseMatchingElementsForwardToOffset(const NodeListType& node
List, unsigned offset, Element& currentElement, unsigned& currentOffset, const C
ontainerNode& root) | |
318 { | |
319 ASSERT(currentOffset < offset); | |
320 Element* next = ¤tElement; | |
321 while ((next = nextMatchingElement(nodeList, *next, root))) { | |
322 if (++currentOffset == offset) | |
323 return next; | |
324 } | |
325 return 0; | |
326 } | |
327 | |
328 // FIXME: This should be in LiveNodeList.cpp but it needs to stay here until fir
stMatchingElement() | |
329 // and others are moved to a separate header. | |
330 Element* LiveNodeList::traverseToFirstElement(const ContainerNode& root) const | |
331 { | |
332 return firstMatchingElement(*this, root); | |
333 } | |
334 | |
335 // FIXME: This should be in LiveNodeList.cpp but it needs to stay here until tra
verseMatchingElementsForwardToOffset() | |
336 // and others are moved to a separate header. | |
337 Element* LiveNodeList::traverseForwardToOffset(unsigned offset, Element& current
Node, unsigned& currentOffset, const ContainerNode& root) const | |
338 { | |
339 return traverseMatchingElementsForwardToOffset(*this, offset, currentNode, c
urrentOffset, root); | |
340 } | |
341 | |
342 Element* HTMLCollection::virtualItemAfter(Element*) const | 285 Element* HTMLCollection::virtualItemAfter(Element*) const |
343 { | 286 { |
344 ASSERT_NOT_REACHED(); | 287 ASSERT_NOT_REACHED(); |
345 return 0; | 288 return 0; |
346 } | 289 } |
347 | 290 |
348 static inline bool nameShouldBeVisibleInDocumentAll(const HTMLElement& element) | 291 static inline bool nameShouldBeVisibleInDocumentAll(const HTMLElement& element) |
349 { | 292 { |
350 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-in
terfaces.html#dom-htmlallcollection-nameditem: | 293 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-in
terfaces.html#dom-htmlallcollection-nameditem: |
351 // The document.all collection returns only certain types of elements by nam
e, | 294 // The document.all collection returns only certain types of elements by nam
e, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 478 |
536 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) | 479 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) |
537 { | 480 { |
538 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).storedValue
->value; | 481 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).storedValue
->value; |
539 if (!vector) | 482 if (!vector) |
540 vector = adoptPtr(new Vector<Element*>); | 483 vector = adoptPtr(new Vector<Element*>); |
541 vector->append(element); | 484 vector->append(element); |
542 } | 485 } |
543 | 486 |
544 } // namespace WebCore | 487 } // namespace WebCore |
OLD | NEW |