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