for (PRInt32 i = 0; i < count; i++) { nsCOMPtr<nsIContent> child; aParent->ChildAt(i, *getter_AddRefs(child)); nsCOMPtr<nsIDOMXULPopupElement> menuPopup(do_QueryInterface(child)); if (child) { *aResult = child.get(); NS_ADDREF(*aResult); return; } }
if (count == 0) return;  aParent->ChildAt(0, *aResult); return;
GetMenuChildrenElement(nsIContent* aParent, nsIContent** aResult){  PRInt32 count;  aParent->ChildCount(count);  for (PRInt32 i = 0; i < count; i++) {    nsCOMPtr<nsIContent> child;    aParent->ChildAt(i, *getter_AddRefs(child));    nsCOMPtr<nsIDOMXULPopupElement> menuPopup(do_QueryInterface(child));    if (child) {      *aResult = child.get();      NS_ADDREF(*aResult);      return;    }  }}