nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(doc->GetScriptGlobalObject());
nsPIDOMWindow *win = doc->GetWindow();
nsHTMLInputElement::Select(){  nsresult rv = NS_OK;  nsIDocument* doc = GetCurrentDoc();  if (!doc)    return NS_OK;  // first see if we are disabled or not. If disabled then do nothing.  if (HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) {    return NS_OK;  }  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<nsPresContext> presContext = GetPresContext();    // 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<nsPIDOMWindow> win =      do_QueryInterface(doc->GetScriptGlobalObject());    if (win) {      nsIFocusController *focusController = win->GetRootFocusController();      PRBool isActive = PR_FALSE;      focusController->GetActive(&isActive);      if (!isActive) {        focusController->SetFocusedWindow(win);        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(nsContentUtils::IsCallerChrome(), 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) {      PRBool shouldFocus = ShouldFocus(this);      if (presContext && shouldFocus) {        nsIEventStateManager *esm = presContext->EventStateManager();        // 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)) {          return rv; // We ended up unfocused, e.g. due to a DOM event handler.        }      }      nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_TRUE);      if (formControlFrame) {        if (shouldFocus) {          formControlFrame->SetFocus(PR_TRUE, PR_TRUE);        }        // Now Select all the text!        SelectAll(presContext);      }    }  }  return rv;}