NS_SUCCEEDED(formControlFrame->QueryInterface(kIFrameIID,
NS_SUCCEEDED(formControlFrame->QueryInterface(NS_GET_IID(nsIFrame),
nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,                            nsEvent* aEvent,                            nsIDOMEvent** aDOMEvent,                            PRUint32 aFlags,                            nsEventStatus* aEventStatus){  NS_ENSURE_ARG_POINTER(aEventStatus);  if ((aEvent->message == NS_FOCUS_CONTENT && mSkipFocusEvent) ||      (aEvent->message == NS_BLUR_CONTENT && mSkipFocusEvent)) {    return NS_OK;  }  nsCOMPtr<nsIDOMEventTarget> oldTarget;        // Do not process any DOM events if the element is disabled  PRBool disabled;  nsresult rv = GetDisabled(&disabled);  if (NS_FAILED(rv) || disabled) {    return rv;  }    // Bugscape 2369: Type might change during JS event handler  //                This pointer is only valid until  //                nsGenericHTMLLeafFormElement::HandleDOMEvent  nsIFormControlFrame* formControlFrame = nsnull;  rv = GetPrimaryFrame(this, formControlFrame, PR_FALSE);  nsIFrame* formFrame = nsnull;  if (formControlFrame &&      NS_SUCCEEDED(formControlFrame->QueryInterface(kIFrameIID,                                                    (void **)&formFrame)) &&      formFrame) {    const nsStyleUserInterface* uiStyle;    formFrame->GetStyleData(eStyleStruct_UserInterface,                            (const nsStyleStruct *&)uiStyle);    if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||        uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {      return NS_OK;    }  }  // If we're a file input we have anonymous content underneath  // that we need to hide.  We need to set the event target now  // to ourselves  //  // Bugscape 2369: Type might change during JS event handler  //                This is only valid until  //                nsGenericHTMLLeafFormElement::HandleDOMEvent  //  PRInt32 type;  GetType(&type);  if (type == NS_FORM_INPUT_FILE ||      type == NS_FORM_INPUT_TEXT ) {    // If the event is starting here that's fine.  If it's not    // init'ing here it started beneath us and needs modification.    if (!(NS_EVENT_FLAG_INIT & aFlags)) {      if (!*aDOMEvent) {        // We haven't made a DOMEvent yet.  Force making one now.        nsCOMPtr<nsIEventListenerManager> listenerManager;        rv = GetListenerManager(getter_AddRefs(listenerManager));        if (NS_FAILED(rv)) {          return rv;        }        nsAutoString empty;        rv = listenerManager->CreateEvent(aPresContext, aEvent, empty,                                          aDOMEvent);        if (NS_FAILED(rv)) {          return rv;        }      }      if (!*aDOMEvent) {        return NS_ERROR_FAILURE;      }      nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(*aDOMEvent));      if (!privateEvent) {        return NS_ERROR_FAILURE;      }      (*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget));      nsCOMPtr<nsIDOMEventTarget> originalTarget;      (*aDOMEvent)->GetOriginalTarget(getter_AddRefs(originalTarget));      if (!originalTarget) {        privateEvent->SetOriginalTarget(oldTarget);      }      nsCOMPtr<nsIDOMEventTarget>        target(do_QueryInterface((nsIDOMHTMLInputElement*)this));      privateEvent->SetTarget(target);    }  }  // Preset the the value of the checkbox or the radiobutton before  // calling into script If the event gets "cancelled" then we have to  // "back out" this change, but the odds of that are slimmer than it  // being set each time  //  // Start by remember the original value and for radio buttons we  // must get the currently selected radiobtn. So we go get the  // content instead of the frame  PRBool orginalCheckedValue = PR_FALSE;  PRBool checkWasSet         = PR_FALSE;  nsCOMPtr<nsIContent> selectedRadiobtn;  if (!(aFlags & NS_EVENT_FLAG_CAPTURE) &&      aEvent->message == NS_MOUSE_LEFT_CLICK) {    GetChecked(&orginalCheckedValue);    checkWasSet = PR_TRUE;    switch(type) {      case NS_FORM_INPUT_CHECKBOX:        {          PRBool checked;          GetChecked(&checked);          SetChecked(!checked);        }        break;      case NS_FORM_INPUT_RADIO:        {          // Get the currently selected button from the radio group          // we get access to that via the nsIRadioControlFrame interface          // because the current grouping is kept in the frame.          nsIRadioControlFrame * rb = nsnull;          if (formControlFrame != nsnull) {            nsresult resv = formControlFrame->QueryInterface(NS_GET_IID(nsIRadioControlFrame), (void**)&rb);            if (NS_SUCCEEDED(resv) && rb) {              rb->GetRadioGroupSelectedContent(getter_AddRefs(selectedRadiobtn));            }          }          SetChecked(PR_TRUE);        }        break;      default:        break;    } //switch  }  // Try script event handlers first if its not a focus/blur event  //we dont want the doc to get these  nsresult ret = nsGenericHTMLLeafFormElement::HandleDOMEvent(aPresContext,                                                              aEvent,                                                              aDOMEvent,                                                              aFlags,                                                              aEventStatus);  // now check to see if the event was "cancelled"  if (nsEventStatus_eConsumeNoDefault == *aEventStatus && checkWasSet &&      (type == NS_FORM_INPUT_CHECKBOX || type == NS_FORM_INPUT_RADIO)) {    // if it was cancelled and a radio button, then set the old    // selceted btn to TRUE. if it is a checkbox then set it to it's    // original value    if (selectedRadiobtn) {      nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(selectedRadiobtn));      if (inputElement) {        inputElement->SetChecked(PR_TRUE);      }    } else {      SetChecked(orginalCheckedValue);    }  }  // Bugscape 2369: Frame might have changed during event handler  formControlFrame = nsnull;  rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame, PR_FALSE);  // Finish the special file control processing...  if (oldTarget) {    // If the event is starting here that's fine.  If it's not    // init'ing here it started beneath us and needs modification.    if (!(NS_EVENT_FLAG_INIT & aFlags)) {      if (!*aDOMEvent) {        return NS_ERROR_FAILURE;      }      nsCOMPtr<nsIPrivateDOMEvent> privateEvent =        do_QueryInterface(*aDOMEvent);      if (!privateEvent) {        return NS_ERROR_FAILURE;      }      // This will reset the target to its original value      privateEvent->SetTarget(oldTarget);    }  }  // Bugscape 2369: type might have changed during event handler  GetType(&type);  if ((NS_OK == rv) && (nsEventStatus_eIgnore == *aEventStatus) &&      !(aFlags & NS_EVENT_FLAG_CAPTURE)) {    switch (aEvent->message) {      case NS_FOCUS_CONTENT:      {        if (formControlFrame) {          mSkipFocusEvent = PR_TRUE;          formControlFrame->SetFocus(PR_TRUE, PR_TRUE);          mSkipFocusEvent = PR_FALSE;          return NS_OK;        }      }                                                                               break; // NS_FOCUS_CONTENT      case NS_KEY_PRESS:      {        // For backwards compat, trigger checks/radios/buttons with        // space or enter (bug 25300)        nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;        if (keyEvent->keyCode == NS_VK_RETURN ||            keyEvent->charCode == NS_VK_SPACE) {          switch(type) {            case NS_FORM_INPUT_CHECKBOX:            case NS_FORM_INPUT_RADIO:            case NS_FORM_INPUT_BUTTON:            case NS_FORM_INPUT_RESET:            case NS_FORM_INPUT_SUBMIT:            case NS_FORM_INPUT_IMAGE: // Bug 34418            {              nsEventStatus status = nsEventStatus_eIgnore;              nsMouseEvent event;              event.eventStructType = NS_MOUSE_EVENT;              event.message = NS_MOUSE_LEFT_CLICK;              event.isShift = PR_FALSE;              event.isControl = PR_FALSE;              event.isAlt = PR_FALSE;              event.isMeta = PR_FALSE;              event.clickCount = 0;              event.widget = nsnull;              rv = HandleDOMEvent(aPresContext, &event, nsnull,                                  NS_EVENT_FLAG_INIT, &status);            } // case          } // switch        }      } break;// NS_KEY_PRESS      // cancel all of these events for buttons      case NS_MOUSE_MIDDLE_BUTTON_DOWN:      case NS_MOUSE_MIDDLE_BUTTON_UP:      case NS_MOUSE_MIDDLE_DOUBLECLICK:      case NS_MOUSE_RIGHT_DOUBLECLICK:      case NS_MOUSE_RIGHT_BUTTON_DOWN:      case NS_MOUSE_RIGHT_BUTTON_UP:      {        if (type == NS_FORM_INPUT_BUTTON ||             type == NS_FORM_INPUT_RESET ||             type == NS_FORM_INPUT_SUBMIT ) {          if (aDOMEvent != nsnull && *aDOMEvent != nsnull) {            (*aDOMEvent)->PreventBubble();          } else {            rv = NS_ERROR_FAILURE;          }        }        break;      }      case NS_MOUSE_LEFT_CLICK:      {        switch(type) {          case NS_FORM_INPUT_BUTTON:          case NS_FORM_INPUT_RESET:          case NS_FORM_INPUT_SUBMIT:          case NS_FORM_INPUT_IMAGE:            {              // Tell the frame about the click              if (formControlFrame) {                formControlFrame->MouseClicked(aPresContext);              }            }            break;          default:            break;        } //switch       } break;// NS_MOUSE_LEFT_BUTTON_DOWN    } //switch   } // if  return rv;}