PRInt32 oldIndex = mOptions->IndexOf(aContent);   mOptions->RemoveOption(aContent);   nsIFormControlFrame* fcFrame = nsnull; nsresult result = GetPrimaryFrame(this, fcFrame, PR_FALSE);  if (NS_SUCCEEDED(result) && fcFrame) { nsISelectControlFrame* selectFrame = nsnull;  result = fcFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame), (void **)&selectFrame);  if (NS_SUCCEEDED(result) && selectFrame) {      nsCOMPtr<nsIPresContext> presContext;  GetPresContext(this, getter_AddRefs(presContext));  result = selectFrame->RemoveOption(presContext, oldIndex); } } else {        nsCOMPtr<nsIPresState> presState; nsCOMPtr<nsISupportsArray> value; nsresult res = GetPresState(getter_AddRefs(presState), getter_AddRefs(value));  if (NS_SUCCEEDED(res) && value) {   PRUint32 count = 0;  value->Count(&count);    PRInt32 j=0; PRUint32 i;  for (i = 0; i < count; i++) { nsCOMPtr<nsISupports> suppval = getter_AddRefs(value->ElementAt(i));  if (suppval) { nsCOMPtr<nsISupportsPRInt32> thisVal = do_QueryInterface(suppval);  if (thisVal) { res = thisVal->GetData(&j);   if (NS_SUCCEEDED(res) && j == oldIndex) { res = value->RemoveElementAt(i);  break; } } else { res = NS_ERROR_UNEXPECTED; }  break; } }
if (aOption && NS_SUCCEEDED(aOption->QueryInterface(NS_GET_IID(nsIDOMHTMLOptionElement), getter_AddRefs(option)))) { if (mElements.RemoveElement(option)) {
nsHTMLSelectElement::RemoveOption(nsIContent* aContent){  // When first populating the select, this will be null but that's ok  // as we will manually update the widget at frame construction time.  if (!mOptions)    return NS_OK;  PRInt32 oldIndex = mOptions->IndexOf(aContent);  // Remove the option from the options list  mOptions->RemoveOption(aContent);  // Update the widget  nsIFormControlFrame* fcFrame = nsnull;  nsresult result = GetPrimaryFrame(this, fcFrame, PR_FALSE);  if (NS_SUCCEEDED(result) && fcFrame) {    nsISelectControlFrame* selectFrame = nsnull;    result = fcFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame),                                     (void **)&selectFrame);    if (NS_SUCCEEDED(result) && selectFrame) {      // We can't get our index if we've already been replaced in the      // OptionList. If we couldn't get our index, pass -1, remove      // all options and recreate Coincidentally, IndexOf returns -1      // if the option isn't found in the list      nsCOMPtr<nsIPresContext> presContext;      GetPresContext(this, getter_AddRefs(presContext));      result = selectFrame->RemoveOption(presContext, oldIndex);    }  } else {    // Since there are no frames, then we must adjust which options    // are selcted in the content and the current select state is kept in    // the PreState    //    // Call the helper method to get the PresState and     // the SupportsArray that contains the value    //    nsCOMPtr<nsIPresState> presState;    nsCOMPtr<nsISupportsArray> value;    nsresult res = GetPresState(getter_AddRefs(presState),                                getter_AddRefs(value));    if (NS_SUCCEEDED(res) && value) {      // The nsISupportArray is a list of selected options      // Get the number of "selected" options in the select      PRUint32 count = 0;      value->Count(&count);      // look through the list to see if the option being removed is selected      // then remove it from the nsISupportsArray      PRInt32 j=0;      PRUint32 i;      for (i = 0; i < count; i++) {        nsCOMPtr<nsISupports> suppval = getter_AddRefs(value->ElementAt(i));        if (suppval) {          nsCOMPtr<nsISupportsPRInt32> thisVal = do_QueryInterface(suppval);          if (thisVal) {            res = thisVal->GetData(&j);            // the the index being removed match the indexed that is cached?            if (NS_SUCCEEDED(res) && j == oldIndex) {              res = value->RemoveElementAt(i);              break;            }          } else {            res = NS_ERROR_UNEXPECTED;          }          break;        }      } // for    }  }  return result;}