frameState &= ~NS_FRAME_SELECTED_CONTENT;
{ SelectionDetails *details = nsnull; nsCOMPtr<nsIPresShell> shell; nsCOMPtr<nsIFrameSelection> frameSelection;  nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell){ rv = shell->GetFrameSelection(getter_AddRefs(frameSelection)); if (NS_SUCCEEDED(rv) && frameSelection){ nsCOMPtr<nsIContent> content; rv = GetContent(getter_AddRefs(content)); if (NS_SUCCEEDED(rv) && content){ rv = frameSelection->LookUpSelection(content, mContentOffset, mContentLength , &details, PR_TRUE);   } } } if (!details) frameState &= ~NS_FRAME_SELECTED_CONTENT; }
nsTextFrame::SetSelected(nsIPresContext* aPresContext,                         nsIDOMRange *aRange,                         PRBool aSelected,                         nsSpread aSpread){  nsresult result;  if (aSelected && ParentDisablesSelection())    return NS_OK;  nsFrameState  frameState;  GetFrameState(&frameState);  PRBool isSelected = ((frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT);  if (!aSelected && !isSelected) //already set thanks  {    return NS_OK;  }  PRBool found = PR_FALSE;  PRBool wholeContentFound = PR_FALSE;//if the entire content we look at is selected.  if (aRange) {    //lets see if the range contains us, if so we must redraw!    nsCOMPtr<nsIDOMNode> endNode;    PRInt32 endOffset;    nsCOMPtr<nsIDOMNode> startNode;    PRInt32 startOffset;    aRange->GetEndParent(getter_AddRefs(endNode));    aRange->GetEndOffset(&endOffset);    aRange->GetStartParent(getter_AddRefs(startNode));    aRange->GetStartOffset(&startOffset);    nsCOMPtr<nsIContent> content;    result = GetContent(getter_AddRefs(content));    nsCOMPtr<nsIDOMNode> thisNode;    thisNode = do_QueryInterface(content);    if (thisNode == startNode)    {      if ((mContentOffset + mContentLength) >= startOffset)      {        found = PR_TRUE;        if (thisNode == endNode)        { //special case          if (endOffset == startOffset) //no need to redraw since drawing takes place with cursor            found = PR_FALSE;          if (mContentOffset > endOffset)            found = PR_FALSE;        }      }    }    else if (thisNode == endNode)    {      if (mContentOffset < endOffset)        found = PR_TRUE;      else      {        found = PR_FALSE;        wholeContentFound = PR_TRUE;      }    }    else    {      found = PR_TRUE;    }  }  else {    if ( aSelected != (PRBool)(frameState | NS_FRAME_SELECTED_CONTENT) ){      found = PR_TRUE;    }  }  if ( aSelected )    frameState |=  NS_FRAME_SELECTED_CONTENT;  else    frameState &= ~NS_FRAME_SELECTED_CONTENT;  SetFrameState(frameState);  if (found){ //if range contains this frame...    nsRect frameRect;    GetRect(frameRect);    nsRect rect(0, 0, frameRect.width, frameRect.height);    Invalidate(aPresContext, rect, PR_FALSE);//    ForceDrawFrame(this);  }  if (aSpread == eSpreadDown)  {    nsIFrame *frame;    GetPrevInFlow(&frame);    while(frame){      frame->SetSelected(aPresContext, aRange,aSelected,eSpreadNone);      result = frame->GetPrevInFlow(&frame);      if (NS_FAILED(result))        break;    }    GetNextInFlow(&frame);    while (frame){      frame->SetSelected(aPresContext, aRange,aSelected,eSpreadNone);      result = frame->GetNextInFlow(&frame);      if (NS_FAILED(result))        break;    }#if 0    else //we need to talk to siblings as well as flow    {      result = GetNextSibling(&frame);      while (NS_SUCCEEDED(result) && frame){        frame->SetSelected(aRange,aSelected,eSpreadDown);        result = frame->GetNextSibling(&frame);        if (NS_FAILED(result))          break;      }    }#endif  }  return NS_OK;}