nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(doc->GetScriptGlobalObject());
nsPIDOMWindow *ourWindow = doc->GetWindow();
XULPopupListenerImpl::FireFocusOnTargetContent(nsIDOMNode* aTargetNode){  nsresult rv;  nsCOMPtr<nsIDOMDocument> domDoc;  rv = aTargetNode->GetOwnerDocument(getter_AddRefs(domDoc));  if(NS_SUCCEEDED(rv) && domDoc)  {    nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);    // Get nsIDOMElement for targetNode    nsIPresShell *shell = doc->GetShellAt(0);    if (!shell)      return NS_ERROR_FAILURE;    // strong reference to keep this from going away between events    nsCOMPtr<nsPresContext> context = shell->GetPresContext();     nsCOMPtr<nsIContent> content = do_QueryInterface(aTargetNode);    nsIFrame* targetFrame = shell->GetPrimaryFrameFor(content);    if (!targetFrame) return NS_ERROR_FAILURE;          PRBool suppressBlur = PR_FALSE;    const nsStyleUserInterface* ui = targetFrame->GetStyleUserInterface();    suppressBlur = (ui->mUserFocus == NS_STYLE_USER_FOCUS_IGNORE);    nsCOMPtr<nsIDOMElement> element;    nsCOMPtr<nsIContent> newFocus = do_QueryInterface(content);    nsIFrame* currFrame = targetFrame;    // Look for the nearest enclosing focusable frame.    while (currFrame) {        if (currFrame->IsFocusable()) {          newFocus = currFrame->GetContent();          nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(newFocus));          if (domElement) {            element = domElement;            break;          }        }        currFrame = currFrame->GetParent();    }     nsCOMPtr<nsIContent> focusableContent = do_QueryInterface(element);    nsIEventStateManager *esm = context->EventStateManager();    if (focusableContent) {      // Lock to scroll by SetFocus. See bug 309075.      nsCOMPtr<nsIFocusController> focusController = nsnull;      PRBool isAlreadySuppressed = PR_FALSE;      nsCOMPtr<nsPIDOMWindow> ourWindow =        do_QueryInterface(doc->GetScriptGlobalObject());      if (ourWindow) {        focusController = ourWindow->GetRootFocusController();        if (focusController) {          focusController->GetSuppressFocusScroll(&isAlreadySuppressed);          if (!isAlreadySuppressed)            focusController->SetSuppressFocusScroll(PR_TRUE);        }      }      focusableContent->SetFocus(context);      // Unlock scroll if it's needed.      if (focusController && !isAlreadySuppressed)        focusController->SetSuppressFocusScroll(PR_FALSE);    } else if (!suppressBlur)      esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS);    esm->SetContentState(focusableContent, NS_EVENT_STATE_ACTIVE);  }  return rv;}