PRInt32 type; GetType(&type);
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;  }    nsIFormControlFrame* formControlFrame = nsnull;  rv = nsGenericHTMLElement::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  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;        if (NS_FAILED(rv = mInner.GetListenerManager(getter_AddRefs(listenerManager)))) {          return rv;        }        nsAutoString empty;        if (NS_FAILED(rv = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) {          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);    }  }  // When a user clicks on a checkbox the value needs to be set after the onmouseup  // and before the onclick event is processed via script. The EVM always lets script  // get first crack at the processing, and script can cancel further processing of   // the event by return null.  //  // This means the checkbox needs to have it's new value set before it goes to script   // to process the onclick and then if script cancels the event it needs to be set back.  // In Nav and IE there is a flash of it being set and then unset  //   // We have added this extra method to the checkbox to tell it to temporarily return the  // opposite value while processing the click event. This way script gets the correct "future"  // value of the checkbox, but there is no visual updating until after script is done processing.  // That way if the event is cancelled then the checkbox will not flash.  //  // So get the Frame for the checkbox and tell it we are processing an onclick event  nsCOMPtr<nsICheckboxControlFrame> chkBx;  nsCOMPtr<nsIRadioControlFrame> radio;  if (NS_SUCCEEDED(rv)) {    chkBx = do_QueryInterface(formControlFrame);    if (!chkBx) {      radio = do_QueryInterface(formControlFrame);    }  }  if (aEvent->message == NS_MOUSE_LEFT_CLICK) {    if (chkBx) chkBx->SetIsInClickEvent(PR_TRUE);    if (radio) radio->SetIsInClickEvent(PR_TRUE);  }  // Try script event handlers first if its not a focus/blur event  //we dont want the doc to get these  nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,                               aFlags, aEventStatus);  // Script is done processing, now tell the checkbox we are no longer doing an onclick  // and if it was cancelled the checkbox will get the propriate value via the DOM listener  if (aEvent->message == NS_MOUSE_LEFT_CLICK) {    if (chkBx) chkBx->SetIsInClickEvent(PR_FALSE);    if (radio) radio->SetIsInClickEvent(PR_FALSE);  }  // Finish the special file control processing...  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) {        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);    }  }  if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&      !(aFlags & NS_EVENT_FLAG_CAPTURE)) {    switch (aEvent->message) {      case NS_FOCUS_CONTENT:      {        nsIFormControlFrame* formControlFrame = nsnull;        rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);        if (NS_SUCCEEDED(rv)) {          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) {          PRInt32 type;          GetType(&type);          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_GUI_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      case NS_MOUSE_MIDDLE_BUTTON_DOWN:     // cancel all of these events for buttons      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: {          PRInt32 type;          GetType(&type);          if (type == NS_FORM_INPUT_BUTTON ||               type == NS_FORM_INPUT_RESET ||               type == NS_FORM_INPUT_SUBMIT ) {            if (aDOMEvent != nsnull && *aDOMEvent != nsnull) {              (*aDOMEvent)->PreventBubble();            } else {              ret = NS_ERROR_FAILURE;            }          }        } break;      case NS_MOUSE_LEFT_CLICK:      {        PRInt32 type;        GetType(&type);        switch(type) {          case NS_FORM_INPUT_CHECKBOX:            {              PRBool checked;              GetChecked(&checked);              SetChecked(!checked);            }            break;          case NS_FORM_INPUT_RADIO:            SetChecked(PR_TRUE);            break;          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              nsIFormControlFrame* formControlFrame = nsnull;              nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);              if (NS_SUCCEEDED(rv)) {                formControlFrame->MouseClicked(aPresContext);              }            }            break;        } //switch       } break;// NS_MOUSE_LEFT_BUTTON_DOWN      case NS_FORM_SELECTED:      {        // XXX Bug?  We have to give the input focus before contents can be selected        // Just like SetFocus() but without the ScrollIntoView()!        nsCOMPtr<nsIEventStateManager> esm;        if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {          esm->SetContentState(this, NS_EVENT_STATE_FOCUS);        }        nsIFormControlFrame* formControlFrame = nsnull;        nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame);        if (NS_SUCCEEDED(rv)) {          formControlFrame->SetFocus(PR_TRUE, PR_TRUE);        }        // Now Select all the text!        if (NS_SUCCEEDED(rv)) {          SelectAll(aPresContext);        }      } break; //NS_FORM_SELECTED    } //switch   } // if  return ret;}