selectFrames(aFrame, aOffset, frame,focusFrameOffsetEnd, PR_TRUE, PR_FALSE);
selectFrames(aFrame, aOffset, frame,PR_MAX(focusFrameOffsetEnd,focusFrameOffsetBegin), PR_TRUE, PR_FALSE);
nsRangeList::TakeFocus(nsIFocusTracker *aTracker, nsIFrame *aFrame, PRInt32 aOffset, PRInt32 aContentOffset, PRBool aContinueSelection){  if (!aTracker || !aFrame)    return NS_ERROR_NULL_POINTER;  //HACKHACKHACK  nsIFrame *parent = aFrame;  for (int i=0; i <3; i++){    if (NS_FAILED(parent->GetParent(parent)) || !parent)      return NS_ERROR_NULL_POINTER;  }  //END HACK  nsIFrame *frame;  nsIFrame *anchor;  nsCOMPtr<nsIContent> content;  nsCOMPtr<nsIDOMNode> domNode;  if (NS_SUCCEEDED(aFrame->GetContent(*getter_AddRefs(content)))){    domNode = (nsIContent *)content;    if (domNode && NS_SUCCEEDED(aTracker->GetFocus(&frame, &anchor))){      //traverse through document and unselect crap here      if (!aContinueSelection){        if (anchor && frame && anchor != frame ){//selected across frames, must "deselect" frames between in correct order          PRInt32 compareResult = compareFrames(anchor,frame);          if ( compareResult < 0 )            selectFrames(anchor,0,frame, -1, PR_FALSE, PR_TRUE); //unselect all between          else if (compareResult > 0 )            selectFrames(frame,0,anchor, -1, PR_FALSE, PR_FALSE); //unselect all between//          else real bad put in assert here        }        else if (frame && frame != aFrame){          frame->SetSelected(PR_FALSE, 0, -1, PR_TRUE);//just turn off selection if the previous frame        }//DEBUG CRAP#if 0        nsCOMPtr<nsIContent>oldContent;        if (frame && NS_SUCCEEDED(frame->GetContent(*getter_AddRefs(oldContent)))){          nsCOMPtr<nsIDOMNode>oldDomNode(oldContent);          if (oldDomNode  && oldDomNode == mFocusNode) {            PRInt32 result1 = ComparePoints(domNode, aOffset + aContentOffset, mFocusNode, mFocusOffset);            printf("result1 = %i\n",result1);          }        }#endif                        aFrame->SetSelected(PR_TRUE,aOffset,aOffset,PR_FALSE);        aTracker->SetFocus(aFrame,aFrame);        nsCOMPtr<nsIDOMRange> range;        if (NS_SUCCEEDED(nsRepository::CreateInstance(kRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange          if (domNode) {//get the node interface for the range object            mFocusNode = domNode;            mFocusOffset = aOffset + aContentOffset;            mAnchorNode = domNode;            mAnchorOffset = aOffset + aContentOffset;            range->SetStart(domNode,aOffset + aContentOffset);            range->SetEnd(domNode,aOffset + aContentOffset);            nsCOMPtr<nsISupports> rangeISupports (range);            if (rangeISupports) {              AddItem(rangeISupports);            }          }        }      }      else {        if (aFrame == frame){ //drag to same frame          PRInt32 beginoffset;          PRInt32 begincontentoffset;          PRInt32 endoffset;          PRBool selected;          if (NS_SUCCEEDED(aFrame->GetSelected(&selected,&beginoffset,&endoffset, &begincontentoffset))){            aFrame->SetSelected(PR_TRUE, beginoffset, aOffset,PR_FALSE);            aTracker->SetFocus(aFrame,anchor);          }            nsCOMPtr<nsIDOMRange> range;          if (NS_SUCCEEDED(nsRepository::CreateInstance(kRangeCID, nsnull, kIDOMRangeIID, getter_AddRefs(range)))){ //create an irange            if (domNode){              mFocusNode = domNode;              mFocusOffset = aOffset + aContentOffset;              range->SetStart(mAnchorNode,mAnchorOffset);              range->SetEnd(domNode,aOffset + aContentOffset);              nsCOMPtr<nsISupports> rangeISupports(range);              if (rangeISupports) {                AddItem(rangeISupports);                return NS_OK;              }            }          }        }        else if (frame){ //we need to check to see what the order is.          nsCOMPtr<nsIContent>oldContent;          if (NS_SUCCEEDED(frame->GetContent(*getter_AddRefs(oldContent)))){            nsCOMPtr<nsIDOMNode>oldDomNode(oldContent);            if (oldDomNode && oldDomNode == mFocusNode) {              nsCOMPtr<nsIContent>anchorContent;              if (NS_SUCCEEDED(anchor->GetContent(*getter_AddRefs(anchorContent)))){                nsCOMPtr<nsIDOMNode>anchorDomNode(anchorContent);                if (anchorDomNode && anchorDomNode == mAnchorNode) {                  //get offsets                  PRBool selected = PR_FALSE;                  PRInt32 anchorFrameOffsetBegin = 0;                  PRInt32 anchorFrameOffsetEnd = 0;                  PRInt32 anchorFrameContentOffset = 0;                  if (NS_FAILED(anchor->GetSelected(&selected, &anchorFrameOffsetBegin, &anchorFrameOffsetEnd, &anchorFrameContentOffset)) || !selected)                    return NS_ERROR_FAILURE;                  selected = PR_FALSE;                  PRInt32 focusFrameOffsetBegin = 0;                  PRInt32 focusFrameOffsetEnd = 0;                  PRInt32 focusFrameContentOffset = 0;                  if (NS_FAILED(frame->GetSelected(&selected, &focusFrameOffsetBegin, &focusFrameOffsetEnd, &focusFrameContentOffset)) || !selected)                    return NS_ERROR_FAILURE;                  //compare anchor to old cursor.                  PRInt32 result1 = compareFrames(anchor,frame); //nothing else matters. if they are the same frame.                  //compare old cursor to new cursor                  PRInt32 result2 = compareFrames(frame,aFrame);                  if (result2 == 0)                    result2 = ComparePoints(mFocusNode, mFocusOffset, domNode, aOffset + aContentOffset);                  //compare anchor to new cursor                  PRInt32 result3 = compareFrames(anchor,aFrame);                  if (result3 == 0)                    result3 = ComparePoints(mAnchorNode, mAnchorOffset ,domNode , aOffset + aContentOffset);                  if (result1 == 0 && result3 < 0)                  {                    selectFrames(anchor,anchorFrameOffsetBegin, aFrame, aOffset + aContentOffset, PR_TRUE, PR_TRUE); //last true is forwards                  }                  else if (result1 == 0 && result3 > 0)                  {                    selectFrames(aFrame, aOffset , anchor,anchorFrameOffsetBegin, PR_TRUE, PR_FALSE);//last true is backwards                  }                  else if (result1 <= 0 && result2 <= 0) {//a,1,2 or a1,2 or a,12 or a12                    //continue selection from 1 to 2                    selectFrames(frame,PR_MIN(focusFrameOffsetEnd,focusFrameOffsetBegin), aFrame, aOffset, PR_TRUE, PR_TRUE);                  }                  else if (result3 <= 0 && result2 >= 0) {//a,2,1 or a2,1 or a,21 or a21                    //deselect from 2 to 1                    selectFrames(aFrame, aOffset, frame,focusFrameOffsetEnd, PR_FALSE, PR_TRUE);                    if (anchor != aFrame)                      selectFrames(aFrame, 0, aFrame,aOffset, PR_TRUE, PR_TRUE);                    else                      selectFrames(anchor, anchorFrameOffsetBegin, aFrame, aOffset, PR_TRUE ,PR_TRUE);                  }                  else if (result1 >= 0 && result3 <= 0) {//1,a,2 or 1a,2 or 1,a2 or 1a2                    //deselect from 1 to a                    selectFrames(frame, focusFrameOffsetEnd, anchor, anchorFrameOffsetBegin, PR_FALSE, PR_FALSE);                    //select from a to 2                    selectFrames(anchor, anchorFrameOffsetBegin, aFrame, aOffset, PR_TRUE, PR_TRUE);                  }                  else if (result2 <= 0 && result3 >= 0) {//1,2,a or 12,a or 1,2a or 12a                    //deselect from 1 to 2                    selectFrames(frame, focusFrameOffsetEnd, aFrame, aOffset, PR_FALSE, PR_FALSE);                    if (anchor != aFrame)                      selectFrames(aFrame, aOffset, aFrame, -1, PR_TRUE, PR_FALSE);                    else                      selectFrames(aFrame, aOffset, anchor, anchorFrameOffsetBegin, PR_TRUE ,PR_FALSE);                  }                  else if (result3 >= 0 && result1 <= 0) {//2,a,1 or 2a,1 or 2,a1 or 2a1                    //deselect from a to 1                    selectFrames(anchor, anchorFrameOffsetBegin, frame, focusFrameOffsetEnd, PR_FALSE, PR_TRUE);                    //select from 2 to a                    selectFrames(aFrame, aOffset, anchor, anchorFrameOffsetBegin, PR_TRUE, PR_FALSE);                  }                  else if (result2 <= 0 && result1 >= 0) {//2,1,a or 21,a or 2,1a or 21a                    //continue selection from 2 to 1                    selectFrames(aFrame, aOffset, frame,focusFrameOffsetEnd, PR_TRUE, PR_FALSE);                  }                }                mFocusNode = domNode;                mFocusOffset = aOffset + aContentOffset;                aTracker->SetFocus(aFrame,anchor);              }            }          }        }/*#1 figure out the orderwe can tell the direction of the selection by asking for the anchors selectionif the begin is less than the end then we know the selection is to the "right".else it is a backwards selection.a = anchor1 = old cursor2 = new cursor  if (a <= 1 && 1 <=2)    a,1,2  or (a1,2)  if (a < 2 && 1 > 2)     a,2,1  if (1 < a && a <2)      1,a,2  if (a > 2 && 2 >1)      1,2,a  if (2 < a && a <1)      2,a,1  if (a > 1 && 1 >2)      2,1,athen executea  1  2 select from 1 to 2a  2  1 deselect from 2 to 11  a  2 deselect from 1 to a select from a to 21  2  a deselect from 1 to 22  1  a = continue selection from 2 to 1      */      }    }  }  return NS_OK;}