nsCOMPtr<nsIDOMNode> targetNode; uiEvent->GetTarget( getter_AddRefs( targetNode ) );   nsCOMPtr<nsIDocument> document; nsCOMPtr<nsIContent> content = do_QueryInterface(mElement); nsresult rv; if (NS_FAILED(rv = content->GetDocument(*getter_AddRefs(document)))) { NS_ERROR("Unable to retrieve the document."); return rv; }   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; }   xulDocument->SetPopupNode( targetNode );
XULPopupListenerImpl::MouseDown(nsIDOMEvent* aMouseEvent){  PRUint16 button;  nsCOMPtr<nsIDOMUIEvent>uiEvent;  uiEvent = do_QueryInterface(aMouseEvent);  if (!uiEvent) {    //non-ui event passed in.  bad things.    return NS_OK;  }  switch (popupType) {    case eXULPopupType_popup:      // Check for left mouse button down      uiEvent->GetButton(&button);      if (button == 1) {        // Time to launch a popup menu.        LaunchPopup(aMouseEvent);      }      break;    case eXULPopupType_context:#ifdef	XP_MAC      // XXX: Handle Mac (currently checks if CTRL key is down)	    PRBool	ctrlKey = PR_FALSE;	    uiEvent->GetCtrlKey(&ctrlKey);	    if (ctrlKey == PR_TRUE)#else      // Check for right mouse button down      uiEvent->GetButton(&button);      if (button == 3)#endif      {        // Time to launch a context menu.        LaunchPopup(aMouseEvent);      }      break;        case eXULPopupType_tooltip:    case eXULPopupType_blur:      // ignore      break;  }  return NS_OK;}