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 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 15 matching lines...) Expand all Loading... |
26 #define LiveNodeListBase_h | 26 #define LiveNodeListBase_h |
27 | 27 |
28 #include "HTMLNames.h" | 28 #include "HTMLNames.h" |
29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
30 #include "core/html/CollectionType.h" | 30 #include "core/html/CollectionType.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 enum NodeListRootType { | 34 enum NodeListRootType { |
35 NodeListIsRootedAtNode, | 35 NodeListIsRootedAtNode, |
36 NodeListIsRootedAtDocument, | 36 NodeListIsRootedAtDocument |
37 NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr, | |
38 }; | 37 }; |
39 | 38 |
40 class LiveNodeListBase { | 39 class LiveNodeListBase { |
41 public: | 40 public: |
42 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, | 41 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, |
43 CollectionType collectionType) | 42 CollectionType collectionType) |
44 : m_ownerNode(ownerNode) | 43 : m_ownerNode(ownerNode) |
45 , m_rootType(rootType) | 44 , m_rootType(rootType) |
46 , m_invalidationType(invalidationType) | 45 , m_invalidationType(invalidationType) |
47 , m_collectionType(collectionType) | 46 , m_collectionType(collectionType) |
48 { | 47 { |
49 ASSERT(m_ownerNode); | 48 ASSERT(m_ownerNode); |
50 ASSERT(m_rootType == static_cast<unsigned>(rootType)); | 49 ASSERT(m_rootType == static_cast<unsigned>(rootType)); |
51 ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType)); | 50 ASSERT(m_invalidationType == static_cast<unsigned>(invalidationType)); |
52 ASSERT(m_collectionType == static_cast<unsigned>(collectionType)); | 51 ASSERT(m_collectionType == static_cast<unsigned>(collectionType)); |
53 | 52 |
54 document().registerNodeList(this); | 53 document().registerNodeList(this); |
55 } | 54 } |
56 | 55 |
57 virtual ~LiveNodeListBase() | 56 virtual ~LiveNodeListBase() |
58 { | 57 { |
59 document().unregisterNodeList(this); | 58 document().unregisterNodeList(this); |
60 } | 59 } |
61 | 60 |
62 ContainerNode& rootNode() const; | 61 ContainerNode& rootNode() const; |
63 | 62 |
64 void didMoveToDocument(Document& oldDocument, Document& newDocument); | 63 void didMoveToDocument(Document& oldDocument, Document& newDocument); |
65 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } | 64 ALWAYS_INLINE bool hasIdNameCache() const { return !isLiveNodeListType(type(
)); } |
66 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis
tIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemref
Attr; } | 65 ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeLis
tIsRootedAtDocument; } |
67 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta
tic_cast<NodeListInvalidationType>(m_invalidationType); } | 66 ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return sta
tic_cast<NodeListInvalidationType>(m_invalidationType); } |
68 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp
e>(m_collectionType); } | 67 ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionTyp
e>(m_collectionType); } |
69 ContainerNode* ownerNode() const { return m_ownerNode.get(); } | 68 ContainerNode* ownerNode() const { return m_ownerNode.get(); } |
70 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const | 69 ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const |
71 { | 70 { |
72 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) | 71 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(
), *attrName)) |
73 invalidateCache(); | 72 invalidateCache(); |
74 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam
e == HTMLNames::nameAttr)) | 73 else if (hasIdNameCache() && (*attrName == HTMLNames::idAttr || *attrNam
e == HTMLNames::nameAttr)) |
75 invalidateIdNameCacheMaps(); | 74 invalidateIdNameCacheMaps(); |
76 } | 75 } |
77 virtual void invalidateCache(Document* oldDocument = 0) const = 0; | 76 virtual void invalidateCache(Document* oldDocument = 0) const = 0; |
78 | 77 |
79 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); | 78 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); |
80 | 79 |
81 protected: | 80 protected: |
82 Document& document() const { return m_ownerNode->document(); } | 81 Document& document() const { return m_ownerNode->document(); } |
83 | 82 |
84 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } | 83 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } |
85 | 84 |
86 template <typename Collection> | 85 template <typename Collection> |
87 static Element* iterateForPreviousNode(const Collection&, Node* current); | 86 static Element* iterateForPreviousNode(const Collection&, Node* current); |
88 template <typename Collection> | 87 template <typename Collection> |
89 static Element* itemBefore(const Collection&, const Element* previousItem); | 88 static Element* itemBefore(const Collection&, const Element* previousItem); |
90 | 89 |
91 private: | 90 private: |
92 void invalidateIdNameCacheMaps() const; | 91 void invalidateIdNameCacheMaps() const; |
93 | 92 |
94 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. | 93 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. |
95 const unsigned m_rootType : 2; | 94 const unsigned m_rootType : 1; |
96 const unsigned m_invalidationType : 4; | 95 const unsigned m_invalidationType : 4; |
97 const unsigned m_collectionType : 5; | 96 const unsigned m_collectionType : 5; |
98 }; | 97 }; |
99 | 98 |
100 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) | 99 ALWAYS_INLINE bool LiveNodeListBase::shouldInvalidateTypeOnAttributeChange(NodeL
istInvalidationType type, const QualifiedName& attrName) |
101 { | 100 { |
102 switch (type) { | 101 switch (type) { |
103 case InvalidateOnClassAttrChange: | 102 case InvalidateOnClassAttrChange: |
104 return attrName == HTMLNames::classAttr; | 103 return attrName == HTMLNames::classAttr; |
105 case InvalidateOnNameAttrChange: | 104 case InvalidateOnNameAttrChange: |
(...skipping 11 matching lines...) Expand all Loading... |
117 return false; | 116 return false; |
118 case InvalidateOnAnyAttrChange: | 117 case InvalidateOnAnyAttrChange: |
119 return true; | 118 return true; |
120 } | 119 } |
121 return false; | 120 return false; |
122 } | 121 } |
123 | 122 |
124 } // namespace WebCore | 123 } // namespace WebCore |
125 | 124 |
126 #endif // LiveNodeListBase_h | 125 #endif // LiveNodeListBase_h |
OLD | NEW |