// Get the nsITreeBoxObject interface from any levels DOMNode under the <tree> void nsXULTreeAccessible::GetTreeBoxObject(nsIDOMNode *aDOMNode, nsITreeBoxObject **aBoxObject) { nsAutoString name; nsCOMPtr<nsIDOMNode> parentNode, currentNode; // Find DOMNode's parents recursively until reach the <tree> tag currentNode = aDOMNode; while (currentNode) { currentNode->GetLocalName(name); if (name.EqualsLiteral("tree")) { // We will get the nsITreeBoxObject from the tree node nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(currentNode)); if (xulElement) { nsCOMPtr<nsIBoxObject> box; xulElement->GetBoxObject(getter_AddRefs(box)); nsCOMPtr<nsITreeBoxObject> treeBox(do_QueryInterface(box)); if (treeBox) { *aBoxObject = treeBox; NS_ADDREF(*aBoxObject); return; } } } currentNode->GetParentNode(getter_AddRefs(parentNode)); currentNode = parentNode; } *aBoxObject = nsnull; }
already_AddRefed<nsITreeBoxObject> nsCoreUtils::GetTreeBoxObject(nsIContent *aContent) { // Find DOMNode's parents recursively until reach the <tree> tag nsIContent* currentContent = aContent; while (currentContent) { if (currentContent->NodeInfo()->Equals(nsGkAtoms::tree, kNameSpaceID_XUL)) { // We will get the nsITreeBoxObject from the tree node nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(currentContent)); if (xulElement) { nsCOMPtr<nsIBoxObject> box; xulElement->GetBoxObject(getter_AddRefs(box)); nsCOMPtr<nsITreeBoxObject> treeBox(do_QueryInterface(box)); if (treeBox) return treeBox.forget(); } } currentContent = currentContent->GetParent(); } return nullptr; }