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 20 matching lines...) Expand all Loading... |
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 static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType
); | 36 static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType
); |
37 virtual ~HTMLCollection(); | 37 virtual ~HTMLCollection(); |
38 virtual void invalidateCache() const OVERRIDE; | 38 virtual void invalidateCache() const OVERRIDE; |
39 | 39 |
40 // DOM API | 40 // DOM API |
| 41 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); } |
| 42 Node* item(unsigned offset) const { return m_collectionIndexCache.nodeAt(*th
is, offset); } |
41 virtual Element* namedItem(const AtomicString& name) const; | 43 virtual Element* namedItem(const AtomicString& name) const; |
42 | 44 |
43 // Non-DOM API | 45 // Non-DOM API |
44 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; | 46 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; |
45 bool isEmpty() const | 47 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); } |
46 { | 48 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne
Node(*this); } |
47 if (isLengthCacheValid()) | |
48 return !cachedLength(); | |
49 if (cachedItem()) | |
50 return false; | |
51 return !item(0); | |
52 } | |
53 bool hasExactlyOneItem() const | |
54 { | |
55 if (isLengthCacheValid()) | |
56 return cachedLength() == 1; | |
57 if (cachedItem()) | |
58 return !cachedItemOffset() && !item(1); | |
59 return item(0) && !item(1); | |
60 } | |
61 | 49 |
62 virtual Element* virtualItemAfter(Element*) const; | 50 virtual Element* virtualItemAfter(Element*) const; |
63 | 51 |
| 52 // CollectionIndexCache API. |
64 Element* traverseToFirstElement(const ContainerNode& root) const; | 53 Element* traverseToFirstElement(const ContainerNode& root) const; |
65 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u
nsigned& currentOffset, const ContainerNode& root) const; | 54 Element* traverseForwardToOffset(unsigned offset, Node& currentElement, unsi
gned& currentOffset, const ContainerNode& root) const; |
66 | 55 |
67 protected: | 56 protected: |
68 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType); | 57 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType); |
69 | 58 |
70 virtual void updateNameCache() const; | 59 virtual void updateNameCache() const; |
71 bool hasNameCache() const { return m_isNameCacheValid; } | 60 bool hasNameCache() const { return m_isNameCacheValid; } |
72 void setHasNameCache() const { m_isNameCacheValid = true; } | 61 void setHasNameCache() const { m_isNameCacheValid = true; } |
73 | 62 |
74 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; | 63 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; |
75 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache
.get(name.impl()); } | 64 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache
.get(name.impl()); } |
76 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC
ache.get(name.impl()); } | 65 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC
ache.get(name.impl()); } |
77 void appendIdCache(const AtomicString& name, Element* element) const { appen
d(m_idCache, name, element); } | 66 void appendIdCache(const AtomicString& name, Element* element) const { appen
d(m_idCache, name, element); } |
78 void appendNameCache(const AtomicString& name, Element* element) const { app
end(m_nameCache, name, element); } | 67 void appendNameCache(const AtomicString& name, Element* element) const { app
end(m_nameCache, name, element); } |
79 | 68 |
80 private: | 69 private: |
81 bool checkForNameMatch(const Element&, bool checkName, const AtomicString& n
ame) const; | 70 bool checkForNameMatch(const Element&, bool checkName, const AtomicString& n
ame) const; |
82 Element* traverseNextElement(Element& previous, const ContainerNode& root) c
onst; | 71 Element* traverseNextElement(Element& previous, const ContainerNode& root) c
onst; |
83 | 72 |
84 static void append(NodeCacheMap&, const AtomicString&, Element*); | 73 static void append(NodeCacheMap&, const AtomicString&, Element*); |
85 void invalidateIdNameCacheMaps() const | 74 void invalidateIdNameCacheMaps() const |
86 { | 75 { |
87 m_idCache.clear(); | 76 m_idCache.clear(); |
88 m_nameCache.clear(); | 77 m_nameCache.clear(); |
89 m_isNameCacheValid = false; | 78 m_isNameCacheValid = false; |
90 } | 79 } |
91 | 80 |
92 mutable unsigned m_isNameCacheValid : 1; | 81 mutable unsigned m_isNameCacheValid : 1; |
93 mutable NodeCacheMap m_idCache; | 82 mutable NodeCacheMap m_idCache; |
94 mutable NodeCacheMap m_nameCache; | 83 mutable NodeCacheMap m_nameCache; |
| 84 mutable CollectionIndexCache<HTMLCollection> m_collectionIndexCache; |
95 | 85 |
96 friend class LiveNodeListBase; | 86 friend class LiveNodeListBase; |
97 }; | 87 }; |
98 | 88 |
99 } // namespace | 89 } // namespace |
100 | 90 |
101 #endif | 91 #endif |
OLD | NEW |