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 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2006, 2007 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 virtual ~LiveNodeListBase() | 71 virtual ~LiveNodeListBase() |
72 { | 72 { |
73 if (type() != ChildNodeListType) | 73 if (type() != ChildNodeListType) |
74 document().unregisterNodeList(this); | 74 document().unregisterNodeList(this); |
75 } | 75 } |
76 | 76 |
77 ContainerNode& rootNode() const; | 77 ContainerNode& rootNode() const; |
78 bool overridesItemAfter() const { return m_overridesItemAfter; } | 78 bool overridesItemAfter() const { return m_overridesItemAfter; } |
79 Node* itemBefore(const Node* previousItem) const; | |
80 | 79 |
81 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } | 80 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } |
82 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis
tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref
Attr; } | 81 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis
tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref
Attr; } |
83 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta
tic_cast<NodeListInvalidationType>(m_invalidationType); } | 82 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta
tic_cast<NodeListInvalidationType>(m_invalidationType); } |
84 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp
e>(m_collectionType); } | 83 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp
e>(m_collectionType); } |
85 ContainerNode* ownerNode() const { return m_ownerNode.get(); } | 84 ContainerNode* ownerNode() const { return m_ownerNode.get(); } |
86 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const | 85 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const |
87 { | 86 { |
88 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) | 87 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) |
89 invalidateCache(); | 88 invalidateCache(); |
90 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam
e == HTMLNames::nameAttr)) | 89 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam
e == HTMLNames::nameAttr)) |
91 invalidateIdNameCacheMaps(); | 90 invalidateIdNameCacheMaps(); |
92 } | 91 } |
93 virtual void invalidateCache() const = 0; | 92 virtual void invalidateCache() const = 0; |
94 | 93 |
95 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); | 94 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); |
96 | 95 |
97 protected: | 96 protected: |
98 Document& document() const { return m_ownerNode->document(); } | 97 Document& document() const { return m_ownerNode->document(); } |
99 | 98 |
100 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } | 99 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } |
101 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } | 100 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } |
102 | 101 |
| 102 template <typename Collection> |
| 103 static Element* iterateForPreviousNode(const Collection&, Node* current); |
| 104 template <typename Collection> |
| 105 static Element* itemBefore(const Collection&, const Node* previousItem); |
| 106 |
103 private: | 107 private: |
104 Node* iterateForPreviousNode(Node* current) const; | |
105 void invalidateIdNameCacheMaps() const; | 108 void invalidateIdNameCacheMaps() const; |
106 | 109 |
107 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. | 110 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. |
108 const unsigned m_rootType : 2; | 111 const unsigned m_rootType : 2; |
109 const unsigned m_invalidationType : 4; | 112 const unsigned m_invalidationType : 4; |
110 const unsigned m_shouldOnlyIncludeDirectChildren : 1; | 113 const unsigned m_shouldOnlyIncludeDirectChildren : 1; |
111 const unsigned m_collectionType : 5; | 114 const unsigned m_collectionType : 5; |
112 | 115 |
113 // From HTMLCollection | 116 // From HTMLCollection |
114 const unsigned m_overridesItemAfter : 1; | 117 const unsigned m_overridesItemAfter : 1; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } | 152 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } |
150 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } | 153 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } |
151 virtual Node* namedItem(const AtomicString&) const OVERRIDE FINAL; | 154 virtual Node* namedItem(const AtomicString&) const OVERRIDE FINAL; |
152 virtual bool nodeMatches(const Element&) const = 0; | 155 virtual bool nodeMatches(const Element&) const = 0; |
153 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. | 156 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. |
154 using LiveNodeListBase::ownerNode; | 157 using LiveNodeListBase::ownerNode; |
155 | 158 |
156 virtual void invalidateCache() const OVERRIDE FINAL; | 159 virtual void invalidateCache() const OVERRIDE FINAL; |
157 | 160 |
158 // Collection IndexCache API. | 161 // Collection IndexCache API. |
| 162 Node* itemBefore(const Node* previousItem) const; |
159 Node* traverseToFirstElement(const ContainerNode& root) const; | 163 Node* traverseToFirstElement(const ContainerNode& root) const; |
160 Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned&
currentOffset, const ContainerNode& root) const; | 164 Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned&
currentOffset, const ContainerNode& root) const; |
161 | 165 |
162 private: | 166 private: |
163 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } | 167 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } |
164 | 168 |
165 mutable CollectionIndexCache<LiveNodeList> m_collectionIndexCache; | 169 mutable CollectionIndexCache<LiveNodeList, Node> m_collectionIndexCache; |
166 }; | 170 }; |
167 | 171 |
168 } // namespace WebCore | 172 } // namespace WebCore |
169 | 173 |
170 #endif // LiveNodeList_h | 174 #endif // LiveNodeList_h |
OLD | NEW |