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 26 matching lines...) Expand all Loading... |
37 class Element; | 37 class Element; |
38 | 38 |
39 enum NodeListRootType { | 39 enum NodeListRootType { |
40 NodeListIsRootedAtNode, | 40 NodeListIsRootedAtNode, |
41 NodeListIsRootedAtDocument, | 41 NodeListIsRootedAtDocument, |
42 NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr, | 42 NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr, |
43 }; | 43 }; |
44 | 44 |
45 class LiveNodeListBase { | 45 class LiveNodeListBase { |
46 public: | 46 public: |
47 enum ItemAfterOverrideType { | |
48 OverridesItemAfter, | |
49 DoesNotOverrideItemAfter, | |
50 }; | |
51 | |
52 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, | 47 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, |
53 bool shouldOnlyIncludeDirectChildren, CollectionType collectionType, Ite
mAfterOverrideType itemAfterOverrideType) | 48 bool shouldOnlyIncludeDirectChildren, CollectionType collectionType) |
54 : m_ownerNode(ownerNode) | 49 : m_ownerNode(ownerNode) |
55 , m_rootType(rootType) | 50 , m_rootType(rootType) |
56 , m_invalidationType(invalidationType) | 51 , m_invalidationType(invalidationType) |
57 , m_shouldOnlyIncludeDirectChildren(shouldOnlyIncludeDirectChildren) | 52 , m_shouldOnlyIncludeDirectChildren(shouldOnlyIncludeDirectChildren) |
58 , m_collectionType(collectionType) | 53 , m_collectionType(collectionType) |
59 , m_overridesItemAfter(itemAfterOverrideType == OverridesItemAfter) | |
60 { | 54 { |
61 ASSERT(m_ownerNode); | 55 ASSERT(m_ownerNode); |
62 ASSERT(m_rootType == static_cast<unsigned>(rootType)); | 56 ASSERT(m_rootType == static_cast<unsigned>(rootType)); |
63 ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType)); | 57 ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType)); |
64 ASSERT(m_collectionType == static_cast<unsigned>(collectionType)); | 58 ASSERT(m_collectionType == static_cast<unsigned>(collectionType)); |
65 ASSERT(!m_overridesItemAfter || !isLiveNodeListType(collectionType)); | |
66 | 59 |
67 if (collectionType != ChildNodeListType) | 60 if (collectionType != ChildNodeListType) |
68 document().registerNodeList(this); | 61 document().registerNodeList(this); |
69 } | 62 } |
70 | 63 |
71 virtual ~LiveNodeListBase() | 64 virtual ~LiveNodeListBase() |
72 { | 65 { |
73 if (type() != ChildNodeListType) | 66 if (type() != ChildNodeListType) |
74 document().unregisterNodeList(this); | 67 document().unregisterNodeList(this); |
75 } | 68 } |
76 | 69 |
77 ContainerNode& rootNode() const; | 70 ContainerNode& rootNode() const; |
78 bool overridesItemAfter() const { return m_overridesItemAfter; } | |
79 Node* itemBefore(const Node* previousItem) const; | 71 Node* itemBefore(const Node* previousItem) const; |
80 | 72 |
81 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } | 73 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } |
82 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis
tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref
Attr; } | 74 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); } | 75 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); } | 76 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp
e>(m_collectionType); } |
85 ContainerNode* ownerNode() const { return m_ownerNode.get(); } | 77 ContainerNode* ownerNode() const { return m_ownerNode.get(); } |
86 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const | 78 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const |
87 { | 79 { |
88 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) | 80 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) |
(...skipping 13 matching lines...) Expand all Loading... |
102 | 94 |
103 private: | 95 private: |
104 Node* iterateForPreviousNode(Node* current) const; | 96 Node* iterateForPreviousNode(Node* current) const; |
105 void invalidateIdNameCacheMaps() const; | 97 void invalidateIdNameCacheMaps() const; |
106 | 98 |
107 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. | 99 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. |
108 const unsigned m_rootType : 2; | 100 const unsigned m_rootType : 2; |
109 const unsigned m_invalidationType : 4; | 101 const unsigned m_invalidationType : 4; |
110 const unsigned m_shouldOnlyIncludeDirectChildren : 1; | 102 const unsigned m_shouldOnlyIncludeDirectChildren : 1; |
111 const unsigned m_collectionType : 5; | 103 const unsigned m_collectionType : 5; |
112 | |
113 // From HTMLCollection | |
114 const unsigned m_overridesItemAfter : 1; | |
115 }; | 104 }; |
116 | 105 |
117 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) | 106 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) |
118 { | 107 { |
119 switch (type) { | 108 switch (type) { |
120 case InvalidateOnClassAttrChange: | 109 case InvalidateOnClassAttrChange: |
121 return attrName == HTMLNames::classAttr; | 110 return attrName == HTMLNames::classAttr; |
122 case InvalidateOnNameAttrChange: | 111 case InvalidateOnNameAttrChange: |
123 return attrName == HTMLNames::nameAttr; | 112 return attrName == HTMLNames::nameAttr; |
124 case InvalidateOnIdNameAttrChange: | 113 case InvalidateOnIdNameAttrChange: |
(...skipping 11 matching lines...) Expand all Loading... |
136 case InvalidateOnAnyAttrChange: | 125 case InvalidateOnAnyAttrChange: |
137 return true; | 126 return true; |
138 } | 127 } |
139 return false; | 128 return false; |
140 } | 129 } |
141 | 130 |
142 class LiveNodeList : public NodeList, public LiveNodeListBase { | 131 class LiveNodeList : public NodeList, public LiveNodeListBase { |
143 public: | 132 public: |
144 LiveNodeList(PassRefPtr<ContainerNode> ownerNode, CollectionType collectionT
ype, NodeListInvalidationType invalidationType, NodeListRootType rootType = Node
ListIsRootedAtNode) | 133 LiveNodeList(PassRefPtr<ContainerNode> ownerNode, CollectionType collectionT
ype, NodeListInvalidationType invalidationType, NodeListRootType rootType = Node
ListIsRootedAtNode) |
145 : LiveNodeListBase(ownerNode.get(), rootType, invalidationType, collecti
onType == ChildNodeListType, | 134 : LiveNodeListBase(ownerNode.get(), rootType, invalidationType, collecti
onType == ChildNodeListType, |
146 collectionType, DoesNotOverrideItemAfter) | 135 collectionType) |
147 { } | 136 { } |
148 | 137 |
149 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } | 138 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); } | 139 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } |
151 virtual Node* namedItem(const AtomicString&) const OVERRIDE FINAL; | 140 virtual Node* namedItem(const AtomicString&) const OVERRIDE FINAL; |
152 virtual bool nodeMatches(const Element&) const = 0; | 141 virtual bool nodeMatches(const Element&) const = 0; |
153 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. | 142 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. |
154 using LiveNodeListBase::ownerNode; | 143 using LiveNodeListBase::ownerNode; |
155 | 144 |
156 virtual void invalidateCache() const OVERRIDE FINAL; | 145 virtual void invalidateCache() const OVERRIDE FINAL; |
157 | 146 |
158 // Collection IndexCache API. | 147 // Collection IndexCache API. |
| 148 bool canTraverseBackward() const { return true; } |
159 Node* traverseToFirstElement(const ContainerNode& root) const; | 149 Node* traverseToFirstElement(const ContainerNode& root) const; |
160 Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned&
currentOffset, const ContainerNode& root) const; | 150 Node* traverseForwardToOffset(unsigned offset, Node& currentNode, unsigned&
currentOffset, const ContainerNode& root) const; |
161 | 151 |
162 private: | 152 private: |
163 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } | 153 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } |
164 | 154 |
165 mutable CollectionIndexCache<LiveNodeList> m_collectionIndexCache; | 155 mutable CollectionIndexCache<LiveNodeList> m_collectionIndexCache; |
166 }; | 156 }; |
167 | 157 |
168 } // namespace WebCore | 158 } // namespace WebCore |
169 | 159 |
170 #endif // LiveNodeList_h | 160 #endif // LiveNodeList_h |
OLD | NEW |