nsresult result = NS_ERROR_UNEXPECTED; if (mSelect) { if (mDirty) { GetOptions(); } result = mSelect->GetSelectedIndex(aSelectedIndex);
nsIFormControlFrame* formControlFrame = nsnull; nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv)) { nsString value; rv = formControlFrame->GetProperty(nsHTMLAtoms::selectedindex, value); if (NS_SUCCEEDED(rv) && (value.Length() > 0)) { PRInt32 retval = 0; PRInt32 error = 0; retval = value.ToInteger(&error, 10); if (!error) { *aValue = retval; } else { rv = NS_ERROR_UNEXPECTED; } } } else { *aValue = -1;    nsCOMPtr<nsIPresState> presState; nsCOMPtr<nsISupportsArray> value; nsresult res = GetPresState(getter_AddRefs(presState), getter_AddRefs(value)); if (NS_SUCCEEDED(res) && presState) { nsCOMPtr<nsISupports> supp; presState->GetStatePropertyAsSupports("selecteditems", getter_AddRefs(supp));  nsresult res = NS_ERROR_NULL_POINTER; if (!supp) return NS_ERROR_FAILURE;  nsCOMPtr<nsISupportsArray> value = do_QueryInterface(supp); if (!value) return NS_ERROR_FAILURE;  PRUint32 count = 0; value->Count(&count);  nsCOMPtr<nsISupportsPRInt32> thisVal; PRInt32 j=0; for (PRUint32 i=0; i<count; i++) { nsCOMPtr<nsISupports> suppval = getter_AddRefs(value->ElementAt(i)); thisVal = do_QueryInterface(suppval); if (thisVal) { res = thisVal->GetData(aValue); if (NS_SUCCEEDED(res)) { return NS_OK; } } else { res = NS_ERROR_UNEXPECTED; } if (!NS_SUCCEEDED(res)) break; } } else {     PRBool isMultiple; rv = GetMultiple(&isMultiple); if (NS_SUCCEEDED(rv) && !isMultiple) { PRInt32 size = 1; rv = GetSize(&size); if (NS_SUCCEEDED(rv) && ((1 >= size) || (NS_CONTENT_ATTR_NOT_THERE == size))) { *aValue = 0; } } nsCOMPtr<nsIDOMNSHTMLOptionCollection> options; rv = GetOptions(getter_AddRefs(options)); if (NS_SUCCEEDED(rv) && options) { PRUint32 numOptions; rv = options->GetLength(&numOptions); if (NS_SUCCEEDED(rv)) { for (PRUint32 i = 0; i < numOptions; i++) { nsCOMPtr<nsIDOMNode> node; rv = options->Item(i, getter_AddRefs(node)); if (NS_SUCCEEDED(rv) && node) { nsCOMPtr<nsIDOMHTMLOptionElement> option = do_QueryInterface(node, &rv); if (NS_SUCCEEDED(rv) && option) { PRBool selected; rv = option->GetDefaultSelected(&selected); if (NS_SUCCEEDED(rv) && selected) { *aValue = i; break; } } } } } } }
nsHTMLOptionCollection::GetSelectedIndex(PRInt32 *aSelectedIndex){  nsresult result = NS_ERROR_UNEXPECTED;  if (mSelect) {    if (mDirty) {      GetOptions();    }      result = mSelect->GetSelectedIndex(aSelectedIndex);  }  return result;  }