PRBool test_basic() { for (unsigned int i = 0; i < NS_ARRAY_LENGTH(ValidStrings); ++i) { nsDependentString str16(ValidStrings[i].m16); nsDependentCString str8(ValidStrings[i].m8); nsCOMPtr<nsIAtom> atom = do_GetAtom(str16); if (!atom->Equals(str16) || !atom->EqualsUTF8(str8)) return PR_FALSE; nsString tmp16; nsCString tmp8; atom->ToString(tmp16); atom->ToUTF8String(tmp8); if (!str16.Equals(tmp16) || !str8.Equals(tmp8)) return PR_FALSE; if (!nsDependentString(atom->GetUTF16String()).Equals(str16)) return PR_FALSE; if (!nsAtomString(atom).Equals(str16) || !nsDependentAtomString(atom).Equals(str16) || !nsAtomCString(atom).Equals(str8)) return PR_FALSE; } return PR_TRUE; }
nsresult txMozillaXMLOutput::createTxWrapper() { NS_ASSERTION(mDocument == mCurrentNode, "creating wrapper when document isn't parent"); PRInt32 namespaceID; nsresult rv = nsContentUtils::NameSpaceManager()-> RegisterNameSpace(NS_LITERAL_STRING(kTXNameSpaceURI), namespaceID); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIContent> wrapper; rv = mDocument->CreateElem(nsAtomString(nsGkAtoms::result), nsGkAtoms::transformiix, namespaceID, PR_FALSE, getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); PRUint32 i, j, childCount = mDocument->GetChildCount(); #ifdef DEBUG // Keep track of the location of the current documentElement, if there is // one, so we can verify later PRUint32 rootLocation = 0; #endif for (i = 0, j = 0; i < childCount; ++i) { nsCOMPtr<nsIContent> childContent = mDocument->GetChildAt(j); #ifdef DEBUG if (childContent->IsElement()) { rootLocation = j; } #endif if (childContent->Tag() == nsGkAtoms::documentTypeNodeName) { #ifdef DEBUG // The new documentElement should go after the document type. // This is needed for cases when there is no existing // documentElement in the document. rootLocation = PR_MAX(rootLocation, j + 1); #endif ++j; } else { rv = mDocument->RemoveChildAt(j, PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); rv = wrapper->AppendChildTo(childContent, PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); break; } } if (!mCurrentNodeStack.AppendObject(wrapper)) { return NS_ERROR_OUT_OF_MEMORY; } mCurrentNode = wrapper; mRootContentCreated = PR_TRUE; NS_ASSERTION(rootLocation == mDocument->GetChildCount(), "Incorrect root location"); return mDocument->AppendChildTo(wrapper, PR_TRUE); }
// Search in the list of frames aCandidates if the element with the id "aLabelTargetId" // is present. static bool IsElementPresent(nsTArray<nsIFrame*>& aCandidates, const nsAutoString& aLabelTargetId) { for (uint32_t i = 0; i < aCandidates.Length(); ++i) { nsIFrame* f = aCandidates[i]; nsIContent* aContent = f->GetContent(); if (aContent && aContent->IsElement()) { if (aContent->GetID() && aLabelTargetId == nsAtomString(aContent->GetID())) { return true; } } } return false; }
void nsMutationReceiver::AttributeWillChange(nsIDocument* aDocument, mozilla::dom::Element* aElement, int32_t aNameSpaceID, nsIAtom* aAttribute, int32_t aModType) { if (nsAutoMutationBatch::IsBatching() || !ObservesAttr(aElement, aNameSpaceID, aAttribute) || aElement->ChromeOnlyAccess()) { return; } nsDOMMutationRecord* m = Observer()->CurrentRecord(NS_LITERAL_STRING("attributes")); NS_ASSERTION(!m->mTarget || m->mTarget == aElement, "Wrong target!"); NS_ASSERTION(m->mAttrName.IsVoid() || m->mAttrName.Equals(nsDependentAtomString(aAttribute)), "Wrong attribute!"); if (!m->mTarget) { m->mTarget = aElement; m->mAttrName = nsAtomString(aAttribute); if (aNameSpaceID == kNameSpaceID_None) { m->mAttrNamespace.SetIsVoid(true); } else { nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, m->mAttrNamespace); } } if (AttributeOldValue() && m->mPrevValue.IsVoid()) { if (!aElement->GetAttr(aNameSpaceID, aAttribute, m->mPrevValue)) { m->mPrevValue.SetIsVoid(true); } } }