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. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 template <> inline bool isMatchingElement(const HTMLTagCollection& collection, c
onst Element& element) | 277 template <> inline bool isMatchingElement(const HTMLTagCollection& collection, c
onst Element& element) |
278 { | 278 { |
279 return collection.elementMatches(element); | 279 return collection.elementMatches(element); |
280 } | 280 } |
281 | 281 |
282 template <> inline bool isMatchingElement(const LiveNodeList& nodeList, const El
ement& element) | 282 template <> inline bool isMatchingElement(const LiveNodeList& nodeList, const El
ement& element) |
283 { | 283 { |
284 return nodeList.nodeMatches(element); | 284 return nodeList.nodeMatches(element); |
285 } | 285 } |
286 | 286 |
287 static Node* previousNode(const ContainerNode& base, const Node& previous, bool
onlyIncludeDirectChildren) | |
288 { | |
289 return onlyIncludeDirectChildren ? previous.previousSibling() : NodeTraversa
l::previous(previous, &base); | |
290 } | |
291 | |
292 static inline Node* lastDescendant(const ContainerNode& node) | |
293 { | |
294 Node* descendant = node.lastChild(); | |
295 for (Node* current = descendant; current; current = current->lastChild()) | |
296 descendant = current; | |
297 return descendant; | |
298 } | |
299 | |
300 static Node* lastNode(const ContainerNode& rootNode, bool onlyIncludeDirectChild
ren) | |
301 { | |
302 return onlyIncludeDirectChildren ? rootNode.lastChild() : lastDescendant(roo
tNode); | |
303 } | |
304 | |
305 template <typename Collection> | |
306 ALWAYS_INLINE Element* LiveNodeListBase::iterateForPreviousNode(const Collection
& collection, Node* current) | |
307 { | |
308 bool onlyIncludeDirectChildren = collection.shouldOnlyIncludeDirectChildren(
); | |
309 ContainerNode& rootNode = collection.rootNode(); | |
310 for (; current; current = previousNode(rootNode, *current, onlyIncludeDirect
Children)) { | |
311 if (current->isElementNode() && isMatchingElement(collection, toElement(
*current))) | |
312 return toElement(current); | |
313 } | |
314 return 0; | |
315 } | |
316 | |
317 template <typename Collection> | |
318 Element* LiveNodeListBase::itemBefore(const Collection& collection, const Elemen
t* previous) | |
319 { | |
320 Node* current; | |
321 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1
0% slower. | |
322 current = previousNode(collection.rootNode(), *previous, collection.shou
ldOnlyIncludeDirectChildren()); | |
323 else | |
324 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi
rectChildren()); | |
325 | |
326 return iterateForPreviousNode(collection, current); | |
327 } | |
328 | |
329 Element* LiveNodeList::itemBefore(const Element* previous) const | 287 Element* LiveNodeList::itemBefore(const Element* previous) const |
330 { | 288 { |
331 return LiveNodeListBase::itemBefore(*this, previous); | 289 return LiveNodeListBase::itemBefore(*this, previous); |
332 } | 290 } |
333 | 291 |
334 Element* HTMLCollection::itemBefore(const Element* previous) const | 292 Element* HTMLCollection::itemBefore(const Element* previous) const |
335 { | 293 { |
336 return LiveNodeListBase::itemBefore(*this, previous); | 294 return LiveNodeListBase::itemBefore(*this, previous); |
337 } | 295 } |
338 | 296 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 535 |
578 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) | 536 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) |
579 { | 537 { |
580 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).storedValue
->value; | 538 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).storedValue
->value; |
581 if (!vector) | 539 if (!vector) |
582 vector = adoptPtr(new Vector<Element*>); | 540 vector = adoptPtr(new Vector<Element*>); |
583 vector->append(element); | 541 vector->append(element); |
584 } | 542 } |
585 | 543 |
586 } // namespace WebCore | 544 } // namespace WebCore |
OLD | NEW |