PRInt32 oldIndex = mOptions->IndexOf(aContent);   mOptions->RemoveOption(aContent);   nsIFormControlFrame* fcFrame = nsnull; nsresult result = nsGenericHTMLElement::GetPrimaryFrame(this, fcFrame, PR_FALSE); if (NS_SUCCEEDED(result) && (nsnull != fcFrame)) { nsISelectControlFrame* selectFrame = nsnull; result = fcFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame),(void **) &selectFrame); if (NS_SUCCEEDED(result) && (nsnull != selectFrame)) {    nsIPresContext* presContext; nsGenericHTMLElement::GetPresContext(this, &presContext); result = selectFrame->RemoveOption(presContext, oldIndex); NS_IF_RELEASE(presContext);
if ((nsnull != aOption) && NS_SUCCEEDED(aOption->QueryInterface(NS_GET_IID(nsIDOMHTMLOptionElement), (void**)&option))) { if (mElements.RemoveElement(option)) { nsresult result; NS_RELEASE2(option, result);
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 = nsGenericHTMLElement::GetPrimaryFrame(this, fcFrame, PR_FALSE);  if (NS_SUCCEEDED(result) && (nsnull != fcFrame)) {    nsISelectControlFrame* selectFrame = nsnull;    result = fcFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame),(void **) &selectFrame);    if (NS_SUCCEEDED(result) && (nsnull != 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      nsIPresContext* presContext;      nsGenericHTMLElement::GetPresContext(this, &presContext);      result = selectFrame->RemoveOption(presContext, oldIndex);      NS_IF_RELEASE(presContext);    }  } 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;      for (PRUint32 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;          }          if (!NS_SUCCEEDED(res)) break;          break;        }      } // for    }  }  return result;}