| 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-2008, 2011, 2012, 2014 Apple Inc. All rights reserved. | 4 * Copyright (C) 2003-2008, 2011, 2012, 2014 Apple Inc. All rights 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 return DoNotInvalidateOnAttributeChanges; | 162 return DoNotInvalidateOnAttributeChanges; |
| 163 } | 163 } |
| 164 | 164 |
| 165 HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, It
emAfterOverrideType itemAfterOverrideType) | 165 HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, It
emAfterOverrideType itemAfterOverrideType) |
| 166 : LiveNodeListBase(ownerNode, rootTypeFromCollectionType(type), invalidation
TypeExcludingIdAndNameAttributes(type), type) | 166 : LiveNodeListBase(ownerNode, rootTypeFromCollectionType(type), invalidation
TypeExcludingIdAndNameAttributes(type), type) |
| 167 , m_overridesItemAfter(itemAfterOverrideType == OverridesItemAfter) | 167 , m_overridesItemAfter(itemAfterOverrideType == OverridesItemAfter) |
| 168 , m_shouldOnlyIncludeDirectChildren(shouldTypeOnlyIncludeDirectChildren(type
)) | 168 , m_shouldOnlyIncludeDirectChildren(shouldTypeOnlyIncludeDirectChildren(type
)) |
| 169 { | 169 { |
| 170 } | 170 } |
| 171 | 171 |
| 172 PassRefPtrWillBeRawPtr<HTMLCollection> HTMLCollection::create(ContainerNode& bas
e, CollectionType type) | 172 RawPtr<HTMLCollection> HTMLCollection::create(ContainerNode& base, CollectionTyp
e type) |
| 173 { | 173 { |
| 174 return adoptRefWillBeNoop(new HTMLCollection(base, type, DoesNotOverrideItem
After)); | 174 return new HTMLCollection(base, type, DoesNotOverrideItemAfter); |
| 175 } | 175 } |
| 176 | 176 |
| 177 HTMLCollection::~HTMLCollection() | 177 HTMLCollection::~HTMLCollection() |
| 178 { | 178 { |
| 179 #if !ENABLE(OILPAN) | 179 #if !ENABLE(OILPAN) |
| 180 if (hasValidIdNameCache()) | 180 if (hasValidIdNameCache()) |
| 181 unregisterIdNameCacheFromDocument(document()); | 181 unregisterIdNameCacheFromDocument(document()); |
| 182 // Named HTMLCollection types remove cache by themselves. | 182 // Named HTMLCollection types remove cache by themselves. |
| 183 if (isUnnamedHTMLCollectionType(type())) | 183 if (isUnnamedHTMLCollectionType(type())) |
| 184 ownerNode().nodeLists()->removeCache(this, type()); | 184 ownerNode().nodeLists()->removeCache(this, type()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 IsMatch(const HTMLCollectionType& list) | 283 IsMatch(const HTMLCollectionType& list) |
| 284 : m_list(&list) | 284 : m_list(&list) |
| 285 { } | 285 { } |
| 286 | 286 |
| 287 bool operator() (const Element& element) const | 287 bool operator() (const Element& element) const |
| 288 { | 288 { |
| 289 return m_list->elementMatches(element); | 289 return m_list->elementMatches(element); |
| 290 } | 290 } |
| 291 | 291 |
| 292 private: | 292 private: |
| 293 RawPtrWillBeMember<const HTMLCollectionType> m_list; | 293 Member<const HTMLCollectionType> m_list; |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 } // namespace | 296 } // namespace |
| 297 | 297 |
| 298 template <class HTMLCollectionType> | 298 template <class HTMLCollectionType> |
| 299 static inline IsMatch<HTMLCollectionType> makeIsMatch(const HTMLCollectionType&
list) { return IsMatch<HTMLCollectionType>(list); } | 299 static inline IsMatch<HTMLCollectionType> makeIsMatch(const HTMLCollectionType&
list) { return IsMatch<HTMLCollectionType>(list); } |
| 300 | 300 |
| 301 Element* HTMLCollection::virtualItemAfter(Element*) const | 301 Element* HTMLCollection::virtualItemAfter(Element*) const |
| 302 { | 302 { |
| 303 ASSERT_NOT_REACHED(); | 303 ASSERT_NOT_REACHED(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 Element* HTMLCollection::namedItem(const AtomicString& name) const | 392 Element* HTMLCollection::namedItem(const AtomicString& name) const |
| 393 { | 393 { |
| 394 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit
em.asp | 394 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit
em.asp |
| 395 // This method first searches for an object with a matching id | 395 // This method first searches for an object with a matching id |
| 396 // attribute. If a match is not found, the method then searches for an | 396 // attribute. If a match is not found, the method then searches for an |
| 397 // object with a matching name attribute, but only on those elements | 397 // object with a matching name attribute, but only on those elements |
| 398 // that are allowed a name attribute. | 398 // that are allowed a name attribute. |
| 399 updateIdNameCache(); | 399 updateIdNameCache(); |
| 400 | 400 |
| 401 const NamedItemCache& cache = namedItemCache(); | 401 const NamedItemCache& cache = namedItemCache(); |
| 402 WillBeHeapVector<RawPtrWillBeMember<Element>>* idResults = cache.getElements
ById(name); | 402 HeapVector<Member<Element>>* idResults = cache.getElementsById(name); |
| 403 if (idResults && !idResults->isEmpty()) | 403 if (idResults && !idResults->isEmpty()) |
| 404 return idResults->first(); | 404 return idResults->first(); |
| 405 | 405 |
| 406 WillBeHeapVector<RawPtrWillBeMember<Element>>* nameResults = cache.getElemen
tsByName(name); | 406 HeapVector<Member<Element>>* nameResults = cache.getElementsByName(name); |
| 407 if (nameResults && !nameResults->isEmpty()) | 407 if (nameResults && !nameResults->isEmpty()) |
| 408 return nameResults->first(); | 408 return nameResults->first(); |
| 409 | 409 |
| 410 return nullptr; | 410 return nullptr; |
| 411 } | 411 } |
| 412 | 412 |
| 413 bool HTMLCollection::namedPropertyQuery(const AtomicString& name, ExceptionState
&) | 413 bool HTMLCollection::namedPropertyQuery(const AtomicString& name, ExceptionState
&) |
| 414 { | 414 { |
| 415 return namedItem(name); | 415 return namedItem(name); |
| 416 } | 416 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta
te&) | 449 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta
te&) |
| 450 { | 450 { |
| 451 supportedPropertyNames(names); | 451 supportedPropertyNames(names); |
| 452 } | 452 } |
| 453 | 453 |
| 454 void HTMLCollection::updateIdNameCache() const | 454 void HTMLCollection::updateIdNameCache() const |
| 455 { | 455 { |
| 456 if (hasValidIdNameCache()) | 456 if (hasValidIdNameCache()) |
| 457 return; | 457 return; |
| 458 | 458 |
| 459 OwnPtrWillBeRawPtr<NamedItemCache> cache = NamedItemCache::create(); | 459 RawPtr<NamedItemCache> cache = NamedItemCache::create(); |
| 460 unsigned length = this->length(); | 460 unsigned length = this->length(); |
| 461 for (unsigned i = 0; i < length; ++i) { | 461 for (unsigned i = 0; i < length; ++i) { |
| 462 Element* element = item(i); | 462 Element* element = item(i); |
| 463 const AtomicString& idAttrVal = element->getIdAttribute(); | 463 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 464 if (!idAttrVal.isEmpty()) | 464 if (!idAttrVal.isEmpty()) |
| 465 cache->addElementWithId(idAttrVal, element); | 465 cache->addElementWithId(idAttrVal, element); |
| 466 if (!element->isHTMLElement()) | 466 if (!element->isHTMLElement()) |
| 467 continue; | 467 continue; |
| 468 const AtomicString& nameAttrVal = element->getNameAttribute(); | 468 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 469 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc
All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) | 469 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc
All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) |
| 470 cache->addElementWithName(nameAttrVal, element); | 470 cache->addElementWithName(nameAttrVal, element); |
| 471 } | 471 } |
| 472 // Set the named item cache last as traversing the tree may cause cache inva
lidation. | 472 // Set the named item cache last as traversing the tree may cause cache inva
lidation. |
| 473 setNamedItemCache(cache.release()); | 473 setNamedItemCache(cache.release()); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void HTMLCollection::namedItems(const AtomicString& name, WillBeHeapVector<RefPt
rWillBeMember<Element>>& result) const | 476 void HTMLCollection::namedItems(const AtomicString& name, HeapVector<Member<Elem
ent>>& result) const |
| 477 { | 477 { |
| 478 ASSERT(result.isEmpty()); | 478 ASSERT(result.isEmpty()); |
| 479 if (name.isEmpty()) | 479 if (name.isEmpty()) |
| 480 return; | 480 return; |
| 481 | 481 |
| 482 updateIdNameCache(); | 482 updateIdNameCache(); |
| 483 | 483 |
| 484 const NamedItemCache& cache = namedItemCache(); | 484 const NamedItemCache& cache = namedItemCache(); |
| 485 if (WillBeHeapVector<RawPtrWillBeMember<Element>>* idResults = cache.getElem
entsById(name)) { | 485 if (HeapVector<Member<Element>>* idResults = cache.getElementsById(name)) { |
| 486 for (unsigned i = 0; i < idResults->size(); ++i) | 486 for (unsigned i = 0; i < idResults->size(); ++i) |
| 487 result.append(idResults->at(i)); | 487 result.append(idResults->at(i)); |
| 488 } | 488 } |
| 489 if (WillBeHeapVector<RawPtrWillBeMember<Element>>* nameResults = cache.getEl
ementsByName(name)) { | 489 if (HeapVector<Member<Element>>* nameResults = cache.getElementsByName(name)
) { |
| 490 for (unsigned i = 0; i < nameResults->size(); ++i) | 490 for (unsigned i = 0; i < nameResults->size(); ++i) |
| 491 result.append(nameResults->at(i)); | 491 result.append(nameResults->at(i)); |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 | 494 |
| 495 HTMLCollection::NamedItemCache::NamedItemCache() | 495 HTMLCollection::NamedItemCache::NamedItemCache() |
| 496 { | 496 { |
| 497 } | 497 } |
| 498 | 498 |
| 499 DEFINE_TRACE(HTMLCollection) | 499 DEFINE_TRACE(HTMLCollection) |
| 500 { | 500 { |
| 501 visitor->trace(m_namedItemCache); | 501 visitor->trace(m_namedItemCache); |
| 502 visitor->trace(m_collectionItemsCache); | 502 visitor->trace(m_collectionItemsCache); |
| 503 LiveNodeListBase::trace(visitor); | 503 LiveNodeListBase::trace(visitor); |
| 504 } | 504 } |
| 505 | 505 |
| 506 } // namespace blink | 506 } // namespace blink |
| OLD | NEW |