nsTypedSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength, SelectionDetails **aReturnDetails, SelectionType aType, PRBool aSlowCheck)
nsSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength, SelectionDetails **aReturnDetails, PRBool aSlowCheck)
nsTypedSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength,                           SelectionDetails **aReturnDetails, SelectionType aType, PRBool aSlowCheck){  PRInt32 cnt;  nsresult rv = GetRangeCount(&cnt);  if (NS_FAILED(rv))     return rv;  PRInt32 i;  nsCOMPtr<nsIDOMNode> passedInNode;  passedInNode = do_QueryInterface(aContent);  if (!passedInNode)    return NS_ERROR_FAILURE;  SelectionDetails *details = nsnull;  SelectionDetails *newDetails = details;  for (i =0; i<cnt; i++){    nsCOMPtr<nsIDOMRange> range = mRangeArray[i];    if (range){      nsCOMPtr<nsIDOMNode> startNode;      nsCOMPtr<nsIDOMNode> endNode;      PRInt32 startOffset;      PRInt32 endOffset;      range->GetStartContainer(getter_AddRefs(startNode));      range->GetStartOffset(&startOffset);      range->GetEndContainer(getter_AddRefs(endNode));      range->GetEndOffset(&endOffset);      if (passedInNode == startNode && passedInNode == endNode){        if (startOffset < (aContentOffset + aContentLength)  &&            endOffset > aContentOffset){          if (!details){            details = new SelectionDetails;            newDetails = details;          }          else{            newDetails->mNext = new SelectionDetails;            newDetails = newDetails->mNext;          }          if (!newDetails)            return NS_ERROR_OUT_OF_MEMORY;          newDetails->mNext = nsnull;          newDetails->mStart = PR_MAX(0,startOffset - aContentOffset);          newDetails->mEnd = PR_MIN(aContentLength, endOffset - aContentOffset);          newDetails->mType = aType;        }      }      else if (passedInNode == startNode){ //are we at the beginning?        if (startOffset < (aContentOffset + aContentLength)){          if (!details){            details = new SelectionDetails;            newDetails = details;          }          else{            newDetails->mNext = new SelectionDetails;            newDetails = newDetails->mNext;          }          if (!newDetails)            return NS_ERROR_OUT_OF_MEMORY;          newDetails->mNext = nsnull;          newDetails->mStart = PR_MAX(0,startOffset - aContentOffset);          newDetails->mEnd = aContentLength;          newDetails->mType = aType;        }      }      else if (passedInNode == endNode){//are we at the end?        if (endOffset > aContentOffset){          if (!details){            details = new SelectionDetails;            newDetails = details;          }          else{            newDetails->mNext = new SelectionDetails;            newDetails = newDetails->mNext;          }          if (!newDetails)            return NS_ERROR_OUT_OF_MEMORY;          newDetails->mNext = nsnull;          newDetails->mStart = 0;          newDetails->mEnd = PR_MIN(aContentLength, endOffset - aContentOffset);          newDetails->mType = aType;        }      }      else { //then we MUST be completely selected! unless someone needs us to check to make sure with slowcheck        if (cnt > 1 || aSlowCheck){ //if more than 1 selection or we need to do                                    //slow check see if farther than start or                                    //less than end.          //we only have to look at start offset because anything else would          //have been in the range          PRInt32 resultnum = nsRange::ComparePoints(startNode,                                                     startOffset,                                                     passedInNode,                                                     aContentOffset);          if (resultnum > 0)            continue;           resultnum = nsRange::ComparePoints(endNode, endOffset,                                             passedInNode, aContentOffset);          if (resultnum <0)            continue;        }        if (!details){          details = new SelectionDetails;          newDetails = details;        }        else{          newDetails->mNext = new SelectionDetails;          newDetails = newDetails->mNext;        }        if (!newDetails)          return NS_ERROR_OUT_OF_MEMORY;        newDetails->mNext = nsnull;        newDetails->mStart = 0;        newDetails->mEnd = aContentLength;        newDetails->mType = aType;     }    }    else      continue;  }  if (*aReturnDetails && newDetails)    newDetails->mNext = *aReturnDetails;  if (details)    *aReturnDetails = details;  return NS_OK;}