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 * | 7 * |
7 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
11 * | 12 * |
12 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 16 * Library General Public License for more details. |
16 * | 17 * |
17 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
21 * | 22 * |
22 */ | 23 */ |
23 | 24 |
24 #ifndef LiveNodeList_h | 25 #ifndef LiveNodeListBase_h |
25 #define LiveNodeList_h | 26 #define LiveNodeListBase_h |
26 | 27 |
27 #include "HTMLNames.h" | 28 #include "HTMLNames.h" |
28 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
29 #include "core/dom/NodeList.h" | |
30 #include "core/html/CollectionIndexCache.h" | |
31 #include "core/html/CollectionType.h" | 30 #include "core/html/CollectionType.h" |
32 #include "wtf/Forward.h" | |
33 #include "wtf/RefPtr.h" | |
34 | 31 |
35 namespace WebCore { | 32 namespace WebCore { |
36 | 33 |
37 class Element; | |
38 | |
39 enum NodeListRootType { | 34 enum NodeListRootType { |
40 NodeListIsRootedAtNode, | 35 NodeListIsRootedAtNode, |
41 NodeListIsRootedAtDocument, | 36 NodeListIsRootedAtDocument, |
42 NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr, | 37 NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr, |
43 }; | 38 }; |
44 | 39 |
45 class LiveNodeListBase { | 40 class LiveNodeListBase { |
46 public: | 41 public: |
47 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, | 42 LiveNodeListBase(ContainerNode* ownerNode, NodeListRootType rootType, NodeLi
stInvalidationType invalidationType, |
48 CollectionType collectionType) | 43 CollectionType collectionType) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 case InvalidateOnHRefAttrChange: | 114 case InvalidateOnHRefAttrChange: |
120 return attrName == HTMLNames::hrefAttr; | 115 return attrName == HTMLNames::hrefAttr; |
121 case DoNotInvalidateOnAttributeChanges: | 116 case DoNotInvalidateOnAttributeChanges: |
122 return false; | 117 return false; |
123 case InvalidateOnAnyAttrChange: | 118 case InvalidateOnAnyAttrChange: |
124 return true; | 119 return true; |
125 } | 120 } |
126 return false; | 121 return false; |
127 } | 122 } |
128 | 123 |
129 class LiveNodeList : public NodeList, public LiveNodeListBase { | |
130 public: | |
131 LiveNodeList(PassRefPtr<ContainerNode> ownerNode, CollectionType collectionT
ype, NodeListInvalidationType invalidationType, NodeListRootType rootType = Node
ListIsRootedAtNode) | |
132 : LiveNodeListBase(ownerNode.get(), rootType, invalidationType, | |
133 collectionType) | |
134 { } | |
135 | |
136 virtual unsigned length() const OVERRIDE FINAL { return m_collectionIndexCac
he.nodeCount(*this); } | |
137 virtual Node* item(unsigned offset) const OVERRIDE FINAL { return m_collecti
onIndexCache.nodeAt(*this, offset); } | |
138 virtual bool nodeMatches(const Element&) const = 0; | |
139 | |
140 virtual void invalidateCache(Document* oldDocument) const OVERRIDE FINAL; | |
141 bool shouldOnlyIncludeDirectChildren() const { return false; } | |
142 | |
143 // Collection IndexCache API. | |
144 bool canTraverseBackward() const { return true; } | |
145 Element* itemBefore(const Element* previousItem) const; | |
146 Element* traverseToFirstElement(const ContainerNode& root) const; | |
147 Element* traverseForwardToOffset(unsigned offset, Element& currentNode, unsi
gned& currentOffset, const ContainerNode& root) const; | |
148 | |
149 private: | |
150 virtual Node* virtualOwnerNode() const OVERRIDE FINAL; | |
151 | |
152 mutable CollectionIndexCache<LiveNodeList, Element> m_collectionIndexCache; | |
153 }; | |
154 | |
155 } // namespace WebCore | 124 } // namespace WebCore |
156 | 125 |
157 #endif // LiveNodeList_h | 126 #endif // LiveNodeListBase_h |
OLD | NEW |