nsresult nsAttrAndChildArray::DoSetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet) { NS_PRECONDITION(mImpl && mImpl->mMappedAttrs, "Should have mapped attrs here!"); if (aSheet == mImpl->mMappedAttrs->GetStyleSheet()) { return NS_OK; } nsRefPtr<nsMappedAttributes> mapped = GetModifiableMapped(nullptr, nullptr, false); mapped->SetStyleSheet(aSheet); return MakeMappedUnique(mapped); }
nsresult nsAttrAndChildArray::SetAndTakeMappedAttr(nsIAtom* aLocalName, nsAttrValue& aValue, nsMappedAttributeElement* aContent, nsHTMLStyleSheet* aSheet) { nsRefPtr<nsMappedAttributes> mapped; nsresult rv = GetModifiableMapped(aContent, aSheet, PR_TRUE, getter_AddRefs(mapped)); NS_ENSURE_SUCCESS(rv, rv); rv = mapped->SetAndTakeAttr(aLocalName, aValue); NS_ENSURE_SUCCESS(rv, rv); return MakeMappedUnique(mapped); }
nsresult nsAttrAndChildArray::SetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet) { if (!mImpl || !mImpl->mMappedAttrs || aSheet == mImpl->mMappedAttrs->GetStyleSheet()) { return NS_OK; } nsRefPtr<nsMappedAttributes> mapped; nsresult rv = GetModifiableMapped(nsnull, nsnull, false, getter_AddRefs(mapped)); NS_ENSURE_SUCCESS(rv, rv); mapped->SetStyleSheet(aSheet); return MakeMappedUnique(mapped); }
nsresult nsAttrAndChildArray::DoSetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet) { NS_PRECONDITION(mImpl && mImpl->mMappedAttrs, "Should have mapped attrs here!"); if (aSheet == mImpl->mMappedAttrs->GetStyleSheet()) { return NS_OK; } nsRefPtr<nsMappedAttributes> mapped; nsresult rv = GetModifiableMapped(nsnull, nsnull, false, getter_AddRefs(mapped)); NS_ENSURE_SUCCESS(rv, rv); mapped->SetStyleSheet(aSheet); return MakeMappedUnique(mapped); }
nsresult nsAttrAndChildArray::SetAndTakeMappedAttr(nsIAtom* aLocalName, nsAttrValue& aValue, nsMappedAttributeElement* aContent, nsHTMLStyleSheet* aSheet) { bool willAdd = true; if (mImpl && mImpl->mMappedAttrs) { willAdd = !mImpl->mMappedAttrs->GetAttr(aLocalName); } nsRefPtr<nsMappedAttributes> mapped = GetModifiableMapped(aContent, aSheet, willAdd); mapped->SetAndTakeAttr(aLocalName, aValue); return MakeMappedUnique(mapped); }
nsresult nsAttrAndChildArray::SetAndTakeMappedAttr(nsIAtom* aLocalName, nsAttrValue& aValue, nsMappedAttributeElement* aContent, nsHTMLStyleSheet* aSheet) { nsRefPtr<nsMappedAttributes> mapped; bool willAdd = true; if (mImpl && mImpl->mMappedAttrs) { willAdd = mImpl->mMappedAttrs->GetAttr(aLocalName) == nsnull; } nsresult rv = GetModifiableMapped(aContent, aSheet, willAdd, getter_AddRefs(mapped)); NS_ENSURE_SUCCESS(rv, rv); rv = mapped->SetAndTakeAttr(aLocalName, aValue); NS_ENSURE_SUCCESS(rv, rv); return MakeMappedUnique(mapped); }
nsresult nsAttrAndChildArray::RemoveAttrAt(PRUint32 aPos, nsAttrValue& aValue) { NS_ASSERTION(aPos < AttrCount(), "out-of-bounds"); PRUint32 mapped = MappedAttrCount(); if (aPos < mapped) { if (mapped == 1) { // We're removing the last mapped attribute. Can't swap in this // case; have to copy. aValue.SetTo(*mImpl->mMappedAttrs->AttrAt(0)); NS_RELEASE(mImpl->mMappedAttrs); return NS_OK; } nsRefPtr<nsMappedAttributes> mapped; nsresult rv = GetModifiableMapped(nsnull, nsnull, false, getter_AddRefs(mapped)); NS_ENSURE_SUCCESS(rv, rv); mapped->RemoveAttrAt(aPos, aValue); return MakeMappedUnique(mapped); } aPos -= mapped; ATTRS(mImpl)[aPos].mValue.SwapValueWith(aValue); ATTRS(mImpl)[aPos].~InternalAttr(); PRUint32 slotCount = AttrSlotCount(); memmove(&ATTRS(mImpl)[aPos], &ATTRS(mImpl)[aPos + 1], (slotCount - aPos - 1) * sizeof(InternalAttr)); memset(&ATTRS(mImpl)[slotCount - 1], nsnull, sizeof(InternalAttr)); return NS_OK; }