if (mDidMouseDown) { 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; } } mDidMouseDown = PR_FALSE;
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; }
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;  }  // Do not process any DOM events if the element is disabled  PRBool disabled;  nsresult rv = GetDisabled(&disabled);  if (NS_FAILED(rv) || disabled) {    return rv;  }  // Try script event handlers first  nsresult ret = mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,                               aFlags, aEventStatus);  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_BLUR_CONTENT:        mDidMouseDown = PR_FALSE;        break; // NS_BLUR_CONTENT                case NS_KEY_PRESS:      {        nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;        if (keyEvent->keyCode == NS_VK_RETURN || keyEvent->charCode == 0x20) {          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:            {              //Checkboxes and radio trigger off return or space but buttons              //just trigger off space, go figure.              if (keyEvent->charCode == 0x20) {                //XXX We should just be able to call Click() here but then                //Click wouldn't have a PresContext.                nsIFormControlFrame* formControlFrame = nsnull;                if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {                  if (formControlFrame) {                    formControlFrame->MouseClicked(aPresContext);                  }                }              }            }            break;          }        }      } 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_BUTTON_DOWN:        mDidMouseDown = PR_TRUE;        break;      case NS_MOUSE_LEFT_BUTTON_UP:      {        if (mDidMouseDown) {          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;          } //switch         }        mDidMouseDown = PR_FALSE;      } break;// NS_MOUSE_LEFT_BUTTON_DOWN    } //switch   } // if  return ret;}