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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 document().registerNodeList(this); | 61 document().registerNodeList(this); |
62 } | 62 } |
63 | 63 |
64 virtual ~LiveNodeListBase() | 64 virtual ~LiveNodeListBase() |
65 { | 65 { |
66 if (type() != ChildNodeListType) | 66 if (type() != ChildNodeListType) |
67 document().unregisterNodeList(this); | 67 document().unregisterNodeList(this); |
68 } | 68 } |
69 | 69 |
70 ContainerNode& rootNode() const; | 70 ContainerNode& rootNode() const; |
71 Node* itemBefore(const Node* previousItem) const; | |
72 | 71 |
73 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } | 72 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } |
74 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis
tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref
Attr; } | 73 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis
tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref
Attr; } |
75 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta
tic_cast<NodeListInvalidationType>(m_invalidationType); } | 74 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta
tic_cast<NodeListInvalidationType>(m_invalidationType); } |
76 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp
e>(m_collectionType); } | 75 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp
e>(m_collectionType); } |
77 ContainerNode* ownerNode() const { return m_ownerNode.get(); } | 76 ContainerNode* ownerNode() const { return m_ownerNode.get(); } |
78 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const | 77 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const |
79 { | 78 { |
80 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) | 79 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) |
81 invalidateCache(); | 80 invalidateCache(); |
82 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam
e == HTMLNames::nameAttr)) | 81 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam
e == HTMLNames::nameAttr)) |
83 invalidateIdNameCacheMaps(); | 82 invalidateIdNameCacheMaps(); |
84 } | 83 } |
85 virtual void invalidateCache() const = 0; | 84 virtual void invalidateCache() const = 0; |
86 | 85 |
87 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); | 86 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); |
88 | 87 |
89 protected: | 88 protected: |
90 Document& document() const { return m_ownerNode->document(); } | 89 Document& document() const { return m_ownerNode->document(); } |
91 | 90 |
92 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } | 91 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } |
93 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } | 92 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } |
94 | 93 |
| 94 template <typename Collection> |
| 95 static Element* iterateForPreviousNode(const Collection&, Node* current); |
| 96 template <typename Collection> |
| 97 static Element* itemBefore(const Collection&, const Node* previousItem); |
| 98 |
95 private: | 99 private: |
96 Node* iterateForPreviousNode(Node* current) const; | |
97 void invalidateIdNameCacheMaps() const; | 100 void invalidateIdNameCacheMaps() const; |
98 | 101 |
99 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. | 102 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. |
100 const unsigned m_rootType : 2; | 103 const unsigned m_rootType : 2; |
101 const unsigned m_invalidationType : 4; | 104 const unsigned m_invalidationType : 4; |
102 const unsigned m_shouldOnlyIncludeDirectChildren : 1; | 105 const unsigned m_shouldOnlyIncludeDirectChildren : 1; |
103 const unsigned m_collectionType : 5; | 106 const unsigned m_collectionType : 5; |
104 }; | 107 }; |
105 | 108 |
106 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) | 109 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } | 141 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } |
139 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } | 142 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } |
140 virtual bool nodeMatches(const Element&) const = 0; | 143 virtual bool nodeMatches(const Element&) const = 0; |
141 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. | 144 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. |
142 using LiveNodeListBase::ownerNode; | 145 using LiveNodeListBase::ownerNode; |
143 | 146 |
144 virtual void invalidateCache() const OVERRIDE FINAL; | 147 virtual void invalidateCache() const OVERRIDE FINAL; |
145 | 148 |
146 // Collection IndexCache API. | 149 // Collection IndexCache API. |
147 bool canTraverseBackward() const { return true; } | 150 bool canTraverseBackward() const { return true; } |
| 151 Node* itemBefore(const Node* previousItem) const; |
148 Node* traverseToFirstElement(const ContainerNode& root) const; | 152 Node* traverseToFirstElement(const ContainerNode& root) const; |
149 Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned&
currentOffset, const ContainerNode& root) const; | 153 Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned&
currentOffset, const ContainerNode& root) const; |
150 | 154 |
151 private: | 155 private: |
152 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } | 156 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } |
153 | 157 |
154 mutable CollectionIndexCache<LiveNodeList> m_collectionIndexCache; | 158 mutable CollectionIndexCache<LiveNodeList, Node> m_collectionIndexCache; |
155 }; | 159 }; |
156 | 160 |
157 } // namespace WebCore | 161 } // namespace WebCore |
158 | 162 |
159 #endif // LiveNodeList_h | 163 #endif // LiveNodeList_h |
OLD | NEW |