| 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, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2006, 2007, 2008, 2010 Apple Inc. 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "core/dom/LiveNodeList.h" | 24 #include "core/dom/LiveNodeList.h" |
| 25 | 25 |
| 26 #include "core/dom/Document.h" | 26 #include "core/dom/Document.h" |
| 27 #include "core/dom/Element.h" | 27 #include "core/dom/Element.h" |
| 28 #include "core/html/HTMLCollection.h" | 28 #include "core/html/HTMLCollection.h" |
| 29 | 29 |
| 30 namespace WebCore { | 30 namespace WebCore { |
| 31 | 31 |
| 32 Node* LiveNodeListBase::rootNode() const | 32 Node& LiveNodeListBase::rootNode() const |
| 33 { | 33 { |
| 34 if (isRootedAtDocument() && m_ownerNode->inDocument()) | 34 if (isRootedAtDocument() && m_ownerNode->inDocument()) |
| 35 return &m_ownerNode->document(); | 35 return m_ownerNode->document(); |
| 36 return m_ownerNode.get(); | 36 return *m_ownerNode; |
| 37 } | 37 } |
| 38 | 38 |
| 39 ContainerNode* LiveNodeListBase::rootContainerNode() const | 39 ContainerNode* LiveNodeListBase::rootContainerNode() const |
| 40 { | 40 { |
| 41 Node* rootNode = this->rootNode(); | 41 Node& rootNode = this->rootNode(); |
| 42 if (!rootNode->isContainerNode()) | 42 if (!rootNode.isContainerNode()) |
| 43 return 0; | 43 return 0; |
| 44 return toContainerNode(rootNode); | 44 return toContainerNode(&rootNode); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void LiveNodeListBase::invalidateCache() const | 47 void LiveNodeListBase::invalidateCache() const |
| 48 { | 48 { |
| 49 m_cachedItem = 0; | 49 m_cachedItem = 0; |
| 50 m_isLengthCacheValid = false; | 50 m_isLengthCacheValid = false; |
| 51 m_isItemCacheValid = false; | 51 m_isItemCacheValid = false; |
| 52 m_isNameCacheValid = false; | 52 m_isNameCacheValid = false; |
| 53 m_isItemRefElementsCacheValid = false; | 53 m_isItemRefElementsCacheValid = false; |
| 54 if (isNodeList(type())) | 54 if (isNodeList(type())) |
| 55 return; | 55 return; |
| 56 | 56 |
| 57 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); | 57 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); |
| 58 cacheBase->m_idCache.clear(); | 58 cacheBase->m_idCache.clear(); |
| 59 cacheBase->m_nameCache.clear(); | 59 cacheBase->m_nameCache.clear(); |
| 60 cacheBase->m_cachedElementsArrayOffset = 0; | 60 cacheBase->m_cachedElementsArrayOffset = 0; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void LiveNodeListBase::invalidateIdNameCacheMaps() const | 63 void LiveNodeListBase::invalidateIdNameCacheMaps() const |
| 64 { | 64 { |
| 65 ASSERT(hasIdNameCache()); | 65 ASSERT(hasIdNameCache()); |
| 66 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); | 66 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); |
| 67 cacheBase->m_idCache.clear(); | 67 cacheBase->m_idCache.clear(); |
| 68 cacheBase->m_nameCache.clear(); | 68 cacheBase->m_nameCache.clear(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 Node* LiveNodeList::namedItem(const AtomicString& elementId) const | 71 Node* LiveNodeList::namedItem(const AtomicString& elementId) const |
| 72 { | 72 { |
| 73 Node* rootNode = this->rootNode(); | 73 Node& rootNode = this->rootNode(); |
| 74 | 74 |
| 75 if (rootNode->inDocument()) { | 75 if (rootNode.inDocument()) { |
| 76 Element* element = rootNode->treeScope().getElementById(elementId); | 76 Element* element = rootNode.treeScope().getElementById(elementId); |
| 77 if (element && nodeMatches(element) && element->isDescendantOf(rootNode)
) | 77 if (element && nodeMatches(element) && element->isDescendantOf(&rootNode
)) |
| 78 return element; | 78 return element; |
| 79 if (!element) | 79 if (!element) |
| 80 return 0; | 80 return 0; |
| 81 // In the case of multiple nodes with the same name, just fall through. | 81 // In the case of multiple nodes with the same name, just fall through. |
| 82 } | 82 } |
| 83 | 83 |
| 84 unsigned length = this->length(); | 84 unsigned length = this->length(); |
| 85 for (unsigned i = 0; i < length; i++) { | 85 for (unsigned i = 0; i < length; i++) { |
| 86 Node* node = item(i); | 86 Node* node = item(i); |
| 87 // FIXME: This should probably be using getIdAttribute instead of idForS
tyleResolution. | 87 // FIXME: This should probably be using getIdAttribute instead of idForS
tyleResolution. |
| 88 if (node->hasID() && toElement(node)->idForStyleResolution() == elementI
d) | 88 if (node->hasID() && toElement(node)->idForStyleResolution() == elementI
d) |
| 89 return node; | 89 return node; |
| 90 } | 90 } |
| 91 | 91 |
| 92 return 0; | 92 return 0; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace WebCore | 95 } // namespace WebCore |
| OLD | NEW |