nsresult XULSortServiceImpl::GetTemplateItemsToSort(nsIContent* aContainer, nsIXULTemplateBuilder* aBuilder, nsSortState* aSortState, nsTArray<contentSortInfo>& aSortItems) { PRUint32 numChildren = aContainer->GetChildCount(); for (PRUint32 childIndex = 0; childIndex < numChildren; childIndex++) { nsIContent *child = aContainer->GetChildAt(childIndex); nsCOMPtr<nsIDOMElement> childnode = do_QueryInterface(child); nsCOMPtr<nsIXULTemplateResult> result; nsresult rv = aBuilder->GetResultForContent(childnode, getter_AddRefs(result)); NS_ENSURE_SUCCESS(rv, rv); if (result) { contentSortInfo* cinfo = aSortItems.AppendElement(); if (!cinfo) return NS_ERROR_OUT_OF_MEMORY; cinfo->content = child; cinfo->result = result; } else if (aContainer->Tag() != nsGkAtoms::_template) { rv = GetTemplateItemsToSort(child, aBuilder, aSortState, aSortItems); NS_ENSURE_SUCCESS(rv, rv); } } return NS_OK; }
nsresult XULSortServiceImpl::GetTemplateItemsToSort(nsIContent* aContainer, nsIXULTemplateBuilder* aBuilder, nsSortState* aSortState, nsTArray<contentSortInfo>& aSortItems) { for (nsIContent* child = aContainer->GetFirstChild(); child; child = child->GetNextSibling()) { nsCOMPtr<nsIDOMElement> childnode = do_QueryInterface(child); nsCOMPtr<nsIXULTemplateResult> result; nsresult rv = aBuilder->GetResultForContent(childnode, getter_AddRefs(result)); NS_ENSURE_SUCCESS(rv, rv); if (result) { contentSortInfo* cinfo = aSortItems.AppendElement(); if (!cinfo) return NS_ERROR_OUT_OF_MEMORY; cinfo->content = child; cinfo->result = result; } else if (!aContainer->IsXULElement(nsGkAtoms::_template)) { rv = GetTemplateItemsToSort(child, aBuilder, aSortState, aSortItems); NS_ENSURE_SUCCESS(rv, rv); } } return NS_OK; }
nsresult XULSortServiceImpl::GetItemsToSort(nsIContent *aContainer, nsSortState* aSortState, nsTArray<contentSortInfo>& aSortItems) { // if there is a template attached to the sort node, use the builder to get // the items to be sorted nsCOMPtr<nsIDOMXULElement> element = do_QueryInterface(aContainer); if (element) { nsCOMPtr<nsIXULTemplateBuilder> builder; element->GetBuilder(getter_AddRefs(builder)); if (builder) { nsresult rv = builder->GetQueryProcessor(getter_AddRefs(aSortState->processor)); if (NS_FAILED(rv) || !aSortState->processor) return rv; return GetTemplateItemsToSort(aContainer, builder, aSortState, aSortItems); } } // if there is no template builder, just get the children. For trees, // get the treechildren element as use that as the parent nsCOMPtr<nsIContent> treechildren; if (aContainer->NodeInfo()->Equals(nsGkAtoms::tree, kNameSpaceID_XUL)) { nsXULContentUtils::FindChildByTag(aContainer, kNameSpaceID_XUL, nsGkAtoms::treechildren, getter_AddRefs(treechildren)); if (!treechildren) return NS_OK; aContainer = treechildren; } PRUint32 count = aContainer->GetChildCount(); for (PRUint32 c = 0; c < count; c++) { nsIContent *child = aContainer->GetChildAt(c); contentSortInfo* cinfo = aSortItems.AppendElement(); if (!cinfo) return NS_ERROR_OUT_OF_MEMORY; cinfo->content = child; } return NS_OK; }