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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 void invalidateCacheForAttribute(const QualifiedName*) const; | 46 void invalidateCacheForAttribute(const QualifiedName*) const; |
47 | 47 |
48 // DOM API | 48 // DOM API |
49 unsigned length() const; | 49 unsigned length() const; |
50 Element* item(unsigned offset) const; | 50 Element* item(unsigned offset) const; |
51 virtual Element* namedItem(const AtomicString& name) const; | 51 virtual Element* namedItem(const AtomicString& name) const; |
52 bool namedPropertyQuery(const AtomicString&, ExceptionState&); | 52 bool namedPropertyQuery(const AtomicString&, ExceptionState&); |
53 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&); | 53 void namedPropertyEnumerator(Vector<String>& names, ExceptionState&); |
54 | 54 |
55 // Non-DOM API | 55 // Non-DOM API |
56 void namedItems(const AtomicString& name, WillBeHeapVector<RefPtrWillBeMembe
r<Element> >&) const; | 56 void namedItems(const AtomicString& name, WillBeHeapVector<RefPtrWillBeMembe
r<Element>>&) const; |
57 bool isEmpty() const { return m_collectionItemsCache.isEmpty(*this); } | 57 bool isEmpty() const { return m_collectionItemsCache.isEmpty(*this); } |
58 bool hasExactlyOneItem() const { return m_collectionItemsCache.hasExactlyOne
Node(*this); } | 58 bool hasExactlyOneItem() const { return m_collectionItemsCache.hasExactlyOne
Node(*this); } |
59 bool elementMatches(const Element&) const; | 59 bool elementMatches(const Element&) const; |
60 | 60 |
61 // CollectionIndexCache API. | 61 // CollectionIndexCache API. |
62 bool canTraverseBackward() const { return !overridesItemAfter(); } | 62 bool canTraverseBackward() const { return !overridesItemAfter(); } |
63 Element* traverseToFirst() const; | 63 Element* traverseToFirst() const; |
64 Element* traverseToLast() const; | 64 Element* traverseToLast() const; |
65 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u
nsigned& currentOffset) const; | 65 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u
nsigned& currentOffset) const; |
66 Element* traverseBackwardToOffset(unsigned offset, Element& currentElement,
unsigned& currentOffset) const; | 66 Element* traverseBackwardToOffset(unsigned offset, Element& currentElement,
unsigned& currentOffset) const; |
67 | 67 |
68 virtual void trace(Visitor*); | 68 virtual void trace(Visitor*); |
69 | 69 |
70 protected: | 70 protected: |
71 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); | 71 HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType); |
72 | 72 |
73 class NamedItemCache final : public NoBaseWillBeGarbageCollected<NamedItemCa
che> { | 73 class NamedItemCache final : public NoBaseWillBeGarbageCollected<NamedItemCa
che> { |
74 public: | 74 public: |
75 static PassOwnPtrWillBeRawPtr<NamedItemCache> create() | 75 static PassOwnPtrWillBeRawPtr<NamedItemCache> create() |
76 { | 76 { |
77 return adoptPtrWillBeNoop(new NamedItemCache); | 77 return adoptPtrWillBeNoop(new NamedItemCache); |
78 } | 78 } |
79 | 79 |
80 WillBeHeapVector<RawPtrWillBeMember<Element> >* getElementsById(const At
omicString& id) const { return m_idCache.get(id.impl()); } | 80 WillBeHeapVector<RawPtrWillBeMember<Element>>* getElementsById(const Ato
micString& id) const { return m_idCache.get(id.impl()); } |
81 WillBeHeapVector<RawPtrWillBeMember<Element> >* getElementsByName(const
AtomicString& name) const { return m_nameCache.get(name.impl()); } | 81 WillBeHeapVector<RawPtrWillBeMember<Element>>* getElementsByName(const A
tomicString& name) const { return m_nameCache.get(name.impl()); } |
82 void addElementWithId(const AtomicString& id, Element* element) { addEle
mentToMap(m_idCache, id, element); } | 82 void addElementWithId(const AtomicString& id, Element* element) { addEle
mentToMap(m_idCache, id, element); } |
83 void addElementWithName(const AtomicString& name, Element* element) { ad
dElementToMap(m_nameCache, name, element); } | 83 void addElementWithName(const AtomicString& name, Element* element) { ad
dElementToMap(m_nameCache, name, element); } |
84 | 84 |
85 void trace(Visitor* visitor) | 85 void trace(Visitor* visitor) |
86 { | 86 { |
87 #if ENABLE(OILPAN) | 87 #if ENABLE(OILPAN) |
88 visitor->trace(m_idCache); | 88 visitor->trace(m_idCache); |
89 visitor->trace(m_nameCache); | 89 visitor->trace(m_nameCache); |
90 #endif | 90 #endif |
91 } | 91 } |
92 | 92 |
93 private: | 93 private: |
94 NamedItemCache(); | 94 NamedItemCache(); |
95 typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<WillBeHeapVect
or<RawPtrWillBeMember<Element> > > > StringToElementsMap; | 95 typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<WillBeHeapVect
or<RawPtrWillBeMember<Element>>>> StringToElementsMap; |
96 static void addElementToMap(StringToElementsMap& map, const AtomicString
& key, Element* element) | 96 static void addElementToMap(StringToElementsMap& map, const AtomicString
& key, Element* element) |
97 { | 97 { |
98 OwnPtrWillBeMember<WillBeHeapVector<RawPtrWillBeMember<Element> > >&
vector = map.add(key.impl(), nullptr).storedValue->value; | 98 OwnPtrWillBeMember<WillBeHeapVector<RawPtrWillBeMember<Element>>>& v
ector = map.add(key.impl(), nullptr).storedValue->value; |
99 if (!vector) | 99 if (!vector) |
100 vector = adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillBeMem
ber<Element> >); | 100 vector = adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillBeMem
ber<Element>>); |
101 vector->append(element); | 101 vector->append(element); |
102 } | 102 } |
103 | 103 |
104 StringToElementsMap m_idCache; | 104 StringToElementsMap m_idCache; |
105 StringToElementsMap m_nameCache; | 105 StringToElementsMap m_nameCache; |
106 }; | 106 }; |
107 | 107 |
108 bool overridesItemAfter() const { return m_overridesItemAfter; } | 108 bool overridesItemAfter() const { return m_overridesItemAfter; } |
109 virtual Element* virtualItemAfter(Element*) const; | 109 virtual Element* virtualItemAfter(Element*) const; |
110 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } | 110 bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDir
ectChildren; } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 { | 158 { |
159 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), *
attrName)) | 159 if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), *
attrName)) |
160 invalidateCache(); | 160 invalidateCache(); |
161 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr) | 161 else if (*attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr) |
162 invalidateIdNameCacheMaps(); | 162 invalidateIdNameCacheMaps(); |
163 } | 163 } |
164 | 164 |
165 } // namespace blink | 165 } // namespace blink |
166 | 166 |
167 #endif // HTMLCollection_h | 167 #endif // HTMLCollection_h |
OLD | NEW |