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 27 matching lines...) Expand all Loading... |
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 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, | 47 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, |
48 bool shouldOnlyIncludeDirectChildren, CollectionType collectionType) | 48 CollectionType collectionType) |
49 : m_ownerNode(ownerNode) | 49 : m_ownerNode(ownerNode) |
50 , m_rootType(rootType) | 50 , m_rootType(rootType) |
51 , m_invalidationType(invalidationType) | 51 , m_invalidationType(invalidationType) |
52 , m_shouldOnlyIncludeDirectChildren(shouldOnlyIncludeDirectChildren) | |
53 , m_collectionType(collectionType) | 52 , m_collectionType(collectionType) |
54 { | 53 { |
55 ASSERT(m_ownerNode); | 54 ASSERT(m_ownerNode); |
56 ASSERT(m_rootType == static_cast<unsigned>(rootType)); | 55 ASSERT(m_rootType == static_cast<unsigned>(rootType)); |
57 ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType)); | 56 ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType)); |
58 ASSERT(m_collectionType == static_cast<unsigned>(collectionType)); | 57 ASSERT(m_collectionType == static_cast<unsigned>(collectionType)); |
59 | 58 |
60 document().registerNodeList(this); | 59 document().registerNodeList(this); |
61 } | 60 } |
62 | 61 |
(...skipping 17 matching lines...) Expand all Loading... |
80 invalidateIdNameCacheMaps(); | 79 invalidateIdNameCacheMaps(); |
81 } | 80 } |
82 virtual void invalidateCache() const = 0; | 81 virtual void invalidateCache() const = 0; |
83 | 82 |
84 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); | 83 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); |
85 | 84 |
86 protected: | 85 protected: |
87 Document& document() const { return m_ownerNode->document(); } | 86 Document& document() const { return m_ownerNode->document(); } |
88 | 87 |
89 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } | 88 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } |
90 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } | |
91 | 89 |
92 template <typename Collection> | 90 template <typename Collection> |
93 static Element* iterateForPreviousNode(const Collection&, Node* current); | 91 static Element* iterateForPreviousNode(const Collection&, Node* current); |
94 template <typename Collection> | 92 template <typename Collection> |
95 static Element* itemBefore(const Collection&, const Element* previousItem); | 93 static Element* itemBefore(const Collection&, const Element* previousItem); |
96 | 94 |
97 private: | 95 private: |
98 void invalidateIdNameCacheMaps() const; | 96 void invalidateIdNameCacheMaps() const; |
99 | 97 |
100 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. | 98 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. |
101 const unsigned m_rootType : 2; | 99 const unsigned m_rootType : 2; |
102 const unsigned m_invalidationType : 4; | 100 const unsigned m_invalidationType : 4; |
103 const unsigned m_shouldOnlyIncludeDirectChildren : 1; | |
104 const unsigned m_collectionType : 5; | 101 const unsigned m_collectionType : 5; |
105 }; | 102 }; |
106 | 103 |
107 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) | 104 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) |
108 { | 105 { |
109 switch (type) { | 106 switch (type) { |
110 case InvalidateOnClassAttrChange: | 107 case InvalidateOnClassAttrChange: |
111 return attrName == HTMLNames::classAttr; | 108 return attrName == HTMLNames::classAttr; |
112 case InvalidateOnNameAttrChange: | 109 case InvalidateOnNameAttrChange: |
113 return attrName == HTMLNames::nameAttr; | 110 return attrName == HTMLNames::nameAttr; |
(...skipping 11 matching lines...) Expand all Loading... |
125 return false; | 122 return false; |
126 case InvalidateOnAnyAttrChange: | 123 case InvalidateOnAnyAttrChange: |
127 return true; | 124 return true; |
128 } | 125 } |
129 return false; | 126 return false; |
130 } | 127 } |
131 | 128 |
132 class LiveNodeList : public NodeList, public LiveNodeListBase { | 129 class LiveNodeList : public NodeList, public LiveNodeListBase { |
133 public: | 130 public: |
134 LiveNodeList(PassRefPtr<ContainerNode> ownerNode, CollectionType collectionT
ype, NodeListInvalidationType invalidationType, NodeListRootType rootType = Node
ListIsRootedAtNode) | 131 LiveNodeList(PassRefPtr<ContainerNode> ownerNode, CollectionType collectionT
ype, NodeListInvalidationType invalidationType, NodeListRootType rootType = Node
ListIsRootedAtNode) |
135 : LiveNodeListBase(ownerNode.get(), rootType, invalidationType, false, | 132 : LiveNodeListBase(ownerNode.get(), rootType, invalidationType, |
136 collectionType) | 133 collectionType) |
137 { } | 134 { } |
138 | 135 |
139 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } | 136 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } |
140 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } | 137 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } |
141 virtual bool nodeMatches(const Element&) const = 0; | 138 virtual bool nodeMatches(const Element&) const = 0; |
142 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. | 139 // Avoid ambiguity since both NodeList and LiveNodeListBase have an ownerNod
e() method. |
143 using LiveNodeListBase::ownerNode; | 140 using LiveNodeListBase::ownerNode; |
144 | 141 |
145 virtual void invalidateCache() const OVERRIDE FINAL; | 142 virtual void invalidateCache() const OVERRIDE FINAL; |
| 143 bool shouldOnlyIncludeDirectChildren() const { return false; } |
146 | 144 |
147 // Collection IndexCache API. | 145 // Collection IndexCache API. |
148 bool canTraverseBackward() const { return true; } | 146 bool canTraverseBackward() const { return true; } |
149 Element* itemBefore(const Element* previousItem) const; | 147 Element* itemBefore(const Element* previousItem) const; |
150 Element* traverseToFirstElement(const ContainerNode& root) const; | 148 Element* traverseToFirstElement(const ContainerNode& root) const; |
151 Element* traverseForwardToOffset(unsigned offset, Element& currentNode, unsi
gned& currentOffset, const ContainerNode& root) const; | 149 Element* traverseForwardToOffset(unsigned offset, Element& currentNode, unsi
gned& currentOffset, const ContainerNode& root) const; |
152 | 150 |
153 private: | 151 private: |
154 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } | 152 virtual bool isLiveNodeList() const OVERRIDE FINAL { return true; } |
155 | 153 |
156 mutable CollectionIndexCache<LiveNodeList, Element> m_collectionIndexCache; | 154 mutable CollectionIndexCache<LiveNodeList, Element> m_collectionIndexCache; |
157 }; | 155 }; |
158 | 156 |
159 } // namespace WebCore | 157 } // namespace WebCore |
160 | 158 |
161 #endif // LiveNodeList_h | 159 #endif // LiveNodeList_h |
OLD | NEW |