nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(doc->GetScriptGlobalObject());
nsCOMPtr<nsPIDOMWindow> win = doc->GetWindow();
nsXFormsSwitchElement::SetFocus(nsIDOMElement* aDeselected,                               nsIDOMElement* aSelected){  if (aDeselected == aSelected)    return;  nsCOMPtr<nsIDOMDocument> domDoc;  mElement->GetOwnerDocument(getter_AddRefs(domDoc));  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));  if (!doc)    return;  nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(doc->GetScriptGlobalObject());  if (!win)    return;  nsIFocusController *focusController = win->GetRootFocusController();  if (!focusController)    return;  nsCOMPtr<nsIDOMElement> focused;  focusController->GetFocusedElement(getter_AddRefs(focused));  if (!focused)    return;    PRBool hasFocus = PR_FALSE;  nsCOMPtr<nsIDOMNode> current(do_QueryInterface(focused));  do {    nsCOMPtr<nsIDOMElement> currentElement(do_QueryInterface(current));    if (aDeselected == current) {      hasFocus = PR_TRUE;      break;    }    nsCOMPtr<nsIDOMNode> parent;    current->GetParentNode(getter_AddRefs(parent));    current.swap(parent);  } while(current);    if (hasFocus) {    // Flush layout before moving focus. Otherwise focus controller might    // (re)focus something in the deselected <case>.    doc->FlushPendingNotifications(Flush_Layout);    focusController->MoveFocus(PR_TRUE, mElement);  }}