if (aSpread == eSpreadDown) { nsIFrame *frame = GetPrevInFlow(); while(frame){ frame->SetSelected(aRange,aSelected,eSpreadNone); result = frame->GetPrevInFlow(&frame); if (NS_FAILED(result)) break; } frame = GetNextInFlow(); while (frame){ frame->SetSelected(aRange,aSelected,eSpreadNone); result = frame->GetNextInFlow(&frame); if (NS_FAILED(result)) break; } }
nsTextFrame::SetSelected(nsIDOMRange *aRange,PRBool aSelected, nsSpread aSpread){  nsresult result;  if (aSelected && ParentDisablesSelection())    return NS_OK;  if (aSpread == eSpreadDown)  {    nsIFrame *frame = GetPrevInFlow();    while(frame){      frame->SetSelected(aRange,aSelected,eSpreadNone);      result = frame->GetPrevInFlow(&frame);      if (NS_FAILED(result))        break;    }    frame = GetNextInFlow();    while (frame){      frame->SetSelected(aRange,aSelected,eSpreadNone);      result = frame->GetNextInFlow(&frame);      if (NS_FAILED(result))        break;    }  }  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;  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;    }    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(rect, PR_FALSE);//    ForceDrawFrame(this);  }  return NS_OK;}