| 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 14 matching lines...) Expand all Loading... |
| 25 #define HTMLCollection_h | 25 #define HTMLCollection_h |
| 26 | 26 |
| 27 #include "core/CoreExport.h" | 27 #include "core/CoreExport.h" |
| 28 #include "core/dom/LiveNodeListBase.h" | 28 #include "core/dom/LiveNodeListBase.h" |
| 29 #include "core/html/CollectionItemsCache.h" | 29 #include "core/html/CollectionItemsCache.h" |
| 30 #include "core/html/CollectionType.h" | 30 #include "core/html/CollectionType.h" |
| 31 #include "wtf/Forward.h" | 31 #include "wtf/Forward.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 class CORE_EXPORT HTMLCollection : public RefCountedWillBeGarbageCollectedFinali
zed<HTMLCollection>, public ScriptWrappable, public LiveNodeListBase { | 35 class CORE_EXPORT HTMLCollection : public GarbageCollectedFinalized<HTMLCollecti
on>, public ScriptWrappable, public LiveNodeListBase { |
| 36 DEFINE_WRAPPERTYPEINFO(); | 36 DEFINE_WRAPPERTYPEINFO(); |
| 37 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLCollection); | 37 USING_GARBAGE_COLLECTED_MIXIN(HTMLCollection); |
| 38 public: | 38 public: |
| 39 enum ItemAfterOverrideType { | 39 enum ItemAfterOverrideType { |
| 40 OverridesItemAfter, | 40 OverridesItemAfter, |
| 41 DoesNotOverrideItemAfter, | 41 DoesNotOverrideItemAfter, |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 static PassRefPtrWillBeRawPtr<HTMLCollection> create(ContainerNode& base, Co
llectionType); | 44 static RawPtr<HTMLCollection> create(ContainerNode& base, CollectionType); |
| 45 virtual ~HTMLCollection(); | 45 virtual ~HTMLCollection(); |
| 46 void invalidateCache(Document* oldDocument = 0) const override; | 46 void invalidateCache(Document* oldDocument = 0) const override; |
| 47 void invalidateCacheForAttribute(const QualifiedName*) const; | 47 void invalidateCacheForAttribute(const QualifiedName*) const; |
| 48 | 48 |
| 49 // DOM API | 49 // DOM API |
| 50 unsigned length() const; | 50 unsigned length() const; |
| 51 Element* item(unsigned offset) const; | 51 Element* item(unsigned offset) const; |
| 52 virtual Element* namedItem(const AtomicString& name) const; | 52 virtual Element* namedItem(const AtomicString& name) const; |
| 53 bool namedPropertyQuery(const AtomicString&, ExceptionState&); | 53 bool namedPropertyQuery(const AtomicString&, ExceptionState&); |
| 54 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&); | 54 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&); |
| 55 | 55 |
| 56 // Non-DOM API | 56 // Non-DOM API |
| 57 void namedItems(const AtomicString& name, WillBeHeapVector<RefPtrWillBeMembe
r<Element>>&) const; | 57 void namedItems(const AtomicString& name, HeapVector<Member<Element>>&) cons
t; |
| 58 bool isEmpty() const { return m_collectionItemsCache.isEmpty(*this); } | 58 bool isEmpty() const { return m_collectionItemsCache.isEmpty(*this); } |
| 59 bool hasExactlyOneItem() const { return m_collectionItemsCache.hasExactlyOne
Node(*this); } | 59 bool hasExactlyOneItem() const { return m_collectionItemsCache.hasExactlyOne
Node(*this); } |
| 60 bool elementMatches(const Element&) const; | 60 bool elementMatches(const Element&) const; |
| 61 | 61 |
| 62 // CollectionIndexCache API. | 62 // CollectionIndexCache API. |
| 63 bool canTraverseBackward() const { return !overridesItemAfter(); } | 63 bool canTraverseBackward() const { return !overridesItemAfter(); } |
| 64 Element* traverseToFirst() const; | 64 Element* traverseToFirst() const; |
| 65 Element* traverseToLast() const; | 65 Element* traverseToLast() const; |
| 66 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u
nsigned& currentOffset) const; | 66 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u
nsigned& currentOffset) const; |
| 67 Element* traverseBackwardToOffset(unsigned offset, Element& currentElement,
unsigned& currentOffset) const; | 67 Element* traverseBackwardToOffset(unsigned offset, Element& currentElement,
unsigned& currentOffset) const; |
| 68 | 68 |
| 69 DECLARE_VIRTUAL_TRACE(); | 69 DECLARE_VIRTUAL_TRACE(); |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); | 72 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); |
| 73 | 73 |
| 74 class NamedItemCache final : public NoBaseWillBeGarbageCollected<NamedItemCa
che> { | 74 class NamedItemCache final : public GarbageCollected<NamedItemCache> { |
| 75 public: | 75 public: |
| 76 static PassOwnPtrWillBeRawPtr<NamedItemCache> create() | 76 static RawPtr<NamedItemCache> create() |
| 77 { | 77 { |
| 78 return adoptPtrWillBeNoop(new NamedItemCache); | 78 return adoptPtrWillBeNoop(new NamedItemCache); |
| 79 } | 79 } |
| 80 | 80 |
| 81 WillBeHeapVector<RawPtrWillBeMember<Element>>* getElementsById(const Ato
micString& id) const { return m_idCache.get(id.impl()); } | 81 HeapVector<Member<Element>>* getElementsById(const AtomicString& id) con
st { return m_idCache.get(id.impl()); } |
| 82 WillBeHeapVector<RawPtrWillBeMember<Element>>* getElementsByName(const A
tomicString& name) const { return m_nameCache.get(name.impl()); } | 82 HeapVector<Member<Element>>* getElementsByName(const AtomicString& name)
const { return m_nameCache.get(name.impl()); } |
| 83 void addElementWithId(const AtomicString& id, Element* element) { addEle
mentToMap(m_idCache, id, element); } | 83 void addElementWithId(const AtomicString& id, Element* element) { addEle
mentToMap(m_idCache, id, element); } |
| 84 void addElementWithName(const AtomicString& name, Element* element) { ad
dElementToMap(m_nameCache, name, element); } | 84 void addElementWithName(const AtomicString& name, Element* element) { ad
dElementToMap(m_nameCache, name, element); } |
| 85 | 85 |
| 86 DEFINE_INLINE_TRACE() | 86 DEFINE_INLINE_TRACE() |
| 87 { | 87 { |
| 88 #if ENABLE(OILPAN) | 88 #if ENABLE(OILPAN) |
| 89 visitor->trace(m_idCache); | 89 visitor->trace(m_idCache); |
| 90 visitor->trace(m_nameCache); | 90 visitor->trace(m_nameCache); |
| 91 #endif | 91 #endif |
| 92 } | 92 } |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 NamedItemCache(); | 95 NamedItemCache(); |
| 96 typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<WillBeHeapVect
or<RawPtrWillBeMember<Element>>>> StringToElementsMap; | 96 typedef HeapHashMap<StringImpl*, Member<HeapVector<Member<Element>>>> St
ringToElementsMap; |
| 97 static void addElementToMap(StringToElementsMap& map, const AtomicString
& key, Element* element) | 97 static void addElementToMap(StringToElementsMap& map, const AtomicString
& key, Element* element) |
| 98 { | 98 { |
| 99 OwnPtrWillBeMember<WillBeHeapVector<RawPtrWillBeMember<Element>>>& v
ector = map.add(key.impl(), nullptr).storedValue->value; | 99 Member<HeapVector<Member<Element>>>& vector = map.add(key.impl(), nu
llptr).storedValue->value; |
| 100 if (!vector) | 100 if (!vector) |
| 101 vector = adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillBeMem
ber<Element>>); | 101 vector = adoptPtrWillBeNoop(new HeapVector<Member<Element>>); |
| 102 vector->append(element); | 102 vector->append(element); |
| 103 } | 103 } |
| 104 | 104 |
| 105 StringToElementsMap m_idCache; | 105 StringToElementsMap m_idCache; |
| 106 StringToElementsMap m_nameCache; | 106 StringToElementsMap m_nameCache; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 bool overridesItemAfter() const { return m_overridesItemAfter; } | 109 bool overridesItemAfter() const { return m_overridesItemAfter; } |
| 110 virtual Element* virtualItemAfter(Element*) const; | 110 virtual Element* virtualItemAfter(Element*) const; |
| 111 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } | 111 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } |
| 112 virtual void supportedPropertyNames(Vector<String>& names); | 112 virtual void supportedPropertyNames(Vector<String>& names); |
| 113 | 113 |
| 114 virtual void updateIdNameCache() const; | 114 virtual void updateIdNameCache() const; |
| 115 bool hasValidIdNameCache() const { return m_namedItemCache; } | 115 bool hasValidIdNameCache() const { return m_namedItemCache; } |
| 116 | 116 |
| 117 void setNamedItemCache(PassOwnPtrWillBeRawPtr<NamedItemCache> cache) const | 117 void setNamedItemCache(RawPtr<NamedItemCache> cache) const |
| 118 { | 118 { |
| 119 ASSERT(!m_namedItemCache); | 119 ASSERT(!m_namedItemCache); |
| 120 // Do not repeat registration for the same invalidation type. | 120 // Do not repeat registration for the same invalidation type. |
| 121 if (invalidationType() != InvalidateOnIdNameAttrChange) | 121 if (invalidationType() != InvalidateOnIdNameAttrChange) |
| 122 document().registerNodeListWithIdNameCache(this); | 122 document().registerNodeListWithIdNameCache(this); |
| 123 m_namedItemCache = std::move(cache); | 123 m_namedItemCache = std::move(cache); |
| 124 } | 124 } |
| 125 | 125 |
| 126 NamedItemCache& namedItemCache() const | 126 NamedItemCache& namedItemCache() const |
| 127 { | 127 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 146 void unregisterIdNameCacheFromDocument(Document& document) const | 146 void unregisterIdNameCacheFromDocument(Document& document) const |
| 147 { | 147 { |
| 148 ASSERT(hasValidIdNameCache()); | 148 ASSERT(hasValidIdNameCache()); |
| 149 // Do not repeat unregistration for the same invalidation type. | 149 // Do not repeat unregistration for the same invalidation type. |
| 150 if (invalidationType() != InvalidateOnIdNameAttrChange) | 150 if (invalidationType() != InvalidateOnIdNameAttrChange) |
| 151 document.unregisterNodeListWithIdNameCache(this); | 151 document.unregisterNodeListWithIdNameCache(this); |
| 152 } | 152 } |
| 153 | 153 |
| 154 const unsigned m_overridesItemAfter : 1; | 154 const unsigned m_overridesItemAfter : 1; |
| 155 const unsigned m_shouldOnlyIncludeDirectChildren : 1; | 155 const unsigned m_shouldOnlyIncludeDirectChildren : 1; |
| 156 mutable OwnPtrWillBeMember<NamedItemCache> m_namedItemCache; | 156 mutable Member<NamedItemCache> m_namedItemCache; |
| 157 mutable CollectionItemsCache<HTMLCollection, Element> m_collectionItemsCache
; | 157 mutable CollectionItemsCache<HTMLCollection, Element> m_collectionItemsCache
; |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 DEFINE_TYPE_CASTS(HTMLCollection, LiveNodeListBase, collection, isHTMLCollection
Type(collection->type()), isHTMLCollectionType(collection.type())); | 160 DEFINE_TYPE_CASTS(HTMLCollection, LiveNodeListBase, collection, isHTMLCollection
Type(collection->type()), isHTMLCollectionType(collection.type())); |
| 161 | 161 |
| 162 inline void HTMLCollection::invalidateCacheForAttribute(const QualifiedName* att
rName) const | 162 inline void HTMLCollection::invalidateCacheForAttribute(const QualifiedName* att
rName) const |
| 163 { | 163 { |
| 164 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), *
attrName)) | 164 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), *
attrName)) |
| 165 invalidateCache(); | 165 invalidateCache(); |
| 166 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr) | 166 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr) |
| 167 invalidateIdNameCacheMaps(); | 167 invalidateIdNameCacheMaps(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 } // namespace blink | 170 } // namespace blink |
| 171 | 171 |
| 172 #endif // HTMLCollection_h | 172 #endif // HTMLCollection_h |
| OLD | NEW |