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. |
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 #include "config.h" | 23 #include "config.h" |
24 #include "LiveNodeList.h" | 24 #include "LiveNodeList.h" |
25 | 25 |
26 #include "Document.h" | 26 #include "Document.h" |
27 #include "Element.h" | 27 #include "Element.h" |
28 #include "HTMLCollection.h" | 28 #include "HTMLCollection.h" |
29 #include "HTMLPropertiesCollection.h" | |
30 #include "PropertyNodeList.h" | |
31 #include "WebCoreMemoryInstrumentation.h" | 29 #include "WebCoreMemoryInstrumentation.h" |
32 | 30 |
33 namespace WebCore { | 31 namespace WebCore { |
34 | 32 |
35 Node* LiveNodeListBase::rootNode() const | 33 Node* LiveNodeListBase::rootNode() const |
36 { | 34 { |
37 if (isRootedAtDocument() && m_ownerNode->inDocument()) | 35 if (isRootedAtDocument() && m_ownerNode->inDocument()) |
38 return m_ownerNode->document(); | 36 return m_ownerNode->document(); |
39 | |
40 #if ENABLE(MICRODATA) | |
41 if (m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr && toEleme
nt(ownerNode())->fastHasAttribute(HTMLNames::itemrefAttr)) { | |
42 if (m_ownerNode->inDocument()) | |
43 return m_ownerNode->document(); | |
44 | |
45 Node* root = m_ownerNode.get(); | |
46 while (Node* parent = root->parentNode()) | |
47 root = parent; | |
48 return root; | |
49 } | |
50 #endif | |
51 | |
52 return m_ownerNode.get(); | 37 return m_ownerNode.get(); |
53 } | 38 } |
54 | 39 |
55 ContainerNode* LiveNodeListBase::rootContainerNode() const | 40 ContainerNode* LiveNodeListBase::rootContainerNode() const |
56 { | 41 { |
57 Node* rootNode = this->rootNode(); | 42 Node* rootNode = this->rootNode(); |
58 if (!rootNode->isContainerNode()) | 43 if (!rootNode->isContainerNode()) |
59 return 0; | 44 return 0; |
60 return toContainerNode(rootNode); | 45 return toContainerNode(rootNode); |
61 } | 46 } |
62 | 47 |
63 void LiveNodeListBase::invalidateCache() const | 48 void LiveNodeListBase::invalidateCache() const |
64 { | 49 { |
65 m_cachedItem = 0; | 50 m_cachedItem = 0; |
66 m_isLengthCacheValid = false; | 51 m_isLengthCacheValid = false; |
67 m_isItemCacheValid = false; | 52 m_isItemCacheValid = false; |
68 m_isNameCacheValid = false; | 53 m_isNameCacheValid = false; |
69 m_isItemRefElementsCacheValid = false; | 54 m_isItemRefElementsCacheValid = false; |
70 if (isNodeList(type())) | 55 if (isNodeList(type())) |
71 return; | 56 return; |
72 | 57 |
73 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); | 58 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); |
74 cacheBase->m_idCache.clear(); | 59 cacheBase->m_idCache.clear(); |
75 cacheBase->m_nameCache.clear(); | 60 cacheBase->m_nameCache.clear(); |
76 cacheBase->m_cachedElementsArrayOffset = 0; | 61 cacheBase->m_cachedElementsArrayOffset = 0; |
77 | |
78 #if ENABLE(MICRODATA) | |
79 // FIXME: There should be more generic mechanism to clear caches in subclass
es. | |
80 if (type() == ItemProperties) | |
81 static_cast<const HTMLPropertiesCollection*>(this)->invalidateCache(); | |
82 #endif | |
83 } | 62 } |
84 | 63 |
85 void LiveNodeListBase::invalidateIdNameCacheMaps() const | 64 void LiveNodeListBase::invalidateIdNameCacheMaps() const |
86 { | 65 { |
87 ASSERT(hasIdNameCache()); | 66 ASSERT(hasIdNameCache()); |
88 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); | 67 const HTMLCollection* cacheBase = static_cast<const HTMLCollection*>(this); |
89 cacheBase->m_idCache.clear(); | 68 cacheBase->m_idCache.clear(); |
90 cacheBase->m_nameCache.clear(); | 69 cacheBase->m_nameCache.clear(); |
91 } | 70 } |
92 | 71 |
93 void LiveNodeListBase::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) con
st | 72 void LiveNodeListBase::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) con
st |
94 { | 73 { |
95 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); | 74 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); |
96 NodeList::reportMemoryUsage(memoryObjectInfo); | 75 NodeList::reportMemoryUsage(memoryObjectInfo); |
97 info.addMember(m_ownerNode, "ownerNode"); | 76 info.addMember(m_ownerNode, "ownerNode"); |
98 info.addWeakPointer(m_cachedItem); | 77 info.addWeakPointer(m_cachedItem); |
99 } | 78 } |
100 | 79 |
101 Node* LiveNodeList::namedItem(const AtomicString& elementId) const | 80 Node* LiveNodeList::namedItem(const AtomicString& elementId) const |
102 { | 81 { |
103 Node* rootNode = this->rootNode(); | 82 Node* rootNode = this->rootNode(); |
104 | 83 |
105 if (rootNode->inDocument()) { | 84 if (rootNode->inDocument()) { |
106 #if ENABLE(MICRODATA) | |
107 if (type() == PropertyNodeListType) | |
108 static_cast<const PropertyNodeList*>(this)->updateRefElements(); | |
109 #endif | |
110 | |
111 Element* element = rootNode->treeScope()->getElementById(elementId); | 85 Element* element = rootNode->treeScope()->getElementById(elementId); |
112 if (element && nodeMatches(element) && element->isDescendantOf(rootNode)
) | 86 if (element && nodeMatches(element) && element->isDescendantOf(rootNode)
) |
113 return element; | 87 return element; |
114 if (!element) | 88 if (!element) |
115 return 0; | 89 return 0; |
116 // In the case of multiple nodes with the same name, just fall through. | 90 // In the case of multiple nodes with the same name, just fall through. |
117 } | 91 } |
118 | 92 |
119 unsigned length = this->length(); | 93 unsigned length = this->length(); |
120 for (unsigned i = 0; i < length; i++) { | 94 for (unsigned i = 0; i < length; i++) { |
121 Node* node = item(i); | 95 Node* node = item(i); |
122 // FIXME: This should probably be using getIdAttribute instead of idForS
tyleResolution. | 96 // FIXME: This should probably be using getIdAttribute instead of idForS
tyleResolution. |
123 if (node->hasID() && toElement(node)->idForStyleResolution() == elementI
d) | 97 if (node->hasID() && toElement(node)->idForStyleResolution() == elementI
d) |
124 return node; | 98 return node; |
125 } | 99 } |
126 | 100 |
127 return 0; | 101 return 0; |
128 } | 102 } |
129 | 103 |
130 } // namespace WebCore | 104 } // namespace WebCore |
OLD | NEW |