nsGUIEvent event(NS_MOUSE_LEFT_CLICK);
nsMouseEvent event(NS_MOUSE_LEFT_CLICK);
nsHTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext){  if (!mForm) {    // Nothing to do here.    return NS_OK;  }    // Find the first submit control in elements[]  // and also check how many text controls we have in the form  nsCOMPtr<nsIContent> submitControl;  PRInt32 numTextControlsFound = 0;  nsCOMPtr<nsISimpleEnumerator> formControls;  mForm->GetControlEnumerator(getter_AddRefs(formControls));  nsCOMPtr<nsISupports> currentControlSupports;  nsCOMPtr<nsIFormControl> currentControl;  PRBool hasMoreElements;  nsresult rv;  while (NS_SUCCEEDED(rv = formControls->HasMoreElements(&hasMoreElements)) &&         hasMoreElements) {    rv = formControls->GetNext(getter_AddRefs(currentControlSupports));    NS_ENSURE_SUCCESS(rv, rv);    currentControl = do_QueryInterface(currentControlSupports);    if (currentControl) {      PRInt32 type = currentControl->GetType();      if (!submitControl &&          (type == NS_FORM_INPUT_SUBMIT ||           type == NS_FORM_BUTTON_SUBMIT ||           type == NS_FORM_INPUT_IMAGE)) {        submitControl = do_QueryInterface(currentControl);        // We know as soon as we find a submit control that it no        // longer matters how many text controls there are--we are        // going to fire the onClick handler.        break;      } else if (type == NS_FORM_INPUT_TEXT ||                 type == NS_FORM_INPUT_PASSWORD) {        numTextControlsFound++;      }    }  }  NS_ENSURE_SUCCESS(rv, rv);              nsIPresShell* shell = aPresContext->GetPresShell();  if (shell) {    if (submitControl) {      // Fire the button's onclick handler and let the button handle      // submitting the form.      nsGUIEvent event(NS_MOUSE_LEFT_CLICK);      nsEventStatus status = nsEventStatus_eIgnore;      shell->HandleDOMEventWithTarget(submitControl, &event, &status);    } else if (numTextControlsFound == 1) {      // If there's only one text control, just submit the form      nsCOMPtr<nsIContent> form = do_QueryInterface(mForm);      nsFormEvent event(NS_FORM_SUBMIT);      nsEventStatus status  = nsEventStatus_eIgnore;      shell->HandleDOMEventWithTarget(form, &event, &status);    }  }  return NS_OK;}