void HTMLFormControlsCollection::updateIdNameCache() const { if (hasValidIdNameCache()) return; NamedItemCache* cache = NamedItemCache::create(); HashSet<StringImpl*> foundInputElements; const FormAssociatedElement::List& elementsArray = formControlElements(); for (unsigned i = 0; i < elementsArray.size(); ++i) { FormAssociatedElement* associatedElement = elementsArray[i]; if (associatedElement->isEnumeratable()) { HTMLElement* element = toHTMLElement(associatedElement); const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getNameAttribute(); if (!idAttrVal.isEmpty()) { cache->addElementWithId(idAttrVal, element); foundInputElements.add(idAttrVal.impl()); } if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { cache->addElementWithName(nameAttrVal, element); foundInputElements.add(nameAttrVal.impl()); } } } if (isHTMLFormElement(ownerNode())) { // HTMLFormControlsCollection doesn't support named getter for IMG // elements. However we still need to handle IMG elements here because // HTMLFormElement named getter relies on this. const HeapVector<Member<HTMLImageElement>>& imageElementsArray = formImageElements(); for (unsigned i = 0; i < imageElementsArray.size(); ++i) { HTMLImageElement* element = imageElementsArray[i]; const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getNameAttribute(); if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) cache->addElementWithId(idAttrVal, element); if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl())) cache->addElementWithName(nameAttrVal, element); } } // Set the named item cache last as traversing the tree may cause cache invalidation. setNamedItemCache(cache); }
void HTMLFormControlsCollection::updateIdNameCache() const { if (hasValidIdNameCache()) return; OwnPtr<NamedItemCache> cache = NamedItemCache::create(); HashSet<StringImpl*> foundInputElements; const FormAssociatedElement::List& elementsArray = formControlElements(); for (unsigned i = 0; i < elementsArray.size(); ++i) { FormAssociatedElement* associatedElement = elementsArray[i]; if (associatedElement->isEnumeratable()) { HTMLElement* element = toHTMLElement(associatedElement); const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getNameAttribute(); if (!idAttrVal.isEmpty()) { cache->addElementWithId(idAttrVal, element); foundInputElements.add(idAttrVal.impl()); } if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { cache->addElementWithName(nameAttrVal, element); foundInputElements.add(nameAttrVal.impl()); } } } if (isHTMLFormElement(ownerNode())) { const Vector<HTMLImageElement*>& imageElementsArray = formImageElements(); for (unsigned i = 0; i < imageElementsArray.size(); ++i) { HTMLImageElement* element = imageElementsArray[i]; const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getNameAttribute(); if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) cache->addElementWithId(idAttrVal, element); if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl())) cache->addElementWithName(nameAttrVal, element); } } // Set the named item cache last as traversing the tree may cause cache invalidation. setNamedItemCache(cache.release()); }
void HTMLFormControlsCollection::updateNameCache() const { if (hasNameCache()) return; HashSet<AtomicStringImpl*> foundInputElements; const Vector<FormAssociatedElement*>& elementsArray = formControlElements(); for (unsigned i = 0; i < elementsArray.size(); ++i) { FormAssociatedElement* associatedElement = elementsArray[i]; if (associatedElement->isEnumeratable()) { HTMLElement* element = toHTMLElement(associatedElement); const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getNameAttribute(); if (!idAttrVal.isEmpty()) { appendIdCache(idAttrVal, element); foundInputElements.add(idAttrVal.impl()); } if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { appendNameCache(nameAttrVal, element); foundInputElements.add(nameAttrVal.impl()); } } } if (isHTMLFormElement(ownerNode())) { const Vector<HTMLImageElement*>& imageElementsArray = formImageElements(); for (unsigned i = 0; i < imageElementsArray.size(); ++i) { HTMLImageElement* element = imageElementsArray[i]; const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getNameAttribute(); if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) appendIdCache(idAttrVal, element); if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl())) appendNameCache(nameAttrVal, element); } } setHasNameCache(); }
void HTMLFormCollection::updateNameCache() const { if (m_cache.hasNameCache) return; HashSet<AtomicStringImpl*> foundInputElements; HTMLFormElement* f = static_cast<HTMLFormElement*>(base()); for (unsigned i = 0; i < f->m_associatedElements.size(); ++i) { FormAssociatedElement* associatedElement = f->m_associatedElements[i]; if (associatedElement->isEnumeratable()) { HTMLElement* element = toHTMLElement(associatedElement); const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getAttribute(nameAttr); if (!idAttrVal.isEmpty()) { append(m_cache.idCache, idAttrVal, element); foundInputElements.add(idAttrVal.impl()); } if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { append(m_cache.nameCache, nameAttrVal, element); foundInputElements.add(nameAttrVal.impl()); } } } for (unsigned i = 0; i < f->m_imageElements.size(); ++i) { HTMLImageElement* element = f->m_imageElements[i]; const AtomicString& idAttrVal = element->getIdAttribute(); const AtomicString& nameAttrVal = element->getAttribute(nameAttr); if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) append(m_cache.idCache, idAttrVal, element); if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl())) append(m_cache.nameCache, nameAttrVal, element); } m_cache.hasNameCache = true; }
void HTMLFormCollection::updateNameCache() const { if (info()->hasNameCache) return; HashSet<AtomicStringImpl*> foundInputElements; HTMLFormElement* f = static_cast<HTMLFormElement*>(base()); for (unsigned i = 0; i < f->m_associatedElements.size(); ++i) { HTMLFormControlElement* e = f->m_associatedElements[i]; if (e->isEnumeratable()) { const AtomicString& idAttrVal = e->getIdAttribute(); const AtomicString& nameAttrVal = e->getAttribute(nameAttr); if (!idAttrVal.isEmpty()) { // add to id cache Vector<Element*>* idVector = info()->idCache.get(idAttrVal.impl()); if (!idVector) { idVector = new Vector<Element*>; info()->idCache.add(idAttrVal.impl(), idVector); } idVector->append(e); foundInputElements.add(idAttrVal.impl()); } if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { // add to name cache Vector<Element*>* nameVector = info()->nameCache.get(nameAttrVal.impl()); if (!nameVector) { nameVector = new Vector<Element*>; info()->nameCache.add(nameAttrVal.impl(), nameVector); } nameVector->append(e); foundInputElements.add(nameAttrVal.impl()); } } } for (unsigned i = 0; i < f->m_imageElements.size(); ++i) { HTMLImageElement* e = f->m_imageElements[i]; const AtomicString& idAttrVal = e->getIdAttribute(); const AtomicString& nameAttrVal = e->getAttribute(nameAttr); if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) { // add to id cache Vector<Element*>* idVector = info()->idCache.get(idAttrVal.impl()); if (!idVector) { idVector = new Vector<Element*>; info()->idCache.add(idAttrVal.impl(), idVector); } idVector->append(e); } if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl())) { // add to name cache Vector<Element*>* nameVector = info()->nameCache.get(nameAttrVal.impl()); if (!nameVector) { nameVector = new Vector<Element*>; info()->nameCache.add(nameAttrVal.impl(), nameVector); } nameVector->append(e); } } info()->hasNameCache = true; }