NS_IMETHODIMP nsPopupBoxObject::ShowPopup(nsIDOMElement* aAnchorElement, nsIDOMElement* aPopupElement, int32_t aXPos, int32_t aYPos, const PRUnichar *aPopupType, const PRUnichar *aAnchorAlignment, const PRUnichar *aPopupAlignment) { NS_ENSURE_TRUE(aPopupElement, NS_ERROR_INVALID_ARG); // srcContent can be null. nsXULPopupManager* pm = nsXULPopupManager::GetInstance(); if (pm && mContent) { nsCOMPtr<nsIContent> anchorContent(do_QueryInterface(aAnchorElement)); nsAutoString popupType(aPopupType); nsAutoString anchor(aAnchorAlignment); nsAutoString align(aPopupAlignment); pm->ShowPopupWithAnchorAlign(mContent, anchorContent, anchor, align, aXPos, aYPos, popupType.EqualsLiteral("context")); } return NS_OK; }
NS_IMETHODIMP nsPopupBoxObject::ShowPopup(nsIDOMElement* aSrcContent, nsIDOMElement* aPopupContent, PRInt32 aXPos, PRInt32 aYPos, const PRUnichar *aPopupType, const PRUnichar *anAnchorAlignment, const PRUnichar *aPopupAlignment) { nsCOMPtr<nsIPresShell> shell = GetPresShell(); if (!shell) { return NS_OK; } nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame(); if (!rootFrame) return NS_OK; if (rootFrame) { rootFrame = rootFrame->GetFirstChild(nsnull); } nsIRootBox* rootBox = nsnull; CallQueryInterface(rootFrame, &rootBox); if (!rootBox) return NS_OK; nsIFrame* popupSetFrame; rootBox->GetPopupSetFrame(&popupSetFrame); if (!popupSetFrame) return NS_OK; nsIPopupSetFrame* popupSet = nsnull; CallQueryInterface(popupSetFrame, &popupSet); if (!popupSet) return NS_OK; nsCOMPtr<nsIContent> srcContent(do_QueryInterface(aSrcContent)); nsCOMPtr<nsIContent> popupContent(do_QueryInterface(aPopupContent)); nsAutoString popupType(aPopupType); nsAutoString anchorAlign(anAnchorAlignment); nsAutoString popupAlign(aPopupAlignment); // Use |left| and |top| dimension attributes to position the popup if // present, as they may have been persisted. nsAutoString left, top; popupContent->GetAttr(kNameSpaceID_None, nsXULAtoms::left, left); popupContent->GetAttr(kNameSpaceID_None, nsXULAtoms::top, top); PRInt32 err; if (!left.IsEmpty()) { aXPos = left.ToInteger(&err); if (NS_FAILED(err)) return err; } if (!top.IsEmpty()) { aYPos = top.ToInteger(&err); if (NS_FAILED(err)) return err; } return popupSet->ShowPopup(srcContent, popupContent, aXPos, aYPos, popupType, anchorAlign, popupAlign); }