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 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 5 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> , public LiveNodeListBase { | 35 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> , public LiveNodeListBase { |
36 public: | 36 public: |
37 enum ItemAfterOverrideType { | 37 enum ItemAfterOverrideType { |
38 OverridesItemAfter, | 38 OverridesItemAfter, |
39 DoesNotOverrideItemAfter, | 39 DoesNotOverrideItemAfter, |
40 }; | 40 }; |
41 | 41 |
42 static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType ); | 42 static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType ); |
43 virtual ~HTMLCollection(); | 43 virtual ~HTMLCollection(); |
44 virtual void invalidateCache() const OVERRIDE; | 44 virtual void invalidateCache(Document* oldDocument = 0) const OVERRIDE; |
45 | 45 |
46 // DOM API | 46 // DOM API |
47 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); } | 47 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); } |
48 Element* item(unsigned offset) const { return m_collectionIndexCache.nodeAt( *this, offset); } | 48 Element* item(unsigned offset) const { return m_collectionIndexCache.nodeAt( *this, offset); } |
49 virtual Element* namedItem(const AtomicString& name) const; | 49 virtual Element* namedItem(const AtomicString& name) const; |
50 bool namedPropertyQuery(const AtomicString&, ExceptionState&); | 50 bool namedPropertyQuery(const AtomicString&, ExceptionState&); |
51 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&); | 51 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&); |
52 | 52 |
53 // Non-DOM API | 53 // Non-DOM API |
54 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; | 54 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; |
55 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); } | 55 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); } |
56 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne Node(*this); } | 56 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne Node(*this); } |
57 | 57 |
58 // CollectionIndexCache API. | 58 // CollectionIndexCache API. |
59 bool canTraverseBackward() const { return !overridesItemAfter(); } | 59 bool canTraverseBackward() const { return !overridesItemAfter(); } |
60 Element* itemBefore(const Element* previousItem) const; | 60 Element* itemBefore(const Element* previousItem) const; |
61 Element* traverseToFirstElement(const ContainerNode& root) const; | 61 Element* traverseToFirstElement(const ContainerNode& root) const; |
62 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset, const ContainerNode& root) const; | 62 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset, const ContainerNode& root) const; |
63 | 63 |
64 protected: | 64 protected: |
65 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType); | 65 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType); |
66 | 66 |
67 bool overridesItemAfter() const { return m_overridesItemAfter; } | 67 bool overridesItemAfter() const { return m_overridesItemAfter; } |
68 virtual Element* virtualItemAfter(Element*) const; | 68 virtual Element* virtualItemAfter(Element*) const; |
69 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir ectChildren; } | 69 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir ectChildren; } |
70 virtual void supportedPropertyNames(Vector<String>& names); | 70 virtual void supportedPropertyNames(Vector<String>& names); |
71 | 71 |
72 virtual void updateNameCache() const; | 72 virtual void updateIdNameCache() const; |
73 bool hasNameCache() const { return m_isNameCacheValid; } | 73 bool hasValidIdNameCache() const { return m_hasValidIdNameCache; } |
Inactive
2014/02/12 18:26:08
Just a naming update to make it clear that:
- the
| |
74 void setHasNameCache() const { m_isNameCacheValid = true; } | 74 void setHasValidIdNameCache() const |
75 { | |
76 ASSERT(!m_hasValidIdNameCache); | |
77 m_hasValidIdNameCache = true; | |
78 document().incrementNodeListWithIdNameCacheCount(); | |
79 } | |
75 | 80 |
76 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; | 81 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; |
77 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); } | 82 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); } |
78 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); } | 83 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); } |
79 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); } | 84 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); } |
80 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); } | 85 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); } |
81 | 86 |
82 private: | 87 private: |
83 Element* traverseNextElement(Element& previous, const ContainerNode& root) c onst; | 88 Element* traverseNextElement(Element& previous, const ContainerNode& root) c onst; |
84 | 89 |
85 static void append(NodeCacheMap&, const AtomicString&, Element*); | 90 static void append(NodeCacheMap&, const AtomicString&, Element*); |
86 void invalidateIdNameCacheMaps() const | 91 void invalidateIdNameCacheMaps(Document* oldDocument = 0) const |
87 { | 92 { |
93 if (!m_hasValidIdNameCache) | |
94 return; | |
95 | |
96 // Make sure we decrement the NodeListWithIdNameCache count from | |
97 // the old document instead of the new one in the case the collection | |
98 // is moved to a new document. | |
99 unregisterIdNameCacheFromDocument(oldDocument ? *oldDocument : document( )); | |
100 | |
88 m_idCache.clear(); | 101 m_idCache.clear(); |
89 m_nameCache.clear(); | 102 m_nameCache.clear(); |
90 m_isNameCacheValid = false; | 103 m_hasValidIdNameCache = false; |
104 } | |
105 | |
106 void unregisterIdNameCacheFromDocument(Document& document) const | |
107 { | |
108 ASSERT(m_hasValidIdNameCache); | |
109 document.decrementNodeListWithIdNameCacheCount(); | |
91 } | 110 } |
92 | 111 |
93 const unsigned m_overridesItemAfter : 1; | 112 const unsigned m_overridesItemAfter : 1; |
94 const unsigned m_shouldOnlyIncludeDirectChildren : 1; | 113 const unsigned m_shouldOnlyIncludeDirectChildren : 1; |
95 mutable unsigned m_isNameCacheValid : 1; | 114 mutable unsigned m_hasValidIdNameCache : 1; |
96 mutable NodeCacheMap m_idCache; | 115 mutable NodeCacheMap m_idCache; |
97 mutable NodeCacheMap m_nameCache; | 116 mutable NodeCacheMap m_nameCache; |
98 mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache ; | 117 mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache ; |
99 | 118 |
100 friend class LiveNodeListBase; | 119 friend class LiveNodeListBase; |
101 }; | 120 }; |
102 | 121 |
103 } // namespace | 122 } // namespace |
104 | 123 |
105 #endif | 124 #endif |
OLD | NEW |