NS_INTERFACE_MAP_END NS_IMETHODIMP nsAnonymousContentList::GetLength(uint32_t* aLength) { if (!mParent) { *aLength = 0; return NS_OK; } uint32_t count = 0; for (nsIContent* child = mParent->GetFirstChild(); child; child = child->GetNextSibling()) { if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) { XBLChildrenElement* point = static_cast<XBLChildrenElement*>(child); if (!point->mInsertedChildren.IsEmpty()) { count += point->mInsertedChildren.Length(); } else { count += point->GetChildCount(); } } else { ++count; } } *aLength = count; return NS_OK; }
nsIContent* nsAnonymousContentList::Item(uint32_t aIndex) { if (!mParent) { return nullptr; } uint32_t remIndex = aIndex; for (nsIContent* child = mParent->GetFirstChild(); child; child = child->GetNextSibling()) { if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) { XBLChildrenElement* point = static_cast<XBLChildrenElement*>(child); if (!point->mInsertedChildren.IsEmpty()) { if (remIndex < point->mInsertedChildren.Length()) { return point->mInsertedChildren[remIndex]; } remIndex -= point->mInsertedChildren.Length(); } else { if (remIndex < point->GetChildCount()) { return point->GetChildAt(remIndex); } remIndex -= point->GetChildCount(); } } else { if (remIndex == 0) { return child; } --remIndex; } } return nullptr; }
int32_t nsAnonymousContentList::IndexOf(nsIContent* aContent) { NS_ASSERTION(!aContent->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL), "Looking for insertion point"); if (!mParent) { return -1; } uint32_t index = 0; for (nsIContent* child = mParent->GetFirstChild(); child; child = child->GetNextSibling()) { if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) { XBLChildrenElement* point = static_cast<XBLChildrenElement*>(child); if (!point->mInsertedChildren.IsEmpty()) { uint32_t insIndex = point->mInsertedChildren.IndexOf(aContent); if (insIndex != point->mInsertedChildren.NoIndex) { return index + insIndex; } index += point->mInsertedChildren.Length(); } else { int32_t insIndex = point->IndexOf(aContent); if (insIndex != -1) { return index + (uint32_t)insIndex; } index += point->GetChildCount(); } } else { if (child == aContent) { return index; } ++index; } } return -1; }