nsCOMPtr<nsIDOMWindowInternal> domWin(do_QueryInterface(globalObj));
nsCOMPtr<nsIDOMWindowInternal> domWin(do_QueryInterface(win));
nsHTMLInputElement::Select(){  nsresult rv = NS_OK;  if (!mDocument)    return NS_OK;  // first see if we are disabled or not. If disabled then do nothing.  nsAutoString disabled;  if (NS_CONTENT_ATTR_HAS_VALUE == GetAttr(kNameSpaceID_None,                                           nsHTMLAtoms::disabled, disabled)) {    return rv;  }  if (mType == NS_FORM_INPUT_PASSWORD || mType == NS_FORM_INPUT_TEXT) {    // XXX Bug?  We have to give the input focus before contents can be    // selected    nsCOMPtr<nsIPresContext> presContext;    GetPresContext(this, getter_AddRefs(presContext));     // If the window is not active, do not allow the select to bring the    // window to the front.  We update the focus controller, but do    // nothing else.    nsCOMPtr<nsIScriptGlobalObject> globalObj;    mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObj));    nsCOMPtr<nsIFocusController> focusController;    win->GetRootFocusController(getter_AddRefs(focusController));    PRBool isActive = PR_FALSE;    focusController->GetActive(&isActive);    if (!isActive) {      nsCOMPtr<nsIDOMWindowInternal> domWin(do_QueryInterface(globalObj));      focusController->SetFocusedWindow(domWin);      focusController->SetFocusedElement(this);      SelectAll(presContext);      return NS_OK;    }    // Just like SetFocus() but without the ScrollIntoView()!    nsEventStatus status = nsEventStatus_eIgnore;        //If already handling select event, don't dispatch a second.    if (!GET_BOOLBIT(mBitField, BF_HANDLING_SELECT_EVENT)) {      nsEvent event;      event.eventStructType = NS_EVENT;      event.message = NS_FORM_SELECTED;        SET_BOOLBIT(mBitField, BF_HANDLING_SELECT_EVENT, PR_TRUE);      rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT,                          &status);      SET_BOOLBIT(mBitField, BF_HANDLING_SELECT_EVENT, PR_FALSE);    }    // If the DOM event was not canceled (e.g. by a JS event handler    // returning false)    if (status == nsEventStatus_eIgnore) {      if (presContext) {        nsCOMPtr<nsIEventStateManager> esm;        presContext->GetEventStateManager(getter_AddRefs(esm));        if (esm) {          // XXX Fix for bug 135345 - ESM currently does not check to see if we          // have focus before attempting to set focus again and may cause          // infinite recursion.  For now check if we have focus and do not set          // focus again if already focused.          PRInt32 currentState;          esm->GetContentState(this, currentState);          if (!(currentState & NS_EVENT_STATE_FOCUS)) {            esm->SetContentState(this, NS_EVENT_STATE_FOCUS);          }        }      }      nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);      if (formControlFrame) {        formControlFrame->SetFocus(PR_TRUE, PR_TRUE);        // Now Select all the text!        SelectAll(presContext);      }    }  }  return rv;}