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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "core/dom/LiveNodeList.h" | 26 #include "core/dom/LiveNodeList.h" |
27 #include "core/html/CollectionType.h" | 27 #include "core/html/CollectionType.h" |
28 #include "wtf/Forward.h" | 28 #include "wtf/Forward.h" |
29 #include "wtf/HashMap.h" | 29 #include "wtf/HashMap.h" |
30 #include "wtf/Vector.h" | 30 #include "wtf/Vector.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection>
, public LiveNodeListBase { | 34 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection>
, public LiveNodeListBase { |
35 public: | 35 public: |
| 36 enum ItemAfterOverrideType { |
| 37 OverridesItemAfter, |
| 38 DoesNotOverrideItemAfter, |
| 39 }; |
| 40 |
36 static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType
); | 41 static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType
); |
37 virtual ~HTMLCollection(); | 42 virtual ~HTMLCollection(); |
38 virtual void invalidateCache() const OVERRIDE; | 43 virtual void invalidateCache() const OVERRIDE; |
39 | 44 |
40 // DOM API | 45 // DOM API |
41 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); } | 46 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); } |
42 Node* item(unsigned offset) const { return m_collectionIndexCache.nodeAt(*th
is, offset); } | 47 Node* item(unsigned offset) const { return m_collectionIndexCache.nodeAt(*th
is, offset); } |
43 virtual Element* namedItem(const AtomicString& name) const; | 48 virtual Element* namedItem(const AtomicString& name) const; |
44 | 49 |
45 // Non-DOM API | 50 // Non-DOM API |
46 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; | 51 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; |
47 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); } | 52 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); } |
48 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne
Node(*this); } | 53 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne
Node(*this); } |
49 | 54 |
50 virtual Element* virtualItemAfter(Element*) const; | |
51 | |
52 // CollectionIndexCache API. | 55 // CollectionIndexCache API. |
| 56 bool canTraverseBackward() const { return !overridesItemAfter(); } |
53 Element* traverseToFirstElement(const ContainerNode& root) const; | 57 Element* traverseToFirstElement(const ContainerNode& root) const; |
54 Element* traverseForwardToOffset(unsigned offset, Node& currentElement, unsi
gned& currentOffset, const ContainerNode& root) const; | 58 Element* traverseForwardToOffset(unsigned offset, Node& currentElement, unsi
gned& currentOffset, const ContainerNode& root) const; |
55 | 59 |
56 protected: | 60 protected: |
57 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType); | 61 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType); |
58 | 62 |
| 63 bool overridesItemAfter() const { return m_overridesItemAfter; } |
| 64 virtual Element* virtualItemAfter(Element*) const; |
| 65 |
59 virtual void updateNameCache() const; | 66 virtual void updateNameCache() const; |
60 bool hasNameCache() const { return m_isNameCacheValid; } | 67 bool hasNameCache() const { return m_isNameCacheValid; } |
61 void setHasNameCache() const { m_isNameCacheValid = true; } | 68 void setHasNameCache() const { m_isNameCacheValid = true; } |
62 | 69 |
63 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; | 70 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; |
64 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache
.get(name.impl()); } | 71 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache
.get(name.impl()); } |
65 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC
ache.get(name.impl()); } | 72 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC
ache.get(name.impl()); } |
66 void appendIdCache(const AtomicString& name, Element* element) const { appen
d(m_idCache, name, element); } | 73 void appendIdCache(const AtomicString& name, Element* element) const { appen
d(m_idCache, name, element); } |
67 void appendNameCache(const AtomicString& name, Element* element) const { app
end(m_nameCache, name, element); } | 74 void appendNameCache(const AtomicString& name, Element* element) const { app
end(m_nameCache, name, element); } |
68 | 75 |
69 private: | 76 private: |
70 bool checkForNameMatch(const Element&, bool checkName, const AtomicString& n
ame) const; | 77 bool checkForNameMatch(const Element&, bool checkName, const AtomicString& n
ame) const; |
71 Element* traverseNextElement(Element& previous, const ContainerNode& root) c
onst; | 78 Element* traverseNextElement(Element& previous, const ContainerNode& root) c
onst; |
72 | 79 |
73 static void append(NodeCacheMap&, const AtomicString&, Element*); | 80 static void append(NodeCacheMap&, const AtomicString&, Element*); |
74 void invalidateIdNameCacheMaps() const | 81 void invalidateIdNameCacheMaps() const |
75 { | 82 { |
76 m_idCache.clear(); | 83 m_idCache.clear(); |
77 m_nameCache.clear(); | 84 m_nameCache.clear(); |
78 m_isNameCacheValid = false; | 85 m_isNameCacheValid = false; |
79 } | 86 } |
80 | 87 |
| 88 const unsigned m_overridesItemAfter : 1; |
81 mutable unsigned m_isNameCacheValid : 1; | 89 mutable unsigned m_isNameCacheValid : 1; |
82 mutable NodeCacheMap m_idCache; | 90 mutable NodeCacheMap m_idCache; |
83 mutable NodeCacheMap m_nameCache; | 91 mutable NodeCacheMap m_nameCache; |
84 mutable CollectionIndexCache<HTMLCollection> m_collectionIndexCache; | 92 mutable CollectionIndexCache<HTMLCollection> m_collectionIndexCache; |
85 | 93 |
86 friend class LiveNodeListBase; | 94 friend class LiveNodeListBase; |
87 }; | 95 }; |
88 | 96 |
89 } // namespace | 97 } // namespace |
90 | 98 |
91 #endif | 99 #endif |
OLD | NEW |