SetOptionSelected(i, selectedInView);
SetOptionSelectedCache(i, selectedInView);
nsNativeSelectControlFrame::ControlChanged(nsIPresContext* aPresContext){  if (!nsFormFrame::GetDisabled(this)) {    PRBool changed = PR_FALSE;    PRBool multiple;    GetMultiple(&multiple);    if (!multiple) {      nsIListWidget* listWidget;      nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget);      if ((NS_OK == result) && listWidget) {        PRInt32 viewIndex = listWidget->GetSelectedIndex();        NS_RELEASE(listWidget);        PRBool wasSelected = PR_FALSE;        GetOptionSelected(viewIndex, &wasSelected);        if (wasSelected == PR_FALSE) {          changed = PR_TRUE;        }        // Update the locally cached array        for (PRInt32 i=0; i < mNumOptions; i++)          SetOptionSelected(i, PR_FALSE);        SetOptionSelected(viewIndex, PR_TRUE);              }    } else {      // Get the selected option from the widget      nsIListBox* listBox;      nsresult result = mWidget->QueryInterface(kListBoxIID, (void **) &listBox);      if (!(NS_OK == result) || !listBox) {        return;      }      PRInt32 numSelected = listBox->GetSelectedCount();      PRInt32* selOptions = nsnull;      if (numSelected > 0) {        selOptions = new PRInt32[numSelected];        listBox->GetSelectedIndices(selOptions, numSelected);      }      NS_RELEASE(listBox);      // XXX Assume options are sorted in selOptions      PRInt32 selIndex = 0;      PRInt32 nextSel = 0;      if ((nsnull != selOptions) && (numSelected > 0)) {        nextSel = selOptions[selIndex];      }      // Step through each option in local cache      for (PRInt32 i=0; i < mNumOptions; i++) {        PRBool selectedInLocalCache = PR_FALSE;        PRBool selectedInView = (i == nextSel);        GetOptionSelected(i, &selectedInLocalCache);        if (selectedInView != selectedInLocalCache) {          changed = PR_TRUE;          SetOptionSelected(i, selectedInView);          if (selectedInView) {            // Get the next selected option in the view            selIndex++;             if (selIndex < numSelected) {              nextSel = selOptions[selIndex];            }          }        }      }      delete[] selOptions;    }    if (changed) {      nsEventStatus status = nsEventStatus_eIgnore;      nsEvent event;      event.eventStructType = NS_EVENT;      event.message = NS_FORM_CHANGE;      if (nsnull != mContent) {        mContent->HandleDOMEvent(*aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);      }    }  }}