void ElementAttributeData::cloneDataFrom(const ElementAttributeData& sourceData, const Element& sourceElement, Element& targetElement) { // FIXME: Cloned elements could start out with immutable attribute data. ASSERT(isMutable()); const AtomicString& oldID = targetElement.getIdAttribute(); const AtomicString& newID = sourceElement.getIdAttribute(); if (!oldID.isNull() || !newID.isNull()) targetElement.updateId(oldID, newID); const AtomicString& oldName = targetElement.getNameAttribute(); const AtomicString& newName = sourceElement.getNameAttribute(); if (!oldName.isNull() || !newName.isNull()) targetElement.updateName(oldName, newName); clearAttributes(); if (sourceData.isMutable()) mutableAttributeVector() = sourceData.mutableAttributeVector(); else { mutableAttributeVector().reserveInitialCapacity(sourceData.m_arraySize); for (unsigned i = 0; i < sourceData.m_arraySize; ++i) mutableAttributeVector().uncheckedAppend(sourceData.immutableAttributeArray()[i]); } for (unsigned i = 0; i < length(); ++i) { const Attribute& attribute = mutableAttributeVector().at(i); if (targetElement.isStyledElement() && attribute.name() == HTMLNames::styleAttr) { static_cast<StyledElement&>(targetElement).styleAttributeChanged(attribute.value(), StyledElement::DoNotReparseStyleAttribute); continue; } targetElement.attributeChanged(attribute.name(), attribute.value()); } if (targetElement.isStyledElement() && sourceData.m_inlineStyleDecl) { m_inlineStyleDecl = sourceData.m_inlineStyleDecl->immutableCopyIfNeeded(); targetElement.setIsStyleAttributeValid(sourceElement.isStyleAttributeValid()); } }
void ElementAttributeData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const { size_t actualSize = m_isMutable ? sizeof(ElementAttributeData) : sizeForImmutableElementAttributeDataWithAttributeCount(m_arraySize); MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM, actualSize); info.addMember(m_inlineStyleDecl); info.addMember(m_attributeStyle); info.addMember(m_classNames); info.addMember(m_idForStyleResolution); if (m_isMutable) info.addMember(mutableAttributeVector()); for (unsigned i = 0, len = length(); i < len; i++) info.addMember(*attributeItem(i)); }
void ElementAttributeData::clearAttributes() { ASSERT(isMutable()); clearClass(); mutableAttributeVector().clear(); }
void ElementAttributeData::removeAttribute(size_t index) { ASSERT(isMutable()); ASSERT(index < length()); mutableAttributeVector().remove(index); }
void ElementAttributeData::addAttribute(const Attribute& attribute) { ASSERT(isMutable()); mutableAttributeVector().append(attribute); }
void ElementAttributeData::removeAttribute(size_t index) { ASSERT(isMutable()); ASSERT_WITH_SECURITY_IMPLICATION(index < length()); mutableAttributeVector().remove(index); }
PassRefPtr<ElementAttributeData> ElementAttributeData::makeImmutableCopy() const { ASSERT(isMutable()); void* slot = WTF::fastMalloc(sizeForImmutableElementAttributeDataWithAttributeCount(mutableAttributeVector().size())); return adoptRef(new (slot) ImmutableElementAttributeData(static_cast<const MutableElementAttributeData&>(*this))); }