ALWAYS_INLINE void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) { if (newValue.isNull()) { if (index != kNotFound) removeAttributeInternal(index, inSynchronizationOfLazyAttribute); return; } if (index == kNotFound) { appendAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute); return; } const Attribute& existingAttribute = elementData()->attributes().at(index); QualifiedName existingAttributeName = existingAttribute.name(); if (newValue == existingAttribute.value()) return; if (!inSynchronizationOfLazyAttribute) willModifyAttribute(existingAttributeName, existingAttribute.value(), newValue); ensureUniqueElementData().attributes().at(index).setValue(newValue); if (!inSynchronizationOfLazyAttribute) attributeChanged(existingAttributeName, newValue); }
void Element::appendAttributeInternal(const QualifiedName& name, const AtomicString& value, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) { if (!inSynchronizationOfLazyAttribute) willModifyAttribute(name, nullAtom, value); ensureUniqueElementData().attributes().append(name, value); if (!inSynchronizationOfLazyAttribute) attributeChanged(name, value); }
MutableStyleProperties& StyledElement::ensureMutableInlineStyle() { RefPtr<StyleProperties>& inlineStyle = ensureUniqueElementData().m_inlineStyle; if (!inlineStyle) inlineStyle = MutableStyleProperties::create(strictToCSSParserMode(isHTMLElement() && !document().inQuirksMode())); else if (!is<MutableStyleProperties>(*inlineStyle)) inlineStyle = inlineStyle->mutableCopy(); return downcast<MutableStyleProperties>(*inlineStyle); }
MutableStylePropertySet& Element::ensureMutableInlineStyle() { ASSERT(isStyledElement()); RefPtr<StylePropertySet>& inlineStyle = ensureUniqueElementData().m_inlineStyle; if (!inlineStyle) { inlineStyle = MutableStylePropertySet::create(HTMLStandardMode); } else if (!inlineStyle->isMutable()) { inlineStyle = inlineStyle->mutableCopy(); } return *toMutableStylePropertySet(inlineStyle); }
void Element::styleAttributeChanged(const AtomicString& newStyleString) { ASSERT(isStyledElement()); if (newStyleString.isNull()) { ensureUniqueElementData().m_inlineStyle.clear(); } else { setInlineStyleFromString(newStyleString); } elementData()->m_styleAttributeIsDirty = false; setNeedsStyleRecalc(LocalStyleChange); }
void StyledElement::rebuildPresentationAttributeStyle() { PresentationAttributeCacheKey cacheKey; makePresentationAttributeCacheKey(cacheKey); unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); PresentationAttributeCache::iterator cacheIterator; if (cacheHash) { cacheIterator = presentationAttributeCache().add(cacheHash, nullptr).iterator; if (cacheIterator->value && cacheIterator->value->key != cacheKey) cacheHash = 0; } else cacheIterator = presentationAttributeCache().end(); RefPtr<StyleProperties> style; if (cacheHash && cacheIterator->value) { style = cacheIterator->value->value; presentationAttributeCacheCleaner().didHitPresentationAttributeCache(); } else { style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : CSSQuirksMode); for (const Attribute& attribute : attributesIterator()) collectStyleForPresentationAttribute(attribute.name(), attribute.value(), static_cast<MutableStyleProperties&>(*style)); } // ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData. UniqueElementData& elementData = ensureUniqueElementData(); elementData.setPresentationAttributeStyleIsDirty(false); elementData.m_presentationAttributeStyle = style->isEmpty() ? 0 : style; if (!cacheHash || cacheIterator->value) return; std::unique_ptr<PresentationAttributeCacheEntry> newEntry = std::make_unique<PresentationAttributeCacheEntry>(); newEntry->key = cacheKey; newEntry->value = style.release(); static const int presentationAttributeCacheMaximumSize = 4096; if (presentationAttributeCache().size() > presentationAttributeCacheMaximumSize) { // Start building from scratch if the cache ever gets big. presentationAttributeCache().clear(); presentationAttributeCache().set(cacheHash, WTF::move(newEntry)); } else cacheIterator->value = WTF::move(newEntry); }
void Element::removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) { MutableAttributeCollection attributes = ensureUniqueElementData().attributes(); ASSERT_WITH_SECURITY_IMPLICATION(index < attributes.size()); QualifiedName name = attributes[index].name(); AtomicString valueBeingRemoved = attributes[index].value(); if (!inSynchronizationOfLazyAttribute) { if (!valueBeingRemoved.isNull()) willModifyAttribute(name, valueBeingRemoved, nullAtom); } attributes.remove(index); if (!inSynchronizationOfLazyAttribute) attributeChanged(name, nullAtom); }
void StyledElement::styleAttributeChanged(const AtomicString& newStyleString, AttributeModificationReason reason) { WTF::OrdinalNumber startLineNumber = WTF::OrdinalNumber::beforeFirst(); if (document().scriptableDocumentParser() && !document().isInDocumentWrite()) startLineNumber = document().scriptableDocumentParser()->textPosition().m_line; if (newStyleString.isNull()) { if (PropertySetCSSStyleDeclaration* cssomWrapper = inlineStyleCSSOMWrapper()) cssomWrapper->clearParentElement(); ensureUniqueElementData().m_inlineStyle = nullptr; } else if (reason == ModifiedByCloning || document().contentSecurityPolicy()->allowInlineStyle(document().url(), startLineNumber, isInUserAgentShadowTree())) setInlineStyleFromString(newStyleString); elementData()->setStyleAttributeIsDirty(false); setNeedsStyleRecalc(InlineStyleChange); InspectorInstrumentation::didInvalidateStyleAttr(document(), *this); }
void SVGElement::setWebAnimationsPending() { document().accessSVGExtensions().addWebAnimationsPendingSVGElement(*this); ensureSVGRareData()->setWebAnimatedAttributesDirty(true); ensureUniqueElementData().m_animatedSVGAttributesAreDirty = true; }
void Element::clearMutableInlineStyleIfEmpty() { if (ensureMutableInlineStyle().isEmpty()) { ensureUniqueElementData().m_inlineStyle.clear(); } }