nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(aDocument->GetScriptGlobalObject());
nsPIDOMWindow *ourWindow = aDocument->GetWindow();
FocusElementButNotDocument(nsIDocument* aDocument, nsIContent* aContent){  nsIFocusController *focusController = nsnull;  nsCOMPtr<nsPIDOMWindow> ourWindow =    do_QueryInterface(aDocument->GetScriptGlobalObject());  if (ourWindow)    focusController = ourWindow->GetRootFocusController();  if (!focusController)    return;  // Get previous focus  nsCOMPtr<nsIDOMElement> oldFocusedElement;  focusController->GetFocusedElement(getter_AddRefs(oldFocusedElement));  nsCOMPtr<nsIContent> oldFocusedContent =    do_QueryInterface(oldFocusedElement);  // Notify focus controller of new focus for this document  nsCOMPtr<nsIDOMElement> newFocusedElement(do_QueryInterface(aContent));  focusController->SetFocusedElement(newFocusedElement);  nsIPresShell* presShell = aDocument->GetShellAt(0);  nsIEventStateManager* esm = presShell->GetPresContext()->EventStateManager();  // Temporarily set esm::mCurrentFocus so that esm::GetContentState() tells   // layout system to show focus on this element.   esm->SetFocusedContent(aContent);  // Reset back to null at the end.  aDocument->BeginUpdate(UPDATE_CONTENT_STATE);  aDocument->ContentStatesChanged(oldFocusedContent, aContent,                                   NS_EVENT_STATE_FOCUS);  aDocument->EndUpdate(UPDATE_CONTENT_STATE);  // Reset esm::mCurrentFocus = nsnull for this doc, so when this document  // does get focus next time via preHandleEvent() NS_GOTFOCUS,  // the old document gets blurred  esm->SetFocusedContent(nsnull);}