nsCOMPtr<nsIContent> content;  result = aFrame->GetContent(getter_AddRefs(content));  if (NS_FAILED(result)) return result;
nsIContent* content = aFrame->GetContent();
nsSelection::ConstrainFrameAndPointToAnchorSubtree(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, nsIFrame **aRetFrame, nsPoint& aRetPoint){  //  // The whole point of this method is to return a frame and point that  // that lie within the same valid subtree as the anchor node's frame,  // for use with the method GetContentAndOffsetsFromPoint().  //  // A valid subtree is defined to be one where all the content nodes in  // the tree have a valid parent-child relationship.  //  // If the anchor frame and aFrame are in the same subtree, aFrame will  // be returned in aRetFrame. If they are in different subtrees, we  // return the frame for the root of the subtree.  //  if (!aFrame || !aRetFrame)    return NS_ERROR_NULL_POINTER;  *aRetFrame = aFrame;  aRetPoint  = aPoint;  //  // Get the frame and content for the selection's anchor point!  //  nsresult result;  nsCOMPtr<nsIDOMNode> anchorNode;  PRInt32 anchorOffset = 0;  PRInt32 anchorFrameOffset = 0;  PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);  if (! mDomSelections[index])    return NS_ERROR_NULL_POINTER;  result = mDomSelections[index]->GetAnchorNode(getter_AddRefs(anchorNode));  if (NS_FAILED(result))    return result;  if (!anchorNode)    return NS_OK;  result = mDomSelections[index]->GetAnchorOffset(&anchorOffset);  if (NS_FAILED(result))    return result;  nsIFrame *anchorFrame = 0;  nsCOMPtr<nsIContent> anchorContent = do_QueryInterface(anchorNode);  if (!anchorContent)    return NS_ERROR_FAILURE;    result = GetFrameForNodeOffset(anchorContent, anchorOffset, mHint, &anchorFrame, &anchorFrameOffset);  //  // Now find the root of the subtree containing the anchor's content.  //  nsCOMPtr<nsIContent> anchorRoot;  result = GetRootForContentSubtree(anchorContent, getter_AddRefs(anchorRoot));  if (NS_FAILED(result))    return result;  //  // Now find the root of the subtree containing aFrame's content.  //  nsCOMPtr<nsIContent> content;  result = aFrame->GetContent(getter_AddRefs(content));  if (NS_FAILED(result))    return result;  if (content)  {    nsCOMPtr<nsIContent> contentRoot;    result = GetRootForContentSubtree(content, getter_AddRefs(contentRoot));    if (anchorRoot == contentRoot)    {      //      // The anchor and AFrame's root are the same. There      // is no need to constrain, simply return aFrame.      //      *aRetFrame = aFrame;      return NS_OK;    }  }  //  // aFrame's root does not match the anchor's root, or there is no  // content associated with aFrame. Just return the primary frame  // for the anchor's root. We'll let GetContentAndOffsetsFromPoint()  // find the closest frame aPoint.  //  result = mTracker->GetPrimaryFrameFor(anchorRoot, aRetFrame);  if (NS_FAILED(result))    return result;  if (! *aRetFrame)    return NS_ERROR_FAILURE;  //  // Now make sure that aRetPoint is converted to the same coordinate  // system used by aRetFrame.  //  nsPoint frameOffset;  nsPoint retFrameOffset;  result = GetGlobalViewOffsetsFromFrame(aPresContext, aFrame, &frameOffset.x, &frameOffset.y);  if (NS_FAILED(result))    return result;  result = GetGlobalViewOffsetsFromFrame(aPresContext, *aRetFrame, &retFrameOffset.x, &retFrameOffset.y);  if (NS_FAILED(result))    return result;  aRetPoint = aPoint + frameOffset - retFrameOffset;  return NS_OK;}