nsCOMPtr<nsIDOMUIEvent> uiEvent ( do_QueryInterface(anEvent) ); if (!uiEvent) {  return NS_OK;
XULPopupListenerImpl::LaunchPopup( nsIDOMElement* aElement, PRInt32 aScreenX, PRInt32 aScreenY,                                       PRInt32 aOffsetX, PRInt32 aOffsetY ){#ifdef NS_DEBUGprintf("screen coords %ld %ld\n", aScreenX, aScreenY);printf("client coords %ld %ld\n", aOffsetX, aOffsetY);#endif  nsresult rv = NS_OK;  nsAutoString type("popup");  if ( popupType == eXULPopupType_context )    type = "context";  else if ( popupType == eXULPopupType_tooltip )    type = "tooltip";  nsAutoString identifier;  mElement->GetAttribute(type, identifier);  if (identifier == "")    return rv;  // Try to find the popup content and the document. We don't use FindDocumentForNode()  // in this case because we need the nsIDocument interface anyway for the script   // context.   nsCOMPtr<nsIDocument> document;  nsCOMPtr<nsIContent> content = do_QueryInterface(mElement);  if (NS_FAILED(rv = content->GetDocument(*getter_AddRefs(document)))) {    NS_ERROR("Unable to retrieve the document.");    return rv;  }  // Turn the document into a XUL document so we can use getElementById  nsCOMPtr<nsIDOMXULDocument> xulDocument = do_QueryInterface(document);  if (xulDocument == nsnull) {    NS_ERROR("Popup attached to an element that isn't in XUL!");    return NS_ERROR_FAILURE;  }  // XXX Handle the _child case for popups and context menus!  // Use getElementById to obtain the popup content and gracefully fail if   // we didn't find any popup content in the document.   nsCOMPtr<nsIDOMElement> popupContent;  if (NS_FAILED(rv = xulDocument->GetElementById(identifier, getter_AddRefs(popupContent)))) {    NS_ERROR("GetElementById had some kind of spasm.");    return rv;  }  if ( !popupContent )    return NS_OK;  // We have some popup content. Obtain our window.  nsIScriptContextOwner* owner = document->GetScriptContextOwner();  nsCOMPtr<nsIScriptContext> context;  if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) {    nsIScriptGlobalObject* global = context->GetGlobalObject();    if (global) {      // Get the DOM window      nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(global);      if (domWindow != nsnull) {        // Find out if we're anchored.        nsAutoString anchorAlignment("none");        mElement->GetAttribute("popupanchor", anchorAlignment);        nsAutoString popupAlignment("topleft");        mElement->GetAttribute("popupalign", popupAlignment);        // Set the popup in the document for the duration of this call.        xulDocument->SetPopupElement(mElement);                // If we're anchored, we pass in client/screen offsets so that        // we can translate the frames corners to screen coords.         PRInt32 xPos = aScreenX, yPos = aScreenY;        if (anchorAlignment != "none") {          xPos -= aOffsetX;          yPos -= aOffsetY;        }printf("***creating XUL popup at %ld %ld\n", xPos, yPos);        domWindow->CreatePopup(mElement, popupContent,                                xPos, yPos,                                type, anchorAlignment, popupAlignment,                               getter_AddRefs(mPopup));        if ( popupType == eXULPopupType_popup && mPopup )          mPopup->Focus();              // XXX For menus only, clear the document.popup field.      }      NS_RELEASE(global);    }  }  NS_IF_RELEASE(owner);  return NS_OK;}