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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 virtual void invalidateCache(Document* oldDocument = 0) const = 0; | 72 virtual void invalidateCache(Document* oldDocument = 0) const = 0; |
73 void invalidateCacheForAttribute(const QualifiedName*) const; | 73 void invalidateCacheForAttribute(const QualifiedName*) const; |
74 | 74 |
75 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); | 75 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType,
const QualifiedName&); |
76 | 76 |
77 protected: | 77 protected: |
78 Document& document() const { return m_ownerNode->document(); } | 78 Document& document() const { return m_ownerNode->document(); } |
79 | 79 |
80 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } | 80 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis
tRootType>(m_rootType); } |
81 | 81 |
82 template <class NodeListType> | 82 template <typename MatchFunc> |
83 static Element* firstMatchingElement(const NodeListType&); | 83 static Element* traverseMatchingElementsForwardToOffset(Element& currentElem
ent, const ContainerNode* stayWithin, unsigned offset, unsigned& currentOffset,
MatchFunc); |
84 template <class NodeListType> | 84 template <typename MatchFunc> |
85 static Element* lastMatchingElement(const NodeListType&); | 85 static Element* traverseMatchingElementsBackwardToOffset(Element& currentEle
ment, const ContainerNode* stayWithin, unsigned offset, unsigned& currentOffset,
MatchFunc); |
86 template <class NodeListType> | |
87 static Element* nextMatchingElement(const NodeListType&, Element& current); | |
88 template <class NodeListType> | |
89 static Element* previousMatchingElement(const NodeListType&, Element& curren
t); | |
90 template <class NodeListType> | |
91 static Element* traverseMatchingElementsForwardToOffset(const NodeListType&,
unsigned offset, Element& currentElement, unsigned& currentOffset); | |
92 template <class NodeListType> | |
93 static Element* traverseMatchingElementsBackwardToOffset(const NodeListType&
, unsigned offset, Element& currentElement, unsigned& currentOffset); | |
94 | 86 |
95 virtual void trace(Visitor* visitor) { visitor->trace(m_ownerNode); } | 87 virtual void trace(Visitor* visitor) { visitor->trace(m_ownerNode); } |
96 | 88 |
97 private: | 89 private: |
98 RefPtrWillBeMember<ContainerNode> m_ownerNode; // Cannot be null. | 90 RefPtrWillBeMember<ContainerNode> m_ownerNode; // Cannot be null. |
99 const unsigned m_rootType : 1; | 91 const unsigned m_rootType : 1; |
100 const unsigned m_invalidationType : 4; | 92 const unsigned m_invalidationType : 4; |
101 const unsigned m_collectionType : 5; | 93 const unsigned m_collectionType : 5; |
102 }; | 94 }; |
103 | 95 |
(...skipping 14 matching lines...) Expand all Loading... |
118 case InvalidateOnHRefAttrChange: | 110 case InvalidateOnHRefAttrChange: |
119 return attrName == HTMLNames::hrefAttr; | 111 return attrName == HTMLNames::hrefAttr; |
120 case DoNotInvalidateOnAttributeChanges: | 112 case DoNotInvalidateOnAttributeChanges: |
121 return false; | 113 return false; |
122 case InvalidateOnAnyAttrChange: | 114 case InvalidateOnAnyAttrChange: |
123 return true; | 115 return true; |
124 } | 116 } |
125 return false; | 117 return false; |
126 } | 118 } |
127 | 119 |
128 template <typename NodeListType> | 120 template <typename MatchFunc> |
129 Element* LiveNodeListBase::lastMatchingElement(const NodeListType& nodeList) | 121 Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(Element& curr
entElement, const ContainerNode* stayWithin, unsigned offset, unsigned& currentO
ffset, MatchFunc isMatch) |
130 { | |
131 ContainerNode& root = nodeList.rootNode(); | |
132 Element* element = ElementTraversal::lastWithin(root); | |
133 while (element && !isMatchingElement(nodeList, *element)) | |
134 element = ElementTraversal::previous(*element, &root); | |
135 return element; | |
136 } | |
137 | |
138 template <class NodeListType> | |
139 Element* LiveNodeListBase::firstMatchingElement(const NodeListType& nodeList) | |
140 { | |
141 ContainerNode& root = nodeList.rootNode(); | |
142 Element* element = ElementTraversal::firstWithin(root); | |
143 while (element && !isMatchingElement(nodeList, *element)) | |
144 element = ElementTraversal::next(*element, &root); | |
145 return element; | |
146 } | |
147 | |
148 template <class NodeListType> | |
149 Element* LiveNodeListBase::nextMatchingElement(const NodeListType& nodeList, Ele
ment& current) | |
150 { | |
151 ContainerNode& root = nodeList.rootNode(); | |
152 Element* next = ¤t; | |
153 do { | |
154 next = ElementTraversal::next(*next, &root); | |
155 } while (next && !isMatchingElement(nodeList, *next)); | |
156 return next; | |
157 } | |
158 | |
159 template <class NodeListType> | |
160 Element* LiveNodeListBase::previousMatchingElement(const NodeListType& nodeList,
Element& current) | |
161 { | |
162 ContainerNode& root = nodeList.rootNode(); | |
163 Element* previous = ¤t; | |
164 do { | |
165 previous = ElementTraversal::previous(*previous, &root); | |
166 } while (previous && !isMatchingElement(nodeList, *previous)); | |
167 return previous; | |
168 } | |
169 | |
170 template <class NodeListType> | |
171 Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(const NodeLis
tType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOffs
et) | |
172 { | 122 { |
173 ASSERT(currentOffset < offset); | 123 ASSERT(currentOffset < offset); |
174 for (Element* next = nextMatchingElement(nodeList, currentElement); next; ne
xt = nextMatchingElement(nodeList, *next)) { | 124 for (Element* next = ElementTraversal::next(currentElement, stayWithin, isMa
tch); next; next = ElementTraversal::next(*next, stayWithin, isMatch)) { |
175 if (++currentOffset == offset) | 125 if (++currentOffset == offset) |
176 return next; | 126 return next; |
177 } | 127 } |
178 return 0; | 128 return 0; |
179 } | 129 } |
180 | 130 |
181 template <class NodeListType> | 131 template <typename MatchFunc> |
182 Element* LiveNodeListBase::traverseMatchingElementsBackwardToOffset(const NodeLi
stType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOff
set) | 132 Element* LiveNodeListBase::traverseMatchingElementsBackwardToOffset(Element& cur
rentElement, const ContainerNode* stayWithin, unsigned offset, unsigned& current
Offset, MatchFunc isMatch) |
183 { | 133 { |
184 ASSERT(currentOffset > offset); | 134 ASSERT(currentOffset > offset); |
185 for (Element* previous = previousMatchingElement(nodeList, currentElement);
previous; previous = previousMatchingElement(nodeList, *previous)) { | 135 for (Element* previous = ElementTraversal::previous(currentElement, stayWith
in, isMatch); previous; previous = ElementTraversal::previous(*previous, stayWit
hin, isMatch)) { |
186 if (--currentOffset == offset) | 136 if (--currentOffset == offset) |
187 return previous; | 137 return previous; |
188 } | 138 } |
189 return 0; | 139 return 0; |
190 } | 140 } |
191 | 141 |
192 } // namespace blink | 142 } // namespace blink |
193 | 143 |
194 #endif // LiveNodeListBase_h | 144 #endif // LiveNodeListBase_h |
OLD | NEW |